From c854b18bc1b552a46a6f35a91752324ae58906b3 Mon Sep 17 00:00:00 2001 From: Marek Kasik Date: Wed, 24 Jun 2015 14:20:15 +0200 Subject: [PATCH] Embed Type1 fonts to PostScript files correctly Remove PFB headers from embedded Type1 fonts before embedding them into a PostScript file. https://bugs.freedesktop.org/show_bug.cgi?id=19747 --- poppler/PSOutputDev.cc | 57 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc index 5dc89be..c701159 100644 --- a/poppler/PSOutputDev.cc +++ b/poppler/PSOutputDev.cc @@ -2122,7 +2122,7 @@ void PSOutputDev::setupEmbeddedType1Font(Ref *id, GooString *psName) { static const char hexChar[17] = "0123456789abcdef"; Object refObj, strObj, obj1, obj2, obj3; Dict *dict; - int length1, length2, length3; + long length1, length2, length3; int c; int start[4]; GBool binMode; @@ -2172,8 +2172,18 @@ void PSOutputDev::setupEmbeddedType1Font(Ref *id, GooString *psName) { embFontList->append(psName->getCString()); embFontList->append("\n"); - // copy ASCII portion of font strObj.streamReset(); + if (strObj.streamGetChar() == 0x80 && + strObj.streamGetChar() == 1) { + // PFB format + length1 = strObj.streamGetChar() | + (strObj.streamGetChar() << 8) | + (strObj.streamGetChar() << 16) | + (strObj.streamGetChar() << 24); + } else { + strObj.streamReset(); + } + // copy ASCII portion of font for (i = 0; i < length1 && (c = strObj.streamGetChar()) != EOF; ++i) { writePSChar(c); } @@ -2206,9 +2216,18 @@ void PSOutputDev::setupEmbeddedType1Font(Ref *id, GooString *psName) { // convert binary data to ASCII if (binMode) { - for (i = 0; i < 4; ++i) { - writePSChar(hexChar[(start[i] >> 4) & 0x0f]); - writePSChar(hexChar[start[i] & 0x0f]); + if (start[0] == 0x80 && + start[1] == 2) { + length2 = start[2] | + (start[3] << 8) | + (strObj.streamGetChar() << 16) | + (strObj.streamGetChar() << 24); + i = 0; + } else { + for (i = 0; i < 4; ++i) { + writePSChar(hexChar[(start[i] >> 4) & 0x0f]); + writePSChar(hexChar[start[i] & 0x0f]); + } } #if 0 // this causes trouble for various PostScript printers // if Length2 is incorrect (too small), font data gets chopped, so @@ -2246,8 +2265,32 @@ void PSOutputDev::setupEmbeddedType1Font(Ref *id, GooString *psName) { { if (length3 > 0) { // write fixed-content portion - while ((c = strObj.streamGetChar()) != EOF) { - writePSChar(c); + c = strObj.streamGetChar(); + if (c == 0x80) { + c = strObj.streamGetChar(); + if (c == 1) { + length3 = strObj.streamGetChar() | + (strObj.streamGetChar() << 8) | + (strObj.streamGetChar() << 16) | + (strObj.streamGetChar() << 24); + + i = 0; + while (i < length3) { + if ((c = strObj.streamGetChar()) == EOF) { + break; + } + writePSChar(c); + ++i; + } + } + } else { + if (c != EOF) { + writePSChar(c); + + while ((c = strObj.streamGetChar()) != EOF) { + writePSChar(c); + } + } } } else { // write padding and "cleartomark" -- 2.4.3