From 55356d999638491980a90cb2263b55c5d2e53e91 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 30 Mar 2011 06:59:43 +0200 Subject: Font Refactoring ; Misc Changes ; Demo/Test Update Font Refactoring - Notion of distributed FontSet - FontFactory may produce FontSet and/or a Font by absolute ttf file path - Adding support for free Ubuntu fonts - Remove Vertex.Factory dependency for Font creation - Typecast Impl - Fix CmapTable selection - Fix horizontal spacing of space - Misc Changes - HwTextRenderer - Offer reshape for perspective and orthogonal view - Expose PMVMatrix, allowing user to setup their own view math. Demo Update - Dump font set a-zA-Z... - Dump 'lazy dog ..' text - Action: - s: toogle 'font set' - f: toggle fps - v: toggle v-sync - space: toggle font (ubuntu/java) - formated screenshot filename w/ font name Test Update: - add font set iteration --- src/jogamp/graph/font/JavaFontLoader.java | 157 ++++++++++++++++-------------- 1 file changed, 82 insertions(+), 75 deletions(-) (limited to 'src/jogamp/graph/font/JavaFontLoader.java') 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