Java Code Examples for java.awt.font.GlyphVector#getGlyphCharIndex()
The following examples show how to use
java.awt.font.GlyphVector#getGlyphCharIndex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetGlyphCharIndexTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 2
Source File: GetGlyphCharIndexTest.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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); } }
Example 3
Source File: UnicodeFont.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * @see org.newdawn.slick.Font#getHeight(java.lang.String) */ @Override 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; }
Example 4
Source File: UnicodeFont.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @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; }