You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ac...@apache.org on 2008/07/18 11:17:25 UTC

svn commit: r677864 - in /xmlgraphics/fop/branches/Temp_AFPGOCAResources: ./ src/java/org/apache/fop/fonts/FontInfo.java src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java

Author: acumiskey
Date: Fri Jul 18 02:17:24 2008
New Revision: 677864

URL: http://svn.apache.org/viewvc?rev=677864&view=rev
Log:
Merged revisions 677863 via svnmerge from 
https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk

........
  r677863 | acumiskey | 2008-07-18 10:11:10 +0100 (Fri, 18 Jul 2008) | 4 lines
  
  Ok, I am much happier with this fix now, it doesn't feel like a temporary hack anymore :).
  
  I have revised the fontLookup() algorithm in FontInfo so it now first tries to find matching font triplets by iterating over all the font family names *without substitutions*, if this fails it then iterates over all the font family names looking for matching font triplets *with substitutions* rather then just take the last one in the font family name list with substitutions.
........

Modified:
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/   (props changed)
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java
    xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java

Propchange: xmlgraphics/fop/branches/Temp_AFPGOCAResources/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Jul 18 02:17:24 2008
@@ -1 +1 @@
-/xmlgraphics/fop/trunk:1-677679
+/xmlgraphics/fop/trunk:1-677863

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java?rev=677864&r1=677863&r2=677864&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/fonts/FontInfo.java Fri Jul 18 02:17:24 2008
@@ -188,12 +188,12 @@
      * @param family font family
      * @param style font style
      * @param weight font weight
-     * @param substFont true if the font may be substituted with the
+     * @param substitutable true if the font may be substituted with the
      *                  default font if not found
      * @return internal font triplet key
      */
     private FontTriplet fontLookup(String family, String style,
-                             int weight, boolean substFont) {
+                             int weight, boolean substitutable) {
         if (log.isTraceEnabled()) {
             log.trace("Font lookup: " + family + " " + style + " " + weight);
         }
@@ -203,7 +203,7 @@
         // first try given parameters
         String internalFontKey = getInternalFontKey(fontTriplet);
         if (internalFontKey == null) {
-            fontTriplet = fuzzyFontLookup(family, style, weight, startKey, substFont);
+            fontTriplet = fuzzyFontLookup(family, style, weight, startKey, substitutable);
         }
 
         if (fontTriplet != null) {
@@ -345,6 +345,19 @@
         return fontLookup(family, style, weight, true);
     }
 
+    private List/*<FontTriplet>*/ fontLookup(String[] families, String style,
+            int weight, boolean substitutable) {
+        List matchingTriplets = new java.util.ArrayList();
+        FontTriplet triplet = null;
+        for (int i = 0; i < families.length; i++) {
+            triplet = fontLookup(families[i], style, weight, substitutable);
+            if (triplet != null) {
+                matchingTriplets.add(triplet);
+            }
+        }
+        return matchingTriplets;
+    }
+
     /**
      * Looks up a set of fonts.
      * <br>
@@ -363,28 +376,32 @@
         if (families.length == 0) {
             throw new IllegalArgumentException("Specify at least one font family");
         }
-        FontTriplet triplet;
-        List tmpTriplets = new java.util.ArrayList();
-        for (int i = 0, c = families.length; i < c; i++) {
-            boolean substitutable = (i >= families.length - 1);
-            triplet = fontLookup(families[i], style, weight, substitutable);
-            if (triplet != null) {
-                tmpTriplets.add(triplet);
-            }
-        }
-        if (tmpTriplets.size() != 0) {
-            return (FontTriplet[]) tmpTriplets.toArray(TRIPLETS_TYPE);
+        
+        // try matching without substitutions
+        List/*<FontTriplet>*/ matchedTriplets = fontLookup(families, style, weight, false);
+        
+        // if there are no matching font triplets found try with substitutions
+        if (matchedTriplets.size() == 0) {
+            matchedTriplets = fontLookup(families, style, weight, true);
         }
-        StringBuffer sb = new StringBuffer();
-        for (int i = 0, c = families.length; i < c; i++) {
-            if (i > 0) {
-                sb.append(", ");
+
+        // no matching font triplets found!
+        if (matchedTriplets.size() == 0) {
+            StringBuffer sb = new StringBuffer();
+            for (int i = 0, c = families.length; i < c; i++) {
+                if (i > 0) {
+                    sb.append(", ");
+                }
+                sb.append(families[i]);
             }
-            sb.append(families[i]);
+            throw new IllegalStateException(
+                        "fontLookup must return an array with at least one "
+                        + "FontTriplet on the last call. Lookup: " + sb.toString());
+            
         }
-        throw new IllegalStateException(
-                    "fontLookup must return an array with at least one "
-                    + "FontTriplet on the last call. Lookup: " + sb.toString());
+
+        // found some matching fonts so return them
+        return (FontTriplet[]) matchedTriplets.toArray(TRIPLETS_TYPE);
     }
 
     private Set/*<FontTriplet>*/ getLoggedFontKeys() {

Modified: xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java?rev=677864&r1=677863&r2=677864&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java (original)
+++ xmlgraphics/fop/branches/Temp_AFPGOCAResources/src/java/org/apache/fop/render/afp/fonts/AFPFontCollection.java Fri Jul 18 02:17:24 2008
@@ -97,22 +97,6 @@
             fontInfo.addMetrics("F" + num, bf);
             num++;
         }
-        if (fontInfo.fontLookup("Symbol", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
-            FontTriplet ft = fontInfo.fontLookup(
-                    "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontInfo.addFontProperties(
-                    fontInfo.getInternalFontKey(ft),
-                    "Symbol", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            num++;
-        }
-        if (fontInfo.fontLookup("ZapfDingbats", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
-            FontTriplet ft = fontInfo.fontLookup(
-                    "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            fontInfo.addFontProperties(
-                    fontInfo.getInternalFontKey(ft),
-                    "ZapfDingbats", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);
-            num++;
-        }
         if (fontInfo.fontLookup("any", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL) == null) {
             FontTriplet ft = fontInfo.fontLookup(
                     "sans-serif", Font.STYLE_NORMAL, Font.WEIGHT_NORMAL);



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org