You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ss...@apache.org on 2014/06/20 11:27:07 UTC

svn commit: r1604112 - in /xmlgraphics/fop-pdf-images/branches/Temp_FontMerging: ./ lib/ src/java/org/apache/fop/render/pdf/pdfbox/ test/java/org/apache/fop/render/pdf/ test/resources/

Author: ssteiner
Date: Fri Jun 20 09:27:06 2014
New Revision: 1604112

URL: http://svn.apache.org/r1604112
Log:
Add t1 merging

Added:
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/jacocoant.jar   (with props)
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java   (with props)
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset.pdf   (with props)
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset2.pdf   (with props)
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset3.pdf   (with props)
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset4.pdf   (with props)
Modified:
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/build.xml
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/fop.jar
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/Cache.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxEventProducer.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFUtil.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java
    xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/build.xml
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/build.xml?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/build.xml (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/build.xml Fri Jun 20 09:27:06 2014
@@ -15,7 +15,7 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project default="all" basedir="." name="fop-pdf-images">
+<project default="all" basedir="." name="fop-pdf-images" xmlns:jacoco="antlib:org.jacoco.ant">
 
   <!-- See build.properties and build-local.properties for overriding build settings. -->
   <!-- build-local.properties is not stored in SVN and overrides values from build.properties -->
@@ -111,55 +111,15 @@
       </classpath>
     </javac>
   </target>
-
-  <property name="emma.dir" value="${basedir}/lib" />
-  <property name="coverage.dir" value="${basedir}/build/coverage" />
-  <path id="emma.lib">
-    <pathelement location="${emma.dir}/emma.jar" />
-    <pathelement location="${emma.dir}/emma_ant.jar" />
-  </path>
-  <available file="${emma.dir}/emma.jar" property="emma.present"/>
-
-  <target name="emma" if="emma.present">
-    <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
-    <emma>
-        <instr instrpath="${build.classes.dir}"
-             destdir="${coverage.dir}"
-             metadatafile="${coverage.dir}/metadata.em"
-             merge="true"
-             mode="copy">
-        </instr>
-    </emma>  
-  </target>
   
-  <target name="emma-report" if="emma.present">
-    <emma>
-        <report>
-            <sourcepath>
-                <dirset dir="${basedir}">
-                    <include name="src/java"/>
-                    <include name="test/java"/>
-                </dirset>
-             </sourcepath>
-            <fileset dir="${coverage.dir}">
-                <include name="*.em"/>
-                <include name="*.ec"/>
-            </fileset>
-        <xml outfile="${coverage.dir}/report.xml" />
-        <txt outfile="${coverage.dir}/report.txt" />
-        <html outfile="${coverage.dir}/report.html" />
-        </report>
-    </emma>
-    <taskdef name="emmacheck" classname="org.emmacheck.EmmaCheckTask" classpath="${emma.dir}/emmacheck-0.2.jar"/>
-    <emmacheck coveragefile="${coverage.dir}/coverage.ec"
-           metadatafile="${coverage.dir}/metadata.em"
-           output="${coverage.dir}/requiredcoverage.out"
-           overallcoverage="L76" />  
-  </target>
-  
-  <target name="junit" depends="junit-compile-java,emma" description="Runs PDF Plugin's JUnit basic tests">
+  <property name="jacoco.report.dir" value="${build.dir}/coverage"/>
+  <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml" classpathref="libs-build-classpath"/>
+
+  <target name="junit" depends="junit-compile-java" description="Runs PDF Plugin's JUnit basic tests">
     <property name="junit.reports.dir" value="${build.dir}/test-reports"/>
     <mkdir dir="${junit.reports.dir}"/>
+    
+    <jacoco:coverage destfile="${jacoco.report.dir}/jacoco.exec">
     <junit dir="${basedir}" haltonfailure="yes" fork="true" forkmode="once">
       <sysproperty key="jawa.awt.headless" value="true"/>
       <formatter type="brief" usefile="false"/>
@@ -167,7 +127,6 @@
       <formatter type="xml" usefile="true"/>
       <classpath>
         <pathelement location="${coverage.dir}" />
-        <path refid="emma.lib"/>
         <path refid="standard-junit-classpath"/>
       </classpath>
       <assertions>
@@ -176,9 +135,28 @@
       <batchtest todir="${junit.reports.dir}">
         <fileset dir="${build.unit.tests.dir}" includes="**/*TestCase.class"/>
       </batchtest>
-      <jvmarg value="-Demma.coverage.out.file=${coverage.dir}/coverage.ec" />
     </junit>
-    <antcall target="emma-report"/>
+    </jacoco:coverage>
+    <jacoco:report>
+      <executiondata>
+        <file file="${jacoco.report.dir}/jacoco.exec"/>
+      </executiondata>
+      <structure name="Apache FOP">
+        <classfiles>
+          <fileset dir="${build.classes.dir}"/>
+        </classfiles>
+        <sourcefiles>
+          <fileset dir="${src.java.dir}"/>
+        </sourcefiles>
+      </structure>
+      <html destdir="${jacoco.report.dir}"/>
+      <xml destfile="${jacoco.report.dir}/report.xml"/>
+      <check>
+          <rule element="PACKAGE">
+              <limit counter="LINE" value="COVEREDRATIO" minimum="0.76"/>
+          </rule>
+      </check>      
+    </jacoco:report>    
   </target>
 
   <!-- =================================================================== -->
@@ -441,4 +419,35 @@
 
   <target name="all" depends="package,junit"/>
 
+  <target name="checkstyle" description="Runs Checkstyle for a code quality report">
+    <taskdef name="checkstyle" classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="libs-build-tools-classpath"/>
+    <checkstyle config="checkstyle-5.5.xml" failonviolation="true" maxWarnings="0">
+      <fileset dir="${src.java.dir}" includes="**/*.java"/>
+      <formatter type="plain"/>
+    </checkstyle>
+  </target>
+  
+  <property name="findbugs.lib" value="${findbugs.home.dir}/lib"/>
+  <path id="libs-findbugs">
+    <fileset dir="${findbugs.lib}">
+      <include name="*.jar"/>
+    </fileset>
+  </path>
+  <target name="findbugs">
+    <taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask" classpathref="libs-findbugs"/>
+    <findbugs home="${findbugs.home.dir}" output="text" reportLevel="low" effort="max" jvmargs="-Xmx1024m" warningsProperty="findbugs.warnings">
+      <sourcePath path="${src.java.dir}"/>
+      <class location="${build.classes.dir}"/>
+      <auxClasspath>
+        <path refid="libs-build-classpath"/>
+        <path>
+          <fileset dir="${ant.library.dir}">
+            <include name="ant.jar"/>
+            <include name="ant-launcher.jar"/>
+          </fileset>
+        </path>
+      </auxClasspath>
+    </findbugs>
+    <fail if="findbugs.warnings"/>
+  </target>
 </project>

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/fop.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/fop.jar?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
Binary files - no diff available.

Added: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/jacocoant.jar
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/jacocoant.jar?rev=1604112&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/lib/jacocoant.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/Cache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/Cache.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/Cache.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/Cache.java Fri Jun 20 09:27:06 2014
@@ -1,3 +1,19 @@
+/*
+ * 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.fop.render.pdf.pdfbox;
 
 import java.lang.ref.SoftReference;
@@ -5,7 +21,7 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.WeakHashMap;
 
-abstract class Cache<K,V> {
+abstract class Cache<K, V> {
 
     public enum Type {
         WEAK, SOFT, STRONG;
@@ -13,20 +29,24 @@ abstract class Cache<K,V> {
 
     public abstract V getValue(K key, ValueMaker<V> valueMaker) throws Exception;
 
-    public static <K,V> Cache<K,V> createCache(Type cacheType) {
+    public static <K, V> Cache<K, V> createCache(Type cacheType) {
         switch (cacheType) {
-            case WEAK: return new WeakDocumentCache<K,V>();
-            case SOFT: return new SoftDocumentCache<K,V>();
-            case STRONG: return new StrongDocumentCache<K,V>();
-            default: return createDefaultCache();
+            case WEAK:
+                return new WeakDocumentCache<K, V>();
+            case SOFT:
+                return new SoftDocumentCache<K, V>();
+            case STRONG:
+                return new StrongDocumentCache<K, V>();
+            default:
+                return createDefaultCache();
         }
     }
 
-    private static <K,V> Cache<K,V> createDefaultCache() {
-        return new WeakDocumentCache<K,V>();
+    private static <K, V> Cache<K, V> createDefaultCache() {
+        return new WeakDocumentCache<K, V>();
     }
 
-    private static class StrongDocumentCache<K,V> extends Cache<K,V> {
+    private static class StrongDocumentCache<K, V> extends Cache<K, V> {
 
         private final Map<K, V> cache = new HashMap<K, V>();
 
@@ -41,15 +61,12 @@ abstract class Cache<K,V> {
         }
     }
 
-    private static class SoftDocumentCache<K,V> extends Cache<K,V> {
+    private static class SoftDocumentCache<K, V> extends Cache<K, V> {
 
-        private final Map<K, SoftReference<Object>> softKeys
-                = new HashMap<K, SoftReference<Object>>();
+        private final Map<K, SoftReference<Object>> softKeys = new HashMap<K, SoftReference<Object>>();
 
         private final Map<Object, V> cache = new WeakHashMap<Object, V>();
 
-        private Object currentKey;
-
         @Override
         public V getValue(K key, ValueMaker<V> valueMaker) throws Exception {
             SoftReference<Object> reference = softKeys.get(key);
@@ -61,7 +78,6 @@ abstract class Cache<K,V> {
             } else {
                 softKey = reference.get();
             }
-            currentKey = softKey;
             V value = cache.get(softKey);
             if (value == null) {
                 value = valueMaker.make();
@@ -71,7 +87,7 @@ abstract class Cache<K,V> {
         }
     }
 
-    private static class WeakDocumentCache<K,V> extends Cache<K,V> {
+    private static class WeakDocumentCache<K, V> extends Cache<K, V> {
 
         private V currentValue;
 
@@ -87,7 +103,7 @@ abstract class Cache<K,V> {
         }
     }
 
-    public static interface ValueMaker<V> {
+    public interface ValueMaker<V> {
         V make() throws Exception;
     }
 }

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java Fri Jun 20 09:27:06 2014
@@ -26,12 +26,11 @@ import java.awt.geom.Rectangle2D;
 import java.io.IOException;
 import java.util.Map;
 
-
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
-
 import org.apache.pdfbox.rendering.PageDrawer;
+
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageException;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeCFFFonts.java Fri Jun 20 09:27:06 2014
@@ -43,14 +43,14 @@ public class MergeCFFFonts extends OTFSu
     protected List<LinkedHashMap<Integer, Integer>> subsetGlyphsList = new ArrayList<LinkedHashMap<Integer, Integer>>();
     private boolean fallbackIndex;
     private int charsetOffset;
-    private int fontFileSize = 0;
+    private int fontFileSize;
     private Set<String> used = new HashSet<String>();
     private List<String> strings = new ArrayList<String>();
     private List<Integer> chars = new ArrayList<Integer>();
     private List<String> added = new ArrayList<String>();
     private Map<Integer, Integer> range = new LinkedHashMap<Integer, Integer>();
     private Set<String> stringsForRange = new HashSet<String>();
-    private int noOfFonts = 0;
+    private int noOfFonts;
     private CFFEncoding encoding = null;
 
     public MergeCFFFonts() throws IOException {
@@ -250,10 +250,12 @@ public class MergeCFFFonts extends OTFSu
                 i++;
             }
 
-            updateCIDOffsets(topDictDataOffset, fdArrayOffset, fdSelectOffset, charsetOffset, charStringOffset, encodingOffset);
+            updateCIDOffsets(topDictDataOffset, fdArrayOffset, fdSelectOffset, charsetOffset, charStringOffset,
+                    encodingOffset);
         } else {
             //Update the offsets
-            updateOffsets(topDictOffset, charsetOffset, charStringOffset, privateDictOffset, localIndexOffset, encodingOffset);
+            updateOffsets(topDictOffset, charsetOffset, charStringOffset, privateDictOffset, localIndexOffset,
+                    encodingOffset);
         }
     }
 
@@ -361,7 +363,7 @@ public class MergeCFFFonts extends OTFSu
                 if (cidFont && gid.getKey() == 0) {
                     continue;
                 }
-                writeCard16((cidFont) ? gid.getKey() : gid.getValue());
+                writeCard16(cidFont ? gid.getKey() : gid.getValue());
             }
         } else {
             writeFormat1CS(range, afterstringindex);
@@ -399,7 +401,7 @@ public class MergeCFFFonts extends OTFSu
                 int last = -1;
                 boolean simpleRange = false;
                 for (int i : range.keySet()) {
-                    simpleRange = (last + 1 == i);
+                    simpleRange = last + 1 == i;
                     last = i;
                 }
                 if (simpleRange) {

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java Fri Jun 20 09:27:06 2014
@@ -31,9 +31,10 @@ import org.apache.fop.fonts.truetype.TTF
 
 public class MergeTTFonts extends TTFSubSetFile {
     private Map<Integer, Glyph> added = new TreeMap<Integer, Glyph>();
-    private int origIndexesLen = 0;
-    private int size = 0;
+    private int origIndexesLen;
+    private int size;
     protected MaximumProfileTable maxp = new MaximumProfileTable();
+    private Integer nhmtxDiff = null;
 
     static class Glyph {
         final byte[] data;
@@ -46,6 +47,9 @@ public class MergeTTFonts extends TTFSub
 
     /**
      * Create the glyf table and fill in loca table
+     * @param glyphs map of glyphs
+     * @param in fontfile
+     * @throws IOException on error
      */
     private void readGlyf(Map<Integer, Integer> glyphs, FontFileReader in) throws IOException {
         OFDirTabEntry entry = dirTabs.get(OFTableName.GLYF);
@@ -111,7 +115,7 @@ public class MergeTTFonts extends TTFSub
                     writeULong(locaOffset + i * 4, currentPos - startPos);
                 }
                 if ((currentPos - startPos + glyphLength) > endOffset1) {
-                    endOffset1 = (currentPos - startPos + glyphLength);
+                    endOffset1 = currentPos - startPos + glyphLength;
                 }
 
                 // Store the glyph boundary positions relative to the start of the font
@@ -159,6 +163,7 @@ public class MergeTTFonts extends TTFSub
      * font to subset font. The glyphs Map contains an
      * Integer key and Integer value that maps the original
      * metric (key) to the subset metric (value)
+     * @throws IOException on error
      */
     protected void createHmtx() throws IOException {
         OFTableName hmtx = OFTableName.HMTX;
@@ -167,8 +172,8 @@ public class MergeTTFonts extends TTFSub
             pad4();
             // int offset = (int)entry.offset;
 
-            int longHorMetricSize = added.size() * 4;
-            int leftSideBearingSize = added.size() * 4;
+            int longHorMetricSize = added.size() * 2;
+            int leftSideBearingSize = added.size() * 2;
             int hmtxSize = longHorMetricSize + leftSideBearingSize;
 
             for (Map.Entry<Integer, Glyph> e : added.entrySet()) {
@@ -191,9 +196,10 @@ public class MergeTTFonts extends TTFSub
     /**
      * Returns a subset of the original font.
      *
-     *
+     * @param fontFile font file
      * @param subsetGlyphs Map of glyphs (glyphs has old index as (Integer) key and
      * new index as (Integer) value)
+     * @param cid is cid
      * @throws IOException in case of an I/O problem
      */
     public void readFont(FontFileReader fontFile, Map<Integer, Integer> subsetGlyphs, boolean cid) throws IOException {
@@ -217,10 +223,12 @@ public class MergeTTFonts extends TTFSub
         }
         scanGlyphs(fontFile, subsetGlyphs);
         readGlyf(subsetGlyphs, fontFile);
+        if (nhmtxDiff == null) {
+            nhmtxDiff = subsetGlyphs.size() - nhmtx;
+        }
     }
 
-    protected void scanGlyphs(FontFileReader in, Map<Integer, Integer> subsetGlyphs)
-            throws IOException {
+    protected void scanGlyphs(FontFileReader in, Map<Integer, Integer> subsetGlyphs) throws IOException {
         OFDirTabEntry glyfTableInfo = dirTabs.get(OFTableName.GLYF);
         if (glyfTableInfo == null) {
             throw new IOException("Glyf table could not be found");
@@ -229,8 +237,8 @@ public class MergeTTFonts extends TTFSub
     }
 
     static class MergeGlyfTable extends GlyfTable {
-        public MergeGlyfTable(FontFileReader in, OFMtxEntry[] metrics, OFDirTabEntry dirTableEntry, Map<Integer, Integer> glyphs)
-                throws IOException {
+        public MergeGlyfTable(FontFileReader in, OFMtxEntry[] metrics, OFDirTabEntry dirTableEntry,
+                              Map<Integer, Integer> glyphs) throws IOException {
             super(in, metrics, dirTableEntry, glyphs);
             populateGlyphsWithComposites();
         }
@@ -266,7 +274,7 @@ public class MergeTTFonts extends TTFSub
         createHead(fontFile);
         createOS2(fontFile);                          // copy the OS/2 table
         if (!cid) {
-            createHhea(fontFile, sgsize - 2);    // Create the hhea table
+            createHhea(fontFile, sgsize - nhmtxDiff);    // Create the hhea table
         } else {
             createHhea(fontFile, sgsize);    // Create the hhea table
         }

Added: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java?rev=1604112&view=auto
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java (added)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java Fri Jun 20 09:27:06 2014
@@ -0,0 +1,243 @@
+/*
+ * 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.fop.render.pdf.pdfbox;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.fontbox.encoding.Encoding;
+import org.apache.pdfbox.pdmodel.font.PDType1Font;
+
+import org.apache.fop.fonts.type1.PFBData;
+import org.apache.fop.fonts.type1.PFBParser;
+import org.apache.fop.fonts.type1.PostscriptParser;
+import org.apache.fop.fonts.type1.Type1SubsetFile;
+
+public class MergeType1Fonts extends Type1SubsetFile {
+    private Map<Integer, String> nameMap = new HashMap<Integer, String>();
+    private PostscriptParser.PSElement encoding;
+    private List<String> subsetEncodingEntries = new ArrayList<String>();
+    private PFBData pfbData = null;
+    private byte[] decoded;
+    private PostscriptParser.PSElement charStrings;
+    private ByteArrayOutputStream subrsBeforeStream = new ByteArrayOutputStream();
+    private ByteArrayOutputStream subrsEndStream = new ByteArrayOutputStream();
+    private Map<Integer, byte[]> subByteMap = new HashMap<Integer, byte[]>();
+
+    public MergeType1Fonts() {
+        uniqueSubs = new LinkedHashMap<Integer, byte[]>();
+        subsetCharStrings = new HashMap<String, byte[]>();
+        charNames = new ArrayList<String>();
+        subsetSubroutines = false;
+        subsetEncodingEntries.add("dup 0 /.notdef put");
+    }
+
+    public void readFont(InputStream fontFile, PDType1Font font) throws IOException {
+        PFBParser pfbParser = new PFBParser();
+        pfbData = pfbParser.parsePFB(fontFile);
+
+        PostscriptParser psParser = new PostscriptParser();
+        List<Integer> glyphs = new ArrayList<Integer>();
+        Encoding enc = font.getType1Font().getEncoding();
+        for (int i = font.getFirstChar(); i <= font.getLastChar(); i++) {
+            if (!enc.getName(i).equals(".notdef")) {
+                nameMap.put(i, enc.getName(i));
+                glyphs.add(i);
+            }
+        }
+        Collections.sort(glyphs);
+
+        headerSection = psParser.parse(pfbData.getHeaderSegment());
+        encoding = getElement("/Encoding", headerSection);
+        if (encoding.getFoundUnexpected()) {
+            throw new IOException("unable to interpret postscript on arrays");
+        }
+
+        List<String> encodingEntries = readEncoding(glyphs, encoding);
+        for (String e : encodingEntries) {
+            if (e != null && !subsetEncodingEntries.contains(e)) {
+                subsetEncodingEntries.add(e);
+            }
+        }
+
+        decoded = BinaryCoder.decodeBytes(pfbData.getEncryptedSegment(), 55665, 4);
+        mainSection = psParser.parse(decoded);
+        PostscriptParser.PSFixedArray subroutines = (PostscriptParser.PSFixedArray)getElement("/Subrs", mainSection);
+        charStrings = getElement("/CharStrings", mainSection);
+        if (subroutines != null) {
+            subrsBeforeStream.reset();
+            subrsBeforeStream.write(decoded, 0, subroutines.getStartPoint());
+            subrsEndStream.reset();
+            subrsEndStream.write(decoded, subroutines.getEndPoint(),
+                    charStrings.getStartPoint() - subroutines.getEndPoint());
+        }
+        List<byte[]> subArray = font.getType1Font().getSubrsArray();
+        for (int i = 0; i < subArray.size(); i++) {
+            if (subByteMap.containsKey(i) && !Arrays.equals(subByteMap.get(i), subArray.get(i))) {
+                throw new IOException("Can't merge font subroutines " + font.getBaseFont());
+            }
+            subByteMap.put(i, subArray.get(i));
+        }
+        Map<String, byte[]> cs = font.getType1Font().getCharStringsDict();
+        int skipBytes = 4;
+        PostscriptParser.PSElement element = getElement("lenIV", mainSection);
+        if (element != null && element instanceof PostscriptParser.PSVariable) {
+            PostscriptParser.PSVariable lenIV = (PostscriptParser.PSVariable)element;
+            skipBytes = Integer.parseInt(lenIV.getValue());
+        }
+        for (String e : cs.keySet()) {
+            byte[] charStringEntry = getBinaryEntry(charStrings.getBinaryEntries().get("/" + e), decoded);
+            charStringEntry = BinaryCoder.decodeBytes(charStringEntry, 4330, skipBytes);
+            charStringEntry = BinaryCoder.encodeBytes(charStringEntry, 4330, 4);
+            subsetCharStrings.put("/" + e, charStringEntry);
+        }
+    }
+
+    public byte[] writeFont() throws IOException {
+        ByteArrayOutputStream boasHeader = writeHeader(pfbData, encoding);
+
+        ByteArrayOutputStream boasMain = writeMainSection(decoded, mainSection, charStrings);
+        byte[] mainSectionBytes = BinaryCoder.encodeBytes(boasMain.toByteArray(), 55665, 4);
+        boasMain.reset();
+        boasMain.write(mainSectionBytes);
+
+        ByteArrayOutputStream baosTrailer = new ByteArrayOutputStream();
+        baosTrailer.write(pfbData.getTrailerSegment(), 0, pfbData.getTrailerSegment().length);
+
+        return stitchFont(boasHeader, boasMain, baosTrailer);
+    }
+
+    @Override
+    protected List<String> searchEntries(HashMap<Integer, String> encodingEntries, int glyph) {
+        List<String> matches = new ArrayList<String>();
+        for (Map.Entry<Integer, String> entry : encodingEntries.entrySet()) {
+            String tag = getEntryPart(entry.getValue(), 3);
+            String name = "/" + nameMap.get(glyph);
+            if (name.equals(tag)) {
+                matches.add(entry.getValue());
+            }
+        }
+        return matches;
+    }
+
+    protected List<String> readEncoding(List<Integer> glyphs,
+                                        PostscriptParser.PSElement encoding) {
+        List<String> subsetEncodingEntries = new ArrayList<String>();
+        //Handle custom encoding
+        if (encoding instanceof PostscriptParser.PSFixedArray) {
+            PostscriptParser.PSFixedArray encodingArray = (PostscriptParser.PSFixedArray)encoding;
+            for (int glyph : glyphs) {
+                if (glyph != 0) {
+                    //Find matching entries in the encoding table from the given glyph
+                    List<String> matches = searchEntries(encodingArray.getEntries(), glyph);
+                    /* If no matches are found, perform a lookup using the glyph index.
+                     * This isn't done by default as some symbol based type-1 fonts do not
+                     * place their characters according to the glyph index. */
+                    if (matches.isEmpty()) {
+                        matches.clear();
+                        matches.add(encodingArray.getEntries().get(glyph));
+                    }
+                    for (String match : matches) {
+                        subsetEncodingEntries.add(match);
+                    }
+                }
+            }
+            //Handle fixed encoding
+        } else if (encoding instanceof PostscriptParser.PSVariable) {
+            if (((PostscriptParser.PSVariable) encoding).getValue().equals("StandardEncoding")) {
+                standardEncoding = true;
+                for (Map.Entry<Integer, String> v : nameMap.entrySet()) {
+                    subsetEncodingEntries.add(String.format("dup %d /%s put", v.getKey(), v.getValue()));
+                }
+            } else {
+                throw new RuntimeException(
+                        "Only Custom or StandardEncoding is supported when creating a Type 1 subset.");
+            }
+        }
+        return subsetEncodingEntries;
+    }
+
+    @Override
+    protected ByteArrayOutputStream writeHeader(PFBData pfbData, PostscriptParser.PSElement encoding)
+        throws IOException {
+        ByteArrayOutputStream boasHeader = new ByteArrayOutputStream();
+        boasHeader.write(pfbData.getHeaderSegment(), 0, encoding.getStartPoint() - 1);
+
+        if (!standardEncoding) {
+            //Write out the new encoding table for the subset font
+            String encodingArray = eol + "/Encoding 256 array" + eol
+                    + "0 1 255 {1 index exch /.notdef put } for" + eol;
+            byte[] encodingDefinition = encodingArray.getBytes("ASCII");
+            boasHeader.write(encodingDefinition, 0, encodingDefinition.length);
+            for (Map.Entry<Integer, String> entry : nameMap.entrySet()) {
+                String arrayEntry = String.format("dup %d /%s put", entry.getKey(),
+                        entry.getValue());
+                writeString(arrayEntry + eol, boasHeader);
+            }
+            writeString("readonly def" + eol, boasHeader);
+        } else {
+            String theEncoding = eol + "/Encoding StandardEncoding def" + eol;
+            boasHeader.write(theEncoding.getBytes("ASCII"));
+        }
+        boasHeader.write(pfbData.getHeaderSegment(), encoding.getEndPoint(),
+                pfbData.getHeaderSegment().length - encoding.getEndPoint());
+
+        return boasHeader;
+    }
+
+    @Override
+    protected ByteArrayOutputStream writeMainSection(byte[] decoded, List<PostscriptParser.PSElement> mainSection,
+                                                     PostscriptParser.PSElement charStrings) throws IOException {
+        ByteArrayOutputStream main = new ByteArrayOutputStream();
+        //Find the ID of the three most commonly subroutines defined in Type 1 fonts
+        String rd = findVariable(decoded, mainSection, new String[] {"string currentfile exch readstring pop"}, "RD");
+        String nd = findVariable(decoded, mainSection, new String[] {"def", "noaccess def"}, "noaccess def");
+        String np = findVariable(decoded, mainSection, new String[] {"put", "noaccess put"}, "noaccess put");
+        main.write(subrsBeforeStream.toByteArray());
+        writeString("/Subrs " + subByteMap.size() + " array" + eol, main);
+        for (Map.Entry<Integer, byte[]> e : subByteMap.entrySet()) {
+            byte[] encoded = BinaryCoder.encodeBytes(e.getValue(), 4330, 4);
+            writeString("dup " + e.getKey() + " " + encoded.length + " " + rd + " ", main);
+            main.write(encoded);
+            writeString(" " + np + eol, main);
+        }
+        writeString(nd + eol, main);
+        main.write(subrsEndStream.toByteArray());
+        //Write the subset charString array
+        writeString(eol + String.format("/CharStrings %d dict dup begin",
+                subsetCharStrings.size()), main);
+        for (Map.Entry<String, byte[]> entry : subsetCharStrings.entrySet()) {
+            writeString(eol + String.format("%s %d %s ", entry.getKey(),
+                    entry.getValue().length, rd),
+                    main);
+            main.write(entry.getValue());
+            writeString(" " + nd, main);
+        }
+        writeString(eol + "end", main);
+        main.write(decoded, charStrings.getEndPoint(), decoded.length - charStrings.getEndPoint());
+
+        return main;
+    }
+}

Propchange: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/MergeType1Fonts.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxAdapter.java Fri Jun 20 09:27:06 2014
@@ -46,7 +46,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFFontROS;
-import org.apache.fontbox.cff.CFFParser;
 import org.apache.fontbox.cff.charset.CFFCharset;
 import org.apache.fontbox.cff.encoding.CFFEncoding;
 import org.apache.fontbox.cmap.CMap;
@@ -91,6 +90,7 @@ import org.apache.pdfbox.pdmodel.font.PD
 import org.apache.pdfbox.pdmodel.font.PDType1Font;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotation;
 import org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm;
+import org.apache.pdfbox.util.operator.PDFOperator;
 
 import org.apache.fop.events.EventBroadcaster;
 import org.apache.fop.fonts.CIDFontType;
@@ -116,7 +116,6 @@ import org.apache.fop.pdf.PDFStream;
 import org.apache.fop.pdf.PDFText;
 import org.apache.fop.pdf.RefPDFFont;
 import org.apache.fop.util.CharUtilities;
-import org.apache.pdfbox.util.operator.PDFOperator;
 
 /**
  * This class provides an adapter for transferring content from a PDFBox PDDocument to
@@ -160,8 +159,7 @@ public class PDFBoxAdapter {
         return cloneForNewDocument(base, keyBase, Collections.EMPTY_LIST);
     }
 
-    private Object cloneForNewDocument(Object base, Object keyBase, Collection exclude)
-            throws IOException {
+    private Object cloneForNewDocument(Object base, Object keyBase, Collection exclude) throws IOException {
         if (base == null) {
             return null;
         }
@@ -246,7 +244,7 @@ public class PDFBoxAdapter {
             cacheClonedObject(keyBase, newDict);
             for (COSName key : keys) {
                 if (!exclude.contains(key)) {
-                    (newDict).put(key.getName(), cloneForNewDocument(dic.getItem(key), dic.getItem(key), exclude));
+                    newDict.put(key.getName(), cloneForNewDocument(dic.getItem(key), dic.getItem(key), exclude));
                 }
             }
             return newDict;
@@ -347,9 +345,11 @@ public class PDFBoxAdapter {
         if (font instanceof PDType0Font
                 && ((PDType0Font) font).getDescendantFont() instanceof PDCIDFontType0Font
                 && ((PDCIDFontType0Font) ((PDType0Font) font).getDescendantFont()).getType1CFont() != null) {
-            CFFFont cffFont = ((PDCIDFontType0Font) ((PDType0Font) font).getDescendantFont()).getType1CFont().getCFFFont();
+            CFFFont cffFont =
+                    ((PDCIDFontType0Font) ((PDType0Font) font).getDescendantFont()).getType1CFont().getCFFFont();
             if (cffFont instanceof CFFFontROS
-                    && ((CFFFontROS)cffFont).getFdSelect().getClass().getName().equals("org.apache.fontbox.cff.CFFParser$Format0FDSelect")) {
+                    && ((CFFFontROS)cffFont).getFdSelect().getClass().getName()
+                    .equals("org.apache.fontbox.cff.CFFParser$Format0FDSelect")) {
                 extra += "format0";
             }
             return getName(font.getBaseFont()) + "_" + ((COSName)fontData.getItem(COSName.SUBTYPE)).getName() + extra;
@@ -377,6 +377,9 @@ public class PDFBoxAdapter {
         if (font instanceof PDType1Font) {
             if (((PDType1Font) font).getType1CFont() == null
                     || ((PDType1Font) font).getType1CFont().getCFFFont() == null) {
+                if (font.getFontDescriptor() instanceof PDFontDescriptorDictionary) {
+                    return getName(font.getBaseFont()) + "_" + ((COSName)fontData.getItem(COSName.SUBTYPE)).getName();
+                }
                 return null;
             }
             CFFEncoding encoding = ((PDType1Font)font).getType1CFont().getCFFFont().getEncoding();
@@ -541,7 +544,8 @@ public class PDFBoxAdapter {
         private Map<Integer, String> getMapping(PDSimpleFont font, CMap c, int len) throws IOException {
             Map<Integer, String> mapping = new HashMap<Integer, String>();
             if (font instanceof PDCIDFontType0Font) {
-                Collection<CFFFont.Mapping> mappings = ((PDCIDFontType0Font) font).getType1CFont().getCFFFont().getMappings();
+                Collection<CFFFont.Mapping> mappings =
+                        ((PDCIDFontType0Font) font).getType1CFont().getCFFFont().getMappings();
                 for (CFFFont.Mapping m : mappings) {
                     String character = Encoding.getCharacterForName(m.getName());
                     mapping.put(m.getSID(), character);
@@ -688,33 +692,30 @@ public class PDFBoxAdapter {
     }
 
     public class FOPPDFSingleByteFont extends SingleByteFont implements FOPPDFFont {
-        private int fontCount = 0;
+        private int fontCount;
         private PDSimpleFont font;
         protected PDFDictionary ref;
         private Map<String, Integer> charMapGlobal = new LinkedHashMap<String, Integer>();
         private Map<Integer, Integer> newWidth = new HashMap<Integer, Integer>();
         private Map<String, byte[]> charStringsDict;
         private Cmap newCmap = new Cmap();
-        private byte[] fontCache;
         private Map<Integer, String> encodingMap = new TreeMap<Integer, String>();
         private int encodingSkip;
         private MergeTTFonts mergeTTFonts = new MergeTTFonts();
         private MergeCFFFonts mergeCFFFonts = new MergeCFFFonts();
+        private MergeType1Fonts mergeType1Fonts = new MergeType1Fonts();
         private String embedName;
 
         public FOPPDFSingleByteFont(COSDictionary fontData, String name) throws IOException {
-            super(null);
+            super(null, EmbeddingMode.FULL);
             if (fontData.getItem(COSName.SUBTYPE) == COSName.TRUE_TYPE) {
                 setFontType(FontType.TRUETYPE);
             }
             width = new int[0];
             font = getFont(fontData);
-            if (font instanceof PDType1Font) {
-                fontCache = ((PDFontDescriptorDictionary)font.getFontDescriptor()).getFontFile3().getByteArray();
-            }
             setFirstChar(font.getFirstChar());
             setLastChar(font.getLastChar());
-            readFontFile(font);
+            loadFontFile(font);
             float[] bBoxF = font.getFontBoundingBox().getCOSArray().toFloatArray();
             int[] bBox = new int[bBoxF.length];
             for (int i = 0; i < bBox.length; i++) {
@@ -737,7 +738,8 @@ public class PDFBoxAdapter {
                 //if width contains 0 we cant rely on codeToNameMap
                 boolean usesZero = font.getWidths().contains(0);
                 Set<Integer> codeToName = getCodeToName(font.getFontEncoding()).keySet();
-                for (int i = getFirstChar(); i <= Math.min(getLastChar(), getFirstChar() + font.getWidths().size()); i++) {
+                for (int i = getFirstChar();
+                     i <= Math.min(getLastChar(), getFirstChar() + font.getWidths().size()); i++) {
                     if (usesZero || codeToName.contains(i)) {
                         int w = font.getWidths().get(i - getFirstChar()).intValue();
                         newWidth.put(i, w);
@@ -791,7 +793,7 @@ public class PDFBoxAdapter {
             return font.getToUnicodeCMap();
         }
 
-        private void readFontFile(PDSimpleFont font) throws IOException {
+        private PDStream readFontFile(PDSimpleFont font) throws IOException {
             PDFontDescriptorDictionary fd = (PDFontDescriptorDictionary) font.getFontDescriptor();
             setFlags(fd.getFlags());
             PDStream ff = fd.getFontFile3();
@@ -806,7 +808,12 @@ public class PDFBoxAdapter {
             if (ff == null) {
                 throw new IOException(font.getBaseFont() + " no font file");
             }
-            mergeFontFile(ff.createInputStream());
+            return ff;
+        }
+
+        private void loadFontFile(PDSimpleFont font) throws IOException {
+            PDStream ff = readFontFile(font);
+            mergeFontFile(ff.createInputStream(), font);
             if (font instanceof PDTrueTypeFont) {
                 TrueTypeFont ttfont = ((PDTrueTypeFont) font).getTTFFont();
                 CMAPEncodingEntry[] cmapList = ttfont.getCMAP().getCmaps();
@@ -855,7 +862,7 @@ public class PDFBoxAdapter {
 
         public String addFont(COSDictionary fontData) throws IOException {
             PDSimpleFont font = getFont(fontData);
-            if (font instanceof PDType1Font && differentGlyphData(font)) {
+            if (font instanceof PDType1Font && differentGlyphData((PDType1Font) font)) {
                 return null;
             }
             mergeWidths(font);
@@ -867,7 +874,7 @@ public class PDFBoxAdapter {
                     setLastChar(w);
                 }
             }
-            readFontFile(font);
+            loadFontFile(font);
             addEncoding(font);
             return getFontName();
         }
@@ -876,26 +883,18 @@ public class PDFBoxAdapter {
             return fontCount;
         }
 
-        private Map<String, byte[]> getCharStringsDict(PDSimpleFont font, boolean cache) throws IOException {
-            if (font.getFontDescriptor() instanceof PDFontDescriptorDictionary) {
-                PDStream ff3Stream = ((PDFontDescriptorDictionary)font.getFontDescriptor()).getFontFile3();
-                if (ff3Stream != null) {
-                    byte[] data = fontCache;
-                    if (!cache) {
-                        data = ff3Stream.getByteArray();
-                    }
-                    CFFFont ff = new CFFParser().parse(data).get(0);
-                    return ff.getCharStringsDict();
-                }
+        private Map<String, byte[]> getCharStringsDict(PDType1Font font) throws IOException {
+            if (getFontType() == FontType.TYPE1) {
+                return font.getType1Font().getCharStringsDict();
             }
-            return new HashMap<String, byte[]>();
+            return font.getType1CFont().getCFFFont().getCharStringsDict();
         }
 
-        private boolean differentGlyphData(PDSimpleFont otherFont) throws IOException {
-            if (charStringsDict == null && font instanceof PDType1Font) {
-                charStringsDict = getCharStringsDict(font, true);
+        private boolean differentGlyphData(PDType1Font otherFont) throws IOException {
+            if (charStringsDict == null) {
+                charStringsDict = getCharStringsDict((PDType1Font) font);
             }
-            for (Map.Entry<String, byte[]> s : getCharStringsDict(otherFont, false).entrySet()) {
+            for (Map.Entry<String, byte[]> s : getCharStringsDict(otherFont).entrySet()) {
                 if (charStringsDict.containsKey(s.getKey())) {
                     int numberDiff = 0;
                     byte[] b1 = charStringsDict.get(s.getKey());
@@ -925,6 +924,7 @@ public class PDFBoxAdapter {
             int w = 0;
             int skipGlyphIndex = getLastChar() + 1;
             Object cmap = getCmap(font);
+            Set<Integer> codeToName = getCodeToName(font.getFontEncoding()).keySet();
             for (int i = font.getFirstChar(); i <= font.getLastChar(); i++) {
                 boolean addedWidth = false;
                 int glyphIndexPos = skipGlyphIndex;
@@ -935,7 +935,9 @@ public class PDFBoxAdapter {
                 if (font.getWidths() != null) {
                     neww = font.getWidths().get(i - font.getFirstChar()).intValue();
                     if (!newWidth.containsKey(i) || newWidth.get(i) == 0) {
-                        if (font instanceof PDTrueTypeFont || (font.getFontEncoding() != null && getCodeToName(font.getFontEncoding()).keySet().contains(i))) {
+                        if (getFontType() == FontType.TYPE1
+                                || font instanceof PDTrueTypeFont
+                                || codeToName.contains(i)) {
                             newWidth.put(i, neww);
                             glyphIndexPos = i;
                         } else {
@@ -1010,7 +1012,7 @@ public class PDFBoxAdapter {
         }
 
         class FOPPDFEncoding implements SingleByteEncoding {
-            private boolean cmap = false;
+            private boolean cmap;
 
             public String getName() {
                 return "FOPPDFEncoding";
@@ -1055,7 +1057,9 @@ public class PDFBoxAdapter {
                 char[] ret = new char[list.size()];
                 int i = 0;
                 for (String e : list) {
-                    ret[i++] = e.charAt(0);
+                    if (e.length() > 0) {
+                        ret[i++] = e.charAt(0);
+                    }
                 }
                 return ret;
             }
@@ -1086,11 +1090,13 @@ public class PDFBoxAdapter {
             return false;
         }
 
-        private void mergeFontFile(InputStream ff) throws IOException {
+        private void mergeFontFile(InputStream ff, PDSimpleFont pdSimpleFont) throws IOException {
             if (getFontType() == FontType.TRUETYPE) {
                 Map<Integer, Integer> chars = new HashMap<Integer, Integer>();
                 chars.put(0, 0);
                 mergeTTFonts.readFont(new FontFileReader(ff), chars, false);
+            } else if (getFontType() == FontType.TYPE1) {
+                mergeType1Fonts.readFont(ff, (PDType1Font) pdSimpleFont);
             } else {
                 mergeCFFFonts.readType1CFont(ff, getEmbedFontName());
             }
@@ -1106,6 +1112,9 @@ public class PDFBoxAdapter {
                 mergeTTFonts.writeFont(newCmap);
                 return new ByteArrayInputStream(mergeTTFonts.getFontSubset());
             }
+            if (getFontType() == FontType.TYPE1) {
+                return new ByteArrayInputStream(mergeType1Fonts.writeFont());
+            }
             return null;
         }
     }
@@ -1285,7 +1294,7 @@ public class PDFBoxAdapter {
                         return null;
                     }
                 }
-                newHex.append(String.format("%1$04x", (mapped & 0xFFFF)).toUpperCase(Locale.getDefault()));
+                newHex.append(String.format("%1$04x", mapped & 0xFFFF).toUpperCase(Locale.getDefault()));
                 PDFText.escapeStringChar((char)mapped.intValue(), newOct);
                 i++;
             }
@@ -1344,12 +1353,16 @@ public class PDFBoxAdapter {
      * @param sourceDoc the source PDF the given page to be copied belongs to
      * @param page the page to transform into a stream
      * @param key value to use as key for the stream
+     * @param eventBroadcaster events
      * @param atdoc adjustment for stream
+     * @param fontinfo fonts
+     * @param pos rectangle
      * @return the stream
      * @throws IOException if an I/O error occurs
      */
     public String createStreamFromPDFBoxPage(PDDocument sourceDoc, PDPage page, String key,
-            EventBroadcaster eventBroadcaster, AffineTransform atdoc, FontInfo fontinfo, Rectangle pos) throws IOException {
+            EventBroadcaster eventBroadcaster, AffineTransform atdoc, FontInfo fontinfo, Rectangle pos)
+        throws IOException {
         handleAcroForm(sourceDoc, page, eventBroadcaster, atdoc);
         PDResources sourcePageResources = page.findResources();
         PDFDictionary pageResources = null;
@@ -1360,7 +1373,8 @@ public class PDFBoxAdapter {
         String newStream = null;
         if (fonts != null && pdfDoc.isMergeFontsEnabled()) {
             fontsBackup = new COSDictionary(fonts);
-            MergeFontsPDFWriter m = new MergeFontsPDFWriter(fonts, fontinfo, uniqueName, getResourceNames(sourcePageResources.getCOSDictionary()));
+            MergeFontsPDFWriter m = new MergeFontsPDFWriter(fonts, fontinfo, uniqueName,
+                    getResourceNames(sourcePageResources.getCOSDictionary()));
             newStream = m.writeText(pdStream);
             parentFonts = m.fontsToRemove.values();
 //            if (newStream != null) {
@@ -1373,7 +1387,8 @@ public class PDFBoxAdapter {
 //            }
         }
         if (newStream == null) {
-            newStream = new PDFWriter(uniqueName, getResourceNames(sourcePageResources.getCOSDictionary())).writeText(pdStream);
+            newStream = new PDFWriter(uniqueName,
+                    getResourceNames(sourcePageResources.getCOSDictionary())).writeText(pdStream);
         }
         pdStream = new PDStream(sourceDoc, new ByteArrayInputStream(newStream.getBytes("ISO-8859-1")));
         mergeXObj(sourcePageResources.getCOSDictionary(), fontinfo, uniqueName);
@@ -1426,7 +1441,7 @@ public class PDFBoxAdapter {
 
         PDRectangle mediaBox = page.findMediaBox();
         PDRectangle cropBox = page.findCropBox();
-        PDRectangle viewBox = (cropBox != null ? cropBox : mediaBox);
+        PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
 
         //Handle the /Rotation entry on the page dict
         int rotation = PDFUtil.getNormalizedRotation(page);
@@ -1492,7 +1507,8 @@ public class PDFBoxAdapter {
                                 }
                             }
                         }
-                        PDFWriter writer = new MergeFontsPDFWriter(src, fontinfo, uniqueName, getResourceNames(sourcePageResources));
+                        PDFWriter writer = new MergeFontsPDFWriter(src, fontinfo, uniqueName,
+                                getResourceNames(sourcePageResources));
                         String c = writer.writeText(PDStream.createFromCOS(stream));
                         if (c != null) {
                             stream.removeItem(COSName.FILTER);
@@ -1538,7 +1554,8 @@ public class PDFBoxAdapter {
         return resourceNames;
     }
 
-    private void transferPageDict(COSDictionary fonts, String uniqueName, PDResources sourcePageResources) throws IOException {
+    private void transferPageDict(COSDictionary fonts, String uniqueName, PDResources sourcePageResources)
+        throws IOException {
         if (fonts != null) {
             for (Map.Entry<COSName, COSBase> f : fonts.entrySet()) {
                 String name = f.getKey().getName() + uniqueName;
@@ -1571,7 +1588,8 @@ public class PDFBoxAdapter {
         }
     }
 
-    private String getNewFont(COSDictionary fontData, FontInfo fontinfo, Collection<String> usedFonts) throws IOException {
+    private String getNewFont(COSDictionary fontData, FontInfo fontinfo, Collection<String> usedFonts)
+        throws IOException {
         String base = getUniqueFontName(fontData);
         if (base == null || usedFonts.contains(base) || (parentFonts != null && parentFonts.contains(base))) {
             return null;
@@ -1582,13 +1600,14 @@ public class PDFBoxAdapter {
                     return ((FOPPDFFont)t).addFont(fontData);
                 }
             }
-            if (base.endsWith("cid") || fontData.getItem(COSName.SUBTYPE) != COSName.TYPE1 && fontData.getItem(COSName.SUBTYPE) != COSName.TRUE_TYPE) {
+            if (base.endsWith("cid") || fontData.getItem(COSName.SUBTYPE) != COSName.TYPE1
+                    && fontData.getItem(COSName.SUBTYPE) != COSName.TRUE_TYPE) {
                 fontinfo.addMetrics(base, new FOPPDFMultiByteFont(fontData, base));
             } else {
                 fontinfo.addMetrics(base, new FOPPDFSingleByteFont(fontData, base));
             }
         } catch (IOException e) {
-            log.error(e);
+            log.warn(e.getMessage());
             return null;
         }
         fontinfo.useFont(base);
@@ -1615,7 +1634,7 @@ public class PDFBoxAdapter {
 
         PDRectangle mediaBox = page.findMediaBox();
         PDRectangle cropBox = page.findCropBox();
-        PDRectangle viewBox = (cropBox != null ? cropBox : mediaBox);
+        PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
 
         for (Object obj : pageAnnotations) {
             PDAnnotation annot = (PDAnnotation)obj;
@@ -1675,7 +1694,7 @@ public class PDFBoxAdapter {
             }
         }
 
-        boolean formAlreadyCopied = (getCachedClone(srcAcroForm) != null);
+        boolean formAlreadyCopied = getCachedClone(srcAcroForm) != null;
         PDFRoot catalog = this.pdfDoc.getRoot();
         PDFDictionary destAcroForm = (PDFDictionary)catalog.get(COSName.ACRO_FORM.getName());
         if (formAlreadyCopied) {
@@ -1695,7 +1714,7 @@ public class PDFBoxAdapter {
                 destAcroForm = new PDFDictionary(pdfDoc.getRoot());
             }
             pdfDoc.registerObject(destAcroForm);
-            catalog.put(COSName.ACRO_FORM.getName(), destAcroForm );
+            catalog.put(COSName.ACRO_FORM.getName(), destAcroForm);
         }
         PDFArray clonedFields = (PDFArray) destAcroForm.get(COSName.FIELDS.getName());
         if (clonedFields == null) {

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxEventProducer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxEventProducer.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxEventProducer.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxEventProducer.java Fri Jun 20 09:27:06 2014
@@ -1,3 +1,19 @@
+/*
+ * 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.fop.render.pdf.pdfbox;
 
 import org.apache.fop.events.EventBroadcaster;
@@ -44,7 +60,7 @@ interface PDFBoxEventProducer extends Ev
     /**
      * PDF/A mode is active.
      *
-     * @param source
+     * @param source the event source
      * @event.severity WARN
      */
     void pdfAActive(Object source);
@@ -52,7 +68,7 @@ interface PDFBoxEventProducer extends Ev
     /**
      * PDF/X mode is active.
      *
-     * @param source
+     * @param source the event source
      * @event.severity WARN
      */
     void pdfXActive(Object source);

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFBoxImageHandler.java Fri Jun 20 09:27:06 2014
@@ -26,11 +26,10 @@ import java.io.IOException;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import org.apache.fop.fonts.FontInfo;
 import org.apache.xmlgraphics.image.loader.Image;
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
 
-
+import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.render.ImageHandler;
 import org.apache.fop.render.RenderingContext;
 import org.apache.fop.render.pdf.PDFContentGenerator;

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFUtil.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFUtil.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFUtil.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PDFUtil.java Fri Jun 20 09:27:06 2014
@@ -24,7 +24,9 @@ import org.apache.pdfbox.pdmodel.PDPage;
 /**
  * Common utility functions for PDF access.
  */
-public class PDFUtil {
+public final class PDFUtil {
+
+    private PDFUtil() { }
 
     /**
      * Determines the rotation of a given page and normalizes the returned value to the values
@@ -40,12 +42,12 @@ public class PDFUtil {
             rotation += 360;
         }
         switch (rotation) {
-        case 90:
-        case 180:
-        case 270:
-            return rotation;
-        default:
-            return 0;
+            case 90:
+            case 180:
+            case 270:
+                return rotation;
+            default:
+                return 0;
         }
     }
 

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/src/java/org/apache/fop/render/pdf/pdfbox/PreloaderPDF.java Fri Jun 20 09:27:06 2014
@@ -56,7 +56,7 @@ public class PreloaderPDF extends Abstra
     private static final String PDF_HEADER = "%PDF-";
 
     /** static PDDocument cache for faster multi-page processing */
-    private static final Cache.Type CACHE_TYPE =Cache.Type.valueOf(
+    private static final Cache.Type CACHE_TYPE = Cache.Type.valueOf(
             System.getProperty("fop.pdfbox.preloader-cache", Cache.Type.WEAK.name()).toUpperCase());
 
     private static Map<Object, Cache<URI, PDDocument>> documentCacheMap
@@ -136,7 +136,7 @@ public class PreloaderPDF extends Abstra
         PDPage page = (PDPage)pddoc.getDocumentCatalog().getAllPages().get(selectedPage);
         PDRectangle mediaBox = page.findMediaBox();
         PDRectangle cropBox = page.findCropBox();
-        PDRectangle viewBox = (cropBox != null ? cropBox : mediaBox);
+        PDRectangle viewBox = cropBox != null ? cropBox : mediaBox;
         int w = Math.round(viewBox.getWidth() * 1000);
         int h = Math.round(viewBox.getHeight() * 1000);
 

Modified: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1604112&r1=1604111&r2=1604112&view=diff
==============================================================================
--- xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java (original)
+++ xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Fri Jun 20 09:27:06 2014
@@ -17,12 +17,36 @@
 
 package org.apache.fop.render.pdf;
 
-import junit.framework.Assert;
+import java.awt.Rectangle;
+import java.awt.geom.AffineTransform;
+import java.awt.geom.Rectangle2D;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javax.imageio.ImageIO;
+
+import org.junit.Test;
+
 import org.apache.commons.io.IOUtils;
 import org.apache.fontbox.cff.CFFFont;
 import org.apache.fontbox.cff.CFFParser;
 import org.apache.fontbox.ttf.TTFParser;
-import org.apache.fontbox.ttf.TrueTypeFont;
+import org.apache.fontbox.type1.Type1Font;
+import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.PDResources;
+
+import org.apache.xmlgraphics.image.loader.ImageInfo;
+import org.apache.xmlgraphics.image.loader.ImageSource;
+import org.apache.xmlgraphics.image.loader.impl.DefaultImageContext;
+
 import org.apache.fop.fonts.CustomFont;
 import org.apache.fop.fonts.FontInfo;
 import org.apache.fop.fonts.FontType;
@@ -32,29 +56,9 @@ import org.apache.fop.pdf.PDFDocument;
 import org.apache.fop.pdf.PDFPage;
 import org.apache.fop.pdf.PDFResources;
 import org.apache.fop.render.pdf.pdfbox.PDFBoxAdapter;
-
 import org.apache.fop.render.pdf.pdfbox.PreloaderPDF;
-import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSName;
-import org.apache.pdfbox.pdmodel.PDDocument;
-import org.apache.pdfbox.pdmodel.PDPage;
-import org.apache.pdfbox.pdmodel.PDResources;
-import org.apache.xmlgraphics.image.loader.ImageInfo;
-import org.apache.xmlgraphics.image.loader.ImageSource;
-import org.apache.xmlgraphics.image.loader.impl.DefaultImageContext;
 
-import org.junit.Test;
-
-import javax.imageio.ImageIO;
-
-import java.awt.Rectangle;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Rectangle2D;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.HashMap;
+import junit.framework.Assert;
 
 public class PDFBoxAdapterTestCase {
     private Rectangle2D r = new Rectangle2D.Double();
@@ -70,6 +74,10 @@ public class PDFBoxAdapterTestCase {
     private static final String TTSubset5 = "test/resources/ttsubset5.pdf";
     private static final String CFFCID1 = "test/resources/cffcid1.pdf";
     private static final String CFFCID2 = "test/resources/cffcid2.pdf";
+    private static final String Type1Subset1 = "test/resources/t1subset.pdf";
+    private static final String Type1Subset2 = "test/resources/t1subset2.pdf";
+    private static final String Type1Subset3 = "test/resources/t1subset3.pdf";
+    private static final String Type1Subset4 = "test/resources/t1subset4.pdf";
     private static final String ROTATE = "test/resources/rotate.pdf";
 
     private PDFBoxAdapter getPDFBoxAdapter() {
@@ -101,20 +109,29 @@ public class PDFBoxAdapterTestCase {
         Assert.assertTrue(msg, msg.contains("/Fm01700251251 Do"));
         msg = writeText(fi, CFFCID2);
         Assert.assertTrue(msg, msg.contains("/Fm01701174772 Do"));
+        msg = writeText(fi, Type1Subset1);
+        Assert.assertTrue(msg, msg.contains("/Verdana_Type1"));
+        msg = writeText(fi, Type1Subset2);
+        Assert.assertTrue(msg, msg.contains("[(2nd example)] TJ"));
+        msg = writeText(fi, Type1Subset3);
+        Assert.assertTrue(msg, msg.contains("/URWChanceryL-MediItal_Type1 20 Tf"));
+        msg = writeText(fi, Type1Subset4);
+        Assert.assertTrue(msg, msg.contains("/F15-1521012718 40 Tf"));
 
         for (Typeface font : fi.getUsedFonts().values()) {
             InputStream is = ((CustomFont) font).getInputStream();
-            if (font.getFontType() == FontType.TYPE1C ||
-                    font.getFontType() == FontType.CIDTYPE0) {
+            if (font.getFontType() == FontType.TYPE1C || font.getFontType() == FontType.CIDTYPE0) {
                 byte[] data = IOUtils.toByteArray(is);
                 CFFParser p = new CFFParser();
-                CFFFont ff = p.parse(data).get(0);
+                p.parse(data).get(0);
             } else if (font.getFontType() == FontType.TRUETYPE) {
                 TTFParser parser = new TTFParser();
-                TrueTypeFont ttf = parser.parseTTF(is);
+                parser.parseTTF(is);
             } else if (font.getFontType() == FontType.TYPE0) {
                 TTFParser parser = new TTFParser(true);
-                TrueTypeFont ttf = parser.parseTTF(is);
+                parser.parseTTF(is);
+            } else if (font.getFontType() == FontType.TYPE1) {
+                Type1Font.createWithPFB(is);
             }
             Assert.assertTrue(((CustomFont) font).isEmbeddable());
             if (font instanceof MultiByteFont) {
@@ -148,7 +165,8 @@ public class PDFBoxAdapterTestCase {
     @Test
     public void testCFF() throws Exception {
         PDDocument doc = PDDocument.load(CFF1);
-        PDFBoxAdapter.FOPPDFSingleByteFont sbfont = getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "R11"), "MyriadPro-Regular_Type1f0encstdcs");
+        PDFBoxAdapter.FOPPDFSingleByteFont sbfont = getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "R11"),
+                "MyriadPro-Regular_Type1f0encstdcs");
 
         Assert.assertTrue(Arrays.asList(sbfont.getEncoding().getCharNameMap()).contains("bracketright"));
         Assert.assertTrue(!Arrays.asList(sbfont.getEncoding().getCharNameMap()).contains("A"));
@@ -182,7 +200,8 @@ public class PDFBoxAdapterTestCase {
     @Test
     public void testCFF2() throws Exception {
         PDDocument doc = PDDocument.load(CFF3);
-        PDFBoxAdapter.FOPPDFSingleByteFont sbfont = getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "T1_0"), "Myriad_Pro_Type1f0encf1cs");
+        PDFBoxAdapter.FOPPDFSingleByteFont sbfont = getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "T1_0"),
+                "Myriad_Pro_Type1f0encf1cs");
         Assert.assertTrue(Arrays.asList(sbfont.getEncoding().getCharNameMap()).contains("uni004E"));
         Assert.assertEquals(sbfont.getFontName(), "Myriad_Pro_Type1f0encf1cs");
         Assert.assertEquals(sbfont.getEncodingName(), null);
@@ -199,7 +218,8 @@ public class PDFBoxAdapterTestCase {
     @Test
     public void testTTCID() throws Exception {
         PDDocument doc = PDDocument.load(TTCID1);
-        PDFBoxAdapter.FOPPDFMultiByteFont mbfont = getPDFBoxAdapter().new FOPPDFMultiByteFont(getFont(doc, "C2_0"), "ArialMT_Type0");
+        PDFBoxAdapter.FOPPDFMultiByteFont mbfont = getPDFBoxAdapter().new FOPPDFMultiByteFont(getFont(doc, "C2_0"),
+                "ArialMT_Type0");
         mbfont.addFont(getFont(doc, "C2_0"));
         Assert.assertEquals(mbfont.mapChar('t'), 67);
 
@@ -208,7 +228,7 @@ public class PDFBoxAdapterTestCase {
         Assert.assertEquals(name, "ArialMT_Type0");
         Assert.assertEquals(mbfont.getFontName(), "ArialMT_Type0");
         byte[] is = IOUtils.toByteArray(mbfont.getInputStream());
-        Assert.assertEquals(is.length, 38940);
+        Assert.assertEquals(is.length, 38640);
         doc.close();
         doc2.close();
     }
@@ -216,7 +236,8 @@ public class PDFBoxAdapterTestCase {
     @Test
     public void testTTSubset() throws Exception {
         PDDocument doc = PDDocument.load(TTSubset1);
-        PDFBoxAdapter.FOPPDFSingleByteFont mbfont = getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "R9"), "TimesNewRomanPSMT_TrueType");
+        PDFBoxAdapter.FOPPDFSingleByteFont mbfont = getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "R9"),
+                "TimesNewRomanPSMT_TrueType");
         mbfont.addFont(getFont(doc, "R9"));
         Assert.assertEquals(mbfont.mapChar('t'), 116);
 
@@ -225,7 +246,24 @@ public class PDFBoxAdapterTestCase {
         Assert.assertEquals(name, "TimesNewRomanPSMT_TrueType");
         Assert.assertEquals(mbfont.getFontName(), "TimesNewRomanPSMT_TrueType");
         byte[] is = IOUtils.toByteArray(mbfont.getInputStream());
-        Assert.assertEquals(is.length, 47888);
+        Assert.assertEquals(is.length, 34228);
+        doc.close();
+        doc2.close();
+    }
+
+    @Test
+    public void testType1Subset() throws Exception {
+        PDDocument doc = PDDocument.load(Type1Subset1);
+        PDFBoxAdapter.FOPPDFSingleByteFont mbfont =
+                getPDFBoxAdapter().new FOPPDFSingleByteFont(getFont(doc, "F15"), "");
+        mbfont.addFont(getFont(doc, "F15"));
+        PDDocument doc2 = PDDocument.load(Type1Subset2);
+        mbfont.addFont(getFont(doc2, "F15"));
+        Type1Font f = Type1Font.createWithPFB(mbfont.getInputStream());
+        Set<String> csDict = new TreeSet<String>(f.getCharStringsDict().keySet());
+        Assert.assertEquals(csDict.toString(), "[.notdef, a, d, e, hyphen, l, m, n, p, s, space, t, two, x]");
+        Assert.assertEquals(f.getSubrsArray().size(), 518);
+        Assert.assertEquals(f.getFamilyName(), "Verdana");
         doc.close();
         doc2.close();
     }
@@ -239,7 +277,8 @@ public class PDFBoxAdapterTestCase {
         AffineTransform at = new AffineTransform();
         Rectangle r = new Rectangle(0, 1650, 842000, 595000);
         String stream = adapter.createStreamFromPDFBoxPage(doc, page, "key", null, at, null, r);
-        Assert.assertEquals(at, new AffineTransform(-0.0, 1.0000000554888686, 1.0000000554888686, 0.0, 0.0, -2.0742416381835938E-5));
+        Assert.assertEquals(at, new AffineTransform(-0.0, 1.0000000554888686, 1.0000000554888686, 0.0, 0.0,
+                -2.0742416381835938E-5));
         Assert.assertTrue(stream.contains("/GS0106079 gs"));
         Assert.assertTrue(stream.contains("/TT0106079 1 Tf"));
         doc.close();

Added: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset.pdf?rev=1604112&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset2.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset2.pdf?rev=1604112&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset2.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset3.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset3.pdf?rev=1604112&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset3.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset4.pdf
URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset4.pdf?rev=1604112&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/branches/Temp_FontMerging/test/resources/t1subset4.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org