upgraded to xpdf-3.01pl1
[swftools.git] / pdf2swf / xpdf / FoFiType1.cc
index fe54a63..a8a69fd 100644 (file)
@@ -108,6 +108,9 @@ void FoFiType1::writeEncoded(char **newEncoding,
     for (line = getNextLine(line);
         line && strncmp(line, "readonly def", 12);
         line = getNextLine(line)) ;
+    if (line) {
+      line = getNextLine(line);
+    }
   }
   if (line) {
     (*outputFunc)(outputStream, line, ((char *)file + len) - line);
@@ -156,13 +159,13 @@ void FoFiType1::parse() {
       encoding = fofiType1StandardEncoding;
     } else if (!encoding &&
               !strncmp(line, "/Encoding 256 array", 19)) {
-      encoding = (char **)gmalloc(256 * sizeof(char *));
+      encoding = (char **)gmallocn(256, sizeof(char *));
       for (j = 0; j < 256; ++j) {
        encoding[j] = NULL;
       }
-      line = getNextLine(line);
-      for (j = 0; j < 300 && line; ++j) {
-       line1 = getNextLine(line);
+      for (j = 0, line = getNextLine(line);
+          j < 300 && line && (line1 = getNextLine(line));
+          ++j, line = line1) {
        if ((n = line1 - line) > 255) {
          n = 255;
        }
@@ -187,20 +190,22 @@ void FoFiType1::parse() {
            }
          }
        } else {
-         if (strtok(buf, " \t") &&
-             (p = strtok(NULL, " \t\n\r")) && !strcmp(p, "def")) {
-           break;
+         p = strtok(buf, " \t\n\r");
+         if (p)
+         {
+           if (!strcmp(p, "def")) break;
+           if (!strcmp(p, "readonly")) break;
+           // the spec does not says this but i'm mantaining old xpdf behaviour that accepts "foo def" as end of the encoding array
+           p = strtok(buf, " \t\n\r");
+           if (p && !strcmp(p, "def")) break;
          }
        }
-       line = line1;
       }
       //~ check for getinterval/putinterval junk
 
     } else {
       line = getNextLine(line);
     }
-
-    ++i;
   }
 
   parsed = gTrue;