From 67ec86e539a3db0d06e5cc3550db453589594384 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Thu, 27 Feb 2014 23:56:13 +0100 Subject: Bug 801: Graph TextRenderer Cleanup Part-4: Text[Render->Region]Util API: Better separation of cached and uncached regions --- .../jogamp/graph/font/typecast/TypecastFont.java | 43 ++++++++++++---------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'src/jogl/classes/jogamp') diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 81c06cd83..8dd9ce4d7 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -166,8 +166,8 @@ class TypecastFont implements Font { } @Override - public float getAdvanceWidth(int i, float pixelSize) { - return font.getHmtxTable().getAdvanceWidth(i) * metrics.getScale(pixelSize); + public float getAdvanceWidth(int glyphID, float pixelSize) { + return font.getHmtxTable().getAdvanceWidth(glyphID) * metrics.getScale(pixelSize); } @Override @@ -197,7 +197,7 @@ class TypecastFont implements Font { if(null == glyph) { throw new RuntimeException("Could not retrieve glyph for symbol: <"+symbol+"> "+(int)symbol+" -> glyph id "+code); } - final OutlineShape shape = TypecastRenderer.buildShape(glyph, vertexFactory); + final OutlineShape shape = TypecastRenderer.buildShape(symbol, glyph, vertexFactory); result = new TypecastGlyph(this, symbol, code, glyph.getBBox(), glyph.getAdvanceWidth(), shape); if(DEBUG) { System.err.println("New glyph: " + (int)symbol + " ( " + symbol +" ) -> " + code + ", contours " + glyph.getPointCount() + ": " + shape); @@ -221,13 +221,22 @@ class TypecastFont implements Font { return result; } + @Override + public float getLineHeight(float pixelSize) { + final Metrics metrics = getMetrics(); + final float lineGap = metrics.getLineGap(pixelSize) ; // negative value! + final float ascent = metrics.getAscent(pixelSize) ; // negative value! + final float descent = metrics.getDescent(pixelSize) ; // positive value! + final float advanceY = lineGap - descent + ascent; // negative value! + return -advanceY; + } + @Override public float getStringWidth(CharSequence string, float pixelSize) { float width = 0; final int len = string.length(); - for (int i=0; i< len; i++) - { - char character = string.charAt(i); + for (int i=0; i< len; i++) { + final char character = string.charAt(i); if (character == '\n') { width = 0; } else { @@ -235,7 +244,6 @@ class TypecastFont implements Font { width += glyph.getAdvance(pixelSize, false); } } - return (int)(width + 0.5f); } @@ -243,12 +251,10 @@ class TypecastFont implements Font { public float getStringHeight(CharSequence string, float pixelSize) { int height = 0; - for (int i=0; i 0) { - totalHeight -= advanceY; + totalHeight += lineHeight; totalWidth = Math.max(curLineWidth, totalWidth); } return new AABBox(0, 0, 0, totalWidth, totalHeight,0); -- cgit v1.2.3