pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1656231 - in /pdfbox/trunk: examples/src/main/java/org/apache/pdfbox/examples/pdmodel/ pdfbox/src/main/java/org/apache/pdfbox/cos/ pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/
Date Sat, 31 Jan 2015 18:21:59 GMT
Author: jahewson
Date: Sat Jan 31 18:21:59 2015
New Revision: 1656231

URL: http://svn.apache.org/r1656231
Log:
PDFBOX-2624: Generate CIDSet for Type0/TTF fonts, thanks to Keiji Suzuki

Modified:
    pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java

Modified: pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java?rev=1656231&r1=1656230&r2=1656231&view=diff
==============================================================================
--- pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java
(original)
+++ pdfbox/trunk/examples/src/main/java/org/apache/pdfbox/examples/pdmodel/CreatePDFA.java
Sat Jan 31 18:21:59 2015
@@ -23,10 +23,10 @@ import java.io.InputStream;
 import javax.xml.transform.TransformerException;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.common.PDMetadata;
 import org.apache.pdfbox.pdmodel.PDPageContentStream;
+import org.apache.pdfbox.pdmodel.common.PDMetadata;
 import org.apache.pdfbox.pdmodel.font.PDFont;
-import org.apache.pdfbox.pdmodel.font.PDTrueTypeFont;
+import org.apache.pdfbox.pdmodel.font.PDType0Font;
 import org.apache.pdfbox.pdmodel.graphics.color.PDOutputIntent;
 import org.apache.xmpbox.XMPMetadata;
 import org.apache.xmpbox.schema.PDFAIdentificationSchema;
@@ -58,7 +58,7 @@ public class CreatePDFA
             doc.addPage(page);
 
             // load the font as this needs to be embedded
-            PDFont font = PDTrueTypeFont.loadTTF(doc, new File(fontfile));
+            PDFont font = PDType0Font.load(doc, new File(fontfile));
 
             // create a page with the message
             PDPageContentStream contents = new PDPageContentStream(doc, page);

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1656231&r1=1656230&r2=1656231&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Sat Jan 31 18:21:59
2015
@@ -117,6 +117,7 @@ public final class COSName extends COSBa
     public static final COSName CID_FONT_TYPE0 = new COSName("CIDFontType0");
     public static final COSName CID_FONT_TYPE2 = new COSName("CIDFontType2");
     public static final COSName CID_TO_GID_MAP = new COSName("CIDToGIDMap");
+    public static final COSName CID_SET = new COSName("CIDSet");
     public static final COSName CIDSYSTEMINFO = new COSName("CIDSystemInfo");
     public static final COSName CLR_F = new COSName("ClrF");
     public static final COSName CLR_FF = new COSName("ClrFf");

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java?rev=1656231&r1=1656230&r2=1656231&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2Embedder.java
Sat Jan 31 18:21:59 2015
@@ -19,9 +19,8 @@ package org.apache.pdfbox.pdmodel.font;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
 import java.io.IOException;
-
+import java.io.InputStream;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
@@ -106,11 +105,12 @@ final class PDCIDFontType2Embedder exten
             cidToGid.put(oldGID, newGID);
         }
 
-        // buildSubset the relevant part of the font
+        // rebuild the relevant part of the font
         buildFontFile2(ttfSubset);
         addNameTag(tag);
         buildWidths(cidToGid);
         buildCIDToGIDMap(cidToGid);
+        buildCIDSet(cidToGid);
         buildToUnicodeCMap(gidToCid);
     }
 
@@ -243,7 +243,26 @@ final class PDCIDFontType2Embedder exten
     }
 
     /**
-     * Builds withs with a custom CIDToGIDMap (for embedding font subset).
+     * Builds the CIDSet entry, required by PDF/A. This lists all CIDs in the font.
+     */
+    private void buildCIDSet(Map<Integer, Integer> cidToGid) throws IOException
+    {
+        byte[] bytes = new byte[(Collections.max(cidToGid.keySet()) + 7) / 8];
+        for (int cid : cidToGid.keySet())
+        {
+            int mask = 1 << 7 - cid % 8;
+            bytes[cid / 8] |= mask;
+        }
+
+        InputStream input = new ByteArrayInputStream(bytes);
+        PDStream stream = new PDStream(document, input);
+        stream.addCompression();
+
+        fontDescriptor.setCIDSet(stream);
+    }
+
+    /**
+     * Builds wieths with a custom CIDToGIDMap (for embedding font subset).
      */
     private void buildWidths(Map<Integer, Integer> cidToGid) throws IOException
     {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java?rev=1656231&r1=1656230&r2=1656231&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDFontDescriptor.java
Sat Jan 31 18:21:59 2015
@@ -808,4 +808,15 @@ public final class PDFontDescriptor impl
     {
         dic.setItem( COSName.FONT_FILE3, stream );
     }
+
+    /**
+     * Set a stream containing a CIDSet.
+     *
+     * @param stream The font program stream.
+     */
+    public void setCIDSet( PDStream stream )
+    {
+        dic.setItem( COSName.CID_SET, stream );
+    }
+
 }



Mime
View raw message