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>, <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);
}
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;
}
}
}
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());
}
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();
}
}
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);
}
Aggregations