From: Simon Steiner Date: Wed, 26 Apr 2023 12:59:23 +0000 (+0100) Subject: FOP-3130: Correct font differences table for Chrome X-Git-Tag: 2_9~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=387218dde1dcc8b7bf68065ae5b78411c45a89d6;p=xmlgraphics-fop.git FOP-3130: Correct font differences table for Chrome --- diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java index f0456a53f..0b69a8f64 100644 --- a/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java +++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFFactory.java @@ -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]); diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java index d6d7c50c1..14745cdee 100644 --- a/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java +++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFFactoryTestCase.java @@ -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