]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Make FontInfo look for the same font-family and weight first, but with default font...
authorAndreas L. Delmelle <adelmelle@apache.org>
Tue, 29 Aug 2006 22:00:29 +0000 (22:00 +0000)
committerAndreas L. Delmelle <adelmelle@apache.org>
Tue, 29 Aug 2006 22:00:29 +0000 (22:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@438251 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/fonts/FontInfo.java
test/layoutengine/standard-testcases/block_font-style.xml

index 0104798044a227427f499a29871efeebe2d9230d..993de884898b5b143848513885fc8f24f11ce04a 100644 (file)
@@ -53,6 +53,9 @@ public class FontInfo {
     /** look up a font-name to get a font (that implements FontMetrics at least) */
     private Map fonts;
     
+    /** collection of missing fonts; used to make sure the user gets 
+     *  a warning for a missing font only once (not every time the font is used)
+     */
     private Collection loggedFontKeys;
 
     /** Cache for Font instances. */
@@ -121,7 +124,8 @@ public class FontInfo {
      * @param family font family
      * @param style font style
      * @param weight font weight
-     * @param substFont true if the font may be substituted with the default font if not found
+     * @param substFont true if the font may be substituted with the 
+     *                  default font if not found
      * @return internal key
      */
     private FontTriplet fontLookup(String family, String style,
@@ -138,9 +142,15 @@ public class FontInfo {
             if (!substFont && f == null) {
                 return null;
             }
-            // then try any family with orig weight
+            
+            // try the same font-family and weight with default style
+            if (f == null) {
+                key = createFontKey(family, "normal", weight);
+                f = getInternalFontKey(key);
+            }
+            
+            // then try any family with orig style/weight
             if (f == null) {
-                notifyFontReplacement(startKey);
                 key = createFontKey("any", style, weight);
                 f = getInternalFontKey(key);
             }
@@ -153,6 +163,9 @@ public class FontInfo {
         }
 
         if (f != null) {
+            if (key != startKey) {
+                notifyFontReplacement(startKey, key);
+            }
             return key;
         } else {
             return null;
@@ -231,13 +244,14 @@ public class FontInfo {
         throw new IllegalStateException("fontLookup must return a key on the last call");
     }
     
-    private void notifyFontReplacement(FontTriplet key) {
+    private void notifyFontReplacement(FontTriplet replacedKey, FontTriplet newKey) {
         if (loggedFontKeys == null) {
             loggedFontKeys = new java.util.HashSet();
         }
-        if (!loggedFontKeys.contains(key)) {
-            loggedFontKeys.add(key);
-            log.warn("Font '" + key + "' not found. Substituting with default font.");
+        if (!loggedFontKeys.contains(replacedKey)) {
+            loggedFontKeys.add(replacedKey);
+            log.warn("Font '" + replacedKey + "' not found. "
+                    + "Substituting with '" + newKey + "'.");
         }
     }
     
index 8e84674db971cea0fa38efef3b65c6c1dd9cb312..829eea4a9ff07fbfe3165f1e2335fc2808639f3e 100644 (file)
     <eval expected="normal" xpath="//flow/block[2]/lineArea/text/@font-style"/>
     <eval expected="italic" xpath="//flow/block[3]/lineArea/text/@font-style"/>
     <eval expected="oblique" xpath="//flow/block[4]/lineArea/text/@font-style"/>
-    <eval expected="normal" xpath="//flow/block[5]/lineArea/text/@font-style"/>
-    <eval expected="any" xpath="//flow/block[5]/lineArea/text/@font-name"/> <!-- style not registered -> any, normal -->
-    <eval expected="normal" xpath="//flow/block[6]/lineArea/text/@font-style"/>
-    <eval expected="serif" xpath="//flow/block[6]/lineArea/text/@font-name"/> <!-- illegal style -> back to default=serif, normal -->
+    <eval expected="normal" xpath="//flow/block[5]/lineArea/text/@font-style"/> <!-- style not registered -> normal -->
+    <eval expected="normal" xpath="//flow/block[6]/lineArea/text/@font-style"/> <!-- illegal style -> normal -->
 
     <eval expected="normal" xpath="//flow/block[7]/lineArea/text/@font-style"/>
     <eval expected="normal" xpath="//flow/block[8]/lineArea/text/@font-style"/>
     <eval expected="italic" xpath="//flow/block[9]/lineArea/text/@font-style"/>
     <eval expected="oblique" xpath="//flow/block[10]/lineArea/text/@font-style"/>
-    <eval expected="normal" xpath="//flow/block[11]/lineArea/text/@font-style"/>
-    <eval expected="any" xpath="//flow/block[11]/lineArea/text/@font-name"/> <!-- style not registered -> any, normal -->
-    <eval expected="normal" xpath="//flow/block[12]/lineArea/text/@font-style"/>
-    <eval expected="sans-serif" xpath="//flow/block[12]/lineArea/text/@font-name"/> <!-- illegal style -> back to default=sans-serif, normal -->
+    <eval expected="normal" xpath="//flow/block[11]/lineArea/text/@font-style"/> <!-- style not registered -> normal -->
+    <eval expected="normal" xpath="//flow/block[12]/lineArea/text/@font-style"/> <!-- illegal style -> normal -->
 
     <eval expected="normal" xpath="//flow/block[13]/lineArea/text/@font-style"/>
     <eval expected="normal" xpath="//flow/block[14]/lineArea/text/@font-style"/>
     <eval expected="italic" xpath="//flow/block[15]/lineArea/text/@font-style"/>
     <eval expected="oblique" xpath="//flow/block[16]/lineArea/text/@font-style"/>
-    <eval expected="normal" xpath="//flow/block[17]/lineArea/text/@font-style"/>
-    <eval expected="any" xpath="//flow/block[17]/lineArea/text/@font-name"/> <!-- style not registered -> any, normal -->
-    <eval expected="normal" xpath="//flow/block[18]/lineArea/text/@font-style"/>
-    <eval expected="monospace" xpath="//flow/block[18]/lineArea/text/@font-name"/> <!-- illegal style -> back to default=monospace, normal -->
+    <eval expected="normal" xpath="//flow/block[17]/lineArea/text/@font-style"/> <!-- style not registered -> normal -->
+    <eval expected="normal" xpath="//flow/block[18]/lineArea/text/@font-style"/> <!-- illegal style -> normal -->
   </checks>
 </testcase>