fixed gfxmatrix_multiply
[swftools.git] / pdf2swf / xpdf / Lexer.cc
index 4ca8cfe..ee9dc59 100644 (file)
@@ -2,11 +2,13 @@
 //
 // Lexer.cc
 //
-// Copyright 1996 Derek B. Noonburg
+// Copyright 1996-2003 Glyph & Cog, LLC
 //
 //========================================================================
 
-#ifdef __GNUC__
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
 #pragma implementation
 #endif
 
@@ -44,22 +46,22 @@ static char specialChars[256] = {
 // Lexer
 //------------------------------------------------------------------------
 
-Lexer::Lexer(Stream *str) {
+Lexer::Lexer(XRef *xref, Stream *str) {
   Object obj;
 
   curStr.initStream(str);
-  streams = new Array();
+  streams = new Array(xref);
   streams->add(curStr.copy(&obj));
   strPtr = 0;
   freeArray = gTrue;
   curStr.streamReset();
 }
 
-Lexer::Lexer(Object *obj) {
+Lexer::Lexer(XRef *xref, Object *obj) {
   Object obj2;
 
   if (obj->isStream()) {
-    streams = new Array();
+    streams = new Array(xref);
     freeArray = gTrue;
     streams->add(obj->copy(&obj2));
   } else {
@@ -72,6 +74,7 @@ Lexer::Lexer(Object *obj) {
     curStr.streamReset();
   }
 }
+static int illegalChars = 0;
 
 Lexer::~Lexer() {
   if (!curStr.isNone()) {
@@ -81,6 +84,9 @@ Lexer::~Lexer() {
   if (freeArray) {
     delete streams;
   }
+  if(illegalChars)
+      error(0, "Illegal characters in hex string (%d)", illegalChars);
+  illegalChars = 0;
 }
 
 int Lexer::getChar() {
@@ -169,6 +175,13 @@ Object *Lexer::getObj(Object *obj) {
     scale = 0.1;
     while (1) {
       c = lookChar();
+      if (c == '-') {
+       // ignore minus signs in the middle of numbers to match
+       // Adobe's behavior
+       error(getPos(), "Badly formatted number");
+       getChar();
+       continue;
+      }
       if (!isdigit(c)) {
        break;
       }
@@ -204,11 +217,15 @@ Object *Lexer::getObj(Object *obj) {
 
       case '(':
        ++numParen;
+       c2 = c;
        break;
 
       case ')':
-       if (--numParen == 0)
+       if (--numParen == 0) {
          done = gTrue;
+       } else {
+         c2 = c;
+       }
        break;
 
       case '\\':
@@ -317,7 +334,8 @@ Object *Lexer::getObj(Object *obj) {
        } else if (c2 >= 'a' && c2 <= 'f') {
          c += c2 - 'a' + 10;
        } else {
-         error(getPos(), "Illegal digit in hex char in name");
+         illegalChars++;
+         //error(getPos(), "Illegal digit in hex char in name");
        }
       }
      notEscChar:
@@ -371,8 +389,10 @@ Object *Lexer::getObj(Object *obj) {
            c2 += c - 'A' + 10;
          else if (c >= 'a' && c <= 'f')
            c2 += c - 'a' + 10;
-         else
-           error(getPos(), "Illegal character <%02x> in hex string", c);
+         else {
+           illegalChars++;
+           //error(getPos(), "Illegal character <%02x> in hex string", c);
+         }
          if (++m == 2) {
            if (n == tokBufSize) {
              if (!s)
@@ -408,7 +428,8 @@ Object *Lexer::getObj(Object *obj) {
       tokBuf[2] = '\0';
       obj->initCmd(tokBuf);
     } else {
-      error(getPos(), "Illegal character '>'");
+      illegalChars++;
+      //error(getPos(), "Illegal character '>'");
       obj->initError();
     }
     break;
@@ -417,7 +438,8 @@ Object *Lexer::getObj(Object *obj) {
   case ')':
   case '{':
   case '}':
-    error(getPos(), "Illegal character '%c'", c);
+    //error(getPos(), "Illegal character '%c'", c);
+    illegalChars++;
     obj->initError();
     break;
 
@@ -446,7 +468,6 @@ Object *Lexer::getObj(Object *obj) {
     }
     break;
   }
-
   return obj;
 }
 
@@ -466,3 +487,7 @@ void Lexer::skipToNextLine() {
     }
   }
 }
+
+GBool Lexer::isSpace(int c) {
+  return c >= 0 && c <= 0xff && specialChars[c] == 1;
+}