diff options
author | Sven Gothel <[email protected]> | 2023-02-16 05:41:37 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-02-16 05:41:37 +0100 |
commit | 4aca9d8252afbdc9e7dfd234c086f889623bb140 (patch) | |
tree | 900460e7bb608d98e18f01eef0c4cb7907abc9a8 /src/jogl/classes/jogamp | |
parent | 996ffe0df682981c0eba88130e134c4f94a06415 (diff) |
Graph Font: Enhance API doc (source of values), better get*Bounds() names, dropping redundant getMetricWidth*(); Fix getMetricBoundsFU()
Diffstat (limited to 'src/jogl/classes/jogamp')
3 files changed, 39 insertions, 61 deletions
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index eeee14365..f5358b74b 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -254,53 +254,13 @@ class TypecastFont implements Font { public int getLineHeightFU() { final Metrics metrics = getMetrics(); final int lineGap = metrics.getLineGapFU() ; // negative value! - final int ascent = metrics.getAscentFU() ; // negative value! final int descent = metrics.getDescentFU() ; // positive value! + final int ascent = metrics.getAscentFU() ; // negative value! final int advanceY = lineGap - descent + ascent; // negative value! return -advanceY; } @Override - public float getMetricWidth(final CharSequence string) { - return metrics.getScale( getMetricWidthFU(string) ); - } - - @Override - public int getMetricWidthFU(final CharSequence string) { - int width = 0; - final int len = string.length(); - for (int i=0; i< len; i++) { - final char character = string.charAt(i); - if (character == '\n') { - width = 0; - } else { - final Glyph glyph = getGlyph(getGlyphID(character)); - width += glyph.getAdvanceFU(); - } - } - return width; - } - - @Override - public float getMetricHeight(final CharSequence string) { - return metrics.getScale( getMetricHeightFU(string) ); - } - - @Override - public int getMetricHeightFU(final CharSequence string) { - int height = 0; - - for (int i=0; i<string.length(); i++) { - final char character = string.charAt(i); - if (character != ' ') { - final Glyph glyph = getGlyph(getGlyphID(character)); - height = (int)Math.ceil(Math.max(glyph.getBBoxFU().getHeight(), height)); - } - } - return height; - } - - @Override public AABBox getMetricBounds(final CharSequence string) { return getMetricBoundsFU(string).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]); } @@ -310,6 +270,7 @@ class TypecastFont implements Font { if (null == string || 0 == string.length() ) { return new AABBox(); } + final AABBox res = new AABBox(); final int charCount = string.length(); final int lineHeight = getLineHeightFU(); @@ -322,23 +283,28 @@ class TypecastFont implements Font { if (character == '\n') { advanceTotal = 0; y -= lineHeight; - continue; + } else if (character == ' ') { + advanceTotal += getAdvanceWidthFU(Glyph.ID_SPACE); + } else { + advanceTotal += getAdvanceWidthFU( getGlyphID( character ) ); } - advanceTotal += getAdvanceWidthFU( getGlyphID( character ) ); + res.resize(advanceTotal, y, 0f); } - if (advanceTotal > 0) { + if( 0 < advanceTotal ) { + // add one line for current non '\n' terminated y -= lineHeight; + res.resize(advanceTotal, y, 0f); } - return new AABBox(0,y,0, advanceTotal,0,0); + return res; } @Override - public AABBox getPointsBounds(final AffineTransform transform, final CharSequence string) { - return getPointsBoundsFU(transform, string).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]); + public AABBox getGlyphBounds(final CharSequence string) { + return getGlyphBoundsFU(string).scale2(1.0f/metrics.getUnitsPerEM(), new float[3]); } @Override - public AABBox getPointsBoundsFU(final AffineTransform transform, final CharSequence string) { + public AABBox getGlyphBoundsFU(final CharSequence string) { if (null == string || 0 == string.length() ) { return new AABBox(); } @@ -366,11 +332,7 @@ class TypecastFont implements Font { left_glyph = null; } else { // reset transform - if( null != transform ) { - temp1.setTransform(transform); - } else { - temp1.setToIdentity(); - } + temp1.setToIdentity(); final int glyph_id = getGlyphID(character); final Font.Glyph glyph = getGlyph(glyph_id); final OutlineShape glyphShape = glyph.getShape(); @@ -391,7 +353,11 @@ class TypecastFont implements Font { } @Override - public AABBox getPointsBounds2(final AffineTransform transform, final CharSequence string) { + public AABBox getGlyphShapeBounds(final CharSequence string) { + return getGlyphShapeBounds(null, string); + } + @Override + public AABBox getGlyphShapeBounds(final AffineTransform transform, final CharSequence string) { if (null == string || 0 == string.length() ) { return new AABBox(); } diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java index 9db8fc6d5..12d492f6e 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastGlyph.java @@ -65,7 +65,7 @@ public final class TypecastGlyph implements Font.Glyph { /** in font-units */ public final AABBox getBBoxFU() { return this.bbox; } - /** Return advance in font units to be divided by unitsPerEM */ + /** Return advance in font units, sourced from `hmtx` table. */ public final int getAdvanceFU() { return this.advance; } @Override @@ -187,6 +187,12 @@ public final class TypecastGlyph implements Font.Glyph { } @Override + public final AABBox getBBox() { + final AABBox dest = new AABBox(); + return dest.copy(metrics.getBBoxFU()).scale2(1.0f/metrics.getUnitsPerEM(), new float[2]); + } + + @Override public final int getAdvanceFU() { return metrics.getAdvanceFU(); } @Override diff --git a/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java b/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java index 03a2394d9..5bb610a1c 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/ot/Glyph.java @@ -31,25 +31,31 @@ public abstract class Glyph { public Glyph(final int glyph_id) { _glyph_id = glyph_id; } - + /** Return the assigned glyph ID of this instance */ public final int getID() { return _glyph_id; } - + public abstract void clearPointData(); - /** Return the AABBox in font-units */ + /** + * Return the AABBox in font-units. + * <p> + * This is either the GlyphDescripton's min- and maximum for TTF + * or the calculated box over all points. + * </p> + */ public final AABBox getBBox() { return _bbox; } - + /** hmtx value */ public abstract int getAdvanceWidth(); - + /** hmtx value */ public abstract short getLeftSideBearing(); public abstract Point getPoint(int i); public abstract int getPointCount(); - + @Override public abstract String toString(); } |