[poppler] poppler/CharCodeToUnicode.cc poppler/CharCodeToUnicode.h poppler/GfxFont.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Thu Feb 23 13:57:13 PST 2012


 poppler/CharCodeToUnicode.cc |   18 +++++++++++++-----
 poppler/CharCodeToUnicode.h  |    7 +++++--
 poppler/GfxFont.cc           |   13 +++++++------
 3 files changed, 25 insertions(+), 13 deletions(-)

New commits:
commit 30446bdd7e202eed88d131e04477c76861fd145c
Author: Albert Astals Cid <aacid at kde.org>
Date:   Thu Feb 23 22:56:17 2012 +0100

    Use an Identity CharCodeToUnicode for Adobe-Identity and Adobe-UCS collections
    
    Also fix Identity CharCodeToUnicode code
    
    Bug #35468

diff --git a/poppler/CharCodeToUnicode.cc b/poppler/CharCodeToUnicode.cc
index e44f304..076f5ba 100644
--- a/poppler/CharCodeToUnicode.cc
+++ b/poppler/CharCodeToUnicode.cc
@@ -13,7 +13,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2006, 2008-2010 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2006, 2008-2010, 2012 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2007 Koji Otani <sho at bbr.jp>
 // Copyright (C) 2008 Michael Vrable <mvrable at cs.ucsd.edu>
@@ -111,7 +111,11 @@ static GBool parseHex(char *s, int len, Guint *val) {
 //------------------------------------------------------------------------
 
 CharCodeToUnicode *CharCodeToUnicode::makeIdentityMapping() {
-  return new CharCodeToUnicode();
+  CharCodeToUnicode *ctu = new CharCodeToUnicode();
+  ctu->isIdentity = gTrue;
+  ctu->mapLen = 1;
+  ctu->map = (Unicode *)gmallocn(ctu->mapLen, sizeof(Unicode));
+  return ctu;
 }
 
 CharCodeToUnicode *CharCodeToUnicode::parseCIDToUnicode(GooString *fileName,
@@ -468,6 +472,7 @@ CharCodeToUnicode::CharCodeToUnicode() {
   sMap = NULL;
   sMapLen = sMapSize = 0;
   refCnt = 1;
+  isIdentity = gFalse;
 #if MULTITHREADED
   gInitMutex(&mutex);
 #endif
@@ -485,6 +490,7 @@ CharCodeToUnicode::CharCodeToUnicode(GooString *tagA) {
   sMap = NULL;
   sMapLen = sMapSize = 0;
   refCnt = 1;
+  isIdentity = gFalse;
 #if MULTITHREADED
   gInitMutex(&mutex);
 #endif
@@ -506,6 +512,7 @@ CharCodeToUnicode::CharCodeToUnicode(GooString *tagA, Unicode *mapA,
   sMapLen = sMapLenA;
   sMapSize = sMapSizeA;
   refCnt = 1;
+  isIdentity = gFalse;
 #if MULTITHREADED
   gInitMutex(&mutex);
 #endif
@@ -557,7 +564,7 @@ GBool CharCodeToUnicode::match(GooString *tagA) {
 void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) {
   int i, j;
 
-  if (!map) {
+  if (!map || isIdentity) {
     return;
   }
   if (len == 1) {
@@ -590,8 +597,9 @@ void CharCodeToUnicode::setMapping(CharCode c, Unicode *u, int len) {
 int CharCodeToUnicode::mapToUnicode(CharCode c, Unicode **u) {
   int i;
 
-  if (!map) {
-    *u[0] = (Unicode)c;
+  if (isIdentity) {
+    map[0] = (Unicode)c;
+    *u = map;
     return 1;
   }
   if (c >= mapLen) {
diff --git a/poppler/CharCodeToUnicode.h b/poppler/CharCodeToUnicode.h
index 66417a1..1672105 100644
--- a/poppler/CharCodeToUnicode.h
+++ b/poppler/CharCodeToUnicode.h
@@ -17,7 +17,7 @@
 //
 // Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
 // Copyright (C) 2007 Koji Otani <sho at bbr.jp>
-// Copyright (C) 2008, 2011 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2008, 2011, 2012 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
@@ -86,7 +86,9 @@ public:
   // Set the mapping for <c>.
   void setMapping(CharCode c, Unicode *u, int len);
 
-  // Map a CharCode to Unicode.
+  // Map a CharCode to Unicode. Returns a pointer in u to internal storage
+  // so never store the pointers it returns, just the data, otherwise
+  // your pointed values might get changed by future calls
   int mapToUnicode(CharCode c, Unicode **u);
 
   // Map a Unicode to CharCode.
@@ -113,6 +115,7 @@ private:
   CharCodeToUnicodeString *sMap;
   int sMapLen, sMapSize;
   int refCnt;
+  GBool isIdentity;
 #if MULTITHREADED
   GooMutex mutex;
 #endif
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index cc0f092..0f3d248 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -13,7 +13,7 @@
 // All changes made under the Poppler project to this file are licensed
 // under GPL version 2 or later
 //
-// Copyright (C) 2005, 2006, 2008-2010 Albert Astals Cid <aacid at kde.org>
+// Copyright (C) 2005, 2006, 2008-2010, 2012 Albert Astals Cid <aacid at kde.org>
 // Copyright (C) 2005, 2006 Kristian Høgsberg <krh at redhat.com>
 // Copyright (C) 2006 Takashi Iwai <tiwai at suse.de>
 // Copyright (C) 2007 Julien Rebetez <julienr at svn.gnome.org>
@@ -1785,11 +1785,12 @@ GfxCIDFont::GfxCIDFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA,
   if (!(ctu = readToUnicodeCMap(fontDict, 16, NULL))) {
     ctuUsesCharCode = gFalse;
 
-    // the "Adobe-Identity" and "Adobe-UCS" collections don't have
-    // cidToUnicode files
-    if (collection->cmp("Adobe-Identity") &&
-	collection->cmp("Adobe-UCS")) {
-
+    // use an identity mapping for the "Adobe-Identity" and
+    // "Adobe-UCS" collections
+    if (!collection->cmp("Adobe-Identity") ||
+	!collection->cmp("Adobe-UCS")) {
+      ctu = CharCodeToUnicode::makeIdentityMapping();
+    } else {
       // look for a user-supplied .cidToUnicode file
       if (!(ctu = globalParams->getCIDToUnicode(collection))) {
 	// I'm not completely sure that this is the best thing to do


More information about the poppler mailing list