Search in sources :

Example 1 with TextAreaDefaults

use of processing.app.syntax.TextAreaDefaults in project processing by processing.

the class InputMethodSupport method getTextLayout.

private TextLayout getTextLayout(AttributedCharacterIterator text, int committedCount) {
    boolean antialias = Preferences.getBoolean("editor.smooth");
    TextAreaPainter painter = textArea.getPainter();
    // create attributed string with font info.
    if (text.getEndIndex() - (text.getBeginIndex() + committedCount) > 0) {
        composedTextString = new AttributedString(text, committedCount, text.getEndIndex(), CUSTOM_IM_ATTRIBUTES);
        Font font = painter.getFontMetrics().getFont();
        TextAreaDefaults defaults = textArea.getDefaults();
        Color bgColor = defaults.lineHighlight ? defaults.lineHighlightColor : defaults.bgcolor;
        composedTextString.addAttribute(TextAttribute.FONT, font);
        composedTextString.addAttribute(TextAttribute.FOREGROUND, defaults.fgcolor);
        composedTextString.addAttribute(TextAttribute.BACKGROUND, bgColor);
    } else {
        composedTextString = new AttributedString("");
        return null;
    }
    // set hint of antialiasing to render target.
    Graphics2D g2d = (Graphics2D) painter.getGraphics();
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, antialias ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON : RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    FontRenderContext frc = g2d.getFontRenderContext();
    if (Base.DEBUG) {
        Messages.log("debug: FontRenderContext is Antialiased = " + frc.getAntiAliasingHint());
    }
    return new TextLayout(composedTextString.getIterator(), frc);
}
Also used : TextAreaDefaults(processing.app.syntax.TextAreaDefaults) AttributedString(java.text.AttributedString) TextAreaPainter(processing.app.syntax.TextAreaPainter) Color(java.awt.Color) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Aggregations

Color (java.awt.Color)1 Font (java.awt.Font)1 Graphics2D (java.awt.Graphics2D)1 FontRenderContext (java.awt.font.FontRenderContext)1 TextLayout (java.awt.font.TextLayout)1 AttributedString (java.text.AttributedString)1 TextAreaDefaults (processing.app.syntax.TextAreaDefaults)1 TextAreaPainter (processing.app.syntax.TextAreaPainter)1