diff --git a/platform/lang-impl/src/com/intellij/openapi/editor/richcopy/view/HtmlTransferableData.java b/platform/lang-impl/src/com/intellij/openapi/editor/richcopy/view/HtmlTransferableData.java index 714b9f3d0cdb..e9780b732eec 100644 --- a/platform/lang-impl/src/com/intellij/openapi/editor/richcopy/view/HtmlTransferableData.java +++ b/platform/lang-impl/src/com/intellij/openapi/editor/richcopy/view/HtmlTransferableData.java @@ -19,7 +19,6 @@ import com.intellij.openapi.editor.richcopy.model.ColorRegistry; import com.intellij.openapi.editor.richcopy.model.FontNameRegistry; import com.intellij.openapi.editor.richcopy.model.MarkupHandler; import com.intellij.openapi.editor.richcopy.model.SyntaxInfo; -import com.intellij.util.StringBuilderSpinAllocator; import com.intellij.util.ui.UIUtil; import gnu.trove.TIntObjectHashMap; import org.jetbrains.annotations.NotNull; @@ -40,6 +39,9 @@ public class HtmlTransferableData extends AbstractSyntaxAwareReaderTransferableD private FontNameRegistry myFontNameRegistry; private int myMaxLength; + private int myDefaultForeground; + private int myDefaultBackground; + private int myDefaultFontFamily; private int myForeground; private int myBackground; private int myFontFamily; @@ -57,20 +59,25 @@ public class HtmlTransferableData extends AbstractSyntaxAwareReaderTransferableD myResultBuffer = holder; myColorRegistry = mySyntaxInfo.getColorRegistry(); myFontNameRegistry = mySyntaxInfo.getFontNameRegistry(); + myDefaultForeground = myForeground = mySyntaxInfo.getDefaultForeground(); + myDefaultBackground = myBackground = mySyntaxInfo.getDefaultBackground(); myMaxLength = maxLength; try { buildColorMap(); myResultBuffer.append("
0) {
+ myFontFamily = myDefaultFontFamily = fontIds[0];
+ appendFontFamilyRule(myResultBuffer, myDefaultFontFamily);
}
- appendFontSizeRule(myResultBuffer, mySyntaxInfo.getSingleFontSize());
- myResultBuffer.append("\" bgcolor=\"");
- appendColor(myResultBuffer, mySyntaxInfo.getDefaultBackground());
- myResultBuffer.append("\">");
+ else {
+ myFontFamily = myDefaultFontFamily = -1;
+ }
+ myResultBuffer.append("font-size:").append(mySyntaxInfo.getSingleFontSize()).append("pt;\">");
mySyntaxInfo.processOutputInfo(this);
@@ -84,38 +91,30 @@ public class HtmlTransferableData extends AbstractSyntaxAwareReaderTransferableD
}
}
- private void defineForeground(int id, @NotNull StringBuilder styleBuffer, @NotNull StringBuilder closeTagBuffer) {
- myResultBuffer.append("");
+ private void appendFontFamilyRule(@NotNull StringBuilder styleBuffer, int fontFamilyId) {
+ styleBuffer.append("font-family:'").append(myFontNameRegistry.dataById(fontFamilyId)).append("';");
+ }
+
+ private static void defineBold(@NotNull StringBuilder styleBuffer) {
+ styleBuffer.append("font-weight:bold;");
+ }
+
+ private static void defineItalic(@NotNull StringBuilder styleBuffer) {
+ styleBuffer.append("font-style:italic;");
+ }
+
+ private void defineForeground(int id, @NotNull StringBuilder styleBuffer) {
styleBuffer.append("color:");
appendColor(styleBuffer, id);
styleBuffer.append(";");
- closeTagBuffer.insert(0, "");
}
- private void defineBackground(int id, @NotNull StringBuilder styleBuffer, @NotNull StringBuilder closeTagBuffer) {
- myResultBuffer.append("");
+ private void defineBackground(int id, @NotNull StringBuilder styleBuffer) {
styleBuffer.append("background-color:");
appendColor(styleBuffer, id);
styleBuffer.append(";");
- closeTagBuffer.insert(0, "");
}
- private void defineBold(@NotNull StringBuilder styleBuffer, @NotNull StringBuilder closeTagBuffer) {
- myResultBuffer.append("");
- styleBuffer.append("font-weight:bold;");
- closeTagBuffer.insert(0, "");
- }
-
- private void defineItalic(@NotNull StringBuilder styleBuffer, @NotNull StringBuilder closeTagBuffer) {
- myResultBuffer.append("");
- styleBuffer.append("font-style:italic;");
- closeTagBuffer.insert(0, "");
- }
-
private void appendColor(StringBuilder builder, int id) {
builder.append(myColors.get(id));
}
@@ -128,51 +127,33 @@ public class HtmlTransferableData extends AbstractSyntaxAwareReaderTransferableD
}
}
- private void appendFontFamilyRule(@NotNull StringBuilder styleBuffer, int fontFamilyId) {
- styleBuffer.append("font-family:'").append(myFontNameRegistry.dataById(fontFamilyId)).append("';");
- }
-
- private static void appendFontSizeRule(@NotNull StringBuilder styleBuffer, int fontSize) {
- styleBuffer.append("font-size:").append(fontSize).append("pt;");
- }
-
@Override
public void handleText(int startOffset, int endOffset) {
- boolean formattedText = myForeground > 0 || myBackground > 0 || myFontFamily > 0 || myBold || myItalic;
+ boolean formattedText = myForeground != myDefaultForeground || myBackground != myDefaultBackground || myFontFamily != myDefaultFontFamily || myBold || myItalic;
if (!formattedText) {
escapeAndAdd(startOffset, endOffset);
return;
}
- StringBuilder styleBuffer = StringBuilderSpinAllocator.alloc();
- StringBuilder closeTagBuffer = StringBuilderSpinAllocator.alloc();
- try {
- if (myForeground > 0) {
- defineForeground(myForeground, styleBuffer, closeTagBuffer);
- }
- if (myBackground > 0) {
- defineBackground(myBackground, styleBuffer, closeTagBuffer);
- }
- if (myBold) {
- defineBold(styleBuffer, closeTagBuffer);
- }
- if (myItalic) {
- defineItalic(styleBuffer, closeTagBuffer);
- }
- if (myFontFamily > 0) {
- appendFontFamilyRule(styleBuffer, myFontFamily);
- }
- myResultBuffer.append("");
- escapeAndAdd(startOffset, endOffset);
- myResultBuffer.append("");
- myResultBuffer.append(closeTagBuffer);
+ myResultBuffer.append("");
+ escapeAndAdd(startOffset, endOffset);
+ myResultBuffer.append("");
}
private void escapeAndAdd(int start, int end) {
@@ -199,9 +180,7 @@ public class HtmlTransferableData extends AbstractSyntaxAwareReaderTransferableD
@Override
public void handleFont(int fontNameId) throws Exception {
- if (myFontNameRegistry != null) {
- myFontFamily = fontNameId;
- }
+ myFontFamily = fontNameId;
}
@Override