Java Code Examples for java.awt.font.GlyphMetrics#getAdvanceX()

The following examples show how to use java.awt.font.GlyphMetrics#getAdvanceX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlyphMetricsSerializationWrapper.java    From pumpernickel with MIT License 5 votes vote down vote up
public GlyphMetricsSerializationWrapper(GlyphMetrics gm) {
	// when in doubt, we're just going to guess that this is true. I don't
	// see a clear way to identify this property without reflection?
	boolean horizontal = gm.getAdvanceX() == gm.getAdvanceY() ? true
			: gm.getAdvanceX() == gm.getAdvance();
	map.put(KEY_HORIZONTAL, horizontal);
	map.put(KEY_ADVANCE_X, gm.getAdvanceX());
	map.put(KEY_ADVANCE_Y, gm.getAdvanceY());
	map.put(KEY_BOUNDS,
			new Rectangle2DSerializationWrapper(gm.getBounds2D()));
	map.put(KEY_GLYPH_TYPE, (byte) gm.getType());
}
 
Example 2
Source File: BMFontUtil.java    From gdx-skineditor with Apache License 2.0 5 votes vote down vote up
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};
}
 
Example 3
Source File: BMFontUtil.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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, null, 0, 0).x - unicodeFont.getPaddingLeft();
	int xAdvance = (int)(metrics.getAdvanceX() + unicodeFont.getPaddingAdvanceX() + unicodeFont.getPaddingLeft() + unicodeFont
		.getPaddingRight());
	return new int[] {xOffset, xAdvance};
}
 
Example 4
Source File: FontTag.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
public static float getSystemFontAdvance(Font aFont, Character character, Character nextCharacter) {
    String chars = "" + character + (nextCharacter == null ? "" : nextCharacter);
    GlyphVector gv = aFont.layoutGlyphVector(new FontRenderContext(aFont.getTransform(), true, true), chars.toCharArray(), 0, chars.length(), Font.LAYOUT_LEFT_TO_RIGHT);
    GlyphMetrics gm = gv.getGlyphMetrics(0);
    return gm.getAdvanceX();
}