diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-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; } |