From 4ba099b97df41be220c4b2816c728e6b8cc1b037 Mon Sep 17 00:00:00 2001 From: Sven Göthel Date: Sat, 3 Feb 2024 01:14:10 +0100 Subject: 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 .. ) --- src/jogl/classes/com/jogamp/graph/font/Font.java | 19 +++++++++++++++ .../classes/com/jogamp/graph/font/FontFactory.java | 28 ++++++++++++++++++++++ 2 files changed, 47 insertions(+) (limited to 'src/jogl/classes/com') 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)}. + *
+     * return a.getDefinedCount(text) >= b.getDefinedCount(text) ? a : b;
+     * 
+ */ + 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; } -- cgit v1.2.3