Author: ssteiner Date: Thu Apr 22 11:13:31 2021 New Revision: 1889104 URL: http://svn.apache.org/viewvc?rev=1889104&view=rev Log: FOP-3009: Avoid merging fonts with different number of cmap formats
Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java?rev=1889104&r1=1889103&r2=1889104&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/FOPPDFSingleByteFont.java Thu Apr 22 11:13:31 2021 @@ -105,7 +105,7 @@ public class FOPPDFSingleByteFont extend Set<Integer> codeToName = getCodeToName(font.getEncoding()).keySet(); for (int i = getFirstChar(); i <= Math.min(getLastChar(), getFirstChar() + font.getWidths().size()); i++) { - if (usesZero || codeToName.contains(i)) { + if (usesZero || codeToName.contains(i) || codeToName.isEmpty()) { int w = font.getWidths().get(i - getFirstChar()); newWidth.put(i, w); } else { Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java?rev=1889104&r1=1889103&r2=1889104&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeFontsPDFWriter.java Thu Apr 22 11:13:31 2021 @@ -181,11 +181,15 @@ public class MergeFontsPDFWriter extends } } else if (font instanceof PDTrueTypeFont && isSubsetFont(font.getName())) { TrueTypeFont tt = ((PDTrueTypeFont) font).getTrueTypeFont(); - for (CmapSubtable c : tt.getCmap().getCmaps()) { + CmapSubtable[] cmaps = tt.getCmap().getCmaps(); + for (CmapSubtable c : cmaps) { if (c.getGlyphId(1) > 0) { extra = "cid"; } } + if (cmaps.length != 2) { + extra += "cmap" + cmaps.length; + } return name + extra; } else if (font instanceof PDType1CFont) { return getNamePDType1Font(name, (PDType1CFont) font); Modified: xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java?rev=1889104&r1=1889103&r2=1889104&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java (original) +++ xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/MergeTTFonts.java Thu Apr 22 11:13:31 2021 @@ -18,6 +18,7 @@ package org.apache.fop.render.pdf.pdfbox import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -351,52 +352,50 @@ public class MergeTTFonts extends TTFSub } for (Cmap cmap : cmaps) { - writeUShort(12); //subtableFormat - writeUShort(0); - writeULong(currentPos, (cmap.glyphIdToCharacterCode.size() * 12) + 16); - currentPos += 4; - writeULong(currentPos, 0); - currentPos += 4; - writeULong(currentPos, cmap.glyphIdToCharacterCode.size()); - currentPos += 4; - - for (Map.Entry<Integer, Integer> g : cmap.glyphIdToCharacterCode.entrySet()) { - writeULong(currentPos, g.getKey()); + if (cmap.platformId == 1 && cmaps.size() == 1) { + writeUShort(6); //subtableFormat + int firstCode = -1; + int lastCode = -1; + List<Integer> codes = new ArrayList<Integer>(); + for (Map.Entry<Integer, Integer> g : cmap.glyphIdToCharacterCode.entrySet()) { + if (firstCode < 0) { + firstCode = g.getKey(); + } + while (lastCode > 0 && lastCode + 1 < g.getKey()) { + codes.add(0); + lastCode++; + } + codes.add(g.getValue()); + lastCode = g.getKey(); + } + writeUShort((codes.size() * 2) + 6); //length + writeUShort(0); //version + writeUShort(firstCode); //firstCode + writeUShort(codes.size()); //entryCount + for (int i : codes) { + writeUShort(i); + } + } else { + writeUShort(12); //subtableFormat + writeUShort(0); + writeULong(currentPos, (cmap.glyphIdToCharacterCode.size() * 12) + 16); currentPos += 4; - writeULong(currentPos, g.getKey()); + writeULong(currentPos, 0); currentPos += 4; - writeULong(currentPos, g.getValue()); + writeULong(currentPos, cmap.glyphIdToCharacterCode.size()); currentPos += 4; + + for (Map.Entry<Integer, Integer> g : cmap.glyphIdToCharacterCode.entrySet()) { + writeULong(currentPos, g.getKey()); + currentPos += 4; + writeULong(currentPos, g.getKey()); + currentPos += 4; + writeULong(currentPos, g.getValue()); + currentPos += 4; + } } } -// writeUShort(6); //subtableFormat -// int firstCode = -1; -// int lastCode = -1; -// List<Integer> codes = new ArrayList<Integer>(); -// for (Map.Entry<Integer, Integer> g : glyphIdToCharacterCode.entrySet()) { -// if (firstCode < 0) { -// firstCode = g.getKey(); -// } -// while (lastCode > 0 && lastCode + 1 < g.getKey()) { -// codes.add(0); -// lastCode++; -// } -// codes.add(g.getValue()); -// -// lastCode = g.getKey(); -// } -// -// writeUShort((codes.size() * 2) + 6); //length -// writeUShort(0); //version -// -// writeUShort(firstCode); //firstCode -// writeUShort(codes.size()); //entryCount -// -// for (int i : codes) { -// writeUShort(i); -// } - updateCheckSum(checksum, currentPos - cmapPos, OFTableName.CMAP); realSize += currentPos - cmapPos; } Modified: xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java URL: http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1889104&r1=1889103&r2=1889104&view=diff ============================================================================== --- xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java (original) +++ xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java Thu Apr 22 11:13:31 2021 @@ -152,9 +152,9 @@ public class PDFBoxAdapterTestCase { msg = writeText(fi, TTSubset2); Assert.assertTrue(msg, msg.contains("(t)-0.168 (e)-0.1523 (s)0.1528 (t)")); msg = writeText(fi, TTSubset3); - Assert.assertTrue(msg, msg.contains("[<0001>3 <0002>-7 <0003>] TJ")); + Assert.assertTrue(msg, msg.contains("[<01>3 <02>-7 <03>] TJ")); msg = writeText(fi, TTSubset5); - Assert.assertTrue(msg, msg.contains("[<0003>2 <0004>-7 <0007>] TJ")); + Assert.assertTrue(msg, msg.contains("[(\u0001)2 (\u0002)-7 (\u0003)] TJ")); msg = writeText(fi, TTCID1); Assert.assertTrue(msg, msg.contains("<0028003B0034003000420034>")); msg = writeText(fi, TTCID2); @@ -714,4 +714,11 @@ public class PDFBoxAdapterTestCase { pdfdoc.output(bos); Assert.assertTrue(bos.toString("UTF-8").contains("/Filter /DCTDecode")); } + + @Test + public void testCmapLengthInName() throws IOException { + FontInfo fi = new FontInfo(); + String msg = writeText(fi, TTSubset3); + Assert.assertTrue(msg, msg.contains("/ArialMT_TrueTypecidcmap1")); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: fop-commits-unsubscr...@xmlgraphics.apache.org For additional commands, e-mail: fop-commits-h...@xmlgraphics.apache.org