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 ad...@apache.org on 2006/08/30 00:00:29 UTC

svn commit: r438251 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/FontInfo.java test/layoutengine/standard-testcases/block_font-style.xml

Author: adelmelle
Date: Tue Aug 29 15:00:29 2006
New Revision: 438251

URL: http://svn.apache.org/viewvc?rev=438251&view=rev
Log:
Make FontInfo look for the same font-family and weight first, but with default font-style

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

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java?rev=438251&r1=438250&r2=438251&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/FontInfo.java Tue Aug 29 15:00:29 2006
@@ -53,6 +53,9 @@
     /** 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 @@
      * @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 @@
             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 @@
         }
 
         if (f != null) {
+            if (key != startKey) {
+                notifyFontReplacement(startKey, key);
+            }
             return key;
         } else {
             return null;
@@ -231,13 +244,14 @@
         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 + "'.");
         }
     }
     

Modified: xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/block_font-style.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/block_font-style.xml?rev=438251&r1=438250&r2=438251&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/block_font-style.xml (original)
+++ xmlgraphics/fop/trunk/test/layoutengine/standard-testcases/block_font-style.xml Tue Aug 29 15:00:29 2006
@@ -60,27 +60,21 @@
     <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>



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


Re: svn commit: r438251 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/FontInfo.java test/layoutengine/standard-testcases/block_font-style.xml

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Aug 30, 2006, at 10:24, Chris Bowditch wrote:

> <snip />
> Uhm, just looking more closely at the change you've made here.  
> Shouldn't   FOP also look for the same family but with default  
> weight AND style before trying any family.

Yep, that's one situation I overlooked. Added in the meantime.

Thanks for the feedback.


Cheers,

Andreas




Re: svn commit: r438251 - in /xmlgraphics/fop/trunk: src/java/org/apache/fop/fonts/FontInfo.java test/layoutengine/standard-testcases/block_font-style.xml

Posted by Chris Bowditch <bo...@hotmail.com>.
adelmelle@apache.org wrote:

<snip/>

>              }
> -            // 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 @@
>          }

Uhm, just looking more closely at the change you've made here. Shouldn't 
   FOP also look for the same family but with default weight AND style 
before trying any family. I know Jeremias said there are much more 
sophiscated algorithms we could use here, but the reason I think this 
one extra check is important if the user specifies:

font-family="Symbol" font-weight="bold" font-style="normal"

this will fall back to Helvetica, yet it is very similar to the original 
problem that triggered this change.

Chris