[poppler] poppler/Annot.cc poppler/CharCodeToUnicode.cc poppler/CharCodeToUnicode.h poppler/Gfx.cc poppler/GfxFont.cc poppler/GfxFont.h poppler/PSOutputDev.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sun Jun 1 07:34:15 PDT 2008


 poppler/Annot.cc             |   10 +++++-----
 poppler/CharCodeToUnicode.cc |   37 +++++++++++++++++++++----------------
 poppler/CharCodeToUnicode.h  |    2 +-
 poppler/Gfx.cc               |    8 ++++----
 poppler/GfxFont.cc           |   43 ++++++++++++++++++++++++-------------------
 poppler/GfxFont.h            |    6 +++---
 poppler/PSOutputDev.cc       |    4 ++--
 7 files changed, 60 insertions(+), 50 deletions(-)

New commits:
commit 1614ab3036cf25c9b94967163996678d386ce0ac
Author: Albert Astals Cid <aacid at kde.org>
Date:   Sun Jun 1 16:32:55 2008 +0200

    Do not limit CharCodeToUnicodeString to 8 characters

diff --git a/poppler/Annot.cc b/poppler/Annot.cc
index 5bbe487..81e2e90 100644
--- a/poppler/Annot.cc
+++ b/poppler/Annot.cc
@@ -1896,7 +1896,7 @@ void AnnotWidget::layoutText(GooString *text, GooString *outBuf, int *i,
                              int *charCount, GBool noReencode)
 {
   CharCode c;
-  Unicode uChar;
+  Unicode uChar, *uAux;
   double w = 0.0;
   int uLen, n;
   double dx, dy, ox, oy;
@@ -1995,7 +1995,7 @@ void AnnotWidget::layoutText(GooString *text, GooString *outBuf, int *i,
       dx = 0.0;
       font->getNextChar(outBuf->getCString() + last_o2,
                         outBuf->getLength() - last_o2,
-                        &c, &uChar, 1, &uLen, &dx, &dy, &ox, &oy);
+                        &c, &uAux, &uLen, &dx, &dy, &ox, &oy);
       w += dx;
     }
 
@@ -2058,7 +2058,7 @@ void AnnotWidget::layoutText(GooString *text, GooString *outBuf, int *i,
 
     while (len > 0) {
       dx = 0.0;
-      n = font->getNextChar(s, len, &c, &uChar, 1, &uLen, &dx, &dy, &ox, &oy);
+      n = font->getNextChar(s, len, &c, &uAux, &uLen, &dx, &dy, &ox, &oy);
 
       if (n == 0) {
         break;
@@ -2364,12 +2364,12 @@ void AnnotWidget::drawText(GooString *text, GooString *da, GfxFontDict *fontDict
       xPrev = w;                // so that first character is placed properly
       while (i < comb && len > 0) {
         CharCode code;
-        Unicode u;
+        Unicode *uAux;
         int uLen, n;
         double dx, dy, ox, oy;
 
         dx = 0.0;
-        n = font->getNextChar(s, len, &code, &u, 1, &uLen, &dx, &dy, &ox, &oy);
+        n = font->getNextChar(s, len, &code, &uAux, &uLen, &dx, &dy, &ox, &oy);
         dx *= fontSize;
 
         // center each character within its cell, by advancing the text
diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc
index aba0b0a..de2617a 100644
--- a/poppler/CharCodeToUnicode.cc
+++ b/poppler/CharCodeToUnicode.cc
@@ -24,11 +24,9 @@
 
 //------------------------------------------------------------------------
 
-#define maxUnicodeString 8
-
 struct CharCodeToUnicodeString {
   CharCode c;
-  Unicode u[maxUnicodeString];
+  Unicode *u;
   int len;
 };
 
@@ -104,7 +102,8 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
   char buf[256];
   char *tok;
   Unicode u0;
-  Unicode uBuf[maxUnicodeString];
+  int uBufSize = 8;
+  Unicode *uBuf = (Unicode *)gmallocn(uBufSize, sizeof(Unicode));
   CharCodeToUnicode *ctu;
   int line, n, i;
 
@@ -131,9 +130,11 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
       continue;
     }
     n = 0;
-    while (n < maxUnicodeString) {
-      if (!(tok = strtok(NULL, " \t\r\n"))) {
-	break;
+    while ((tok = strtok(NULL, " \t\r\n"))) {
+      if (n >= uBufSize)
+      {
+        uBufSize += 8;
+        uBuf = (Unicode *)greallocn(uBuf, uBufSize, sizeof(Unicode));
       }
       if (sscanf(tok, "%x", &uBuf[n]) != 1) {
 	error(-1, "Bad line (%d) in unicodeToUnicode file '%s'",
@@ -165,6 +166,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
 	          greallocn(sMapA, sMapSizeA, sizeof(CharCodeToUnicodeString));
       }
       sMapA[sMapLenA].c = u0;
+      sMapA[sMapLenA].u = (Unicode*)gmallocn(n, sizeof(Unicode));
       for (i = 0; i < n; ++i) {
 	sMapA[sMapLenA].u[i] = uBuf[i];
       }
@@ -180,6 +182,7 @@ CharCodeToUnicode *CharCodeToUnicode::parseUnicodeToUnicode(
   ctu = new CharCodeToUnicode(fileName->copy(), mapA, len, gTrue,
 			      sMapA, sMapLenA, sMapSizeA);
   gfree(mapA);
+  gfree(uBuf);
   return ctu;
 }
 
@@ -356,7 +359,8 @@ void CharCodeToUnicode::addMapping(CharCode code, char *uStr, int n,
     map[code] = 0;
     sMap[sMapLen].c = code;
     sMap[sMapLen].len = n / 4;
-    for (j = 0; j < sMap[sMapLen].len && j < maxUnicodeString; ++j) {
+    sMap[sMapLen].u = (Unicode*)gmallocn(sMap[sMapLen].len, sizeof(Unicode));
+    for (j = 0; j < sMap[sMapLen].len; ++j) {
       strncpy(uHex, uStr + j*4, 4);
       uHex[4] = '\0';
       if (sscanf(uHex, "%x", &sMap[sMapLen].u[j]) != 1) {
@@ -412,6 +416,7 @@ CharCodeToUnicode::~CharCodeToUnicode() {
   }
   gfree(map);
   if (sMap) {
+    for (int i = 0; i < sMapLen; ++i) gfree(sMap[i].u);
     gfree(sMap);
   }
 #if MULTITHREADED
@@ -456,6 +461,7 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) {
   } else {
     for (i = 0; i < sMapLen; ++i) {
       if (sMap[i].c == c) {
+	gfree(sMap[i].u);
 	break;
       }
     }
@@ -470,28 +476,27 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) {
     map[c] = 0;
     sMap[i].c = c;
     sMap[i].len = len;
-    for (j = 0; j < len && j < maxUnicodeString; ++j) {
+    sMap[i].u = (Unicode*)gmallocn(len, sizeof(Unicode));
+    for (j = 0; j < len; ++j) {
       sMap[i].u[j] = u[j];
     }
   }
 }
 
-int CharCodeToUnicode::mapToUnicode(CharCode c, Unicode *u, int size) {
-  int i, j;
+int CharCodeToUnicode::mapToUnicode(CharCode c, Unicode **u) {
+  int i;
 
   if (c >= mapLen) {
     return 0;
   }
   if (map[c]) {
-    u[0] = map[c];
+    *u = &map[c];
     return 1;
   }
   for (i = 0; i < sMapLen; ++i) {
     if (sMap[i].c == c) {
-      for (j = 0; j < sMap[i].len && j < size; ++j) {
-	u[j] = sMap[i].u[j];
-      }
-      return j;
+      *u = sMap[i].u;
+      return sMap[i].len;
     }
   }
   return 0;
diff --git a/poppler/CharCodeToUnicode.h b/poppler/CharCodeToUnicode.h
index f3b2173..08e5d75 100644
--- a/poppler/CharCodeToUnicode.h
+++ b/poppler/CharCodeToUnicode.h
@@ -66,7 +66,7 @@ public:
   void setMapping(CharCode c, Unicode *u, int len);
 
   // Map a CharCode to Unicode.
-  int mapToUnicode(CharCode c, Unicode *u, int size);
+  int mapToUnicode(CharCode c, Unicode **u);
 
   int mapToCharCode(Unicode* u, CharCode *c, int usize);
 
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 6fc9b8d..da37016 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -3266,7 +3266,7 @@ void Gfx::doShowText(GooString *s) {
   int wMode;
   double riseX, riseY;
   CharCode code;
-  Unicode u[8];
+  Unicode *u = NULL;
   double x, y, dx, dy, dx2, dy2, curX, curY, tdx, tdy, lineX, lineY;
   double originX, originY, tOriginX, tOriginY;
   double oldCTM[6], newCTM[6];
@@ -3316,7 +3316,7 @@ void Gfx::doShowText(GooString *s) {
     len = s->getLength();
     while (len > 0) {
       n = font->getNextChar(p, len, &code,
-			    u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
+			    &u, &uLen,
 			    &dx, &dy, &originX, &originY);
       dx = dx * state->getFontSize() + state->getCharSpace();
       if (n == 1 && *p == ' ') {
@@ -3365,7 +3365,7 @@ void Gfx::doShowText(GooString *s) {
     len = s->getLength();
     while (len > 0) {
       n = font->getNextChar(p, len, &code,
-			    u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
+			    &u, &uLen,
 			    &dx, &dy, &originX, &originY);
       if (wMode) {
 	dx *= state->getFontSize();
@@ -3399,7 +3399,7 @@ void Gfx::doShowText(GooString *s) {
     nChars = nSpaces = 0;
     while (len > 0) {
       n = font->getNextChar(p, len, &code,
-			    u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
+			    &u, &uLen,
 			    &dx2, &dy2, &originX, &originY);
       dx += dx2;
       dy += dy2;
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 9ec64d5..5c66da9 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -840,16 +840,17 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
 
   // look for a Unicode-to-Unicode mapping
   if (name && (utu = globalParams->getUnicodeToUnicode(name))) {
+    Unicode *uAux;
     for (i = 0; i < 256; ++i) {
       toUnicode[i] = 0;
     }
     ctu2 = CharCodeToUnicode::make8BitToUnicode(toUnicode);
     for (i = 0; i < 256; ++i) {
-      n = ctu->mapToUnicode((CharCode)i, uBuf, 8);
+      n = ctu->mapToUnicode((CharCode)i, &uAux);
       if (n >= 1) {
-	n = utu->mapToUnicode((CharCode)uBuf[0], uBuf, 8);
+	n = utu->mapToUnicode((CharCode)uAux[0], &uAux);
 	if (n >= 1) {
-	  ctu2->setMapping((CharCode)i, uBuf, n);
+	  ctu2->setMapping((CharCode)i, uAux, n);
 	}
       }
     }
@@ -1097,12 +1098,12 @@ static int parseCharName(char *charName, Unicode *uBuf, int uLen,
 }
 
 int Gfx8BitFont::getNextChar(char *s, int len, CharCode *code,
-			     Unicode *u, int uSize, int *uLen,
+			     Unicode **u, int *uLen,
 			     double *dx, double *dy, double *ox, double *oy) {
   CharCode c;
 
   *code = c = (CharCode)(*s & 0xff);
-  *uLen = ctu->mapToUnicode(c, u, uSize);
+  *uLen = ctu->mapToUnicode(c, u);
   *dx = widths[c];
   *dy = *ox = *oy = 0;
   return 1;
@@ -1204,11 +1205,14 @@ Gushort *Gfx8BitFont::getCodeToGIDMap(FoFiTrueType *ff) {
 
   // map Unicode through the cmap
   } else if (useUnicode) {
+    Unicode *uAux;
     for (i = 0; i < 256; ++i) {
-      if (((charName = enc[i]) &&
-	   (u = globalParams->mapNameToUnicode(charName))) ||
-	  (n = ctu->mapToUnicode((CharCode)i, &u, 1))) {
+      if (((charName = enc[i]) && (u = globalParams->mapNameToUnicode(charName))))
 	map[i] = ff->mapCodeToGID(cmap, u);
+      else
+      {
+	n = ctu->mapToUnicode((CharCode)i, &uAux);
+	if (n > 0) map[i] = ff->mapCodeToGID(cmap, uAux[0]);
       }
     }
 
@@ -1273,7 +1277,7 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
   Object obj1, obj2, obj3, obj4, obj5, obj6;
   CharCodeToUnicode *utu;
   CharCode c;
-  Unicode uBuf[8];
+  Unicode *uBuf;
   int c1, c2;
   int excepsSize, i, j, k, n;
 
@@ -1387,9 +1391,9 @@ GfxCIDFont::GfxCIDFont(XRef *xref, char *tagA, Ref idA, GooString *nameA,
   if (name && (utu = globalParams->getUnicodeToUnicode(name))) {
     if (ctu) {
       for (c = 0; c < ctu->getLength(); ++c) {
-	n = ctu->mapToUnicode(c, uBuf, 8);
+	n = ctu->mapToUnicode(c, &uBuf);
 	if (n >= 1) {
-	  n = utu->mapToUnicode((CharCode)uBuf[0], uBuf, 8);
+	  n = utu->mapToUnicode((CharCode)uBuf[0], &uBuf);
 	  if (n >= 1) {
 	    ctu->setMapping(c, uBuf, n);
 	  }
@@ -1621,7 +1625,7 @@ GfxCIDFont::~GfxCIDFont() {
 }
 
 int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
-			    Unicode *u, int uSize, int *uLen,
+			    Unicode **u, int *uLen,
 			    double *dx, double *dy, double *ox, double *oy) {
   CID cid;
   double w, h, vx, vy;
@@ -1636,7 +1640,7 @@ int GfxCIDFont::getNextChar(char *s, int len, CharCode *code,
 
   *code = (CharCode)(cid = cMap->getCID(s, len, &n));
   if (ctu) {
-    *uLen = ctu->mapToUnicode(cid, u, uSize);
+    *uLen = ctu->mapToUnicode(cid, u);
   } else {
     *uLen = 0;
   }
@@ -1867,9 +1871,9 @@ Gushort *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
       CharCode cid;
       for (cid = 0;cid < n ;cid++) {
 	int len;
-	Unicode ucodes[4];
+	Unicode *ucodes;
 
-	len = tctu->mapToUnicode(cid,ucodes,4);
+	len = tctu->mapToUnicode(cid,&ucodes);
 	if (len == 1) {
 	  tumap[cid] = ucodes[0];
 	} else {
@@ -1901,11 +1905,12 @@ Gushort *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
     if ((ctu = getToUnicode()) != 0) {
       CharCode cid;
       for (cid = 0;cid < n ;cid++) {
-	int len;
-	Unicode ucode = 0;
+	Unicode *ucode;
 
-	len = ctu->mapToUnicode(cid,&ucode,1);
-	humap[cid*N_UCS_CANDIDATES] = ucode;
+	if (ctu->mapToUnicode(cid, &ucode))
+	  humap[cid*N_UCS_CANDIDATES] = ucode[0];
+	else
+	  humap[cid*N_UCS_CANDIDATES] = 0;
 	for (i = 1;i < N_UCS_CANDIDATES;i++) {
 	    humap[cid*N_UCS_CANDIDATES+i] = 0;
 	}
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 54de675..72cc71f 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -200,7 +200,7 @@ public:
   // the number actually used.  Returns the number of bytes used by
   // the char code.
   virtual int getNextChar(char *s, int len, CharCode *code,
-			  Unicode *u, int uSize, int *uLen,
+			  Unicode **u, int *uLen,
 			  double *dx, double *dy, double *ox, double *oy) = 0;
 
   /* XXX: dfp shouldn't be public, however the font finding code is currently in
@@ -249,7 +249,7 @@ public:
   virtual ~Gfx8BitFont();
 
   virtual int getNextChar(char *s, int len, CharCode *code,
-			  Unicode *u, int uSize, int *uLen,
+			  Unicode **u, int *uLen,
 			  double *dx, double *dy, double *ox, double *oy);
 
   // Return the encoding.
@@ -311,7 +311,7 @@ public:
   virtual GBool isCIDFont() { return gTrue; }
 
   virtual int getNextChar(char *s, int len, CharCode *code,
-			  Unicode *u, int uSize, int *uLen,
+			  Unicode **u, int *uLen,
 			  double *dx, double *dy, double *ox, double *oy);
 
   // Return the writing mode (0=horizontal, 1=vertical).
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index e8aeb46..6148acd 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -4118,7 +4118,7 @@ void PSOutputDev::drawString(GfxState *state, GooString *s) {
   char *p;
   UnicodeMap *uMap;
   CharCode code;
-  Unicode u[8];
+  Unicode *u;
   char buf[8];
   int len, nChars, uLen, n, m, i, j;
 
@@ -4175,7 +4175,7 @@ void PSOutputDev::drawString(GfxState *state, GooString *s) {
   s2 = new GooString();
   while (len > 0) {
     n = font->getNextChar(p, len, &code,
-			  u, (int)(sizeof(u) / sizeof(Unicode)), &uLen,
+			  &u, &uLen,
 			  &dx2, &dy2, &originX, &originY);
     if (font->isCIDFont()) {
       if (uMap) {


More information about the poppler mailing list