Hello!

Here is my patch on font-family property implementation. It allows the propery 
to contain comma-separated list of font family names. Actually this patch 
doesn't go so far as spec does by introducing concept of glyph lookup in each 
font in turn, it only implements search for the first registered font family 
through the list and I believe that's enough at the stage fop currently is 
(btw, XEP also doesn't support that glyph lookup).

-- 
Oleg Tkachenko
Multiconn International Ltd, Israel
Index: FontInfo.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/layout/FontInfo.java,v
retrieving revision 1.12
diff -u -r1.12 FontInfo.java
--- FontInfo.java       11 Sep 2001 10:04:25 -0000      1.12
+++ FontInfo.java       10 Jun 2002 08:48:40 -0000
@@ -73,6 +73,10 @@
         return this.triplets.get(key) != null;
     }
 
+    public boolean hasFont(String key) {
+        return this.triplets.get(key) != null;
+    }
+
     /**
      * Creates a key from the given strings
      */
Index: FontState.java
===================================================================
RCS file: /home/cvspublic/xml-fop/src/org/apache/fop/layout/FontState.java,v
retrieving revision 1.14.2.3
diff -u -r1.14.2.3 FontState.java
--- FontState.java      12 Feb 2002 01:02:24 -0000      1.14.2.3
+++ FontState.java      10 Jun 2002 08:48:41 -0000
@@ -8,6 +8,7 @@
 package org.apache.fop.layout;
 
 import java.util.Hashtable;
+import java.util.StringTokenizer;
 
 import org.apache.fop.apps.FOPException;
 import org.apache.fop.fo.properties.FontVariant;
@@ -37,7 +38,43 @@
         _fontStyle = fontStyle;
         _fontWeight = fontWeight;
         _fontSize = fontSize;
-        _fontName = fontInfo.fontLookup(fontFamily, fontStyle, fontWeight);
+        String _fontKey = FontInfo.createFontKey(_fontFamily, _fontStyle, 
+_fontWeight);
+        //Quick check-out for simple font family
+        if (!fontInfo.hasFont(_fontKey)) {
+            //Tokenizes font-family list
+            StringTokenizer st = new StringTokenizer(_fontFamily, ",");
+            while (st.hasMoreTokens()) {
+                String token = st.nextToken().trim();
+                //Checks for quoted font family name
+                if (token.charAt(0) == '"' || token.charAt(0) == '\'')
+                    token = token.substring(1, token.length()-1);
+                else {
+                    //In a nonquoted font family name any sequence of whitespace
+                    //inside should be converted to a single space
+                    StringBuffer sb = new StringBuffer();
+                    boolean spaced = false;
+                    for (int i=0; i<token.length(); i++) {
+                        char c = token.charAt(i);
+                        if (!isWhitespace(c)) {
+                            sb.append(c);
+                            spaced = false;
+                        }
+                        else if (!spaced) {
+                            sb.append(c);
+                            spaced = true;
+                        }
+                    }
+                    token = sb.toString();
+                }
+                //Checks found font family name for existence
+                _fontKey = FontInfo.createFontKey(token, _fontStyle, _fontWeight);
+                if (fontInfo.hasFont(_fontKey)) {
+                    _fontFamily = token;
+                    break;
+                }
+            }
+        }
+        _fontName = fontInfo.fontLookup(_fontKey);
         _metric = fontInfo.getMetricsFor(_fontName);
         _fontVariant = fontVariant;
         _letterSpacing = 0;
@@ -51,6 +88,14 @@
         _letterSpacing = letterSpacing;
     }
 
+    private static boolean isWhitespace(char ch) {
+        return (ch <= 0x0020) &&
+            (((((1L << 0x0009) |
+            (1L << 0x000A) |
+            (1L << 0x000C) |
+            (1L << 0x000D) |
+            (1L << 0x0020)) >> ch) & 1L) != 0);
+    }
 
     public int getAscender() {
         return _metric.getAscender(_fontSize) / 1000;

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to