2002/08/07 04:42:00
[org.ibex.core.git] / src / org / xwt / plat / POSIX.java
index 0be6ced..e47cc9b 100644 (file)
@@ -52,14 +52,14 @@ public class POSIX extends GCJ {
     protected native void eventThread();
     private native void natInit();
 
-    /** returns the $BROWSER environment variable, since System.getenv() is useless */
-    private static native String getBrowserEnvString();
-
+    /** returns the value of the environment variable key, or null if no such key exists */
+    protected native String _getEnv(String key);
+    
     /** spawns a process which is immune to SIGHUP */
     private static native void spawnChildProcess(String[] command);
 
     protected void _newBrowserWindow(String url) {
-        String browserString = getBrowserEnvString();
+        String browserString = getEnv("BROWSER");
         if (browserString == null) {
             browserString = "netscape " + url;
         } else if (browserString.indexOf("%s") != -1) {
@@ -256,19 +256,35 @@ public class POSIX extends GCJ {
     public void initFonts() {
         // use the font list to build nativeFontList
         String[] fonts = listNativeFonts();
+
+        Vector v = new Vector();
         for(int k=0; k<fonts.length; k++) {
+
             String s = fonts[k].toLowerCase();
-            StringTokenizer st = new StringTokenizer(s, "-", false);
-            String[] font = new String[st.countTokens()];
-            
+            String s2 = s;
             try {
-                for(int i=0; st.hasMoreTokens(); i++) font[i] = st.nextToken();
+                v.setSize(0);
+                s = s.substring(s.indexOf('-') + 1);
+                while (s.indexOf('-') != -1) {
+                    v.addElement(s.substring(0, s.indexOf('-')));
+                    s = s.substring(s.indexOf('-') + 1);
+                }
+                v.addElement(s);
+                String[] font = new String[v.size()];
+                v.copyInto(font);
+
+                // limit to iso8559 until we can do I18N properly....
+                if (font.length > 12) {
+                    if (!font[12].equals("iso8859") && !font[12].equals("")) continue;
+                    if (font.length < 14 || !font[13].equals("1")) continue;
+                }
+
                 String name = font[1];
                 String size = font[6];
-                String slant = font[3].equals("i") ? "i" : "";
+                String slant = (font[3].equals("i") || font[3].equals("o")) ? "i" : "";
                 String bold = font[2].equals("bold") ? "b" : "";
-                String tail = s.substring(1 + font[0].length() + 1 + font[1].length() + 1 + font[2].length() + 1 +
-                                          font[3].length() + 1 + font[4].length() + 1);
+                String tail = s2.substring(1 + font[0].length() + 1 + font[1].length() + 1 + font[2].length() + 1 +
+                                           font[3].length() + 1 + font[4].length() + 1);
                 
                 if (bold.equals("*") && slant.equals("*")) {
                     nativeFontList.put(name + size, font[0] + "-" + font[1] + "-regular-r-" + font[4] + "-" + tail);
@@ -285,11 +301,11 @@ public class POSIX extends GCJ {
                     nativeFontList.put(name + size + bold + "i", font[0] + "-" + font[1] + "-" + font[2] + "-i-" + font[4] + "-" + tail);
                     
                 } else {
-                    nativeFontList.put(name + size + bold + slant, s);
+                    nativeFontList.put(name + size + bold + slant, s2);
                     
                 }
             } catch (ArrayIndexOutOfBoundsException e) {
-                if (Log.on) Log.log(this, "skipping incomplete font string " + s);
+                if (Log.on) Log.log(this, "skipping incomplete font string " + s2);
                 continue;
             }
         }
@@ -353,6 +369,7 @@ public class POSIX extends GCJ {
             for(int j=0; j<6; j++) i = target.indexOf('-', i + 1);
             target = target.substring(0, i + 1) + arg.size + target.substring(target.indexOf('-', i+1));
         }
+        if (Log.on) Log.log(POSIX.class, "mapping font \"" + s + "\" to \"" + target + "\"");
         RawData ret = fontStringToStruct(target);
         if (ret == null) ret = fontStringToStruct("fixed");
         xwtFontToFontStruct.put(s, new WrappedRawData(ret));