本文整理匯總了Java中java.awt.font.GlyphVector.getGlyphCharIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java GlyphVector.getGlyphCharIndex方法的具體用法?Java GlyphVector.getGlyphCharIndex怎麽用?Java GlyphVector.getGlyphCharIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.font.GlyphVector
的用法示例。
在下文中一共展示了GlyphVector.getGlyphCharIndex方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findWidth
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
/**
* @param text the string to find the width of
* @param logical whether to add the space the letters should occupy on the end
* @return width of string.
*/
private int findWidth(String text,boolean logical) {
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int width = 0;
int extraX = 0;
boolean startNewLine = false;
for (int glyphIndex = 0, n = vector.getNumGlyphs(); glyphIndex < n; glyphIndex++) {
int charIndex = vector.getGlyphCharIndex(glyphIndex);
int codePoint = text.codePointAt(charIndex);
Rectangle bounds = logical ? vector.getLogicalBounds().getBounds() : getGlyphBounds(vector, glyphIndex, codePoint);
if (startNewLine && codePoint != '\n') extraX = -bounds.x;
if (glyphIndex > 0) extraX += paddingLeft + paddingRight + paddingAdvanceX;
width = Math.max(width, bounds.x + extraX + bounds.width);
if (codePoint == '\n') startNewLine = true;
}
return width;
}
示例2: getHeight
import java.awt.font.GlyphVector; //導入方法依賴的package包/類
/**
* @see org.newdawn.slick.Font#getHeight(java.lang.String)
*/
public int getHeight (String text) {
if (text == null) throw new IllegalArgumentException("text cannot be null.");
if (text.length() == 0) return 0;
if (displayListCaching) {
DisplayList displayList = (DisplayList)displayLists.get(text);
if (displayList != null) return displayList.height;
}
char[] chars = text.toCharArray();
GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
int lines = 0, height = 0;
for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) {
int charIndex = vector.getGlyphCharIndex(i);
int codePoint = text.codePointAt(charIndex);
if (codePoint == ' ') continue;
Rectangle bounds = getGlyphBounds(vector, i, codePoint);
height = Math.max(height, ascent + bounds.y + bounds.height);
if (codePoint == '\n') {
lines++;
height = 0;
}
}
return lines * getLineHeight() + height;
}
示例3: main
import java.awt.font.GlyphVector; //導入方法依賴的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);
}
}