pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1678457 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font: PDCIDFont.java PDCIDSystemInfo.java PDType0Font.java
Date Fri, 08 May 2015 23:19:56 GMT
Author: jahewson
Date: Fri May  8 23:19:55 2015
New Revision: 1678457

URL: http://svn.apache.org/r1678457
Log:
PDFBOX-2711: Unicode extraction from Type 0 Identity-H/V fonts with CJK descendants

Added:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java
  (with props)
Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDType0Font.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java?rev=1678457&r1=1678456&r2=1678457&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFont.java Fri May
 8 23:19:55 2015
@@ -375,6 +375,23 @@ public abstract class PDCIDFont implemen
     }
 
     /**
+     * Returns the CIDSystemInfo, or null if it is missing (which isn't allowed but could
happen).
+     */
+    public PDCIDSystemInfo getCIDSystemInfo()
+    {
+        COSDictionary cidSystemInfoDict = (COSDictionary)
+                dict.getDictionaryObject(COSName.CIDSYSTEMINFO);
+
+        PDCIDSystemInfo cidSystemInfo = null;
+        if (cidSystemInfoDict != null)
+        {
+            cidSystemInfo = new PDCIDSystemInfo(cidSystemInfoDict);
+        }
+
+        return cidSystemInfo;
+    }
+    
+    /**
      * Returns the CID for the given character code. If not found then CID 0 is returned.
      *
      * @param code character code

Added: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java?rev=1678457&view=auto
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java
(added)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java
Fri May  8 23:19:55 2015
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.pdfbox.pdmodel.font;
+
+import org.apache.pdfbox.cos.COSBase;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+
+/**
+ * Represents a CIDSystemInfo.
+ *
+ * @author John Hewson
+ */
+public final class PDCIDSystemInfo implements COSObjectable
+{
+    private final COSDictionary dictionary;
+    
+    PDCIDSystemInfo(COSDictionary dictionary)
+    {
+        this.dictionary = dictionary;
+    }
+
+    public String getRegistry()
+    {
+        return dictionary.getNameAsString(COSName.REGISTRY);
+    }
+
+    public String getOrdering()
+    {
+        return dictionary.getNameAsString(COSName.ORDERING);
+    }
+    
+    public int getSupplement()
+    {
+        return dictionary.getInt(COSName.SUPPLEMENT);
+    }
+
+    @Override
+    public COSBase getCOSObject()
+    {
+        return dictionary;
+    }
+}

Propchange: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDSystemInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=1678457&r1=1678456&r2=1678457&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 Fri
May  8 23:19:55 2015
@@ -44,6 +44,7 @@ public class PDType0Font extends PDFont
     private final PDCIDFont descendantFont;
     private CMap cMap, cMapUCS2;
     private boolean isCMapPredefined;
+    private boolean isDescendantCJK;
     private PDCIDFontType2Embedder embedder;
     
     /**
@@ -103,9 +104,9 @@ public class PDType0Font extends PDFont
             throw new IOException("Missing descendant font dictionary");
         }
 
+        descendantFont = PDFontFactory.createDescendantFont(descendantFontDictionary, this);
         readEncoding();
         fetchCMapUCS2();
-        descendantFont = PDFontFactory.createDescendantFont(descendantFontDictionary, this);
     }
 
     /**
@@ -178,6 +179,17 @@ public class PDType0Font extends PDFont
                 LOG.warn("Invalid Encoding CMap in font " + getName());
             }
         }
+        
+        // check if the descendant font is CJK
+        PDCIDSystemInfo ros = descendantFont.getCIDSystemInfo();
+        if (ros != null)
+        {
+            isDescendantCJK = ros.getRegistry().equals("Adobe") &&
+                    (ros.getOrdering().equals("GB1") || 
+                     ros.getOrdering().equals("CNS1") ||
+                     ros.getOrdering().equals("Japan1") ||
+                     ros.getOrdering().equals("Korea1"));
+        }
     }
 
     /**
@@ -203,10 +215,22 @@ public class PDType0Font extends PDFont
             {
                 cMapName = ((COSName)encoding).getName();
             }
-
+            
+            if ("Identity-H".equals(cMapName) || "Identity-V".equals(cMapName))
+            {
+                if (isDescendantCJK)
+                {
+                    cMapName = getCJKCMap(descendantFont.getCIDSystemInfo());
+                }
+                else
+                {
+                    // we can't map Identity-H or Identity-V to Unicode
+                    return;
+                }
+            }
+            
             // try to find the corresponding Unicode (UC2) CMap
-            if (cMapName != null && !cMapName.equals("Identity-H") &&
-                                    !cMapName.equals("Identity-V"))
+            if (cMapName != null)
             {
                 CMap cMap = CMapManager.getPredefinedCMap(cMapName);
                 if (cMap != null)
@@ -223,6 +247,34 @@ public class PDType0Font extends PDFont
     }
 
     /**
+     * Returns the name of CJK CMap represented by the given CIDSystemInfo, if any. 
+     */
+    private String getCJKCMap(PDCIDSystemInfo ros)
+    {
+        // CJK can fallback to using CIDSystemInfo
+        if (ros.getOrdering().equals("GB1"))
+        {
+            return "Adobe-GB1-0";
+        }
+        else if (ros.getOrdering().equals("CNS1"))
+        {
+            return "Adobe-CNS1-0";
+        }
+        else if (ros.getOrdering().equals("Japan1"))
+        {
+            return "Adobe-Japan1-1";
+        }
+        else if (ros.getOrdering().equals("Korea1"))
+        {
+            return "Adobe-Korea1-0";
+        }
+        else
+        {
+            throw new IllegalStateException();
+        }
+    }
+    
+    /**
      * Returns the PostScript name of the font.
      */
     public String getBaseFont()



Mime
View raw message