Search in sources :

Example 1 with GlyphVector

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();
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Example 2 with GlyphVector

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);
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Example 3 with GlyphVector

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);
    }
}
Also used : GlyphVector(java.awt.font.GlyphVector) Rectangle(java.awt.Rectangle)

Example 4 with GlyphVector

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;
}
Also used : GlyphVector(java.awt.font.GlyphVector) Rectangle(java.awt.Rectangle)

Example 5 with GlyphVector

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;
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Aggregations

GlyphVector (java.awt.font.GlyphVector)36 FontRenderContext (java.awt.font.FontRenderContext)18 Font (java.awt.Font)8 Graphics2D (java.awt.Graphics2D)8 Rectangle (java.awt.Rectangle)7 Rectangle2D (java.awt.geom.Rectangle2D)7 BufferedImage (java.awt.image.BufferedImage)5 Shape (java.awt.Shape)3 AffineTransform (java.awt.geom.AffineTransform)3 BasicStroke (java.awt.BasicStroke)2 FontMetrics (java.awt.FontMetrics)2 Image (java.awt.Image)2 Paint (java.awt.Paint)2 TextLayout (java.awt.font.TextLayout)2 Point2D (java.awt.geom.Point2D)2 Map (java.util.Map)2 Texture (com.badlogic.gdx.graphics.Texture)1 FontInfo (com.intellij.openapi.editor.impl.FontInfo)1 AbstractMockGlyphVector (com.intellij.testFramework.AbstractMockGlyphVector)1 MockFontLayoutService (com.intellij.testFramework.MockFontLayoutService)1