当前位置: 首页>>代码示例>>Java>>正文


Java GlyphVector.getGlyphCharIndex方法代码示例

本文整理汇总了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;
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:28,代码来源:UnicodeFont.java

示例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;
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:32,代码来源:UnicodeFont.java

示例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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:GetGlyphCharIndexTest.java


注:本文中的java.awt.font.GlyphVector.getGlyphCharIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。