private GlyphVector getGlyphVector() { final GlyphVector gv = singleUnicodeGlyphVector; if (gv != null) { singleUnicodeGlyphVector = null; // Don't need this anymore return gv; } singleUnicode[0] = (char) unicodeID; return font.createGlyphVector(getFontRenderContext(), singleUnicode); } }
private Glyph getGlyph(final CharSequence inString, final GlyphMetrics glyphMetrics, final int index) { final char unicodeID = inString.charAt(index); if (unicodeID >= unicodes2Glyphs.length) { return null; } final int glyphID = unicodes2Glyphs[unicodeID]; if (glyphID != undefined) { return glyphCache[glyphID]; } // Must fabricate the glyph singleUnicode[0] = unicodeID; final GlyphVector gv = font.createGlyphVector(getFontRenderContext(), singleUnicode); return getGlyph(unicodeID, gv, glyphMetrics); }
private Glyph getGlyph(final int unicodeID) { if (unicodeID >= unicodes2Glyphs.length) { return null; } final int glyphID = unicodes2Glyphs[unicodeID]; if (glyphID != undefined) { return glyphCache[glyphID]; } singleUnicode[0] = (char) unicodeID; final GlyphVector gv = font.createGlyphVector(getFontRenderContext(), singleUnicode); return getGlyph(unicodeID, gv, gv.getGlyphMetrics(0)); }
if (fullRunGlyphVector == null) { iter.initFromCharSequence(inString); fullRunGlyphVector = font.createGlyphVector(getFontRenderContext(), iter); fullGlyphVectorCache.put(inString.toString(), fullRunGlyphVector);
/** Returns the bounding rectangle of the given CharSequence, assuming it was rendered at the origin. The coordinate system of the returned rectangle is Java 2D's, with increasing Y coordinates in the downward direction. The relative coordinate (0, 0) in the returned rectangle corresponds to the baseline of the leftmost character of the rendered string, in similar fashion to the results returned by, for example, {@link java.awt.font.GlyphVector#getVisualBounds}. Most applications will use only the width and height of the returned Rectangle for the purposes of centering or justifying the String. It is not specified which Java 2D bounds ({@link java.awt.font.GlyphVector#getVisualBounds getVisualBounds}, {@link java.awt.font.GlyphVector#getPixelBounds getPixelBounds}, etc.) the returned bounds correspond to, although every effort is made to ensure an accurate bound. */ public Rectangle2D getBounds(final CharSequence str) { // FIXME: this should be more optimized and use the glyph cache final Rect r = stringLocations.get(str); if (r != null) { final TextData data = (TextData) r.getUserData(); // Reconstitute the Java 2D results based on the cached values return new Rectangle2D.Double(-data.origin().x, -data.origin().y, r.w(), r.h()); } // Must return a Rectangle compatible with the layout algorithm -- // must be idempotent return normalize(renderDelegate.getBounds(str, font, getFontRenderContext())); }
private void upload() { final GlyphVector gv = getGlyphVector(); final Rectangle2D origBBox = preNormalize(renderDelegate.getBounds(gv, getFontRenderContext())); final Rectangle2D bbox = normalize(origBBox); final Point origin = new Point((int) -bbox.getMinX(),
@Override public BoundingBox3d drawText(GL gl, GLU glu, Camera cam, String s, Coord3d position, Halign halign, Valign valign, Color color, Coord2d screenOffset, Coord3d sceneOffset) { //gl.getGL2().glPushMatrix(); renderer.begin3DRendering(); if(LAYOUT){ // work in progress Rectangle2D d = style.getBounds(s, font, renderer.getFontRenderContext()); Coord3d left2d = cam.modelToScreen(gl, glu, position); Coord2d right2d = new Coord2d(left2d.x+(float)d.getWidth(), left2d.y+(float)d.getHeight()); Coord3d right3d = cam.screenToModel(gl, glu, new Coord3d(right2d,0)); Coord3d offset3d = right3d.sub(position).div(2);//.mul(0.1f); Coord3d real = position.add(sceneOffset).sub(offset3d); renderer.draw3D(s, real.x, real.y, real.z, 1);//0.005f); } else{ Coord3d real = position.add(sceneOffset); renderer.draw3D(s, real.x, real.y, real.z, 1);//0.005f); } renderer.flush(); renderer.end3DRendering(); //gl.getGL2().glPopMatrix(); return null; }
final Rectangle2D origBBox = preNormalize(renderDelegate.getBounds(curStr, font, getFontRenderContext())); final Rectangle2D bbox = normalize(origBBox); final Point origin = new Point((int) -bbox.getMinX(),
final GlyphVector gv = font.createGlyphVector(getFontRenderContext(), str); float totalAdvance = 0; for (int i = 0; i < gv.getNumGlyphs(); i++) {