/** Returns an image that can be used by effects as a temp image. */ static public BufferedImage getScratchImage () { Graphics2D g = (Graphics2D)scratchImage.getGraphics(); g.setComposite(AlphaComposite.Clear); g.fillRect(0, 0, GlyphPage.MAX_GLYPH_SIZE, GlyphPage.MAX_GLYPH_SIZE); g.setComposite(AlphaComposite.SrcOver); g.setColor(java.awt.Color.white); return scratchImage; }
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 "\u0A1C\u0A47") 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}; }
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); }