Search in sources :

Example 41 with TextLayout

use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.

the class PeekGraphics method drawString.

/**
     * Draws the text given by the specified iterator, using this
     * graphics context's current color. The iterator has to specify a font
     * for each character. The baseline of the
     * first character is at position (<i>x</i>,&nbsp;<i>y</i>) in this
     * graphics context's coordinate system.
     * The rendering attributes applied include the clip, transform,
     * paint or color, and composite attributes.
     * For characters in script systems such as Hebrew and Arabic,
     * the glyphs may be draw from right to left, in which case the
     * coordinate supplied is the the location of the leftmost character
     * on the baseline.
     * @param iterator the iterator whose text is to be drawn
     * @param x,y the coordinates where the iterator's text should be drawn.
     * @see #setPaint
     * @see java.awt.Graphics#setColor
     * @see #setTransform
     * @see #setComposite
     * @see #setClip
     */
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
    if (iterator == null) {
        throw new NullPointerException("AttributedCharacterIterator is null");
    }
    TextLayout layout = new TextLayout(iterator, getFontRenderContext());
    layout.draw(this, x, y);
}
Also used : TextLayout(java.awt.font.TextLayout)

Example 42 with TextLayout

use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.

the class CompositionArea method getLocationOffset.

TextHitInfo getLocationOffset(int x, int y) {
    TextLayout layout = composedTextLayout;
    if (layout == null) {
        return null;
    } else {
        Point location = getLocationOnScreen();
        x -= location.x + TEXT_ORIGIN_X;
        y -= location.y + TEXT_ORIGIN_Y;
        if (layout.getBounds().contains(x, y)) {
            return layout.hitTestChar(x, y);
        } else {
            return null;
        }
    }
}
Also used : Point(java.awt.Point) TextLayout(java.awt.font.TextLayout)

Example 43 with TextLayout

use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.

the class CompositionArea method getCaretRectangle.

// returns a 0-width rectangle
private Rectangle getCaretRectangle(TextHitInfo caret) {
    int caretLocation = 0;
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        caretLocation = Math.round(layout.getCaretInfo(caret)[0]);
    }
    Graphics g = getGraphics();
    FontMetrics metrics = null;
    try {
        metrics = g.getFontMetrics();
    } finally {
        g.dispose();
    }
    return new Rectangle(TEXT_ORIGIN_X + caretLocation, TEXT_ORIGIN_Y - metrics.getAscent(), 0, metrics.getAscent() + metrics.getDescent());
}
Also used : Graphics(java.awt.Graphics) FontMetrics(java.awt.FontMetrics) Rectangle(java.awt.Rectangle) Point(java.awt.Point) TextLayout(java.awt.font.TextLayout)

Example 44 with TextLayout

use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.

the class CompositionArea method paint.

public void paint(Graphics g) {
    super.paint(g);
    g.setColor(getForeground());
    TextLayout layout = composedTextLayout;
    if (layout != null) {
        layout.draw((Graphics2D) g, TEXT_ORIGIN_X, TEXT_ORIGIN_Y);
    }
    if (caret != null) {
        Rectangle rectangle = getCaretRectangle(caret);
        g.setXORMode(getBackground());
        g.fillRect(rectangle.x, rectangle.y, 1, rectangle.height);
        g.setPaintMode();
    }
}
Also used : Rectangle(java.awt.Rectangle) TextLayout(java.awt.font.TextLayout)

Example 45 with TextLayout

use of java.awt.font.TextLayout in project jdk8u_jdk by JetBrains.

the class FontDesignMetrics method charsWidth.

public int charsWidth(char[] data, int off, int len) {
    float width = 0;
    if (font.hasLayoutAttributes()) {
        if (len == 0) {
            return 0;
        }
        String str = new String(data, off, len);
        width = new TextLayout(str, font, frc).getAdvance();
    } else {
        /* Explicit test needed to satisfy superclass spec */
        if (len < 0) {
            throw new IndexOutOfBoundsException("len=" + len);
        }
        int limit = off + len;
        for (int i = off; i < limit; i++) {
            char ch = data[i];
            if (ch < 0x100) {
                width += getLatinCharWidth(ch);
            } else if (FontUtilities.isNonSimpleChar(ch)) {
                String str = new String(data, off, len);
                width = new TextLayout(str, font, frc).getAdvance();
                break;
            } else {
                width += handleCharWidth(ch);
            }
        }
    }
    return (int) (0.5 + width);
}
Also used : TextLayout(java.awt.font.TextLayout)

Aggregations

TextLayout (java.awt.font.TextLayout)108 AttributedString (java.text.AttributedString)32 Graphics2D (java.awt.Graphics2D)25 FontRenderContext (java.awt.font.FontRenderContext)25 Font (java.awt.Font)20 AttributedCharacterIterator (java.text.AttributedCharacterIterator)17 LineBreakMeasurer (java.awt.font.LineBreakMeasurer)16 Point (java.awt.Point)11 Rectangle (java.awt.Rectangle)10 Rectangle2D (java.awt.geom.Rectangle2D)10 Color (java.awt.Color)9 Paint (java.awt.Paint)8 AffineTransform (java.awt.geom.AffineTransform)8 Shape (java.awt.Shape)7 TextLayoutInfo (g4p_controls.StyledString.TextLayoutInfo)5 Dimension (java.awt.Dimension)5 TextHitInfo (java.awt.font.TextHitInfo)4 ArrayList (java.util.ArrayList)4 Graphics (java.awt.Graphics)3 Insets (java.awt.Insets)3