]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Some fonts have spaces in their names (ex. "Arial Unicode MS"). This change modifies...
authorJeremias Maerki <jeremias@apache.org>
Wed, 31 Oct 2007 16:39:04 +0000 (16:39 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 31 Oct 2007 16:39:04 +0000 (16:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@590736 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fonts/CustomFont.java
src/java/org/apache/fop/fonts/autodetect/FontInfoFinder.java

index 4ad24b08b1f6a3ee5c85b84fdeeb4aa7248a49df..916597746a2925c7896a7491577f15577e0270f2 100644 (file)
@@ -21,6 +21,7 @@ package org.apache.fop.fonts;
 
 import java.io.IOException;
 import java.util.Map;
+
 import javax.xml.transform.Source;
 
 /**
@@ -60,6 +61,16 @@ public abstract class CustomFont extends Typeface
     }
 
     /**
+     * Return the font family.
+     * @return the font family
+     */
+    public String getFontFamily() {
+        return fontName;
+    }
+
+    /**
+     * Returns the font family name stripped of whitespace.
+     * @return the stripped font family
      * @see FontUtil#stripWhiteSpace(String)
      */
     public String getStrippedFontName() {
@@ -243,7 +254,6 @@ public abstract class CustomFont extends Typeface
         }
     }
 
-
     /* ---- MutableFont interface ---- */
 
     /**
index 0f7cf0de98c0854704f8a0577be993a6cbd938a8..bb7e00505036f5870b9a1184d66e4e7b11a4706f 100644 (file)
@@ -22,6 +22,7 @@ package org.apache.fop.fonts.autodetect;
 import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
+import java.util.Collection;
 import java.net.URL;
 import java.util.List;
 
@@ -51,17 +52,17 @@ public class FontInfoFinder {
     private static final String[] BOLD_WORDS = {"bold", "black", "heavy", "ultra", "super"};
 
     /**
-     * Attempts to determine FontTriplet from a given CustomFont.
+     * Attempts to determine FontTriplets from a given CustomFont.
      * It seems to be fairly accurate but will probably require some tweaking over time
      * 
      * @param customFont CustomFont
-     * @return newly created font triplet
+     * @param triplet Collection that will take the generated triplets
      */
-    private FontTriplet tripletFromFont(CustomFont customFont) {
+    private void generateTripletsFromFont(CustomFont customFont, Collection triplets) {
         // default style and weight triplet vales (fallback)
-        String name = customFont.getStrippedFontName();
+        String strippedName = customFont.getStrippedFontName();
         String subName = customFont.getFontSubName();
-        String searchName = name.toLowerCase();
+        String searchName = strippedName.toLowerCase();
         if (subName != null) {
             searchName += subName.toLowerCase();
         }
@@ -87,7 +88,11 @@ public class FontInfoFinder {
                 break;
             }            
         }
-        return new FontTriplet(name, style, weight);
+        triplets.add(new FontTriplet(strippedName, style, weight));
+        String familyName = customFont.getFontFamily();
+        if (!strippedName.equals(familyName)) {
+            triplets.add(new FontTriplet(familyName, style, weight));
+        }
     }
     
     /**
@@ -99,9 +104,8 @@ public class FontInfoFinder {
      */
     private EmbedFontInfo fontInfoFromCustomFont(
             URL fontUrl, CustomFont customFont, FontCache fontCache) {
-        FontTriplet fontTriplet = tripletFromFont(customFont);
         List fontTripletList = new java.util.ArrayList();
-        fontTripletList.add(fontTriplet);
+        generateTripletsFromFont(customFont, fontTripletList);
         String embedUrl;
         embedUrl = fontUrl.toExternalForm();
         EmbedFontInfo fontInfo = new EmbedFontInfo(null, customFont.isKerningEnabled(),