- fontList = new String[fontListVec.size()];
- fontListVec.toArray(fontList);
- fontListVec = null;
- }
-
-
- // Font Handling ////////////////////////////////////////////////////////////////////////////
-
- // FEATURE: query the registry for the user's default font
- protected String _getDefaultFont() { return "dialog8"; }
- protected int _getMaxAscent(String font) { return getFont(font).maxAscent; }
- protected int _getMaxDescent(String font) { return getFont(font).maxDescent; }
- protected native int _stringWidth(String font, String text);
-
- // methods/members used to enumerate platform fonts on startup
- public static Vector fontListVec = new Vector();
- public static String[] fontList = null;
- protected String[] _listFonts() { return fontList; }
- public static void addFont(String name, int height, boolean italic, boolean bold) {
- fontListVec.addElement(name.replace(' ', '_').toLowerCase() + "" + height + (italic ? "i" : "") + (bold ? "b" : ""));
- }
-
- static Hash fontCache = new Hash();
- public static class Win32Font {
- int hfont;
- int maxAscent;
- int maxDescent;
- }
-
- /** Called once XWT is initialized and the application is running. On Win32, we need to block the main thread
- * on a semaphore because if the main thread exits, the whole application quits. */
- protected void _running() {
- // gcj-win32 exit()'s when the original thread dies, so we have to deadlock ourselves
- if (Log.on) Log.log(Main.class, "main thread blocking on new semaphore");
- new org.xwt.util.Semaphore().block();
- }
-
- /** takes a parsed font and finds the closest platform-specific font */
- static native Win32Font mapFont(Platform.ParsedFont pf);
-
- /** takes an unparsed font and finds the closest platform-specific font */
- static Win32Font getFont(String font) {
- Win32Font ret = (Win32Font)fontCache.get(font);
- if (ret != null) return ret;
-
- Platform.ParsedFont pf = new Platform.ParsedFont(font);
- if (pf.name.equals("serif")) pf.name = "Times New Roman";
- else if (pf.name.equals("sansserif")) pf.name = "Arial";
- else if (pf.name.equals("monospace")) pf.name = "Courier New";
- else if (pf.name.equals("dialog")) pf.name = "MS Sans Serif";
- else if (pf.name.equals("tty")) pf.name = "FixedSys";
-
- ret = mapFont(pf);
- fontCache.put(font, ret);
- return ret;