aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogamp/graph/font/JavaFontLoader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogamp/graph/font/JavaFontLoader.java')
-rw-r--r--src/jogamp/graph/font/JavaFontLoader.java157
1 files changed, 82 insertions, 75 deletions
diff --git a/src/jogamp/graph/font/JavaFontLoader.java b/src/jogamp/graph/font/JavaFontLoader.java
index f6954944d..6769a691a 100644
--- a/src/jogamp/graph/font/JavaFontLoader.java
+++ b/src/jogamp/graph/font/JavaFontLoader.java
@@ -27,85 +27,92 @@
*/
package jogamp.graph.font;
-public class JavaFontLoader {
+import com.jogamp.common.util.IntObjectHashMap;
+import com.jogamp.graph.font.Font;
+import com.jogamp.graph.font.FontSet;
+import com.jogamp.graph.font.FontFactory;
- static String javaFontPath;
- static
- {
- javaFontPath = System.getProperty("java.home") + "/lib/fonts/";
- }
+public class JavaFontLoader implements FontSet {
+
+ final static FontSet fontLoader = new JavaFontLoader();
- public static final int MAX_BITMAP_FONT_SIZE = 120;
+ public static FontSet get() {
+ return fontLoader;
+ }
+
+ final static String availableFontFileNames[] =
+ {
+ /* 00 */ "LucidaBrightRegular.ttf",
+ /* 01 */ "LucidaBrightItalic.ttf",
+ /* 02 */ "LucidaBrightDemiBold.ttf",
+ /* 03 */ "LucidaBrightDemiItalic.ttf",
+ /* 04 */ "LucidaSansRegular.ttf",
+ /* 05 */ "LucidaSansDemiBold.ttf",
+ /* 06 */ "LucidaTypewriterRegular.ttf",
+ /* 07 */ "LucidaTypewriterBold.ttf",
+ };
+
+ final String javaFontPath;
+
+ private JavaFontLoader() {
+ javaFontPath = System.getProperty("java.home") + "/lib/fonts/";
+ }
- public static final int MONOSPACED = 1;
- public static final int SERIF = 2;
- public static final int SANSERIF = 3;
- public static final int CURSIVE = 4;
- public static final int FANTASY = 5;
-
- final static String availableJavaFontNames[] =
- {
- "Lucida Bright Regular",
- "Lucida Bright Italic",
- "Lucida Bright Demibold",
- "Lucida Bright Demibold Italic",
- "Lucida Sans Regular",
- "Lucida Sans Demibold",
- "Lucida Sans Typewriter Regular",
- "Lucida Sans Typewriter Bold",
- };
- static public String[] getAvailableNames()
- {
- return availableJavaFontNames;
- }
-
- final static String availableJavaFontFileNames[] =
- {
- "LucidaBrightRegular.ttf",
- "LucidaBrightItalic.ttf",
- "LucidaBrightDemiBold.ttf",
- "LucidaBrightDemiItalic.ttf",
- "LucidaSansRegular.ttf",
- "LucidaSansDemiBold.ttf",
- "LucidaTypewriterRegular.ttf",
- "LucidaTypewriterBold.ttf",
- };
+ static final IntObjectHashMap fontMap = new IntObjectHashMap();
+
+ public Font getDefault() {
+ return get(FAMILY_REGULAR, 0) ; // Sans Serif Regular
+ }
+
+ public Font get(int family, int style) {
+ Font font = (Font)fontMap.get( ( family << 8 ) | style );
+ if (font != null) {
+ return font;
+ }
- static public String get(int type)
- {
- String font = null;
-
- switch (type)
- {
- case MONOSPACED:
- font = getByName("Lucida Sans Typewriter Regular");
- break;
- case SERIF:
- font = getByName("Lucida Bright Regular");
- break;
- case SANSERIF:
- font = getByName("Lucida Sans Regular");
- break;
- case CURSIVE:
- font = getByName("Lucida Bright Regular");
- break;
- case FANTASY:
- font = getByName("Lucida Sans Regular");
- break;
- }
+ // 1st process Sans Serif (2 fonts)
+ if( 0 == ( style & STYLE_SERIF ) ) {
+ if( 0 != ( style & STYLE_BOLD ) ) {
+ font = abspath(availableFontFileNames[5]);
+ } else {
+ font = abspath(availableFontFileNames[4]);
+ }
+ return font;
+ }
+
+ // Serif Fonts ..
+ switch (family) {
+ case FAMILY_LIGHT:
+ case FAMILY_MEDIUM:
+ case FAMILY_CONDENSED:
+ case FAMILY_REGULAR:
+ if( 0 != ( style & STYLE_BOLD ) ) {
+ if( 0 != ( style & STYLE_ITALIC ) ) {
+ font = abspath(availableFontFileNames[3]);
+ } else {
+ font = abspath(availableFontFileNames[2]);
+ }
+ } else if( 0 != ( style & STYLE_ITALIC ) ) {
+ font = abspath(availableFontFileNames[1]);
+ } else {
+ font = abspath(availableFontFileNames[0]);
+ }
+ break;
+
+ case FAMILY_MONOSPACED:
+ if( 0 != ( style & STYLE_BOLD ) ) {
+ font = abspath(availableFontFileNames[7]);
+ } else {
+ font = abspath(availableFontFileNames[6]);
+ }
+ break;
+ }
- return font;
- }
+ return font;
+ }
+
+ Font abspath(String fname) {
+ return FontFactory.getFontConstr().create(javaFontPath+fname);
+ }
- static public String getByName(String name)
- {
- for (int i=0; i<availableJavaFontNames.length; i++)
- {
- if (name.equals(availableJavaFontNames[i]) == true)
- {
- return javaFontPath+availableJavaFontFileNames[i];
- }
- }
- return null;
- }
}