From f6dd8e9562d7e0bbf681c268f40ff4c819057915 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 1 Sep 2023 11:57:47 +0200 Subject: Graph Font + Glyph: Fix whitespace definition: Include 'no original underlying shape' and add API doc Regression was introduced with commit 920e529516bb264f04138ed1caca80d4925e3773 'Robust detetection and API definition of non-contour/whitespace Glyphs'. Issue was mistaken a glyph as undefined if not having an underlying shape, which is true for some fonts (e.g. 'space'). +++ Also Use post table's name if no underlying shape exists. --- src/jogl/classes/com/jogamp/graph/font/Font.java | 30 ++++++++++++---------- .../jogamp/graph/font/typecast/TypecastFont.java | 16 +++++++----- 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'src/jogl/classes') diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index ef1179153..c3c997135 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -176,22 +176,10 @@ public interface Font { String getName(); /** - * Return true if the glyph is a whitespace, otherwise false. - *

- * A whitespace glyph has no {@link #getShape()}, but a valid {@link #getBounds()} and {@link #getAdvance()}. - *

- * Being a whitespace glyph excludes {@link #isUndefined()}. - * @see #isUndefined() - * @see #isNonContour() - */ - boolean isWhitespace(); - - /** - * Return true if the Glyph denotes an undefined {@link #getID()} symbol as follows + * Return true if the Glyph denotes an undefined {@link #getID()} symbol, determined as follows * *

* An undefined glyph has no {@link #getShape()} if glyph index is not {@link #ID_UNKNOWN}. @@ -205,6 +193,22 @@ public interface Font { */ boolean isUndefined(); + /** + * Return true if the Glyph denotes a whitespace, determined as follows + *

+ *

+ * A whitespace glyph has no {@link #getShape()}, but a valid {@link #getBounds()} and {@link #getAdvance()}. + *

+ * Being a whitespace glyph excludes {@link #isUndefined()}. + * @see #isUndefined() + * @see #isNonContour() + */ + boolean isWhitespace(); + /** * Returns true if {@link #isWhitespace()} or {@link #isUndefined()}. * @see #isWhitespace() diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java index 8bc832633..b153b813e 100644 --- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java +++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java @@ -198,19 +198,18 @@ class TypecastFont implements Font { if (null == result) { final jogamp.graph.font.typecast.ot.Glyph glyph = font.getGlyph(glyph_id); final String glyph_name; - if( null != glyph ) { + { final PostTable post = font.getPostTable(); glyph_name = null != post ? post.getGlyphName(glyph_id) : ""; - } else { - glyph_name = ""; } - final boolean isUndefined = Glyph.ID_UNKNOWN == glyph_id || null == glyph || TypecastGlyph.isUndefName(glyph_name); + final boolean isUndefined = Glyph.ID_UNKNOWN == glyph_id || TypecastGlyph.isUndefName(glyph_name); final int glyph_height = metrics.getAscentFU() - metrics.getDescentFU(); final int glyph_advance; final int glyph_leftsidebearings; final boolean isWhitespace; final AABBox glyph_bbox; final OutlineShape shape; + final int mode; if( null != glyph ) { glyph_advance = glyph.getAdvanceWidth(); glyph_leftsidebearings = glyph.getLeftSideBearing(); @@ -221,19 +220,22 @@ class TypecastFont implements Font { isWhitespace = isUndefined ? false : os.getBounds().hasZero2DArea(); glyph_bbox = sb; shape = ( !isWhitespace && !isUndefined ) || Glyph.ID_UNKNOWN == glyph_id ? os : null; + mode = 1; } else { // Case 2: Non-contour glyph -> whitespace or undefined isWhitespace = !isUndefined; glyph_bbox = new AABBox(0f,0f,0f, glyph_advance, glyph_height, 0f); shape = Glyph.ID_UNKNOWN == glyph_id ? TypecastRenderer.buildEmptyShape(metrics.getUnitsPerEM(), glyph_bbox) : null; + mode = 2; } } else { - // Case 3: Non-contour glyph -> undefined + // Case 3: Non-contour glyph -> whitespace or undefined glyph_advance = getAdvanceWidthFU(glyph_id); glyph_leftsidebearings = 0; - isWhitespace = false; + isWhitespace = !isUndefined; glyph_bbox = new AABBox(0f,0f,0f, glyph_advance, glyph_height, 0f); shape = Glyph.ID_UNKNOWN == glyph_id ? TypecastRenderer.buildEmptyShape(metrics.getUnitsPerEM(), glyph_bbox) : null; + mode = 3; } KernSubtable kernSub = null; { @@ -245,7 +247,7 @@ class TypecastFont implements Font { result = new TypecastGlyph(this, glyph_id, glyph_name, glyph_bbox, glyph_advance, glyph_leftsidebearings, kernSub, shape, isUndefined, isWhitespace); if( DEBUG || TypecastRenderer.DEBUG ) { - System.err.println("New glyph: " + glyph_id + "/'"+glyph_name+"', shape " + (null != shape)); + System.err.println("New glyph: " + glyph_id + "/'"+glyph_name+"', shape " + (null != shape)+", mode "+mode); System.err.println(" tc_glyph "+glyph); System.err.println(" glyph "+result); } -- cgit v1.2.3