]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
FOP-3130: Correct font differences table for Chrome
authorSimon Steiner <ssteiner@apache.org>
Wed, 26 Apr 2023 12:59:23 +0000 (13:59 +0100)
committerSimon Steiner <ssteiner@apache.org>
Wed, 26 Apr 2023 12:59:23 +0000 (13:59 +0100)
fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java
fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java

index f0456a53f5b74e58ea4e126ab86311ce9c1dd24f..0b69a8f64305c25fdd347fa3ff1dd8b1d9543683 100644 (file)
@@ -1092,7 +1092,7 @@ public class PDFFactory {
                         if (charNameMap.length < len) {
                             len = charNameMap.length;
                         }
-                        int last = 0;
+                        int last = Integer.MIN_VALUE;
                         for (int i = 0; i < len; i++) {
                             if (intmap[i] - 1 != last) {
                                 differences.add(intmap[i]);
index d6d7c50c14c99e686b7c00d840c43d0ba44f3740..14745cdee9ab2c20c6fde7ea2ad406eb8b361ace 100644 (file)
@@ -46,6 +46,7 @@ import org.apache.fop.fonts.FontType;
 import org.apache.fop.fonts.FontUris;
 import org.apache.fop.fonts.MultiByteFont;
 import org.apache.fop.fonts.NamedCharacter;
+import org.apache.fop.fonts.SingleByteEncoding;
 import org.apache.fop.fonts.SingleByteFont;
 import org.apache.fop.fonts.truetype.OFFontLoader;
 
@@ -110,6 +111,35 @@ public class PDFFactoryTestCase {
         assertEquals(sb.getAdditionalEncodingCount(), 1);
     }
 
+    @Test
+    public void testDifferencesStartValue() throws IOException {
+        PDFDocument doc = new PDFDocument("");
+        PDFFactory pdfFactory = new PDFFactory(doc);
+        TestSingleByteFont sb = new TestSingleByteFont(null);
+        sb.setFlags(0);
+        sb.setMapping(new SingleByteEncoding() {
+            public String getName() {
+                return "FOPPDFEncoding";
+            }
+
+            public char mapChar(char c) {
+                return 0;
+            }
+
+            public String[] getCharNameMap() {
+                return new String[]{"a"};
+            }
+
+            public char[] getUnicodeCharMap() {
+                return new char[]{1};
+            }
+        });
+        pdfFactory.makeFont("a", "a", "WinAnsiEncoding", sb, sb);
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        doc.outputTrailer(bos);
+        assertTrue(bos.toString().contains("/Differences [1 /a]"));
+    }
+
     @Test
     public void testMakeTrueTypeFont() throws IOException {
         PDFDocument doc = new PDFDocument("");
@@ -135,6 +165,10 @@ public class PDFFactoryTestCase {
             File f = new File("test/resources/fonts/type1/a010013l.pfb");
             return new FileInputStream(f);
         }
+
+        public void setMapping(SingleByteEncoding mapping) {
+            this.mapping = mapping;
+        }
     }
 
     @Test