diff options
author | Sven Göthel <[email protected]> | 2024-02-03 01:14:10 +0100 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-02-03 01:14:10 +0100 |
commit | 4ba099b97df41be220c4b2816c728e6b8cc1b037 (patch) | |
tree | 7c20f28515ed9d5dba71b0721c24b29c8d3d12eb /src/jogl/classes/com | |
parent | 7928ed90104f71fb53ae8201b3140b8e347b83ee (diff) |
Graph/GraphUI: Move getDefault*() to FontFactory and add {get,set}FallbackFont() + Font.getBestCoverage(..); Use fallback-font in MediaButton in case chosen font doesn't match (foreign languages, e.g. 'zho' Chinese .. )
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/font/Font.java | 19 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/graph/font/FontFactory.java | 28 |
2 files changed, 47 insertions, 0 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/font/Font.java b/src/jogl/classes/com/jogamp/graph/font/Font.java index 26557ec00..068363ce4 100644 --- a/src/jogl/classes/com/jogamp/graph/font/Font.java +++ b/src/jogl/classes/com/jogamp/graph/font/Font.java @@ -384,6 +384,25 @@ public interface Font { /** Returns number of {@link Glyph} IDs available, i.e. retrievable via {@link #getGlyph(int)} [0..count). */ int getGlyphCount(); + /** Returns the number of defined {@link Glyph}s (coverage), i.e. not {@link Glyph#isUndefined()}, of given text. */ + int getDefinedCount(final CharSequence text); + + /** + * Returns {@link Font} with best coverage for given text while favoring {@code a}. See {@link #getDefinedCount(CharSequence)}. + * <pre> + * return a.getDefinedCount(text) >= b.getDefinedCount(text) ? a : b; + * </pre> + */ + public static Font getBestCoverage(final Font a, final Font b, final CharSequence text) { + if( null != a && null != b ) { + return a.getDefinedCount(text) >= b.getDefinedCount(text) ? a : b; + } else if( null != a ) { + return a; + } else { + return b; + } + } + /** Returns the {@link Glyph} (unicode) `codepoint` symbol mapped to given {@link Glyph} `name`. */ char getGlyphCodepoint(final String name); diff --git a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java index cd39abdfe..eb74c5696 100644 --- a/src/jogl/classes/com/jogamp/graph/font/FontFactory.java +++ b/src/jogl/classes/com/jogamp/graph/font/FontFactory.java @@ -217,4 +217,32 @@ public class FontFactory { final Character.UnicodeBlock block = Character.UnicodeBlock.of( c ); return block != null && block != Character.UnicodeBlock.SPECIALS; } + + /** Returns {@link FontSet#getDefault() default} {@link Font} of {@link #getDefault() default} {@link FontSet} or {@code null} if n/a */ + public static Font getDefaultFont() { + try { + return getDefault().getDefault(); + } catch(final IOException ioe) { + ioe.printStackTrace(); + return null; + } + } + + /** Returns the default symbols {@link Font} or {@code null} if n/a */ + public static Font getSymbolsFont() { + try { + return get(SYMBOLS).getDefault(); + } catch(final IOException ioe) { + ioe.printStackTrace(); + return null; + } + } + + /** Returns registered fallback {@link Font}, maybe {@code null}. See {@link #setFallbackFont(Font)}. */ + public static synchronized Font getFallbackFont() { + return fallbackFont; + } + /** Registers given {@link Font} as the default fallback font. */ + public static synchronized void setFallbackFont(final Font f) { fallbackFont = f; } + private static Font fallbackFont = null; } |