pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1525654 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: pdfviewer/font/TTFGlyph2D.java pdmodel/font/PDType0Font.java
Date Mon, 23 Sep 2013 17:30:16 GMT
Author: lehmi
Date: Mon Sep 23 17:30:15 2013
New Revision: 1525654

URL: http://svn.apache.org/r1525654
Log:
PDFBOX-1283: use a suitable mapping to get the correct width value for an CIDType2 font

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java?rev=1525654&r1=1525653&r2=1525654&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdfviewer/font/TTFGlyph2D.java Mon
Sep 23 17:30:15 2013
@@ -77,6 +77,7 @@ public class TTFGlyph2D implements Glyph
     private Map<Integer, GeneralPath> glyphs = new HashMap<Integer, GeneralPath>();
     private Encoding fontEncoding = null;
     private CMap fontCMap = null;
+    private boolean isCIDFont = false;
     private boolean hasIdentityCIDMapping = false;
     private boolean hasCID2GIDMapping = false;
     private boolean hasTwoByteMappings = false;
@@ -163,6 +164,7 @@ public class TTFGlyph2D implements Glyph
         fontEncoding = pdFont.getFontEncoding();
         if (descFont != null)
         {
+            isCIDFont = true;
             descendantFont = descFont;
             hasIdentityCIDMapping = descendantFont.hasIdentityCIDToGIDMap();
             hasCID2GIDMapping = descendantFont.hasCIDToGIDMap();
@@ -232,15 +234,9 @@ public class TTFGlyph2D implements Glyph
      */
     private int getGlyphcode(int code)
     {
-        if (hasIdentityCIDMapping)
-        {
-            // identity mapping
-            return code;
-        }
-        if (hasCID2GIDMapping)
+        if (isCIDFont)
         {
-            // use the provided CID2GID mapping
-            return descendantFont.mapCIDToGID(code);
+            return getGID(code);
         }
 
         int result = 0;
@@ -308,6 +304,35 @@ public class TTFGlyph2D implements Glyph
     }
 
     /**
+     * Get the GID for the given CIDFont.
+     * 
+     * @param code the given CID
+     * @return the mapped GID
+     */
+    private int getGID(int code)
+    {
+        if (hasIdentityCIDMapping)
+        {
+            // identity mapping
+            return code;
+        }
+        if (hasCID2GIDMapping)
+        {
+            // use the provided CID2GID mapping
+            return descendantFont.mapCIDToGID(code);
+        }
+        if (fontCMap != null)
+        {
+            String string = fontCMap.lookup(code, hasTwoByteMappings ? 2 : 1);
+            if (string != null)
+            {
+                return string.codePointAt(0);
+            }
+        }
+        return code;
+    }
+
+    /**
      * {@inheritDoc}
      */
     @Override

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java?rev=1525654&r1=1525653&r2=1525654&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java Mon
Sep 23 17:30:15 2013
@@ -99,6 +99,28 @@ public class PDType0Font extends PDSimpl
      */
     public float getFontWidth(byte[] c, int offset, int length) throws IOException
     {
+        if (descendantFont instanceof PDCIDFontType2Font)
+        {
+            // a suitable mapping is needed to address the correct width value
+            PDCIDFontType2Font cidType2Font = (PDCIDFontType2Font) descendantFont;
+            int code = getCodeFromArray(c, offset, length);
+            if (cidType2Font.hasIdentityCIDToGIDMap())
+            {
+                return cidType2Font.getFontWidth(code);
+            }
+            else if (cidType2Font.hasCIDToGIDMap() && cidType2Font.mapCIDToGID(code)
> -1)
+            {
+                return getFontWidth(cidType2Font.mapCIDToGID(code));
+            }
+            else if (getCMap() != null)
+            {
+                String mappedString = getCMap().lookup(code, length);
+                if (mappedString != null)
+                {
+                    return cidType2Font.getFontWidth(mappedString.codePointAt(0));
+                }
+            }
+        }
         return descendantFont.getFontWidth(c, offset, length);
     }
 



Mime
View raw message