/** * Render based on immediate rendering * * @param text The text to be rendered * @param start The index of the first character in the string to render * @param end The index of the last character in the string to render */ private void render(String text, int start, int end) { GL.glBegin(SGL.GL_QUADS); int x = 0, y = 0; CharDef lastCharDef = null; char[] data = text.toCharArray(); for (int i = 0; i < data.length; i++) { int id = data[i]; if (id == '\n') { x = 0; y += getLineHeight(); continue; } if (id >= chars.length) { continue; } CharDef charDef = chars[id]; if (charDef == null) { continue; } if (lastCharDef != null) x += lastCharDef.getKerning(id); lastCharDef = charDef; if ((i >= start) && (i <= end)) { charDef.draw(x, y); } x += charDef.xadvance; } GL.glEnd(); }
public int getWidth(String text) { if (text == null) { return 0; } Display display = null; for (Display d : displays.values()) { if (d != null && text.equals(d.text)) { display = d; break; } } if (display != null && display.width != 0) { return display.width; } if (display == null) { display = new Display(); } int width = 0; CharDef lastCharDef = null; for (int i = 0, n = text.length(); i < n; i++) { int id = text.charAt(i); if (id == '\n') { width = 0; continue; } if (id >= chars.length) { continue; } CharDef charDef = chars[id]; if (charDef == null) { continue; } if (lastCharDef != null) { width += lastCharDef.getKerning(id); } lastCharDef = charDef; if (i < n - 1) { width += charDef.advance; } else { width += charDef.width; } display.width = MathUtils.max(display.width, width); } return display.width; }
/** @see org.newdawn.slick.Font#getWidth(java.lang.String) */ public int getWidth(String text) { DisplayList displayList = null; if (displayListCaching) { displayList = (DisplayList) displayLists.get(text); if (displayList != null && displayList.width != null) return displayList.width.intValue(); } int maxWidth = 0; int width = 0; CharDef lastCharDef = null; for (int i = 0, n = text.length(); i < n; i++) { int id = text.charAt(i); if (id == '\n') { width = 0; continue; } if (id >= chars.length) { continue; } CharDef charDef = chars[id]; if (charDef == null) { continue; } if (lastCharDef != null) width += lastCharDef.getKerning(id); lastCharDef = charDef; if (i < n - 1) { width += charDef.xadvance; } else { width += charDef.width; } maxWidth = Math.max(maxWidth, width); } if (displayList != null) displayList.width = new Short((short) maxWidth); return maxWidth; }
private void drawBatchString( float tx, float ty, String text, LColor c, int startIndex, int endIndex) { if (isClose) { return; } if (displays.size > DEFAULT_MAX_CHAR) { displays.clear(); } lazyHashCode = 1; if (c != null) { lazyHashCode = LSystem.unite(lazyHashCode, c.r); lazyHashCode = LSystem.unite(lazyHashCode, c.g); lazyHashCode = LSystem.unite(lazyHashCode, c.b); lazyHashCode = LSystem.unite(lazyHashCode, c.a); } String key = text + lazyHashCode; Display display = displays.get(key); if (display == null) { int x = 0, y = 0; displayList.glBegin(); displayList.setBatchPos(tx, ty); if (c != null) { displayList.setImageColor(c); } CharDef lastCharDef = null; char[] data = text.toCharArray(); for (int i = 0; i < data.length; i++) { int id = data[i]; if (id == '\n') { x = 0; y += getLineHeight(); continue; } if (id >= chars.length) { continue; } CharDef charDef = chars[id]; if (charDef == null) { continue; } if (lastCharDef != null) { x += lastCharDef.getKerning(id); } lastCharDef = charDef; if ((i >= startIndex) && (i <= endIndex)) { charDef.draw(x, y); } x += charDef.advance; } if (c != null) { displayList.setImageColor(LColor.white); } displayList.glEnd(); display = new Display(); display.cache = displayList.newBatchCache(); display.text = text; display.width = 0; display.height = 0; displays.put(key, display); } else if (display.cache != null) { display.cache.x = tx; display.cache.y = ty; displayList.postCache(display.cache); } }