[poppler] goo/GooString.cc goo/GooString.h poppler/PDFDoc.cc poppler/PSOutputDev.cc poppler/PSOutputDev.h
Albert Astals Cid
aacid at kemper.freedesktop.org
Sat Dec 27 16:32:04 PST 2008
goo/GooString.cc | 36 ++++++++++++++++++++++++++++++++++++
goo/GooString.h | 7 +++++++
poppler/PDFDoc.cc | 7 ++++++-
poppler/PSOutputDev.cc | 49 +++++++++----------------------------------------
poppler/PSOutputDev.h | 3 +--
5 files changed, 59 insertions(+), 43 deletions(-)
New commits:
commit 217b46484ff56bfd5906b293ebee70b82cc0263d
Author: Albert Astals Cid <aacid at kde.org>
Date: Sun Dec 28 01:29:41 2008 +0100
Move PSOutputDev::filterPSName to GooString::sanitizedName so i can use it from PDFDoc::writeObject
diff --git a/goo/GooString.cc b/goo/GooString.cc
index 036a432..74645aa 100644
--- a/goo/GooString.cc
+++ b/goo/GooString.cc
@@ -18,6 +18,7 @@
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
// Copyright (C) 2007 Jeff Muizelaar <jeff at infidigm.net>
+// Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -742,3 +743,38 @@ GBool GooString::hasUnicodeMarker(void)
{
return (s[0] & 0xff) == 0xfe && (s[1] & 0xff) == 0xff;
}
+
+GooString *GooString::sanitizedName(GBool psmode) const
+{
+ GooString *name;
+ char buf[8];
+ int i;
+ char c;
+
+ name = new GooString();
+
+ if (psmode)
+ {
+ // ghostscript chokes on names that begin with out-of-limits
+ // numbers, e.g., 1e4foo is handled correctly (as a name), but
+ // 1e999foo generates a limitcheck error
+ c = name->getChar(0);
+ if (c >= '0' && c <= '9') {
+ name->append('f');
+ }
+ }
+
+ for (i = 0; i < name->getLength(); ++i) {
+ c = name->getChar(i);
+ if ((psmode && (c <= (char)0x20 || c >= (char)0x7f)) ||
+ c == '(' || c == ')' || c == '<' || c == '>' ||
+ c == '[' || c == ']' || c == '{' || c == '}' ||
+ c == '/' || c == '%') {
+ sprintf(buf, "#%02x", c & 0xff);
+ name->append(buf);
+ } else {
+ name->append(c);
+ }
+ }
+ return name;
+}
diff --git a/goo/GooString.h b/goo/GooString.h
index 7f0671f..bd7b1ff 100644
--- a/goo/GooString.h
+++ b/goo/GooString.h
@@ -17,6 +17,7 @@
//
// Copyright (C) 2006 Kristian Høgsberg <krh at redhat.com>
// Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk at gmail.com>
+// Copyright (C) 2008 Albert Astals Cid <aacid at kde.org>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
@@ -137,6 +138,12 @@ public:
GBool hasUnicodeMarker(void);
+ // Sanitizes the string so that it does
+ // not contain any ( ) < > [ ] { } / %
+ // The postscript mode also has some more strict checks
+ // The caller owns the return value
+ GooString *sanitizedName(GBool psmode) const;
+
private:
// you can tweak this number for a different speed/memory usage tradeoffs.
// In libc malloc() rounding is 16 so it's best to choose a value that
diff --git a/poppler/PDFDoc.cc b/poppler/PDFDoc.cc
index 791f851..c2d03fe 100644
--- a/poppler/PDFDoc.cc
+++ b/poppler/PDFDoc.cc
@@ -727,8 +727,13 @@ Guint PDFDoc::writeObject (Object* obj, Ref* ref, OutStream* outStr)
writeString(obj->getString(), outStr);
break;
case objName:
- outStr->printf("/%s ", obj->getName());
+ {
+ GooString name(obj->getName());
+ GooString *nameToPrint = name.sanitizedName(gFalse /* non ps mode */);
+ outStr->printf("/%s ", nameToPrint->getCString());
+ delete nameToPrint;
break;
+ }
case objNull:
outStr->printf( "null");
break;
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index b94eb42..ada2b4c 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -1648,7 +1648,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
} else if (globalParams->getPSEmbedType1() &&
font->getType() == fontType1 &&
font->getEmbeddedFontID(&fontFileID)) {
- psName = filterPSName(font->getEmbeddedFontName());
+ psName = font->getEmbeddedFontName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedType1Font(&fontFileID, psName);
// check for embedded Type 1C font
@@ -1657,7 +1657,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
font->getEmbeddedFontID(&fontFileID)) {
// use the PDF font name because the embedded font name might
// not include the subset prefix
- psName = filterPSName(font->getOrigName());
+ psName = font->getOrigName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedType1CFont(font, &fontFileID, psName);
// check for embedded OpenType - Type 1C font
@@ -1666,7 +1666,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
font->getEmbeddedFontID(&fontFileID)) {
// use the PDF font name because the embedded font name might
// not include the subset prefix
- psName = filterPSName(font->getOrigName());
+ psName = font->getOrigName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedOpenTypeT1CFont(font, &fontFileID, psName);
// check for external Type 1 font file
@@ -1682,7 +1682,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
(font->getType() == fontTrueType ||
font->getType() == fontTrueTypeOT) &&
font->getEmbeddedFontID(&fontFileID)) {
- psName = filterPSName(font->getEmbeddedFontName());
+ psName = font->getEmbeddedFontName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedTrueTypeFont(font, &fontFileID, psName);
// check for external TrueType font file
@@ -1695,7 +1695,7 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
} else if (globalParams->getPSEmbedCIDPostScript() &&
font->getType() == fontCIDType0C &&
font->getEmbeddedFontID(&fontFileID)) {
- psName = filterPSName(font->getEmbeddedFontName());
+ psName = font->getEmbeddedFontName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedCIDType0Font(font, &fontFileID, psName);
// check for embedded CID TrueType font
@@ -1703,14 +1703,14 @@ void PSOutputDev::setupFont(GfxFont *font, Dict *parentResDict) {
(font->getType() == fontCIDType2 ||
font->getType() == fontCIDType2OT) &&
font->getEmbeddedFontID(&fontFileID)) {
- psName = filterPSName(font->getEmbeddedFontName());
+ psName = font->getEmbeddedFontName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedCIDTrueTypeFont(font, &fontFileID, psName, gTrue);
// check for embedded OpenType - CID CFF font
} else if (globalParams->getPSEmbedCIDPostScript() &&
font->getType() == fontCIDType0COT &&
font->getEmbeddedFontID(&fontFileID)) {
- psName = filterPSName(font->getEmbeddedFontName());
+ psName = font->getEmbeddedFontName()->sanitizedName(gTrue /* ps mode */);
setupEmbeddedOpenTypeCFFFont(font, &fontFileID, psName);
// check for Type 3 font
@@ -2208,7 +2208,7 @@ GooString *PSOutputDev::setupExternalTrueTypeFont(GfxFont *font) {
}
}
- psName = filterPSName(font->getName());
+ psName = font->getName()->sanitizedName(gTrue /* ps mode */);
// add entry to fontFileNames list
if (i == fontFileNameLen) {
if (fontFileNameLen >= fontFileNameSize) {
@@ -2281,7 +2281,7 @@ GooString *PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, GooString *f
}
}
- psName = filterPSName(font->getName());
+ psName = font->getName()->sanitizedName(gTrue /* ps mode */);
// add entry to fontFileNames list
if (i == fontFileNameLen) {
if (fontFileNameLen >= fontFileNameSize) {
@@ -6325,37 +6325,6 @@ void PSOutputDev::writePSName(char *s) {
}
}
-GooString *PSOutputDev::filterPSName(GooString *name) {
- GooString *name2;
- char buf[8];
- int i;
- char c;
-
- name2 = new GooString();
-
- // ghostscript chokes on names that begin with out-of-limits
- // numbers, e.g., 1e4foo is handled correctly (as a name), but
- // 1e999foo generates a limitcheck error
- c = name->getChar(0);
- if (c >= '0' && c <= '9') {
- name2->append('f');
- }
-
- for (i = 0; i < name->getLength(); ++i) {
- c = name->getChar(i);
- if (c <= (char)0x20 || c >= (char)0x7f ||
- c == '(' || c == ')' || c == '<' || c == '>' ||
- c == '[' || c == ']' || c == '{' || c == '}' ||
- c == '/' || c == '%') {
- sprintf(buf, "#%02x", c & 0xff);
- name2->append(buf);
- } else {
- name2->append(c);
- }
- }
- return name2;
-}
-
// Convert GooString to GooString, with appropriate escaping
// of things that can't appear in a label
// This is heavily based on the writePSTextLine() method
diff --git a/poppler/PSOutputDev.h b/poppler/PSOutputDev.h
index ddc2041..e490110 100644
--- a/poppler/PSOutputDev.h
+++ b/poppler/PSOutputDev.h
@@ -15,7 +15,7 @@
//
// Copyright (C) 2005 Martin Kretzschmar <martink at gnome.org>
// Copyright (C) 2005 Kristian Høgsberg <krh at redhat.com>
-// Copyright (C) 2006, 2007 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2006-2008 Albert Astals Cid <aacid at kde.org>
// Copyright (C) 2007 Brad Hards <bradh at kde.org>
//
// To see a description of the changes please see the Changelog file that
@@ -326,7 +326,6 @@ private:
void writePSFmt(const char *fmt, ...);
void writePSString(GooString *s);
void writePSName(char *s);
- GooString *filterPSName(GooString *name);
GooString *filterPSLabel(GooString *label, GBool *needParens=0);
void writePSTextLine(GooString *s);
More information about the poppler
mailing list