You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2015/01/13 21:46:12 UTC
svn commit: r1651484 -
/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java
Author: jahewson
Date: Tue Jan 13 20:46:12 2015
New Revision: 1651484
URL: http://svn.apache.org/r1651484
Log:
PDFBOX-2599: Assume Identity CID2GIDMap when there is no ToUnicode CMap to fallback to
Modified:
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java
Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java?rev=1651484&r1=1651483&r2=1651484&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java Tue Jan 13 20:46:12 2015
@@ -234,39 +234,39 @@ public class PDCIDFontType2 extends PDCI
// encoding specified by the predefined CMap to one of the encodings in the TrueType
// font's 'cmap' table. The means by which this is accomplished are implementation-
// dependent.
+
+ boolean hasUnicodeMap = parent.getCMapUCS2() != null;
- String unicode;
-
- if (cid2gid != null || hasIdentityCid2Gid)
+ if (cid2gid != null)
{
+ // Acrobat allows non-embedded GIDs - todo: can we find a test PDF for this?
int cid = codeToCID(code);
- // strange but true, Acrobat allows non-embedded GIDs, test with PDFBOX-2060
- if (hasIdentityCid2Gid)
- {
- return cid;
- }
- else
- {
- return cid2gid[cid];
- }
+ return cid2gid[cid];
}
- else
+ else if (hasIdentityCid2Gid || !hasUnicodeMap)
{
- // test with PDFBOX-1422 and PDFBOX-2560
- unicode = parent.toUnicode(code);
+ // same as above, but for the default Identity CID2GIDMap or when there is no
+ // ToUnicode CMap to fallback to, see PDFBOX-2599 and PDFBOX-2560
+ // todo: can we find a test PDF for the Identity case?
+ return codeToCID(code);
}
-
- if (unicode == null)
- {
- return 0;
- }
- else if (unicode.length() > 1)
+ else
{
- LOG.warn("trying to map a multi-byte character using 'cmap', result will be poor");
+ // fallback to the ToUnicode CMap, test with PDFBOX-1422 and PDFBOX-2560
+ String unicode = parent.toUnicode(code);
+ if (unicode == null)
+ {
+ LOG.warn("Failed to find a character mapping for " + code + " in " + getName());
+ return 0;
+ }
+ else if (unicode.length() > 1)
+ {
+ LOG.warn("Trying to map multi-byte character using 'cmap', result will be poor");
+ }
+
+ // a non-embedded font always has a cmap (otherwise ExternalFonts won't load it)
+ return cmap.getGlyphId(unicode.codePointAt(0));
}
-
- // a non-embedded font always has a cmap (otherwise ExternalFonts won't load it)
- return cmap.getGlyphId(unicode.codePointAt(0));
}
else
{