pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1618754 - in /pdfbox/branches/no-awt: fontbox/src/main/java/org/apache/fontbox/cff/ fontbox/src/main/java/org/apache/fontbox/cmap/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/ pdfbox/src/main/java/org/apache/pdfbox/rendering/font/
Date Mon, 18 Aug 2014 21:40:13 GMT
Author: jahewson
Date: Mon Aug 18 21:40:13 2014
New Revision: 1618754

URL: http://svn.apache.org/r1618754
Log:
PDFBOX-2262: Implement FDSelect for CIDFonts

Added:
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/FDSelect.java
      - copied, changed from r1618534, pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CIDKeyedFDSelect.java
Removed:
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CIDKeyedFDSelect.java
Modified:
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFCIDFont.java
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
    pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.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/font/CIDGlyph2D.java

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFCIDFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFCIDFont.java?rev=1618754&r1=1618753&r2=1618754&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFCIDFont.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFCIDFont.java Mon
Aug 18 21:40:13 2014
@@ -39,7 +39,7 @@ public class CFFCIDFont extends CFFFont
 
     private List<Map<String, Object>> fontDictionaries = new LinkedList<Map<String,Object>>();
     private List<Map<String, Object>> privateDictionaries = new LinkedList<Map<String,Object>>();
-    private CIDKeyedFDSelect fdSelect;
+    private FDSelect fdSelect;
 
     private final Map<Integer, CIDKeyedType2CharString> charStringCache =
             new HashMap<Integer, CIDKeyedType2CharString>();
@@ -110,7 +110,7 @@ public class CFFCIDFont extends CFFFont
      *
      * @return the fontDict
      */
-    public List<Map<String, Object>> getFontDict() 
+    public List<Map<String, Object>> getFontDicts()
     {
         return fontDictionaries;
     }
@@ -130,7 +130,7 @@ public class CFFCIDFont extends CFFFont
      *
      * @return the privDict
      */
-    public List<Map<String, Object>> getPrivDict() 
+    public List<Map<String, Object>> getPrivDicts()
     {
         return privateDictionaries;
     }
@@ -150,7 +150,7 @@ public class CFFCIDFont extends CFFFont
      *
      * @return the fdSelect
      */
-    public CIDKeyedFDSelect getFdSelect() 
+    public FDSelect getFdSelect()
     {
         return fdSelect;
     }
@@ -160,7 +160,7 @@ public class CFFCIDFont extends CFFFont
      *
      * @param fdSelect the fdSelect to set
      */
-    void setFdSelect(CIDKeyedFDSelect fdSelect)
+    void setFdSelect(FDSelect fdSelect)
     {
         this.fdSelect = fdSelect;
     }
@@ -173,7 +173,7 @@ public class CFFCIDFont extends CFFFont
      */
     private int getDefaultWidthX(int cid)
     {
-        int fdArrayIndex = this.fdSelect.getFd(cid);
+        int fdArrayIndex = this.fdSelect.getFDIndex(cid);
         if (fdArrayIndex == -1)
         {
             return 1000;
@@ -190,7 +190,7 @@ public class CFFCIDFont extends CFFFont
      */
     private int getNominalWidthX(int cid)
     {
-        int fdArrayIndex = this.fdSelect.getFd(cid);
+        int fdArrayIndex = this.fdSelect.getFDIndex(cid);
         if (fdArrayIndex == -1)
         {
             return 0;
@@ -201,7 +201,7 @@ public class CFFCIDFont extends CFFFont
 
     private IndexData getLocalSubrIndex(int cid)
     {
-        int fdArrayIndex = this.fdSelect.getFd(cid);
+        int fdArrayIndex = this.fdSelect.getFDIndex(cid);
         if (fdArrayIndex == -1)
         {
             return new IndexData(0);

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java?rev=1618754&r1=1618753&r2=1618754&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CFFParser.java Mon
Aug 18 21:40:13 2014
@@ -509,7 +509,7 @@ public class CFFParser
         DictData.Entry fdSelectEntry = topDict.getEntry("FDSelect");
         int fdSelectPos = fdSelectEntry.getNumber(0).intValue();
         input.setPosition(fdSelectPos);
-        CIDKeyedFDSelect fdSelect = readFDSelect(input, charStringsIndex.getCount(), font);
+        FDSelect fdSelect = readFDSelect(input, charStringsIndex.getCount(), font);
 
         // todo: almost certainly erroneous - CIDFonts do not have a top-level private dict
         //font.addValueToPrivateDict("defaultWidthX", 1000);
@@ -727,7 +727,7 @@ public class CFFParser
      * @return the FDSelect data
      * @throws IOException
      */
-    private CIDKeyedFDSelect readFDSelect(CFFDataInput dataInput, int nGlyphs, CFFCIDFont
ros) throws IOException
+    private FDSelect readFDSelect(CFFDataInput dataInput, int nGlyphs, CFFCIDFont ros) throws
IOException
     {
         int format = dataInput.readCard8();
         if (format == 0)
@@ -799,9 +799,9 @@ public class CFFParser
     }
 
     /**
-     *  Container of a Format 3 FDSelect data (see "The Compact Font Format Specification"
chapter "FDSelect" ).
+     *  Format 3 FDSelect data.
      */
-    private static class Format3FDSelect extends CIDKeyedFDSelect
+    private static class Format3FDSelect extends FDSelect
     {
         private int format;
         private int nbRanges;
@@ -813,21 +813,16 @@ public class CFFParser
             super(owner);
         }
 
-        /*
-         * (non-Javadoc)
-         * 
-         * @see org.apache.fontbox.cff.CIDKeyedFDSelect#getFd(int)
-         */
         @Override
-        public int getFd(int glyph)
+        public int getFDIndex(int gid)
         {
             for (int i = 0; i < nbRanges; ++i)
             {
-                if (range3[i].first >= glyph)
+                if (range3[i].first >= gid)
                 {
                     if (i + 1 < nbRanges)
                     {
-                        if (range3[i + 1].first > glyph)
+                        if (range3[i + 1].first > gid)
                         {
                             return range3[i].fd;
                         }
@@ -838,8 +833,8 @@ public class CFFParser
                     }
                     else
                     {
-                        // last range reach, the sentinel must be greater than sid
-                        if (sentinel > glyph)
+                        // last range reach, the sentinel must be greater than gid
+                        if (sentinel > gid)
                         {
                             return range3[i].fd;
                         }
@@ -877,9 +872,9 @@ public class CFFParser
     }
 
     /**
-     *  Container of a Format 0 FDSelect data (see "The Compact Font Format Specification"
chapter "FDSelect" ).
+     *  Format 0 FDSelect.
      */
-    private static class Format0FDSelect extends CIDKeyedFDSelect
+    private static class Format0FDSelect extends FDSelect
     {
         private int format;
         private int[] fds;
@@ -890,36 +885,15 @@ public class CFFParser
         }
 
         @Override
-        public int getFd(int glyph)
+        public int getFDIndex(int gid)
         {
-            // todo: needs to be re-implemented
-            throw new UnsupportedOperationException("not implemented: FDSelect");
-
-            /*Map<String, byte[]> charStrings = null;// owner.getCharStringsDict();
-            Set<String> keys = charStrings.keySet();
-            // search the position of the given sid
-            for (Mapping mapping : owner.getMappings())
-            {
-                if (mapping.getSID() == glyph && charStrings.containsKey(mapping.getName()))
-                {
-                    int index = 0;
-                    for (String str : keys)
-                    {
-                        if (mapping.getName().equals(str))
-                        {
-                            return fds[index];
-                        }
-                        ++index;
-                    }
-                }
-            }
-            return -1;*/
+            return fds[gid];
         }
 
         @Override
         public String toString()
         {
-            return getClass().getName() + "[format=" + format + ", fds=" + Arrays.toString(fds)
+ "]";
+            return getClass().getName() + "[fds=" + Arrays.toString(fds) + "]";
         }
     }
 

Copied: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/FDSelect.java
(from r1618534, pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CIDKeyedFDSelect.java)
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/FDSelect.java?p2=pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/FDSelect.java&p1=pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CIDKeyedFDSelect.java&r1=1618534&r2=1618754&rev=1618754&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/CIDKeyedFDSelect.java
(original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cff/FDSelect.java Mon
Aug 18 21:40:13 2014
@@ -17,22 +17,24 @@
 
 package org.apache.fontbox.cff;
 
-public abstract class CIDKeyedFDSelect {
-	
-	protected CFFCIDFont owner = null;
+public abstract class FDSelect
+{
+	protected final CFFCIDFont owner;
 	
 	/**
 	 * Constructor.
+     *
 	 * @param owner the owner of the FDSelect data.
 	 */
-	public CIDKeyedFDSelect(CFFCIDFont owner) {
+	public FDSelect(CFFCIDFont owner)
+    {
 		this.owner = owner;
 	}
+
 	/**
-	 * Returns the Font DICT index for the given glyph identifier
+	 * Returns the Font DICT index for the given GID.
 	 *  
-	 * @param glyph
-	 * @return -1 if the glyph isn't define, otherwise the FD index value
+	 * @param gid GID
 	 */
-	public abstract int getFd(int glyph);
+	public abstract int getFDIndex(int gid);
 }

Modified: pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java?rev=1618754&r1=1618753&r2=1618754&view=diff
==============================================================================
--- pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java (original)
+++ pdfbox/branches/no-awt/fontbox/src/main/java/org/apache/fontbox/cmap/CMap.java Mon Aug
18 21:40:13 2014
@@ -186,10 +186,10 @@ public class CMap
                         return ch;
                     }
                 }
-                return -1;
+                return 0;
             }
         }
-        return -1;
+        return 0;
     }
     
     /**

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=1618754&r1=1618753&r2=1618754&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
Mon Aug 18 21:40:13 2014
@@ -110,7 +110,7 @@ public class PDCIDFontType0 extends PDCI
 
         if (character == null)
         {
-            LOG.error("No character for code " + (bytes[offset] & 0xff) + " in " + fontname);
+            LOG.warn("No character for code " + (bytes[offset] & 0xff) + " in " + fontname);
             return null;
         }
         return character;
@@ -137,7 +137,8 @@ public class PDCIDFontType0 extends PDCI
         int cid = codeToCID(bytes, offset, length);
         if (cid == 0 && !Arrays.equals(SPACE_BYTES, bytes))
         {
-            LOG.error("No name for code " + (bytes[offset] & 0xff) + " in " + fontname);
+            // todo: for debugging only
+            LOG.warn("No name for code " + (bytes[offset] & 0xff) + " in " + fontname);
             return 0;
         }
 
@@ -157,7 +158,8 @@ public class PDCIDFontType0 extends PDCI
         int cid = codeToCID(bytes, offset, length);
         if (cid == 0)
         {
-            LOG.error("No CID for code " + (bytes[offset] & 0xff) + " in " + fontname);
+            // todo: for debugging only
+            LOG.warn("No CID for code " + (bytes[offset] & 0xff) + " in " + fontname);
             return 0;
         }
 

Modified: pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDGlyph2D.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDGlyph2D.java?rev=1618754&r1=1618753&r2=1618754&view=diff
==============================================================================
--- pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDGlyph2D.java
(original)
+++ pdfbox/branches/no-awt/pdfbox/src/main/java/org/apache/pdfbox/rendering/font/CIDGlyph2D.java
Mon Aug 18 21:40:13 2014
@@ -59,6 +59,15 @@ public class CIDGlyph2D implements Glyph
             return cache.get(cid);
         }
 
+        // don't draw CID 0
+        if (cid == 0)
+        {
+            LOG.warn("No glyph for " + code + " (CID 0000) in font " + fontName);
+            GeneralPath path = new GeneralPath();
+            cache.put(cid, path);
+            return path;
+        }
+
         try
         {
             CFFCIDFont cidFont = font.getCFFCIDFont();



Mime
View raw message