Search in sources :

Example 1 with GlyphMetrics

use of java.awt.font.GlyphMetrics in project gdx-skineditor by cobolfoo.

the class BMFontUtil method getGlyphMetrics.

private int[] getGlyphMetrics(Font font, int codePoint) {
    // xOffset and xAdvance will be incorrect for unicode characters such as combining marks or non-spacing characters
    // (eg Pnujabi's "ਜੇ") that require the context of surrounding glyphs to determine spacing, but thisis the
    // best we can do with the BMFont format.
    char[] chars = Character.toChars(codePoint);
    GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
    GlyphMetrics metrics = vector.getGlyphMetrics(0);
    int xOffset = vector.getGlyphPixelBounds(0, GlyphPage.renderContext, 0.5f, 0).x - unicodeFont.getPaddingLeft();
    int xAdvance = (int) (metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont.getPaddingRight());
    return new int[] { xOffset, xAdvance };
}
Also used : GlyphVector(java.awt.font.GlyphVector) GlyphMetrics(java.awt.font.GlyphMetrics)

Example 2 with GlyphMetrics

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

the class StandardGlyphVector method getGlyphMetrics.

public GlyphMetrics getGlyphMetrics(int ix) {
    if (ix < 0 || ix >= glyphs.length) {
        throw new IndexOutOfBoundsException("ix = " + ix);
    }
    Rectangle2D vb = getGlyphVisualBounds(ix).getBounds2D();
    Point2D pt = getGlyphPosition(ix);
    vb.setRect(vb.getMinX() - pt.getX(), vb.getMinY() - pt.getY(), vb.getWidth(), vb.getHeight());
    Point2D.Float adv = getGlyphStrike(ix).strike.getGlyphMetrics(glyphs[ix]);
    GlyphMetrics gm = new GlyphMetrics(true, adv.x, adv.y, vb, GlyphMetrics.STANDARD);
    return gm;
}
Also used : Point2D(java.awt.geom.Point2D) GlyphMetrics(java.awt.font.GlyphMetrics) Rectangle2D(java.awt.geom.Rectangle2D)

Aggregations

GlyphMetrics (java.awt.font.GlyphMetrics)2 GlyphVector (java.awt.font.GlyphVector)1 Point2D (java.awt.geom.Point2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1