You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2016/06/28 20:29:57 UTC
svn commit: r1750580 - in /pdfbox/branches/2.0:
fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java
fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java
Author: tilman
Date: Tue Jun 28 20:29:57 2016
New Revision: 1750580
URL: http://svn.apache.org/viewvc?rev=1750580&view=rev
Log:
PDFBOX-3344: Handle the case where CFF/OTF fonts are embedded where TTF is expected + correct detection of OTF fonts via OTTO header, as done by John Hewson in the trunk
Modified:
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java
pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java
Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java?rev=1750580&r1=1750579&r2=1750580&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/OpenTypeFont.java Tue Jun 28 20:29:57 2016
@@ -40,7 +40,7 @@ public class OpenTypeFont extends TrueTy
@Override
void setVersion(float versionValue)
{
- isPostScript = versionValue != 1.0;
+ isPostScript = Float.floatToIntBits(versionValue) == 0x469EA8A9; // OTTO
super.setVersion(versionValue);
}
Modified: pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java?rev=1750580&r1=1750579&r2=1750580&view=diff
==============================================================================
--- pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java (original)
+++ pdfbox/branches/2.0/fontbox/src/main/java/org/apache/fontbox/ttf/TTFParser.java Tue Jun 28 20:29:57 2016
@@ -175,6 +175,8 @@ public class TTFParser
}
}
+ boolean isPostScript = font.tables.containsKey(CFFTable.TAG);
+
HeaderTable head = font.getHeader();
if (head == null)
{
@@ -200,26 +202,30 @@ public class TTFParser
throw new IOException("post is mandatory");
}
- IndexToLocationTable loc = font.getIndexToLocation();
- if (loc == null)
+ if (!isPostScript)
{
- throw new IOException("loca is mandatory");
- }
- // check other mandatory tables
- if (font.getGlyph() == null)
- {
- throw new IOException("glyf is mandatory");
+ IndexToLocationTable loc = font.getIndexToLocation();
+ if (loc == null)
+ {
+ throw new IOException("loca is mandatory");
+ }
+
+ if (font.getGlyph() == null)
+ {
+ throw new IOException("glyf is mandatory");
+ }
}
+
if (font.getNaming() == null && !isEmbedded)
{
throw new IOException("name is mandatory");
}
+
if (font.getHorizontalMetrics() == null)
{
throw new IOException("hmtx is mandatory");
}
-
- // check others mandatory tables
+
if (!isEmbedded && font.getCmap() == null)
{
throw new IOException("cmap is mandatory");
Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java?rev=1750580&r1=1750579&r2=1750580&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/font/PDCIDFontType2.java Tue Jun 28 20:29:57 2016
@@ -29,7 +29,6 @@ import org.apache.fontbox.ttf.CmapSubtab
import org.apache.fontbox.ttf.GlyphData;
import org.apache.fontbox.ttf.OTFParser;
import org.apache.fontbox.ttf.OpenTypeFont;
-import org.apache.fontbox.ttf.TTFParser;
import org.apache.fontbox.ttf.TrueTypeFont;
import org.apache.fontbox.util.BoundingBox;
import org.apache.pdfbox.cos.COSBase;
@@ -93,48 +92,36 @@ public class PDCIDFontType2 extends PDCI
{
boolean fontIsDamaged = false;
TrueTypeFont ttfFont = null;
- PDStream ff2Stream = fd.getFontFile2();
- PDStream ff3Stream = fd.getFontFile3();
-
- // Acrobat looks in FontFile too, even though it is not in the spec, see PDFBOX-2599
- if (ff2Stream == null && ff3Stream == null)
+
+ PDStream stream;
+ if (fd.getFontFile2() != null)
{
- ff2Stream = fd.getFontFile();
+ stream = fd.getFontFile2();
}
-
- if (ff2Stream != null)
+ else if (fd.getFontFile3() != null)
{
- try
- {
- // embedded
- TTFParser ttfParser = new TTFParser(true);
- ttfFont = ttfParser.parse(ff2Stream.createInputStream());
- }
- catch (NullPointerException e) // TTF parser is buggy
- {
- LOG.warn("Could not read embedded TTF for font " + getBaseFont(), e);
- fontIsDamaged = true;
- }
- catch (IOException e)
- {
- LOG.warn("Could not read embedded TTF for font " + getBaseFont(), e);
- fontIsDamaged = true;
- }
+ stream = fd.getFontFile3();
}
- else if (ff3Stream != null)
+ else
+ {
+ // Acrobat looks in FontFile too, even though it is not in the spec, see PDFBOX-2599
+ stream = fd.getFontFile();
+ }
+
+ if (stream != null)
{
try
{
- // embedded
+ // embedded OTF or TTF
OTFParser otfParser = new OTFParser(true);
- OpenTypeFont otf = otfParser.parse(ff3Stream.createInputStream());
+ OpenTypeFont otf = otfParser.parse(stream.createInputStream());
ttfFont = otf;
if (otf.isPostScript())
{
- // todo: we need more abstraction to support CFF fonts here
- throw new IOException("Not implemented: OpenType font with CFF table " +
- getBaseFont());
+ // PDFBOX-3344 contains PostScript outlines instead of TrueType
+ fontIsDamaged = true;
+ LOG.warn("Found CFF/OTF but expected embedded TTF font " + fd.getFontName());
}
if (otf.hasLayoutTables())
@@ -442,7 +429,9 @@ public class PDCIDFontType2 extends PDCI
{
if (ttf instanceof OpenTypeFont && ((OpenTypeFont)ttf).isPostScript())
{
- int cid = codeToCID(code);
+ // we're not supposed to have CFF fonts inside PDCIDFontType2, but if we do,
+ // then we treat their CIDs as GIDs, see PDFBOX-3344
+ int cid = codeToGID(code);
Type2CharString charstring = ((OpenTypeFont)ttf).getCFF().getFont().getType2CharString(cid);
return charstring.getPath();
}