diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/FontDetails.java b/openpdf/src/main/java/com/lowagie/text/pdf/FontDetails.java index 1c97808e0..40ad92009 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/FontDetails.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/FontDetails.java @@ -111,6 +111,12 @@ class FontDetails { */ protected boolean subset = true; + /** + * Contain glyphs that used but missing in Cmap. the value is int[]{glyph, Unicode code} + */ + private Map fillerCmap; + + Map getFillerCmap() { return fillerCmap; } @@ -119,11 +125,6 @@ void putFillerCmap(Integer key, int[] value) { fillerCmap.put(key, value); } - /** - * Contain glyphs that used but missing in Cmap. the value is int[]{glyph, Unicode code} - */ - private Map fillerCmap; - /** * Each font used in a document has an instance of this class. This class stores the characters used in the document * and other specifics unique to the current working document. diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/TrueTypeFontUnicode.java b/openpdf/src/main/java/com/lowagie/text/pdf/TrueTypeFontUnicode.java index 1dd74e2be..9a2fd472f 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/TrueTypeFontUnicode.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/TrueTypeFontUnicode.java @@ -67,7 +67,10 @@ * * @author Paulo Soares (psoares@consiste.pt) */ -class TrueTypeFontUnicode extends TrueTypeFont implements Comparator { +class TrueTypeFontUnicode extends TrueTypeFont implements Comparator { + + private static final byte[] rotbits = {(byte) 0x80, (byte) 0x40, (byte) 0x20, (byte) 0x10, (byte) 0x08, (byte) 0x04, + (byte) 0x02, (byte) 0x01}; /** * true if the encoding is vertical. @@ -115,7 +118,6 @@ class TrueTypeFontUnicode extends TrueTypeFont implements Comparator { if ((cmap31 == null && !fontSpecific) || (cmap10 == null && fontSpecific)) { directTextToByte = true; } - //throw new DocumentException(MessageLocalization.getComposedMessage("1.2.does.not.contain.an.usable.cmap", fileName, style)); if (fontSpecific) { fontSpecific = false; String tempEncoding = encoding; @@ -131,10 +133,11 @@ class TrueTypeFontUnicode extends TrueTypeFont implements Comparator { vertical = enc.endsWith("V"); } + @Override void readCMaps() throws DocumentException, IOException { super.readCMaps(); - Map cmap = null; + Map cmap = null; if (cmapExt != null) { cmap = cmapExt; } else if (cmap31 != null) { @@ -143,10 +146,9 @@ void readCMaps() throws DocumentException, IOException { if (cmap != null) { inverseCmap = new HashMap<>(); - for (Object o : cmap.entrySet()) { - Map.Entry entry = (Map.Entry) o; - Integer code = (Integer) entry.getKey(); - int[] metrics = (int[]) entry.getValue(); + for (Map.Entry entry : cmap.entrySet()) { + Integer code = entry.getKey(); + int[] metrics = entry.getValue(); inverseCmap.put(metrics[0], code); } } @@ -163,6 +165,7 @@ protected Integer getCharacterCode(int code) { * @param char1 the unicode char to get the width of * @return the width in normalized 1000 units */ + @Override public int getWidth(int char1) { if (vertical) { return 1000; @@ -184,6 +187,7 @@ public int getWidth(int char1) { * @param text the String to get the width of * @return the width in normalized 1000 units */ + @Override public int getWidth(String text) { if (vertical) { return text.length() * 1000; @@ -191,7 +195,6 @@ public int getWidth(String text) { int total = 0; if (fontSpecific) { char[] cc = text.toCharArray(); - int len = cc.length; for (char c : cc) { if ((c & 0xff00) == 0 || (c & 0xff00) == 0xf000) { total += getRawWidth(c & 0xff, null); @@ -284,8 +287,7 @@ private int[][] filterCmapMetrics(int[][] metrics) { } List cmapMetrics = new ArrayList<>(metrics.length); - for (int[] metric1 : metrics) { - int[] metric = metric1; + for (int[] metric : metrics) { // PdfContentByte.showText(GlyphVector) uses glyphs that might not // map to a character. // the glyphs are included in the metrics array, but we need to @@ -355,8 +357,7 @@ private PdfDictionary getCIDFontType2(PdfIndirectReference fontDescriptor, Strin StringBuilder buf = new StringBuilder("["); int lastNumber = -10; boolean firstTime = true; - for (int[] metric1 : metrics) { - int[] metric = metric1; + for (int[] metric : metrics) { if (metric[1] == 1000) { continue; } @@ -396,12 +397,9 @@ private PdfDictionary getFontBaseType(PdfIndirectReference descendant, String su // The PDF Reference manual advises to add -encoding to CID font names if (cff) { dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName + "-" + encoding)); - } - //dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix+fontName)); - else { + } else { dic.put(PdfName.BASEFONT, new PdfName(subsetPrefix + fontName)); } - //dic.put(PdfName.BASEFONT, new PdfName(fontName)); dic.put(PdfName.ENCODING, new PdfName(encoding)); dic.put(PdfName.DESCENDANTFONTS, new PdfArray(descendant)); if (toUnicode != null) { @@ -417,15 +415,12 @@ private PdfDictionary getFontBaseType(PdfIndirectReference descendant, String su * @param o2 the second element * @return the comparison */ - public int compare(Object o1, Object o2) { - int m1 = ((int[]) o1)[0]; - int m2 = ((int[]) o2)[0]; + public int compare(int[] o1, int[] o2) { + int m1 = (o1)[0]; + int m2 = (o2)[0]; return Integer.compare(m1, m2); } - private static final byte[] rotbits = {(byte) 0x80, (byte) 0x40, (byte) 0x20, (byte) 0x10, (byte) 0x08, (byte) 0x04, - (byte) 0x02, (byte) 0x01}; - /** * Outputs to the writer the font dictionaries and streams. * @@ -443,7 +438,7 @@ void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) thro addRangeUni(longTag, true, subset); int[][] metrics = longTag.values().toArray(new int[0][]); Arrays.sort(metrics, this); - PdfIndirectReference ind_font; + PdfIndirectReference indFont; PdfObject pobj; PdfIndirectObject obj; PdfIndirectReference cidset = null; @@ -473,7 +468,7 @@ void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) thro } pobj = new StreamFont(b, "CIDFontType0C", compressionLevel); obj = writer.addToBody(pobj); - ind_font = obj.getIndirectReference(); + indFont = obj.getIndirectReference(); } else { byte[] b; if (subset || directoryOffset != 0) { @@ -486,19 +481,19 @@ void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) thro int[] lengths = new int[]{b.length}; pobj = new StreamFont(b, lengths, compressionLevel); obj = writer.addToBody(pobj); - ind_font = obj.getIndirectReference(); + indFont = obj.getIndirectReference(); } String subsetPrefix = ""; if (subset) { subsetPrefix = createSubsetPrefix(); } - PdfDictionary dic = getFontDescriptor(ind_font, subsetPrefix, cidset); + PdfDictionary dic = getFontDescriptor(indFont, subsetPrefix, cidset); obj = writer.addToBody(dic); - ind_font = obj.getIndirectReference(); + indFont = obj.getIndirectReference(); - pobj = getCIDFontType2(ind_font, subsetPrefix, metrics); + pobj = getCIDFontType2(indFont, subsetPrefix, metrics); obj = writer.addToBody(pobj); - ind_font = obj.getIndirectReference(); + indFont = obj.getIndirectReference(); pobj = getToUnicode(mergeMetricsAndFillerCmap(metrics, fillerCmap)); PdfIndirectReference toUnicodeRef = null; @@ -508,7 +503,7 @@ void writeFont(PdfWriter writer, PdfIndirectReference ref, Object[] params) thro toUnicodeRef = obj.getIndirectReference(); } - pobj = getFontBaseType(ind_font, subsetPrefix, toUnicodeRef); + pobj = getFontBaseType(indFont, subsetPrefix, toUnicodeRef); writer.addToBody(pobj, ref); } @@ -532,6 +527,7 @@ public int[][] mergeMetricsAndFillerCmap(int[][] metric, Map fil * @return a PdfStream with the font program * @since 2.1.3 */ + @Override public PdfStream getFullFontStream() throws IOException, DocumentException { if (cff) { return new StreamFont(readCffFont(), "CIDFontType0C", compressionLevel); @@ -545,10 +541,12 @@ public PdfStream getFullFontStream() throws IOException, DocumentException { * @param text the text * @return always null */ + @Override byte[] convertToBytes(String text) { return null; } + @Override byte[] convertToBytes(int char1) { return null; } @@ -559,6 +557,7 @@ byte[] convertToBytes(int char1) { * @param c the character * @return an int array with {glyph index, width} */ + @Override public int[] getMetricsTT(int c) { if (cmapExt != null) { return cmapExt.get(c); @@ -590,6 +589,7 @@ public int[] getMetricsTT(int c) { * @return true if the character has a glyph, * false otherwise */ + @Override public boolean charExists(int c) { return getMetricsTT(c) != null; } @@ -602,6 +602,7 @@ public boolean charExists(int c) { * @return true if the advance was set, * false otherwise */ + @Override public boolean setCharAdvance(int c, int advance) { int[] m = getMetricsTT(c); if (m == null) { @@ -611,6 +612,7 @@ public boolean setCharAdvance(int c, int advance) { return true; } + @Override public int[] getCharBBox(int c) { if (bboxes == null) { return null; diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/FontSubsetTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/FontSubsetTest.java index acf6c0f51..f33f0e7b9 100644 --- a/openpdf/src/test/java/com/lowagie/text/pdf/FontSubsetTest.java +++ b/openpdf/src/test/java/com/lowagie/text/pdf/FontSubsetTest.java @@ -59,11 +59,11 @@ private byte[] getLiberationFontByte() throws IOException { */ @Test void includeCidSetTest() throws Exception { - checkCidSetPresence(true); - checkCidSetPresence(false); + assertCidSetPresence(true); + assertCidSetPresence(false); } - private void checkCidSetPresence(boolean includeCidSet) throws Exception { + private void assertCidSetPresence(boolean includeCidSet) throws Exception { byte[] documentBytes; try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) { Document document = new Document();