本文整理匯總了Java中java.awt.font.GlyphMetrics.getAdvanceX方法的典型用法代碼示例。如果您正苦於以下問題:Java GlyphMetrics.getAdvanceX方法的具體用法?Java GlyphMetrics.getAdvanceX怎麽用?Java GlyphMetrics.getAdvanceX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.font.GlyphMetrics
的用法示例。
在下文中一共展示了GlyphMetrics.getAdvanceX方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGlyphLogicalBounds
import java.awt.font.GlyphMetrics; //導入方法依賴的package包/類
public Shape getGlyphLogicalBounds(int glyphIndex)
{
GlyphMetrics gm = getGlyphMetrics( glyphIndex );
if( gm == null )
return null;
Rectangle2D r = gm.getBounds2D();
Point2D p = getGlyphPosition( glyphIndex );
double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
p.getY() + r.getY(),
p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
p.getY() + r.getY() + r.getHeight()};
if (glyphTransforms[glyphIndex] != null)
glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);
return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
bounds[3] - bounds[1]);
}
示例2: getGlyphLogicalBounds
import java.awt.font.GlyphMetrics; //導入方法依賴的package包/類
public Shape getGlyphLogicalBounds(int glyphIndex)
{
GlyphMetrics gm = getGlyphMetrics( glyphIndex );
if( gm == null )
return null;
Rectangle2D r = gm.getBounds2D();
Point2D p = getGlyphPosition( glyphIndex );
double[] bounds = new double[] {p.getX() + r.getX() - gm.getLSB(),
p.getY() + r.getY(),
p.getX() + r.getX() - gm.getLSB() + gm.getAdvanceX(),
p.getY() + r.getY() + r.getHeight()};
if (glyphTransforms[glyphIndex] != null)
glyphTransforms[glyphIndex].transform(bounds, 0, bounds, 0, 2);
return new Rectangle2D.Double(bounds[0], bounds[1], bounds[2] - bounds[0],
bounds[3] - bounds[1]);
}
示例3: getGlyphMetrics
import java.awt.font.GlyphMetrics; //導入方法依賴的package包/類
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};
}
示例4: getGlyphMetrics
import java.awt.font.GlyphMetrics; //導入方法依賴的package包/類
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};
}
示例5: getSystemFontAdvance
import java.awt.font.GlyphMetrics; //導入方法依賴的package包/類
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();
}