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 je...@apache.org on 2007/11/03 11:51:32 UTC

svn commit: r591583 - in /xmlgraphics/fop/trunk/src: codegen/fonts/ java/org/apache/fop/fonts/ java/org/apache/fop/pdf/

Author: jeremias
Date: Sat Nov  3 03:51:31 2007
New Revision: 591583

URL: http://svn.apache.org/viewvc?rev=591583&view=rev
Log:
More fine-grained mechanism to detect if a font has been used or not. If a font list is given for a text run and each character should be painted in the right font, it might be accessed but never really used. Needed for PDF text painting improvements.

Modified:
    xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java

Modified: xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl?rev=591583&r1=591582&r2=591583&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl (original)
+++ xmlgraphics/fop/trunk/src/codegen/fonts/font-file.xsl Sat Nov  3 03:51:31 2007
@@ -148,8 +148,9 @@
 </xsl:choose>
 
     public char mapChar(char c) {
+        notifyMapOperation();
         char d = mapping.mapChar(c);
-        if(d != 0) {
+        if (d != 0) {
             return d;
         } else {
             return '#';

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java?rev=591583&r1=591582&r2=591583&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/LazyFont.java Sat Nov  3 03:51:31 2007
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.net.URL;
 import java.util.Map;
+
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
 
@@ -166,6 +167,14 @@
     /**
      * {@inheritDoc}
      */
+    public boolean hadMappingOperations() {
+        load(true);
+        return realFont.hadMappingOperations();
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
     public boolean hasChar(char c) {
         load(true);
         return realFont.hasChar(c);
@@ -332,5 +341,6 @@
         load(true);
         return realFontDescriptor.isEmbeddable();
     }
+
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java?rev=591583&r1=591582&r2=591583&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/MultiByteFont.java Sat Nov  3 03:51:31 2007
@@ -214,6 +214,7 @@
      * {@inheritDoc}
      */
     public char mapChar(char c) {
+        notifyMapOperation();
         int retIdx = findGlyphIndex(c);
 
         if (isEmbeddable()) {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java?rev=591583&r1=591582&r2=591583&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/SingleByteFont.java Sat Nov  3 03:51:31 2007
@@ -98,6 +98,7 @@
      * {@inheritDoc}
      */
     public char mapChar(char c) {
+        notifyMapOperation();
         char d = mapping.mapChar(c);
         if (d != 0) {
             return d;
@@ -129,8 +130,5 @@
         this.width[index] = width;
     }
 
-    public char[] getCharsUsed() {
-        return null;
-    }
 }
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java?rev=591583&r1=591582&r2=591583&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java Sat Nov  3 03:51:31 2007
@@ -27,6 +27,8 @@
  */
 public abstract class Typeface implements FontMetrics {
 
+    private long charMapOps = 0;
+    
     /**
      * Get the encoding of the font.
      * @return the encoding
@@ -39,6 +41,23 @@
      * @return the mapped character
      */
     public abstract char mapChar(char c);
+
+    /**
+     * Used for keeping track of character mapping operations in order to determine if a font
+     * was used at all or not.
+     */
+    protected void notifyMapOperation() {
+        this.charMapOps++;
+    }
+    
+    /**
+     * Indicates whether this font had to do any character mapping operations. If that was 
+     * not the case, it's an indication that the font has never actually been used.
+     * @return true if the font had to do any character mapping operations
+     */
+    public boolean hadMappingOperations() {
+        return (this.charMapOps > 0);
+    }
 
     /**
      * Determines whether this font contains a particular character/glyph.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java?rev=591583&r1=591582&r2=591583&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/pdf/PDFResources.java Sat Nov  3 03:51:31 2007
@@ -19,17 +19,16 @@
  
 package org.apache.fop.pdf;
 
-import org.apache.fop.fonts.FontInfo;
-import org.apache.fop.fonts.Typeface;
-import org.apache.fop.fonts.FontDescriptor;
-import org.apache.fop.util.ColorProfileUtil;
-
-// Java
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-import java.util.HashMap;
-import java.util.HashSet;
+
+import org.apache.fop.fonts.FontDescriptor;
+import org.apache.fop.fonts.FontInfo;
+import org.apache.fop.fonts.Typeface;
+import org.apache.fop.util.ColorProfileUtil;
 
 /**
  * class representing a /Resources object.
@@ -97,17 +96,22 @@
      * @param fontInfo font info object to get font information from
      */
    public void addFonts(PDFDocument doc, FontInfo fontInfo) {
-        Map fonts = fontInfo.getUsedFonts();
-        Iterator e = fonts.keySet().iterator();
+        Map usedFonts = fontInfo.getUsedFonts();
+        Iterator e = usedFonts.keySet().iterator();
         while (e.hasNext()) {
             String f = (String)e.next();
-            Typeface font = (Typeface)fonts.get(f);
-            FontDescriptor desc = null;
-            if (font instanceof FontDescriptor) {
-                desc = (FontDescriptor)font;
+            Typeface font = (Typeface)usedFonts.get(f);
+            
+            //Check if the font actually had any mapping operations. If not, it is an indication
+            //that it has never actually been used and therefore doesn't have to be embedded.
+            if (font.hadMappingOperations()) {
+                FontDescriptor desc = null;
+                if (font instanceof FontDescriptor) {
+                    desc = (FontDescriptor)font;
+                }
+                addFont(doc.getFactory().makeFont(
+                    f, font.getFontName(), font.getEncoding(), font, desc));
             }
-            addFont(doc.getFactory().makeFont(
-                f, font.getFontName(), font.getEncoding(), font, desc));
         }
     }
 



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


Re: svn commit: r591583 - in /xmlgraphics/fop/trunk/src: codegen/fonts/ java/org/apache/fop/fonts/ java/org/apache/fop/pdf/

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Nov 5, 2007, at 12:42, Vincent Hennebert wrote:

> Jeremias Maerki wrote:
>> Statistical interest. Increasing a long shouldn't use many more CPU
>> cycles than setting a boolean to true, right?
>
> That’s not a problem of performance. When I see this I simply  
> wonder why
> a long is used while a boolean would be sufficient. Statistical
> interest, why not, although here it only exists when doing a manual
> debugging session.
> That’s not a very big deal anyway since here the class is small, but
> when you encounter such variables in hundreds of other lines of codes,
> believe me, it takes a while before figuring out that they are  
> actually
> used as booleans...

True, or should I say 'one' :-)
Funny, this description somehow reminds me of the times when I  
familiarized myself with the "good old" Win32 API... ;-)



Cheers

Andreas


Re: svn commit: r591583 - in /xmlgraphics/fop/trunk/src: codegen/fonts/ java/org/apache/fop/fonts/ java/org/apache/fop/pdf/

Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Jeremias Maerki wrote:
> Statistical interest. Increasing a long shouldn't use many more CPU
> cycles than setting a boolean to true, right?

That’s not a problem of performance. When I see this I simply wonder why  
a long is used while a boolean would be sufficient. Statistical 
interest, why not, although here it only exists when doing a manual 
debugging session.
That’s not a very big deal anyway since here the class is small, but 
when you encounter such variables in hundreds of other lines of codes, 
believe me, it takes a while before figuring out that they are actually 
used as booleans... A small comment, perhaps?

Vincent

Re: svn commit: r591583 - in /xmlgraphics/fop/trunk/src: codegen/fonts/ java/org/apache/fop/fonts/ java/org/apache/fop/pdf/

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
Statistical interest. Increasing a long shouldn't use many more CPU
cycles than setting a boolean to true, right?

Jeremias Maerki



On 05.11.2007 11:32:09 Vincent Hennebert wrote:
> Hi Jeremias,
> 
> > Modified: 
> > xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java
> > URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java?rev=591583&r1=591582&r2=591583&view=diff
> > ==============================================================================
> > --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java (original)
> > +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java Sat Nov  3 03:51:31 2007
> > @@ -27,6 +27,8 @@
> >   */
> >  public abstract class Typeface implements FontMetrics {
> >  
> > +    private long charMapOps = 0;
> > +    
> >      /**
> >       * Get the encoding of the font.
> >       * @return the encoding
> > @@ -39,6 +41,23 @@
> >       * @return the mapped character
> >       */
> >      public abstract char mapChar(char c);
> > +
> > +    /**
> > +     * Used for keeping track of character mapping operations in order to determine if a font
> > +     * was used at all or not.
> > +     */
> > +    protected void notifyMapOperation() {
> > +        this.charMapOps++;
> > +    }
> > +    
> > +    /**
> > +     * Indicates whether this font had to do any character mapping operations. If that was 
> > +     * not the case, it's an indication that the font has never actually been used.
> > +     * @return true if the font had to do any character mapping operations
> > +     */
> > +    public boolean hadMappingOperations() {
> > +        return (this.charMapOps > 0);
> > +    }
> 
> Basically you need to know whether the font has been used or not. Then 
> why not just use a boolean for charMapOps?
> 
> Vincent


Re: svn commit: r591583 - in /xmlgraphics/fop/trunk/src: codegen/fonts/ java/org/apache/fop/fonts/ java/org/apache/fop/pdf/

Posted by Vincent Hennebert <vi...@anyware-tech.com>.
Hi Jeremias,

> Modified: 
> xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java
> URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java?rev=591583&r1=591582&r2=591583&view=diff
> ==============================================================================
> --- xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java (original)
> +++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fonts/Typeface.java Sat Nov  3 03:51:31 2007
> @@ -27,6 +27,8 @@
>   */
>  public abstract class Typeface implements FontMetrics {
>  
> +    private long charMapOps = 0;
> +    
>      /**
>       * Get the encoding of the font.
>       * @return the encoding
> @@ -39,6 +41,23 @@
>       * @return the mapped character
>       */
>      public abstract char mapChar(char c);
> +
> +    /**
> +     * Used for keeping track of character mapping operations in order to determine if a font
> +     * was used at all or not.
> +     */
> +    protected void notifyMapOperation() {
> +        this.charMapOps++;
> +    }
> +    
> +    /**
> +     * Indicates whether this font had to do any character mapping operations. If that was 
> +     * not the case, it's an indication that the font has never actually been used.
> +     * @return true if the font had to do any character mapping operations
> +     */
> +    public boolean hadMappingOperations() {
> +        return (this.charMapOps > 0);
> +    }

Basically you need to know whether the font has been used or not. Then 
why not just use a boolean for charMapOps?

Vincent