FOP-3020: Add space to standard position for font merge

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop-pdf-images/trunk@1891101 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java b/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
index b68c77c..f88adec 100644
--- a/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
+++ b/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java
@@ -188,7 +188,7 @@
                 MergeTTFonts.Cmap tempCmap = getNewCmap(c.getPlatformId(), c.getPlatformEncodingId());
                 for (int i = 0; i < 256 * 256; i++) {
                     int gid = c.getGlyphId(i);
-                    if (gid != 0) {
+                    if (gid != 0 && !tempCmap.glyphIdToCharacterCode.containsKey(i)) {
                         tempCmap.glyphIdToCharacterCode.put(i, gid);
                     }
                 }
@@ -328,12 +328,16 @@
                 }
             }
             String mappedChar = getChar(cmap, i);
-            if (mappedChar != null && !charMapGlobal.containsKey(mappedChar)) {
-                charMapGlobal.put(mappedChar, glyphIndexPos);
-                if (!addedWidth && w < font.getWidths().size()) {
-                    newWidth.put(newWidth.size() + getFirstChar(), neww);
+            if (mappedChar != null) {
+                if (!charMapGlobal.containsKey(mappedChar)) {
+                    charMapGlobal.put(mappedChar, glyphIndexPos);
+                    if (!addedWidth && w < font.getWidths().size()) {
+                        newWidth.put(newWidth.size() + getFirstChar(), neww);
+                    }
+                    skipGlyphIndex++;
+                } else if (glyphIndexPos < charMapGlobal.get(mappedChar)) {
+                    charMapGlobal.put(mappedChar, glyphIndexPos);
                 }
-                skipGlyphIndex++;
             }
             w++;
         }
diff --git a/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java b/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java
index c7ad2d8..7dfaa60 100644
--- a/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/FOPPDFSingleMultiByteFontTestCase.java
@@ -215,5 +215,5 @@
         public String addFont(COSDictionary fontData) {
             return null;
         }
-    };
+    }
 }
diff --git a/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java b/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
index f148c9a..eea0627 100644
--- a/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
+++ b/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
@@ -104,6 +104,8 @@
     protected static final String TTSubset2 = "test/resources/ttsubset2.pdf";
     private static final String TTSubset3 = "test/resources/ttsubset3.pdf";
     private static final String TTSubset5 = "test/resources/ttsubset5.pdf";
+    private static final String TTSubset6 = "test/resources/ttsubset6.pdf";
+    private static final String TTSubset7 = "test/resources/ttsubset7.pdf";
     protected static final String CFFCID1 = "test/resources/cffcid1.pdf";
     private static final String CFFCID2 = "test/resources/cffcid2.pdf";
     protected static final String Type1Subset1 = "test/resources/t1subset.pdf";
@@ -721,4 +723,12 @@
         String msg = writeText(fi, TTSubset3);
         Assert.assertTrue(msg, msg.contains("/ArialMT_TrueTypecidcmap1"));
     }
+
+    @Test
+    public void testMapChar() throws Exception {
+        FontInfo fi = new FontInfo();
+        writeText(fi, TTSubset6);
+        String msg = writeText(fi, TTSubset7);
+        Assert.assertTrue(msg, msg.contains("( )Tj"));
+    }
 }
diff --git a/test/resources/ttsubset6.pdf b/test/resources/ttsubset6.pdf
new file mode 100755
index 0000000..ba1ab35
--- /dev/null
+++ b/test/resources/ttsubset6.pdf
Binary files differ
diff --git a/test/resources/ttsubset7.pdf b/test/resources/ttsubset7.pdf
new file mode 100755
index 0000000..5d7c683
--- /dev/null
+++ b/test/resources/ttsubset7.pdf
Binary files differ