java.awt.font.GlyphVector#getGlyphMetrics ( )源码实例Demo

下面列出了java.awt.font.GlyphVector#getGlyphMetrics ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

public GlyphElement(GlyphVector gv, int index) {
	glyphCode = gv.getGlyphCode(index);
	transform = gv.getGlyphTransform(index);
	outline = new ShapeSerializationWrapper(gv.getGlyphOutline(index));
	position = new Point2DSerializationWrapper(
			gv.getGlyphPosition(index));
	logicalBounds = new ShapeSerializationWrapper(
			gv.getGlyphLogicalBounds(index));

	GlyphJustificationInfo gji = gv.getGlyphJustificationInfo(index);
	justificationInfo = gji == null ? null
			: new GlyphJustificationInfoSerializationWrapper(gji);
	glyphMetrics = new GlyphMetricsSerializationWrapper(
			gv.getGlyphMetrics(index));
	visualBounds = new ShapeSerializationWrapper(
			gv.getGlyphVisualBounds(index));
}
 
源代码2 项目: java-swing-tips   文件: MainPanel.java
private static GlyphVector getWrappedGlyphVector(String str, double width, Font font, FontRenderContext frc) {
  Point2D gmPos = new Point2D.Float();
  GlyphVector gv = font.createGlyphVector(frc, str);
  float lineHeight = (float) gv.getLogicalBounds().getHeight();
  float pos = 0f;
  int lineCount = 0;
  GlyphMetrics gm;
  for (int i = 0; i < gv.getNumGlyphs(); i++) {
    gm = gv.getGlyphMetrics(i);
    float advance = gm.getAdvance();
    if (pos < width && width <= pos + advance) {
      lineCount++;
      pos = 0f;
    }
    gmPos.setLocation(pos, lineHeight * lineCount);
    gv.setGlyphPosition(i, gmPos);
    pos += advance;
  }
  return gv;
}
 
源代码3 项目: java-swing-tips   文件: MainPanel.java
private static GlyphVector getWrappedGlyphVector(String str, double width, Font font, FontRenderContext frc) {
  Point2D gmPos = new Point2D.Float();
  GlyphVector gv = font.createGlyphVector(frc, str);
  float lineHeight = (float) gv.getLogicalBounds().getHeight();
  float pos = 0f;
  int lineCount = 0;
  GlyphMetrics gm;
  for (int i = 0; i < gv.getNumGlyphs(); i++) {
    gm = gv.getGlyphMetrics(i);
    float advance = gm.getAdvance();
    if (pos < width && width <= pos + advance) {
      lineCount++;
      pos = 0f;
    }
    gmPos.setLocation(pos, lineHeight * lineCount);
    gv.setGlyphPosition(i, gmPos);
    pos += advance;
  }
  return gv;
}
 
源代码4 项目: java-swing-tips   文件: MainPanel.java
private static GlyphVector makeJustifiedGlyphVector(GlyphVector gv, int width) {
  Rectangle2D r = gv.getVisualBounds();
  float jw = (float) width;
  float vw = (float) r.getWidth();
  if (jw > vw) {
    int num = gv.getNumGlyphs();
    float xx = (jw - vw) / (num - 1f);
    float pos = num == 1 ? (jw - vw) * .5f : 0f;
    Point2D gmPos = new Point2D.Float();
    for (int i = 0; i < num; i++) {
      GlyphMetrics gm = gv.getGlyphMetrics(i);
      gmPos.setLocation(pos, 0f);
      gv.setGlyphPosition(i, gmPos);
      pos += gm.getAdvance() + xx;
    }
  }
  return gv;
}
 
源代码5 项目: java-swing-tips   文件: MainPanel.java
private static GlyphVector getWrappedGlyphVector(String str, double width, Font font, FontRenderContext frc) {
  Point2D gmPos = new Point2D.Float();
  GlyphVector gv = font.createGlyphVector(frc, str);
  float lineHeight = (float) gv.getLogicalBounds().getHeight();
  float pos = 0f;
  int lineCount = 0;
  GlyphMetrics gm;

  for (int i = 0; i < gv.getNumGlyphs(); i++) {
    // TEST: gv.setGlyphTransform(i, at);
    gm = gv.getGlyphMetrics(i);
    float advance = gm.getAdvance();
    if (pos < width && width <= pos + advance) {
      lineCount++;
      pos = 0f;
    }
    gmPos.setLocation(pos, lineHeight * lineCount);
    gv.setGlyphPosition(i, gmPos);
    pos += advance;
  }
  return gv;
}
 
源代码6 项目: dragonwell8_jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码7 项目: TencentKona-8   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码8 项目: jdk8u60   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码9 项目: openjdk-jdk8u   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码10 项目: slick2d-maven   文件: Glyph.java
/**
 * Create a new glyph
 * 
 * @param codePoint The code point in which this glyph can be found
 * @param bounds The bounds that this glrph can fill
 * @param vector The vector this glyph is part of
 * @param index The index of this glyph within the vector
 * @param unicodeFont The font this glyph forms part of
 */
public Glyph(int codePoint, Rectangle bounds, GlyphVector vector, int index, UnicodeFont unicodeFont) {
	this.codePoint = codePoint;

	GlyphMetrics metrics = vector.getGlyphMetrics(index);
	int lsb = (int)metrics.getLSB();
	if (lsb > 0) lsb = 0;
	int rsb = (int)metrics.getRSB();
	if (rsb > 0) rsb = 0;

	int glyphWidth = bounds.width - lsb - rsb;
	int glyphHeight = bounds.height;
	if (glyphWidth > 0 && glyphHeight > 0) {
		int padTop = unicodeFont.getPaddingTop();
		int padRight = unicodeFont.getPaddingRight();
		int padBottom = unicodeFont.getPaddingBottom();
		int padLeft = unicodeFont.getPaddingLeft();
		int glyphSpacing = 1; // Needed to prevent filtering problems.
		width = (short)(glyphWidth + padLeft + padRight + glyphSpacing);
		height = (short)(glyphHeight + padTop + padBottom + glyphSpacing);
		yOffset = (short)(unicodeFont.getAscent() + bounds.y - padTop);
	}

	shape = vector.getGlyphOutline(index, -bounds.x + unicodeFont.getPaddingLeft(), -bounds.y + unicodeFont.getPaddingTop());

	isMissing = !unicodeFont.getFont().canDisplay((char)codePoint);
}
 
源代码11 项目: openjdk-jdk9   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码12 项目: jdk8u-jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码13 项目: slick2d-maven   文件: BMFontUtil.java
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};
}
 
源代码14 项目: openjdk-8-source   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码15 项目: openjdk-8   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码16 项目: jdk8u_jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码17 项目: jdk8u-jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码18 项目: jdk8u-dev-jdk   文件: TextMeasureTests.java
public void runTest(Object ctx, int numReps) {
    GVContext gvctx = (GVContext)ctx;
    GlyphVector gv = gvctx.gv;
    GlyphMetrics gm;
    do {
        for (int i = 0, e = gv.getNumGlyphs(); i < e; ++i) {
            gm = gv.getGlyphMetrics(i);
        }
    } while (--numReps >= 0);
}
 
源代码19 项目: gdx-skineditor   文件: BMFontUtil.java
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};
}
 
源代码20 项目: jpexs-decompiler   文件: FontTag.java
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();
}