use of java.awt.font.GlyphVector in project WordCram by danbernier.
the class WordShaper method makeShape.
private Shape makeShape(String word, Font font) {
char[] chars = word.toCharArray();
// TODO hmm: this doesn't render newlines. Hrm. If your word text is "foo\nbar", you get "foobar".
GlyphVector gv = font.layoutGlyphVector(frc, chars, 0, chars.length, this.rightToLeft ? Font.LAYOUT_RIGHT_TO_LEFT : Font.LAYOUT_LEFT_TO_RIGHT);
return gv.getOutline();
}
use of java.awt.font.GlyphVector in project scriptographer by scriptographer.
the class AbstractGraphics2D method drawString.
public void drawString(AttributedCharacterIterator iterator, float x, float y) {
if (textAsShapes) {
GlyphVector gv = getFont().createGlyphVector(getFontRenderContext(), iterator);
drawGlyphVector(gv, x, y);
}
}
use of java.awt.font.GlyphVector in project libgdx by libgdx.
the class UnicodeFont method addGlyphs.
/** Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until
* {@link #loadGlyphs()} is called. */
public void addGlyphs(String text) {
if (text == null)
throw new IllegalArgumentException("text cannot be null.");
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
int codePoint = text.codePointAt(vector.getGlyphCharIndex(i));
Rectangle bounds = getGlyphBounds(vector, i, codePoint);
getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i);
}
}
use of java.awt.font.GlyphVector in project libgdx by libgdx.
the class UnicodeFont method getHeight.
public int getHeight(String text) {
if (text == null)
throw new IllegalArgumentException("text cannot be null.");
if (text.length() == 0)
return 0;
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int lines = 0, height = 0;
for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
int charIndex = vector.getGlyphCharIndex(i);
int codePoint = text.codePointAt(charIndex);
if (codePoint == ' ')
continue;
Rectangle bounds = getGlyphBounds(vector, i, codePoint);
height = Math.max(height, ascent + bounds.y + bounds.height);
if (codePoint == '\n') {
lines++;
height = 0;
}
}
return lines * getLineHeight() + height;
}
use of java.awt.font.GlyphVector in project libgdx by libgdx.
the class UnicodeFont method getYOffset.
/** Returns the distance from the y drawing location to the top most pixel of the specified text. */
public int getYOffset(String text) {
if (text == null)
throw new IllegalArgumentException("text cannot be null.");
if (renderType == RenderType.FreeType && bitmapFont != null)
return (int) bitmapFont.getAscent();
int index = text.indexOf('\n');
if (index != -1)
text = text.substring(0, index);
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int yOffset = ascent + vector.getPixelBounds(null, 0, 0).y;
return yOffset;
}
Aggregations