aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-02-03 01:14:10 +0100
committerSven Göthel <[email protected]>2024-02-03 01:14:10 +0100
commit4ba099b97df41be220c4b2816c728e6b8cc1b037 (patch)
tree7c20f28515ed9d5dba71b0721c24b29c8d3d12eb /src/jogl
parent7928ed90104f71fb53ae8201b3140b8e347b83ee (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')
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/Font.java19
-rw-r--r--src/jogl/classes/com/jogamp/graph/font/FontFactory.java28
-rw-r--r--src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java11
3 files changed, 58 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;
}
diff --git a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
index c60629582..0a251a378 100644
--- a/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
+++ b/src/jogl/classes/jogamp/graph/font/typecast/TypecastFont.java
@@ -224,6 +224,17 @@ class TypecastFont implements Font {
public int getGlyphCount() { return font.getGlyphCount(); }
@Override
+ public int getDefinedCount(final CharSequence text) {
+ int res = 0;
+ for(int i=text.length()-1; i>=0; --i) {
+ if( !getGlyph(text.charAt(i)).isUndefined() ) {
+ ++res;
+ }
+ }
+ return res;
+ }
+
+ @Override
public char getGlyphCodepoint(final String name) {
final SymAndID value = nameToGlyph.get(name);
if( null != value ) {