[poppler] Branch 'xpdf303merge' - fofi/FoFiType1C.cc fofi/FoFiType1C.h

Carlos Garcia Campos carlosgc at kemper.freedesktop.org
Sat Sep 3 01:52:53 PDT 2011


 fofi/FoFiType1C.cc |   68 ++++++++++++++++++++++++++++++++++++++---------------
 fofi/FoFiType1C.h  |    1 
 2 files changed, 51 insertions(+), 18 deletions(-)

New commits:
commit 4e4a8ec52c5662e21036f219636a39fc97a32353
Author: Carlos Garcia Campos <carlosgc at gnome.org>
Date:   Sat Sep 3 10:52:14 2011 +0200

    xpdf303: Add writePSString() helper function to FoFiType1C

diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 78c212e..1aa7a4a 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -220,39 +220,39 @@ void FoFiType1C::convertToType1(char *psName, const char **newEncoding, GBool as
   (*outputFunc)(outputStream, "12 dict begin\n", 14);
   (*outputFunc)(outputStream, "/FontInfo 10 dict dup begin\n", 28);
   if (topDict.versionSID != 0) {
-    (*outputFunc)(outputStream, "/version (", 10);
-    (*outputFunc)(outputStream, buf2, strlen(buf2));
-    (*outputFunc)(outputStream, ") readonly def\n", 15);
+    (*outputFunc)(outputStream, "/version ", 9);
+    writePSString(buf2, outputFunc, outputStream);
+    (*outputFunc)(outputStream, " readonly def\n", 14);
   }
   if (topDict.noticeSID != 0) {
     getString(topDict.noticeSID, buf2, &ok);
-    (*outputFunc)(outputStream, "/Notice (", 9);
-    (*outputFunc)(outputStream, buf2, strlen(buf2));
-    (*outputFunc)(outputStream, ") readonly def\n", 15);
+    (*outputFunc)(outputStream, "/Notice ", 8);
+    writePSString(buf2, outputFunc, outputStream);
+    (*outputFunc)(outputStream, " readonly def\n", 14);
   }
   if (topDict.copyrightSID != 0) {
     getString(topDict.copyrightSID, buf2, &ok);
-    (*outputFunc)(outputStream, "/Copyright (", 12);
-    (*outputFunc)(outputStream, buf2, strlen(buf2));
-    (*outputFunc)(outputStream, ") readonly def\n", 15);
+    (*outputFunc)(outputStream, "/Copyright ", 11);
+    writePSString(buf2, outputFunc, outputStream);
+    (*outputFunc)(outputStream, " readonly def\n", 14);
   }
   if (topDict.fullNameSID != 0) {
     getString(topDict.fullNameSID, buf2, &ok);
-    (*outputFunc)(outputStream, "/FullName (", 11);
-    (*outputFunc)(outputStream, buf2, strlen(buf2));
-    (*outputFunc)(outputStream, ") readonly def\n", 15);
+    (*outputFunc)(outputStream, "/FullName ", 10);
+    writePSString(buf2, outputFunc, outputStream);
+    (*outputFunc)(outputStream, " readonly def\n", 14);
   }
   if (topDict.familyNameSID != 0) {
     getString(topDict.familyNameSID, buf2, &ok);
-    (*outputFunc)(outputStream, "/FamilyName (", 13);
-    (*outputFunc)(outputStream, buf2, strlen(buf2));
-    (*outputFunc)(outputStream, ") readonly def\n", 15);
+    (*outputFunc)(outputStream, "/FamilyName ", 12);
+    writePSString(buf2, outputFunc, outputStream);
+    (*outputFunc)(outputStream, " readonly def\n", 14);
   }
   if (topDict.weightSID != 0) {
     getString(topDict.weightSID, buf2, &ok);
-    (*outputFunc)(outputStream, "/Weight (", 9);
-    (*outputFunc)(outputStream, buf2, strlen(buf2));
-    (*outputFunc)(outputStream, ") readonly def\n", 15);
+    (*outputFunc)(outputStream, "/Weight ", 8);
+    writePSString(buf2, outputFunc, outputStream);
+    (*outputFunc)(outputStream, " readonly def\n", 14);
   }
   if (topDict.isFixedPitch) {
     (*outputFunc)(outputStream, "/isFixedPitch true def\n", 23);
@@ -1930,6 +1930,38 @@ void FoFiType1C::eexecWriteCharstring(Type1CEexecBuf *eb,
   }
 }
 
+void FoFiType1C::writePSString(char *s, FoFiOutputFunc outputFunc,
+			       void *outputStream) {
+  char buf[80];
+  char *p;
+  int i, c;
+
+  i = 0;
+  buf[i++] = '(';
+  for (p = s; *p; ++p) {
+    c = *p & 0xff;
+    if (c == '(' || c == ')' || c == '\\') {
+      buf[i++] = '\\';
+      buf[i++] = c;
+    } else if (c < 0x20 || c >= 0x80) {
+      buf[i++] = '\\';
+      buf[i++] = '0' + ((c >> 6) & 7);
+      buf[i++] = '0' + ((c >> 3) & 7);
+      buf[i++] = '0' + (c & 7);
+    } else {
+      buf[i++] = c;
+    }
+    if (i >= 64) {
+      buf[i++] = '\\';
+      buf[i++] = '\n';
+      (*outputFunc)(outputStream, buf, i);
+      i = 0;
+    }
+  }
+  buf[i++] = ')';
+  (*outputFunc)(outputStream, buf, i);
+}
+
 GBool FoFiType1C::parse() {
   Type1CIndex fdIdx;
   Type1CIndexVal val;
diff --git a/fofi/FoFiType1C.h b/fofi/FoFiType1C.h
index 2c8d1ba..b9e1933 100644
--- a/fofi/FoFiType1C.h
+++ b/fofi/FoFiType1C.h
@@ -219,6 +219,7 @@ private:
   void cvtNum(double x, GBool isFP, GooString *charBuf);
   void eexecWrite(Type1CEexecBuf *eb, const char *s);
   void eexecWriteCharstring(Type1CEexecBuf *eb, Guchar *s, int n);
+  void writePSString(char *s, FoFiOutputFunc outputFunc, void *outputStream);
   GBool parse();
   void readTopDict();
   void readFD(int offset, int length, Type1CPrivateDict *pDict);


More information about the poppler mailing list