Search in sources :

Example 16 with GlyphVector

use of java.awt.font.GlyphVector 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 17 with GlyphVector

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

the class BMFontUtil method getGlyphCode.

private int getGlyphCode(Font font, int codePoint) {
    char[] chars = Character.toChars(codePoint);
    GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
    return vector.getGlyphCode(0);
}
Also used : GlyphVector(java.awt.font.GlyphVector)

Example 18 with GlyphVector

use of java.awt.font.GlyphVector in project gephi by gephi.

the class EdgeLabelRenderer method renderG2D.

public void renderG2D(G2DTarget target, String label, float x, float y, Color color, float outlineSize, Color outlineColor) {
    Graphics2D graphics = target.getGraphics();
    graphics.setFont(font);
    FontMetrics fm = graphics.getFontMetrics();
    float posX = x - fm.stringWidth(label) / 2f;
    float posY = y + fm.getAscent() / 2f;
    Shape outlineGlyph = null;
    if (outlineSize > 0) {
        FontRenderContext frc = graphics.getFontRenderContext();
        GlyphVector gv = font.createGlyphVector(frc, label);
        outlineGlyph = gv.getOutline(posX, posY);
        graphics.setColor(outlineColor);
        graphics.setStroke(new BasicStroke(outlineSize, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        graphics.draw(outlineGlyph);
    }
    graphics.setColor(color);
    if (null == outlineGlyph) {
        graphics.drawString(label, posX, posY);
    } else {
        graphics.fill(outlineGlyph);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) GlyphVector(java.awt.font.GlyphVector) FontMetrics(java.awt.FontMetrics) FontRenderContext(java.awt.font.FontRenderContext) Graphics2D(java.awt.Graphics2D)

Example 19 with GlyphVector

use of java.awt.font.GlyphVector in project gephi by gephi.

the class NodeLabelRenderer method renderG2D.

public void renderG2D(G2DTarget target, String label, float x, float y, int fontSize, Color color, float outlineSize, Color outlineColor, boolean showBox, Color boxColor) {
    Graphics2D graphics = target.getGraphics();
    Font font = fontCache.get(fontSize);
    graphics.setFont(font);
    FontMetrics fm = graphics.getFontMetrics();
    float posX = x - fm.stringWidth(label) / 2f;
    float posY = y + fm.getDescent();
    Shape outlineGlyph = null;
    //Box
    if (showBox) {
        graphics.setColor(boxColor);
        Rectangle2D.Float rect = new Rectangle2D.Float();
        rect.setFrame(posX - outlineSize / 2f, y - (fm.getAscent() + fm.getDescent()) / 2f - outlineSize / 2f, fm.stringWidth(label) + outlineSize, fm.getAscent() + fm.getDescent() + outlineSize);
        graphics.draw(rect);
    }
    //Outline
    if (outlineSize > 0) {
        FontRenderContext frc = graphics.getFontRenderContext();
        GlyphVector gv = font.createGlyphVector(frc, label);
        outlineGlyph = gv.getOutline(posX, posY);
        graphics.setColor(outlineColor);
        graphics.setStroke(new BasicStroke(outlineSize, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
        graphics.draw(outlineGlyph);
    }
    graphics.setColor(color);
    if (null == outlineGlyph) {
        graphics.drawString(label, posX, posY);
    } else {
        graphics.fill(outlineGlyph);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) GlyphVector(java.awt.font.GlyphVector) FontMetrics(java.awt.FontMetrics) Rectangle2D(java.awt.geom.Rectangle2D) FontRenderContext(java.awt.font.FontRenderContext) BaseFont(com.itextpdf.text.pdf.BaseFont) Font(java.awt.Font) Graphics2D(java.awt.Graphics2D)

Example 20 with GlyphVector

use of java.awt.font.GlyphVector in project libgdx by libgdx.

the class BMFontUtil method getGlyphCode.

private int getGlyphCode(Font font, int codePoint) {
    char[] chars = Character.toChars(codePoint);
    GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
    return vector.getGlyphCode(0);
}
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