You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by je...@apache.org on 2011/03/22 16:20:38 UTC

svn commit: r1084212 - in /xmlgraphics/batik/trunk: CHANGES sources/org/apache/batik/bridge/TextUtilities.java sources/org/apache/batik/css/engine/value/css2/FontFamilyManager.java sources/org/apache/batik/gvt/font/FontFamilyResolver.java

Author: jeremias
Date: Tue Mar 22 15:20:38 2011
New Revision: 1084212

URL: http://svn.apache.org/viewvc?rev=1084212&view=rev
Log:
Bugzilla #49968:
Internally registers not only font families but also makes font available through their font names.
All CSS font weights are now handled for font selection
Font families containing numbers (like "Univers 45 Light") no longer cause errors.

Modified:
    xmlgraphics/batik/trunk/CHANGES
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/TextUtilities.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/value/css2/FontFamilyManager.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/font/FontFamilyResolver.java

Modified: xmlgraphics/batik/trunk/CHANGES
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/CHANGES?rev=1084212&r1=1084211&r2=1084212&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/CHANGES (original)
+++ xmlgraphics/batik/trunk/CHANGES Tue Mar 22 15:20:38 2011
@@ -12,7 +12,7 @@ Bug fixing is an on-going task, so it is
     42408, 43411, 43847, 43950, 44553, 44590, 44919, 44936, 44966,
     45112, 45114, 45117, 45397, 45520, 45883, 45958, 46072, 46124,
     46202, 46430, 46431, 46855, 46871, 47201, 47202, 48182, 48411,
-    49889, 50006, 50100
+    49889, 49968, 50006, 50100
 
 
 2. New features
@@ -37,6 +37,9 @@ Bug fixing is an on-going task, so it is
   * Batik now tries to access content in HTTP error responses (for example, one
     is able to setup custom content for missing - HTTP code 404 - and/or other
     erroneous situations).
+  * Internally registers not only font families but also makes font available
+    through their font names.
+  * All CSS font weights are now handled for font selection
 
 4. Bug fixes
 
@@ -73,6 +76,8 @@ Bug fixing is an on-going task, so it is
   * Correctly handle individual missing <view> attributes by looking at
     the closest ancestor SVG element.
   * Fixed HeadlessExceptions related to WMF transcoding.
+  * Font families containing numbers (like "Univers 45 Light") no longer
+    cause errors.
 
 5. Misc
 

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/TextUtilities.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/TextUtilities.java?rev=1084212&r1=1084211&r2=1084212&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/TextUtilities.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/TextUtilities.java Tue Mar 22 15:20:38 2011
@@ -219,17 +219,25 @@ public abstract class TextUtilities impl
         case 500:
             return TextAttribute.WEIGHT_SEMIBOLD;
         default:
-            return TextAttribute.WEIGHT_BOLD;
-            /* Would like to do this but the JDK 1.3 & 1.4
-               seems to drop back to 'REGULAR' instead of 'BOLD'
-               if there is not a match.
-        case 700:
-            return TextAttribute.WEIGHT_HEAVY;
-        case 800:
-            return TextAttribute.WEIGHT_EXTRABOLD;
-        case 900:
-            return TextAttribute.WEIGHT_ULTRABOLD;
-            */
+            String javaVersionString = System.getProperty("java.specification.version");
+            float javaVersion = (javaVersionString != null
+                    ? Float.parseFloat(javaVersionString) : 1.5f);
+            if (javaVersion < 1.5) {
+                // Would like to do this but the JDK 1.3 & 1.4
+                // seems to drop back to 'REGULAR' instead of 'BOLD'
+                // if there is not a match.
+                return TextAttribute.WEIGHT_BOLD;
+            }
+            switch ((int)f) {
+            case 700:
+                return TextAttribute.WEIGHT_HEAVY;
+            case 800:
+                return TextAttribute.WEIGHT_EXTRABOLD;
+            case 900:
+                return TextAttribute.WEIGHT_ULTRABOLD;
+            default:
+                return TextAttribute.WEIGHT_BOLD;
+            }
         }
     }
 

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/value/css2/FontFamilyManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/value/css2/FontFamilyManager.java?rev=1084212&r1=1084211&r2=1084212&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/value/css2/FontFamilyManager.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/css/engine/value/css2/FontFamilyManager.java Tue Mar 22 15:20:38 2011
@@ -147,14 +147,20 @@ public class FontFamilyManager extends A
             case LexicalUnit.SAC_IDENT:
                 StringBuffer sb = new StringBuffer(lu.getStringValue());
                 lu = lu.getNextLexicalUnit();
-                if (lu != null &&
-                    lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT) {
+                if (lu != null && isIdentOrNumber(lu)) {
                     do {
                         sb.append(' ');
-                        sb.append(lu.getStringValue());
+                        switch (lu.getLexicalUnitType()) {
+                        case LexicalUnit.SAC_IDENT:
+                            sb.append(lu.getStringValue());
+                            break;
+                        case LexicalUnit.SAC_INTEGER:
+                            //Some font names contain integer values but are not quoted!
+                            //Example: "Univers 45 Light"
+                            sb.append(Integer.toString(lu.getIntegerValue()));
+                        }
                         lu = lu.getNextLexicalUnit();
-                    } while (lu != null &&
-                             lu.getLexicalUnitType() == LexicalUnit.SAC_IDENT);
+                    } while (lu != null && isIdentOrNumber(lu));
                     result.append(new StringValue(CSSPrimitiveValue.CSS_STRING,
                                                   sb.toString()));
                 } else {
@@ -167,17 +173,25 @@ public class FontFamilyManager extends A
                                         (CSSPrimitiveValue.CSS_STRING, id));
                 }
             }
-            if (lu == null) {
+            if (lu == null)
                 return result;
-            }
-            if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA) {
+            if (lu.getLexicalUnitType() != LexicalUnit.SAC_OPERATOR_COMMA)
                 throw createInvalidLexicalUnitDOMException
                     (lu.getLexicalUnitType());
-            }
             lu = lu.getNextLexicalUnit();
-            if (lu == null) {
+            if (lu == null)
                 throw createMalformedLexicalUnitDOMException();
-            }
+        }
+    }
+
+    private boolean isIdentOrNumber(LexicalUnit lu) {
+        short type = lu.getLexicalUnitType();
+        switch (type) {
+        case LexicalUnit.SAC_IDENT:
+        case LexicalUnit.SAC_INTEGER:
+            return true;
+        default:
+            return false;
         }
     }
 

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/font/FontFamilyResolver.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/font/FontFamilyResolver.java?rev=1084212&r1=1084211&r2=1084212&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/font/FontFamilyResolver.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/gvt/font/FontFamilyResolver.java Tue Mar 22 15:20:38 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.batik.gvt.font;
 
+import java.awt.Font;
 import java.awt.GraphicsEnvironment;
 import java.util.Collection;
 import java.util.HashMap;
@@ -92,6 +93,15 @@ public class FontFamilyResolver {
             }
         }
 
+        //Also register all font names, not just font families.
+        //Example: Font Family: "Univers", but Font Name: "Univers 45 Light"
+        //Without this, matching "Univers 45 Light" is not possible.
+        Font[] allFonts = env.getAllFonts();
+        for (int i = 0; i < allFonts.length; i++) {
+            Font f = allFonts[i];
+            fonts.put(f.getFontName().toLowerCase(), f.getFontName());
+        }
+
         // first add the default font
         awtFontFamilies.add(defaultFont);
         awtFonts.add(new AWTGVTFont(defaultFont.getFamilyName(), 0, 12));