fix rendering of of text when font style for default text is bold (regression since a fix for IDEA-144224)

This commit is contained in:
Dmitry Batrak
2015-11-09 20:23:57 +03:00
parent 3c2363828c
commit 0f8afb29a6
3 changed files with 22 additions and 4 deletions
@@ -17,10 +17,7 @@ package com.intellij.openapi.editor.impl;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.FoldRegion;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.*;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.ex.*;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
@@ -112,6 +109,7 @@ public final class IterationState {
private final TextAttributes myCaretRowAttributes;
private final Color myDefaultBackground;
private final Color myDefaultForeground;
private final int myDefaultFontType;
private final int myCaretRowStart;
private final int myCaretRowEnd;
private final List<TextAttributes> myCachedAttributesList = new ArrayList<TextAttributes>(5);
@@ -173,6 +171,8 @@ public final class IterationState {
myCaretRowAttributes = editor.isRendererMode() ? null : caretModel.getTextAttributes();
myDefaultBackground = editor.getColorsScheme().getDefaultBackground();
myDefaultForeground = editor.getColorsScheme().getDefaultForeground();
TextAttributes defaultAttributes = editor.getColorsScheme().getAttributes(HighlighterColors.TEXT);
myDefaultFontType = defaultAttributes == null ? Font.PLAIN : defaultAttributes.getFontType();
myCaretRowStart = caretModel.getVisualLineStart();
myCaretRowEnd = caretModel.getVisualLineEnd();
@@ -526,6 +526,7 @@ public final class IterationState {
if (fore == null) fore = myDefaultForeground;
if (back == null) back = myDefaultBackground;
if (effectType == null) effectType = EffectType.BOXED;
if (fontType == Font.PLAIN) fontType = myDefaultFontType;
myMergedAttributes.setAttributes(fore, back, effect, null, effectType, fontType);
@@ -119,6 +119,7 @@ public class IterationState {
private final TextAttributes myCaretRowAttributes;
private final Color myDefaultBackground;
private final Color myDefaultForeground;
private final int myDefaultFontType;
private final int myCaretRowStart;
private final int myCaretRowEnd;
private final boolean myCaretRowStartsWithSoftWrap;
@@ -170,6 +171,8 @@ public class IterationState {
myCaretRowAttributes = editor.isRendererMode() ? null : caretModel.getTextAttributes();
myDefaultBackground = editor.getColorsScheme().getDefaultBackground();
myDefaultForeground = editor.getColorsScheme().getDefaultForeground();
TextAttributes defaultAttributes = editor.getColorsScheme().getAttributes(HighlighterColors.TEXT);
myDefaultFontType = defaultAttributes == null ? Font.PLAIN : defaultAttributes.getFontType();
myCaretRowStart = useCaretAndSelection ? caretModel.getVisualLineStart() : -1;
int visualLineEnd = caretModel.getVisualLineEnd();
@@ -570,6 +573,7 @@ public class IterationState {
if (fore == null) fore = myDefaultForeground;
if (back == null) back = myDefaultBackground;
if (effectType == null) effectType = EffectType.BOXED;
if (fontType == Font.PLAIN) fontType = myDefaultFontType;
myMergedAttributes.setAttributes(fore, back, effect, null, effectType, fontType);
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.editor.impl;
import com.intellij.openapi.editor.HighlighterColors;
import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
@@ -154,6 +155,18 @@ public class IterationStateTest extends LightPlatformCodeInsightFixtureTestCase
new Segment(11, 16, DEFAULT_BACKGROUND),
new Segment(16, 21, DEFAULT_BACKGROUND));
}
public void testBoldDefaultFont() {
init("abc");
myFixture.getEditor().getColorsScheme().setAttributes(HighlighterColors.TEXT,
new TextAttributes(Color.black, Color.white, null, null, Font.BOLD));
IterationState it = new IterationState((EditorEx)myFixture.getEditor(), 0, 3, false);
assertFalse(it.atEnd());
assertEquals(0, it.getStartOffset());
assertEquals(3, it.getEndOffset());
TextAttributes attributes = it.getMergedAttributes();
assertEquals(Font.BOLD, attributes.getFontType());
}
private void verifySplitting(boolean checkForegroundColor, @NotNull Segment... expectedSegments) {
EditorEx editor = (EditorEx)myFixture.getEditor();