diff options
author | Sven Gothel <[email protected]> | 2023-09-24 16:50:49 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-09-24 16:50:49 +0200 |
commit | a8de1673ca83475227fcc914fd94a9a0be1cba79 (patch) | |
tree | f180bafeb037fd66eed565236a054322fe5e229e /src/jogl/classes/com/jogamp/graph | |
parent | 0c8700589abffe13e42f18d3c755541268d44a34 (diff) |
Bug 1462 - Graph Font: Add name + codepoint to ID and Glyph mapping plus traversing through all Glyphs
See UISceneDemo03
new Button(options.renderModes, fontSymbols, " "+fontSymbols.getUTF16String("pause")+" ", buttonWidth, buttonHeight); // pause
Unicode codepoint symbol is also contained in FontGlyph
Diffstat (limited to 'src/jogl/classes/com/jogamp/graph')
3 files changed, 78 insertions, 24 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java index 47f8e1b2a..2cd40c6e4 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/GLRegion.java @@ -186,7 +186,7 @@ public abstract class GLRegion extends Region { final int[] vertIndexCount = { 0, 0 };
final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() {
@Override
- public final void visit(final char symbol, final Font.Glyph glyph) {
+ public final void visit(final Font.Glyph glyph) {
if( !glyph.isNonContour() ) {
Region.countOutlineShape(glyph.getShape(), vertIndexCount);
}
diff --git a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java index 782615c3e..e6e4f3e0c 100644 --- a/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java +++ b/src/jogl/classes/com/jogamp/graph/curve/opengl/TextRegionUtil.java @@ -144,7 +144,7 @@ public class TextRegionUtil { final AffineTransform temp1, final AffineTransform temp2) { final Font.GlyphVisitor visitor = new Font.GlyphVisitor() { @Override - public void visit(final char symbol, final Glyph glyph, final AffineTransform t) { + public void visit(final Glyph glyph, final AffineTransform t) { if( !glyph.isNonContour() ) { region.addOutlineShape(glyph.getShape(), t, rgbaColor); } @@ -173,7 +173,7 @@ public class TextRegionUtil { public static int[] countStringRegion(final Font font, final CharSequence str, final int[/*2*/] vertIndexCount) { final Font.GlyphVisitor2 visitor = new Font.GlyphVisitor2() { @Override - public final void visit(final char symbol, final Font.Glyph glyph) { + public final void visit(final Font.Glyph glyph) { if( !glyph.isNonContour() ) { Region.countOutlineShape(glyph.getShape(), vertIndexCount); } diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 997eacbb8..c8682a4e5 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -240,11 +240,11 @@ public interface Font { */ AABBox getBounds(); - /** Return advance in font units, sourced from `hmtx` table. */ - int getAdvanceFU(); + /** Returns advance in font units, sourced from `hmtx` table. */ + int getAdvanceWidthFU(); - /** Return advance in font em-size [0..1], sourced from `hmtx` table. */ - float getAdvance(); + /** Returns advance in font em-size [0..1], sourced from `hmtx` table. */ + float getAdvanceWidth(); /** Return leftSideBearings in font units, sourced from `hmtx` table. */ int getLeftSideBearingsFU(); @@ -258,7 +258,7 @@ public interface Font { /** True if kerning values are perpendicular to text flow, otherwise along with flow */ boolean isKerningCrossstream(); - /** Return the number of kerning values stored for this glyph, associated to a right hand glyph. */ + /** Returns the number of kerning values stored for this glyph, associated to a right hand glyph. */ int getKerningPairCount(); /** @@ -295,25 +295,47 @@ public interface Font { public static interface GlyphVisitor { /** * Visiting the given {@link Font.Glyph} having an {@link OutlineShape} with it's corresponding {@link AffineTransform}. - * @param symbol the character symbol matching the given glyph * @param glyph {@link Font.Glyph} which contains an {@link OutlineShape} via {@link Font.Glyph#getShape()}. * @param t may be used immediately as is, otherwise a copy shall be made if stored. */ - public void visit(final char symbol, final Glyph glyph, final AffineTransform t); + public void visit(final Glyph glyph, final AffineTransform t); } /** - * Constrained {@link Font.Glyph} visitor w/o {@link AffineTransform}. + * General purpose {@link Font.Glyph} visitor w/o {@link AffineTransform}. */ public static interface GlyphVisitor2 { /** - * Visiting the given {@link Font.Glyph} having an {@link OutlineShape}. - * @param symbol the character symbol matching the given glyph - * @param glyph {@link Font.Glyph} which contains an {@link OutlineShape} via {@link Font.Glyph#getShape()}. + * Visiting the given {@link Font.Glyph} + * @param glyph {@link Font.Glyph} which may contain an {@link OutlineShape} via {@link Font.Glyph#getShape()}. */ - public void visit(final char symbol, final Glyph glyph); + public void visit(final Glyph glyph); } + /** + * General purpose (unicode) `codepoint` symbol and {@link Font.Glyph} ID visitor without enforcing {@link Glyph} caching. + */ + public static interface CodepointIDVisitor { + /** + * Visiting the given (unicode) `codepoint` symbol and {@link Font.Glyph} ID. + * @param codepoint (unicode) `codepoint` symbol + * @param glyph_id {@link Font.Glyph} ID + */ + public void visit(final char codepoint, final int glyph_id); + } + + /** + * Returns UTF-16 representation of the specified (unicode) `codepoint` symbol like {@link Character#toChars(int)} or {@link Character#toString()}. + * <p> + * The returned string can be inserted in any text. + * </p> + * @param codepoint the (unicode) `codepoint` symbol + * @return the Java {@link String} conforming result + */ + public static String getUTF16String(final char codepoint) { + return Character.toString(codepoint); + // return new String(Character.toChars(codepoint)); + } String getName(final int nameIndex); @@ -343,32 +365,64 @@ public interface Font { boolean equals(final Object o); /** - * Return advance-width of given glyphID in font-units, sourced from `hmtx` table. + * Returns advance-width of given glyphID in font-units, sourced from `hmtx` table - same as {@link Glyph#getAdvanceWidthFU()}. * @param glyphID */ int getAdvanceWidthFU(final int glyphID); /** - * Return advance-width of given glyphID in font em-size [0..1], sourced from `hmtx` table. + * Returns advance-width of given glyphID in font em-size [0..1], sourced from `hmtx` table - same as {@link Glyph#getAdvanceWidth()}. * @param glyphID */ float getAdvanceWidth(final int glyphID); Metrics getMetrics(); - /** Return the {@link Glyph} ID mapped to given `symbol`, usually UTF16 unicode. Returned ID can be used to retrieve the {@link Glyph} via {@link #getGlyph(int)}. */ - int getGlyphID(final char symbol); - - /** Return number of {@link Glyph} IDs available, i.e. retrievable via {@link #getGlyph(int)} [0..count). */ + /** Returns number of {@link Glyph} IDs available, i.e. retrievable via {@link #getGlyph(int)} [0..count). */ int getGlyphCount(); - /** Return the {@link Glyph} using given ID, see {@link #getGlyphCount()}. */ + /** Returns the {@link Glyph} (unicode) `codepoint` symbol mapped to given {@link Glyph} `name`. */ + char getGlyphCodepoint(final String name); + + /** + * Returns UTF-16 representation of the specified {@link Glyph} `name` using {@link #getGlyphCodepoint(String)} and {@link #getUTF16String(char)}. + * <p> + * The returned string can be inserted in any text. + * </p> + * @param codepoint the (unicode) `codepoint` symbol + * @return the Java {@link String} conforming result + */ + String getUTF16String(final String name); + + /** Returns the {@link Glyph} ID mapped to given UTF16 (unicode) `codepoint` symbol. */ + int getGlyphID(final char codepoint); + + /** Returns the {@link Glyph} mapped to given `name`. */ + Glyph getGlyph(final String name); + + /** Returns the {@link Glyph} mapped to given (unicode) `codepoint` symbol. */ + Glyph getGlyph(final char codepoint); + + /** Returns the {@link Glyph} using given ID. */ Glyph getGlyph(final int glyph_id); - int getNumGlyphs(); + /** + * Visit all (unicode) `codepoint` symbol and {@link Glyph} ID tuple of this font. + * @param visitor handling each (unicode) `codepoint` symbol and {@link Glyph} ID tuple. + */ + void forAllCodepoints(final Font.CodepointIDVisitor visitor); + + /** + * Visit all {@link Glyph}s of this font. + * <p> + * Warning: All {@link Glyph}s will be cached. + * </p> + * @param visitor handling each {@link Glyph} + */ + void forAllGlyphs(final Font.GlyphVisitor2 visitor); /** - * Return line height, baseline-to-baseline in font-units, composed from `hhea' table entries. + * Returns line height, baseline-to-baseline in font-units, composed from `hhea' table entries. * <pre> * return ascent - descent + linegap; * </pre> |