You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2010/10/15 20:10:13 UTC

svn commit: r1023048 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java

Author: lehmi
Date: Fri Oct 15 18:10:13 2010
New Revision: 1023048

URL: http://svn.apache.org/viewvc?rev=1023048&view=rev
Log:
PDFBOX-861: fixed the calculation of character widths for type3 fonts

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java?rev=1023048&r1=1023047&r2=1023048&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/util/PDFStreamEngine.java Fri Oct 15 18:10:13 2010
@@ -42,7 +42,9 @@ import org.apache.pdfbox.pdfparser.PDFSt
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.PDResources;
 
+import org.apache.pdfbox.pdmodel.common.PDMatrix;
 import org.apache.pdfbox.pdmodel.font.PDFont;
+import org.apache.pdfbox.pdmodel.font.PDType3Font;
 
 import org.apache.pdfbox.pdmodel.graphics.PDExtendedGraphicsState;
 import org.apache.pdfbox.pdmodel.graphics.PDGraphicsState;
@@ -334,6 +336,7 @@ public class PDFStreamEngine
         //were a single byte will result in two output characters "fi"
         
         final PDFont font = graphicsState.getTextState().getFont();
+        PDMatrix fontMatrix = font.getFontMatrix();
         
         //This will typically be 1000 but in the case of a type3 font
         //this might be a different number
@@ -386,7 +389,18 @@ public class PDFStreamEngine
 
             //todo, handle horizontal displacement
             // get the width and height of this character in text units 
-            float characterHorizontalDisplacementText = (font.getFontWidth( string, i, codeLength )/1000f);
+            float characterHorizontalDisplacementText = font.getFontWidth( string, i, codeLength );
+            // Type3 fonts are providing the width of a character in glyph space units
+            if (font instanceof PDType3Font)
+            {
+                // multiply the witdh with the scaling factor of the font matrix
+                characterHorizontalDisplacementText = characterHorizontalDisplacementText * fontMatrix.getValue(0, 0);
+            }
+            // all other fonts are providing the width of a character in thousandths of a unit of text space
+            else
+            {
+                characterHorizontalDisplacementText = characterHorizontalDisplacementText/1000f;
+            }
             maxVerticalDisplacementText = 
                 Math.max( 
                     maxVerticalDisplacementText,