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); } }
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); } }
/** Returns the distance from the y drawing location to the top most pixel of the specified text. */ public int getYOffset (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (renderType == RenderType.FreeType && bitmapFont != null) return (int)bitmapFont.getAscent(); int index = text.indexOf('\n'); if (index != -1) text = text.substring(0, index); char[] chars = text.toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); int yOffset = ascent + vector.getPixelBounds(null, 0, 0).y; return yOffset; }
/** Returns the distance from the y drawing location to the top most pixel of the specified text. */ public int getYOffset (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (renderType == RenderType.FreeType && bitmapFont != null) return (int)bitmapFont.getAscent(); int index = text.indexOf('\n'); if (index != -1) text = text.substring(0, index); char[] chars = text.toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); int yOffset = ascent + vector.getPixelBounds(null, 0, 0).y; return yOffset; }
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
private void initializeFont (Font baseFont, int size, boolean bold, boolean italic) { Map attributes = baseFont.getAttributes(); attributes.put(TextAttribute.SIZE, new Float(size)); attributes.put(TextAttribute.WEIGHT, bold ? TextAttribute.WEIGHT_BOLD : TextAttribute.WEIGHT_REGULAR); attributes.put(TextAttribute.POSTURE, italic ? TextAttribute.POSTURE_OBLIQUE : TextAttribute.POSTURE_REGULAR); try { attributes.put(TextAttribute.class.getDeclaredField("KERNING").get(null), TextAttribute.class.getDeclaredField("KERNING_ON").get(null)); } catch (Throwable ignored) { } font = baseFont.deriveFont(attributes); metrics = GlyphPage.scratchGraphics.getFontMetrics(font); ascent = metrics.getAscent(); descent = metrics.getDescent(); leading = metrics.getLeading(); // Determine width of space glyph (getGlyphPixelBounds gives a width of zero). char[] chars = " ".toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); spaceWidth = vector.getGlyphLogicalBounds(0).getBounds().width; }
public int getWidth (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (text.length() == 0) return 0; 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 = 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; }
public int getWidth (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (text.length() == 0) return 0; 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 = 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; }
public int getHeight (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (text.length() == 0) return 0; 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; }
public int getHeight (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); if (text.length() == 0) return 0; 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; }
/** Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until * {@link #loadGlyphs()} is called. */ public void addGlyphs (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); char[] chars = text.toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) { int codePoint = text.codePointAt(vector.getGlyphCharIndex(i)); Rectangle bounds = getGlyphBounds(vector, i, codePoint); getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i); } }
/** Queues the glyphs in the specified text to be loaded. Note that the glyphs are not actually loaded until * {@link #loadGlyphs()} is called. */ public void addGlyphs (String text) { if (text == null) throw new IllegalArgumentException("text cannot be null."); char[] chars = text.toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); for (int i = 0, n = vector.getNumGlyphs(); i < n; i++) { int codePoint = text.codePointAt(vector.getGlyphCharIndex(i)); Rectangle bounds = getGlyphBounds(vector, i, codePoint); getGlyph(vector.getGlyphCode(i), codePoint, bounds, vector, i); } }
FontMetrics metrics = g.getFontMetrics(); if (numberHeight == 0) { numberHeight = getFont().layoutGlyphVector(g.getFontRenderContext(), new char[] {'0'}, 0, 1, Font.LAYOUT_LEFT_TO_RIGHT) .getGlyphPixelBounds(0, g.getFontRenderContext(), 0, 0).height;
FontMetrics metrics = g.getFontMetrics(); if (numberHeight == 0) { numberHeight = getFont().layoutGlyphVector(g.getFontRenderContext(), new char[] {'0'}, 0, 1, Font.LAYOUT_LEFT_TO_RIGHT) .getGlyphPixelBounds(0, g.getFontRenderContext(), 0, 0).height;
/** @return May be null. */ private Glyph getGlyph (char c) { char[] chars = {c}; GlyphVector vector = unicodeFont.getFont().layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); Rectangle bounds = vector.getGlyphPixelBounds(0, GlyphPage.renderContext, 0, 0); return unicodeFont.getGlyph(vector.getGlyphCode(0), c, bounds, vector, 0); }
/** @return May be null. */ private Glyph getGlyph (char c) { char[] chars = {c}; GlyphVector vector = unicodeFont.getFont().layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); Rectangle bounds = vector.getGlyphPixelBounds(0, GlyphPage.renderContext, 0, 0); return unicodeFont.getGlyph(vector.getGlyphCode(0), c, bounds, vector, 0); }
private void drawUnicode (String text, int startIndex, int endIndex) { char[] chars = text.substring(0, endIndex).toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
private void drawUnicode (String text, int startIndex, int endIndex) { char[] chars = text.substring(0, endIndex).toCharArray(); GlyphVector vector = font.layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT);
GlyphVector charVector = unicodeFont.getFont().layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); GlyphMetrics charMetrics = charVector.getGlyphMetrics(0);
GlyphVector charVector = unicodeFont.getFont().layoutGlyphVector(GlyphPage.renderContext, chars, 0, chars.length, Font.LAYOUT_LEFT_TO_RIGHT); GlyphMetrics charMetrics = charVector.getGlyphMetrics(0);