Java Code Examples for com.intellij.openapi.editor.markup.TextAttributes#getFontType()

The following examples show how to use com.intellij.openapi.editor.markup.TextAttributes#getFontType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLTextPainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void writeStyles(@NonNls final Writer writer) throws IOException {
  writer.write("<style type=\"text/css\">\n");
  writer.write(".ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }\n");
  HighlighterIterator hIterator = myHighlighter.createIterator(myOffset);
  while(!hIterator.atEnd()) {
    TextAttributes textAttributes = hIterator.getTextAttributes();
    if (!myStyleMap.containsKey(textAttributes)) {
      @NonNls String styleName = "s" + myStyleMap.size();
      myStyleMap.put(textAttributes, styleName);
      writer.write("." + styleName + " { ");
      final Color foreColor = textAttributes.getForegroundColor();
      if (foreColor != null) {
        writer.write("color: rgb(" + foreColor.getRed() + "," + foreColor.getGreen() + "," + foreColor.getBlue() + "); ");
      }
      if ((textAttributes.getFontType() & Font.BOLD) != 0) {
        writer.write("font-weight: bold; ");
      }
      if ((textAttributes.getFontType() & Font.ITALIC) != 0) {
        writer.write("font-style: italic; ");
      }
      writer.write("}\n");
    }
    hIterator.advance();
  }
  writer.write("</style>\n");
}
 
Example 2
Source File: HTMLTextPainter.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean equals(TextAttributes attributes1, TextAttributes attributes2) {
  if (attributes2 == null) {
    return attributes1 == null;
  }
  if(attributes1 == null) {
    return false;
  }
  if(!Comparing.equal(attributes1.getForegroundColor(), attributes2.getForegroundColor())) {
    return false;
  }
  if(attributes1.getFontType() != attributes2.getFontType()) {
    return false;
  }
  if(!Comparing.equal(attributes1.getBackgroundColor(), attributes2.getBackgroundColor())) {
    return false;
  }
  if(!Comparing.equal(attributes1.getEffectColor(), attributes2.getEffectColor())) {
    return false;
  }
  return true;
}
 
Example 3
Source File: TodoItemNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static void collectHighlights(@Nonnull List<? super HighlightedRegion> highlights, @Nonnull EditorHighlighter highlighter, int startOffset, int endOffset, int highlightOffsetShift) {
  HighlighterIterator iterator = highlighter.createIterator(startOffset);
  while (!iterator.atEnd()) {
    int start = Math.max(iterator.getStart(), startOffset);
    int end = Math.min(iterator.getEnd(), endOffset);
    if (start >= endOffset) break;

    TextAttributes attributes = iterator.getTextAttributes();
    int fontType = attributes.getFontType();
    if ((fontType & Font.BOLD) != 0) { // suppress bold attribute
      attributes = attributes.clone();
      attributes.setFontType(fontType & ~Font.BOLD);
    }
    HighlightedRegion region = new HighlightedRegion(highlightOffsetShift + start - startOffset, highlightOffsetShift + end - startOffset, attributes);
    highlights.add(region);
    iterator.advance();
  }
}
 
Example 4
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void computeTextAttributesByLogLevelCache() {
  final EditorColorsScheme globalEditorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
  textAttributesByLogLevelCache.clear();
  for (Level level : FlutterLog.Level.values()) {
    try {
      final TextAttributesKey key = LOG_LEVEL_TEXT_ATTRIBUTES_KEY_MAP.get(level);
      final TextAttributes attributes = globalEditorColorsScheme.getAttributes(key);
      int fontType = attributes.getFontType();
      final Color effectColor = attributes.getEffectColor();
      final Integer textStyle = EFFECT_TYPE_TEXT_STYLE_MAP.get(attributes.getEffectType());
      // TextStyle can exist even when unchecked in settings page.
      // only effectColor is null when setting effect is unchecked in setting page.
      // So, we have to check that both effectColor & textStyle are not null.
      if (effectColor != null && textStyle != null) {
        fontType = fontType | textStyle;
      }

      final SimpleTextAttributes textAttributes = new SimpleTextAttributes(
        attributes.getBackgroundColor(),
        attributes.getForegroundColor(),
        effectColor,
        fontType
      );

      textAttributesByLogLevelCache.put(level, textAttributes);
    }
    catch (Exception e) {
      // Should never go here.
      FlutterUtils.warn(LOG, "Error when get text attributes by log level", e);
    }
  }
}
 
Example 5
Source File: FlutterLogView.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void computeTextAttributesByLogLevelCache() {
  final EditorColorsScheme globalEditorColorsScheme = EditorColorsManager.getInstance().getGlobalScheme();
  textAttributesByLogLevelCache.clear();
  for (Level level : FlutterLog.Level.values()) {
    try {
      final TextAttributesKey key = LOG_LEVEL_TEXT_ATTRIBUTES_KEY_MAP.get(level);
      final TextAttributes attributes = globalEditorColorsScheme.getAttributes(key);
      int fontType = attributes.getFontType();
      final Color effectColor = attributes.getEffectColor();
      final Integer textStyle = EFFECT_TYPE_TEXT_STYLE_MAP.get(attributes.getEffectType());
      // TextStyle can exist even when unchecked in settings page.
      // only effectColor is null when setting effect is unchecked in setting page.
      // So, we have to check that both effectColor & textStyle are not null.
      if (effectColor != null && textStyle != null) {
        fontType = fontType | textStyle;
      }

      final SimpleTextAttributes textAttributes = new SimpleTextAttributes(
        attributes.getBackgroundColor(),
        attributes.getForegroundColor(),
        effectColor,
        fontType
      );

      textAttributesByLogLevelCache.put(level, textAttributes);
    }
    catch (Exception e) {
      // Should never go here.
      FlutterUtils.warn(LOG, "Error when get text attributes by log level", e);
    }
  }
}
 
Example 6
Source File: SimpleTextAttributes.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static SimpleTextAttributes fromTextAttributes(TextAttributes attributes) {
  if (attributes == null) return REGULAR_ATTRIBUTES;

  Color foregroundColor = attributes.getForegroundColor();
  if (foregroundColor == null) foregroundColor = REGULAR_ATTRIBUTES.getFgColor();

  int style = attributes.getFontType();
  if (attributes.getEffectColor() != null) {
    EffectType effectType = attributes.getEffectType();
    if (effectType == EffectType.STRIKEOUT) {
      style |= STYLE_STRIKEOUT;
    }
    else if (effectType == EffectType.WAVE_UNDERSCORE) {
      style |= STYLE_WAVED;
    }
    else if (effectType == EffectType.LINE_UNDERSCORE ||
             effectType == EffectType.BOLD_LINE_UNDERSCORE ||
             effectType == EffectType.BOLD_DOTTED_LINE) {
      style |= STYLE_UNDERLINE;
    }
    else if (effectType == EffectType.SEARCH_MATCH) {
      style |= STYLE_SEARCH_MATCH;
    }
    else {
      // not supported
    }
  }
  return new SimpleTextAttributes(attributes.getBackgroundColor(), foregroundColor, attributes.getEffectColor(), style);
}
 
Example 7
Source File: LineExtensionInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
public LineExtensionInfo(@Nonnull String text, @Nonnull TextAttributes attr) {
  myText = text;
  myColor = attr.getForegroundColor();
  myEffectType = attr.getEffectType();
  myEffectColor = attr.getEffectColor();
  myFontType = attr.getFontType();
  myBgColor = attr.getBackgroundColor();
}
 
Example 8
Source File: XDebuggerInlayUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static FontInfo getFontInfo(@Nonnull Editor editor) {
  EditorColorsScheme colorsScheme = editor.getColorsScheme();
  FontPreferences fontPreferences = colorsScheme.getFontPreferences();
  TextAttributes attributes = editor.getColorsScheme().getAttributes(DebuggerColors.INLINED_VALUES_EXECUTION_LINE);
  int fontStyle = attributes == null ? Font.PLAIN : attributes.getFontType();
  return ComplementaryFontsRegistry.getFontAbleToDisplay('a', fontStyle, fontPreferences, FontInfo.getFontRenderContext(editor.getContentComponent()));
}
 
Example 9
Source File: SyntaxInfoBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void advance() {
  if (mySegmentIterator.atEnd()) {
    myRangeIterator.advance();
    TextAttributes textAttributes = myRangeIterator.getTextAttributes();
    myCurrentFontStyle = textAttributes == null ? Font.PLAIN : textAttributes.getFontType();
    myCurrentForegroundColor = textAttributes == null ? null : textAttributes.getForegroundColor();
    myCurrentBackgroundColor = textAttributes == null ? null : textAttributes.getBackgroundColor();
    mySegmentIterator.reset(myRangeIterator.getRangeStart(), myRangeIterator.getRangeEnd(), myCurrentFontStyle);
  }
  mySegmentIterator.advance();
}
 
Example 10
Source File: SyntaxInfoBuilder.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void findNextSuitableRange() {
  myNextAttributes = null;
  while (myIterator.hasNext()) {
    RangeHighlighterEx highlighter = myIterator.next();
    if (highlighter == null || !highlighter.isValid() || !isInterestedInLayer(highlighter.getLayer())) {
      continue;
    }
    // LINES_IN_RANGE highlighters are not supported currently
    myNextStart = Math.max(highlighter.getStartOffset(), myStartOffset);
    myNextEnd = Math.min(highlighter.getEndOffset(), myEndOffset);
    if (myNextStart >= myEndOffset) {
      break;
    }
    if (myNextStart < myCurrentEnd) {
      continue; // overlapping ranges withing document markup model are not supported currently
    }
    TextAttributes attributes = null;
    HighlightInfo info = HighlightInfo.fromRangeHighlighter(highlighter);
    if (info != null) {
      TextAttributesKey key = info.forcedTextAttributesKey;
      if (key == null) {
        HighlightInfoType type = info.type;
        key = type.getAttributesKey();
      }
      if (key != null) {
        attributes = myColorsScheme.getAttributes(key);
      }
    }
    if (attributes == null) {
      continue;
    }
    Color foreground = attributes.getForegroundColor();
    Color background = attributes.getBackgroundColor();
    if ((foreground == null || myDefaultForeground.equals(foreground)) && (background == null || myDefaultBackground.equals(background)) && attributes.getFontType() == Font.PLAIN) {
      continue;
    }
    myNextAttributes = attributes;
    break;
  }
}
 
Example 11
Source File: Breadcrumbs.java    From consulo with Apache License 2.0 4 votes vote down vote up
@FontStyle
protected int getFontStyle(Crumb crumb) {
  TextAttributes attributes = getAttributes(crumb);
  return attributes == null ? Font.PLAIN : attributes.getFontType();
}
 
Example 12
Source File: EditorUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static boolean attributesImpactFontStyleOrColor(@Nullable TextAttributes attributes) {
  return attributes == TextAttributes.ERASE_MARKER || (attributes != null && (attributes.getFontType() != Font.PLAIN || attributes.getForegroundColor() != null));
}
 
Example 13
Source File: SelectionAnnotation.java    From saros with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns the text attributes for caret annotation range highlighters.
 *
 * <p>Caret annotations are mimicking a real caret in the local editor by adding a zero-width
 * range highlighter only consisting of a colored border.
 *
 * <p>The color of the caret range highlighter is determined by the caret color in the local
 * editor.
 *
 * @param editor the editor of the annotation
 * @param user the user of the annotation
 * @return the text attributes for caret annotation range highlighters
 */
private static TextAttributes getCaretTextAttributes(@NotNull Editor editor, @NotNull User user) {
  ColorKeys colorKeys = ColorManager.getColorKeys(user.getColorID());
  TextAttributesKey highlightColorKey = colorKeys.getSelectionColorKey();
  TextAttributes defaultTextAttributes =
      editor.getColorsScheme().getAttributes(highlightColorKey);

  int font = defaultTextAttributes.getFontType();

  Color caretColor = editor.getColorsScheme().getColor(CARET_COLOR);

  return new TextAttributes(null, null, caretColor, EffectType.BOXED, font);
}