Search in sources :

Example 6 with TextAreaPainter

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

the class CompositionTextManager 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.
    AttributedString composed = new AttributedString(text, committedCount, text.getEndIndex());
    Font font = painter.getFontMetrics().getFont();
    composed.addAttribute(TextAttribute.FONT, font);
    // 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();
    Messages.log("debug: FontRenderContext is Antialiased = " + frc.getAntiAliasingHint());
    return new TextLayout(composed.getIterator(), frc);
}
Also used : AttributedString(java.text.AttributedString) TextAreaPainter(processing.app.syntax.TextAreaPainter) FontRenderContext(java.awt.font.FontRenderContext) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D) TextLayout(java.awt.font.TextLayout)

Example 7 with TextAreaPainter

use of processing.app.syntax.TextAreaPainter 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

TextAreaPainter (processing.app.syntax.TextAreaPainter)7 Point (java.awt.Point)5 FontMetrics (java.awt.FontMetrics)3 Font (java.awt.Font)2 Graphics2D (java.awt.Graphics2D)2 Rectangle (java.awt.Rectangle)2 FontRenderContext (java.awt.font.FontRenderContext)2 TextLayout (java.awt.font.TextLayout)2 AttributedString (java.text.AttributedString)2 Color (java.awt.Color)1 TextAreaDefaults (processing.app.syntax.TextAreaDefaults)1