pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1620178 - in /pdfbox/branches/no-awt: fontbox/src/main/java/org/apache/fontbox/cff/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ pdfbox/src/main/java/org/apache/pdfbox/rendering/ pdfbox/src/main/java/org/apache/pdfbox/rendering/font/
Date Sun, 24 Aug 2014 19:30:51 GMT
Author: jahewson
Date: Sun Aug 24 19:30:50 2014
New Revision: 1620178

URL: http://svn.apache.org/r1620178
Log:
PDFBOX-2262: Support Type 0 fonts where Top DICT that does not use CIDFont operators

Modified:
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFType1Font.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
    pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDType0Glyph2D.java

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFType1Font.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFType1Font.java?rev=1620178&r1=1620177&r2=1620178&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFType1Font.java
(original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFType1Font.java
Sun Aug 24 19:30:50 2014
@@ -90,6 +90,25 @@ public class CFFType1Font extends CFFFon
         int sid = charset.getSID(name);
         int gid = charset.getGIDForSID(sid);
 
+        // lookup in CharStrings INDEX
+        return getType2CharString(gid, name);
+    }
+
+    /**
+     * Returns the Type 1 charstring for the given GID.
+     *
+     * @param gid GID
+     * @throws IOException if the charstring could not be read
+     */
+    public Type2CharString getType2CharString(int gid) throws IOException
+    {
+        String name = "GID+" + gid; // for debugging only
+        return getType2CharString(gid, name);
+    }
+
+    // Returns the Type 1 charstring for the given GID, with name for debugging
+    private Type2CharString getType2CharString(int gid, String name) throws IOException
+    {
         Type2CharString type2 = charStringCache.get(gid);
         if (type2 == null)
         {
@@ -101,7 +120,7 @@ public class CFFType1Font extends CFFFon
             Type2CharStringParser parser = new Type2CharStringParser(fontName, name);
             List<Object> type2seq = parser.parse(bytes, globalSubrIndex, getLocalSubrIndex());
             type2 = new Type2CharString(reader, fontName, name, gid, type2seq, getDefaultWidthX(),
-                                        getNominalWidthX());
+                    getNominalWidthX());
             charStringCache.put(gid, type2);
         }
         return type2;

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java?rev=1620178&r1=1620177&r2=1620178&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
(original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType0.java
Sun Aug 24 19:30:50 2014
@@ -20,10 +20,11 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.cff.CFFCIDFont;
+import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
+import org.apache.fontbox.cff.CFFType1Font;
+import org.apache.fontbox.cff.Type2CharString;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.io.IOUtils;
 import org.apache.pdfbox.pdmodel.common.PDStream;
@@ -36,9 +37,9 @@ import org.apache.pdfbox.pdmodel.common.
  */
 public class PDCIDFontType0 extends PDCIDFont
 {
-    private static final Log LOG = LogFactory.getLog(PDCIDFontType0.class);
+    private final CFFCIDFont cidFont;  // Top DICT that uses CIDFont operators
+    private final CFFType1Font t1Font; // Top DICT that does not use CIDFont operators
 
-    private CFFCIDFont cffFont = null;
     private final Map<Integer, Float> glyphHeights = new HashMap<Integer, Float>();
     private Float avgWidth = null;
     private final boolean isEmbedded;
@@ -67,15 +68,26 @@ public class PDCIDFontType0 extends PDCI
         {
             // embedded
             CFFParser cffParser = new CFFParser();
-            cffFont = (CFFCIDFont)cffParser.parse(bytes).get(0);
+            CFFFont cffFont = cffParser.parse(bytes).get(0);
+            if (cffFont instanceof CFFCIDFont)
+            {
+                cidFont = (CFFCIDFont)cffFont;
+                t1Font = null;
+            }
+            else
+            {
+                cidFont = null;
+                t1Font = (CFFType1Font)cffFont;
+            }
             isEmbedded = true;
         }
         else
         {
             // substitute
-            cffFont = ExternalFonts.getCFFCIDFont(getBaseFont());
+            cidFont = ExternalFonts.getCFFCIDFont(getBaseFont());
+            t1Font = null;
 
-            if (cffFont == null)
+            if (cidFont == null)
             {
                 // todo: log message + substitute? But what would we substitute with?
                 throw new UnsupportedOperationException("not implemented: missing CFF");
@@ -87,9 +99,34 @@ public class PDCIDFontType0 extends PDCI
     /**
      * Returns the embedded CFF CIDFont.
      */
-    public CFFCIDFont getCFFCIDFont()
+    public CFFFont getCFFFont()
     {
-        return cffFont;
+        if (cidFont != null)
+        {
+            return cidFont;
+        }
+        else
+        {
+            return t1Font;
+        }
+    }
+
+    /**
+     * Returns the Type 2 charstring for the given CID.
+     *
+     * @param cid CID
+     * @throws IOException if the charstring could not be read
+     */
+    public Type2CharString getType2CharString(int cid) throws IOException
+    {
+        if (cidFont != null)
+        {
+            return cidFont.getType2CharString(cid);
+        }
+        else
+        {
+            return t1Font.getType2CharString(cid);
+        }
     }
 
     /**
@@ -107,14 +144,24 @@ public class PDCIDFontType0 extends PDCI
     public int codeToGID(int code)
     {
         int cid = codeToCID(code);
-        return cffFont.getCharset().getGIDForCID(cid);
+        if (cidFont != null)
+        {
+            // The CIDs shall be used to determine the GID value for the glyph procedure
using the
+            // charset table in the CFF program
+            return cidFont.getCharset().getGIDForCID(cid);
+        }
+        else
+        {
+            // The CIDs shall be used directly as GID values
+            return cid;
+        }
     }
 
     @Override
     protected float getWidthFromFont(int code) throws IOException
     {
         int cid = codeToCID(code);
-        return cffFont.getType2CharString(cid).getWidth();
+        return getType2CharString(cid).getWidth();
     }
 
     @Override
@@ -131,7 +178,7 @@ public class PDCIDFontType0 extends PDCI
         float height = 0;
         if (!glyphHeights.containsKey(cid))
         {
-            height =  (float)cffFont.getType2CharString(cid).getBounds().getHeight();
+            height =  (float) getType2CharString(cid).getBounds().getHeight();
             glyphHeights.put(cid, height);
         }
         return height;
@@ -153,15 +200,4 @@ public class PDCIDFontType0 extends PDCI
         // todo: not implemented, highly suspect
         return 500;
     }
-
-    @Override
-    public void clear()
-    {
-        super.clear();
-        if (cffFont != null)
-        {
-            //cffFont.clear();
-            cffFont = null;
-        }
-    }
 }

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1620178&r1=1620177&r2=1620178&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
(original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Sun Aug 24 19:30:50 2014
@@ -454,12 +454,7 @@ public class PageDrawer extends PDFGraph
             {
                 // a Type0 CIDFont contains CFF font
                 PDCIDFontType0 cidType0Font = (PDCIDFontType0)type0Font.getDescendantFont();
-
-                CFFCIDFont cffCIDFont = cidType0Font.getCFFCIDFont(); // todo: could be null
(need incorporate fallback)
-                if (cffCIDFont != null)
-                {
-                    glyph2D = new CIDType0Glyph2D(cidType0Font);
-                }
+                glyph2D = new CIDType0Glyph2D(cidType0Font); // todo: could be null (need
incorporate fallback)
             }
         }
         else

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDType0Glyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDType0Glyph2D.java?rev=1620178&r1=1620177&r2=1620178&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDType0Glyph2D.java
(original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDType0Glyph2D.java
Sun Aug 24 19:30:50 2014
@@ -22,7 +22,6 @@ import java.util.HashMap;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.fontbox.cff.CFFCIDFont;
 import org.apache.fontbox.cff.Type2CharString;
 import org.apache.pdfbox.pdmodel.font.PDCIDFontType0;
 
@@ -70,8 +69,7 @@ public class CIDType0Glyph2D implements 
 
         try
         {
-            CFFCIDFont cidFont = font.getCFFCIDFont();
-            Type2CharString charString = cidFont.getType2CharString(cid);
+            Type2CharString charString = font.getType2CharString(cid);
 
             if (charString.getGID() == 0)
             {



Mime
View raw message