本文整理匯總了Java中java.awt.Font.layoutGlyphVector方法的典型用法代碼示例。如果您正苦於以下問題:Java Font.layoutGlyphVector方法的具體用法?Java Font.layoutGlyphVector怎麽用?Java Font.layoutGlyphVector使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Font
的用法示例。
在下文中一共展示了Font.layoutGlyphVector方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGlyphMetrics
import java.awt.Font; //導入方法依賴的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};
}
示例2: runTest
import java.awt.Font; //導入方法依賴的package包/類
public void runTest(Object ctx, int numReps) {
TCContext tcctx = (TCContext)ctx;
final Font font = tcctx.font;
final char[] chars = tcctx.chars1;
final int start = 1;
final int limit = chars.length - 1;
final FontRenderContext frc = tcctx.frc;
final int flags = tcctx.flags;
GlyphVector gv;
do {
gv = font.layoutGlyphVector(frc, chars, start, limit, flags);
} while (--numReps >= 0);
}
示例3: main
import java.awt.Font; //導入方法依賴的package包/類
public static void main(String[] args) {
Font font = new Font(Font.MONOSPACED, Font.PLAIN, 12);
FontRenderContext frc = new FontRenderContext(null, false, false);
GlyphVector gv = font.layoutGlyphVector(frc, "abc".toCharArray(), 1, 3,
Font.LAYOUT_LEFT_TO_RIGHT);
int idx0 = gv.getGlyphCharIndex(0);
if (idx0 != 0) {
throw new RuntimeException("Expected 0, got " + idx0);
}
}
示例4: getGlyphCode
import java.awt.Font; //導入方法依賴的package包/類
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);
}
示例5: runTest
import java.awt.Font; //導入方法依賴的package包/類
private static void runTest() {
im = new BufferedImage(W, H, BufferedImage.TYPE_INT_RGB);
Graphics2D g2d = im.createGraphics();
g2d.setColor(Color.white);
g2d.fillRect(0, 0, W, H);
g2d.setColor(Color.black);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
char[] chs = "Sample Text.".toCharArray();
int len = chs.length;
int x = 50, y = 100;
FontRenderContext frc = g2d.getFontRenderContext();
Font plain = new Font("Serif", Font.PLAIN, 48);
GlyphVector pgv = plain.layoutGlyphVector(frc, chs, 0, len, 0);
g2d.setFont(plain);
g2d.drawChars(chs, 0, len, x, y); y +=50;
g2d.drawGlyphVector(pgv, x, y); y += 50;
Rectangle2D plainStrBounds = plain.getStringBounds(chs, 0, len, frc);
Rectangle2D plainGVBounds = pgv.getLogicalBounds();
Font bold = new Font("Serif", Font.BOLD, 48);
GlyphVector bgv = bold.layoutGlyphVector(frc, chs, 0, len, 0);
Rectangle2D boldStrBounds = bold.getStringBounds(chs, 0, len, frc);
Rectangle2D boldGVBounds = bgv.getLogicalBounds();
g2d.setFont(bold);
g2d.drawChars(chs, 0, len, x, y); y +=50;
g2d.drawGlyphVector(bgv, x, y);
System.out.println("Plain String Bounds = " + plainStrBounds);
System.out.println("Bold String Bounds = " + boldStrBounds);
System.out.println("Plain GlyphVector Bounds = " + plainGVBounds);
System.out.println("Bold GlyphVector Bounds = " + boldGVBounds);
if (!plainStrBounds.equals(boldStrBounds) &&
plainGVBounds.equals(boldGVBounds))
{
System.out.println("Test failed: Plain GV bounds same as Bold");
if (!interactive) {
throw new RuntimeException("Plain GV bounds same as Bold");
}
}
}