Bug 100551 - freetype patch for xpdf
Summary: freetype patch for xpdf
Status: RESOLVED FIXED
Alias: None
Product: kpdf
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Albert Astals Cid
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-01 15:21 UTC by LuRan
Modified: 2005-03-08 10:10 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
gentoo's patch (1.24 KB, patch)
2005-03-01 15:23 UTC, LuRan
Details
before the patch (333.36 KB, image/png)
2005-03-02 06:26 UTC, LuRan
Details
after the patch (292.88 KB, image/png)
2005-03-02 06:33 UTC, LuRan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description LuRan 2005-03-01 15:21:27 UTC
Version:           CVS version (using KDE Devel)
Installed from:    Compiled sources
Compiler:          gcc-3.4.3 
OS:                Linux

Where is a freetype patch for xpdf in gentoo distribution that will correct the display of some non-latin pdf file without embed fonts. it can be patched to kpdf's xpdf code with little modification. Hope this patch will be add to the source
Comment 1 LuRan 2005-03-01 15:23:02 UTC
Created attachment 9903 [details]
gentoo's patch

gentoo's patch for xpdf
Comment 2 Albert Astals Cid 2005-03-01 16:41:57 UTC
Hi, without a testcase that demonstrates this patch is necessary in kpdf we are not going to use it. Also someone explaining where the bug is rather than giving just a patch would be useful
Comment 3 LuRan 2005-03-02 06:23:35 UTC
Sorry, my fault. I'll upload two snapshot of a pdf file viewed in kpdf before and after the patch. I can upload the pdf if you want, but it's 4.4 Mb big. About the bug I don't know much, I only heard that it has something to do with the unicode map of truetype fonts, and the patch is originally from the author of xpdf and will be included in the next release of xpdf.
Comment 4 LuRan 2005-03-02 06:26:07 UTC
Created attachment 9914 [details]
before the patch
Comment 5 LuRan 2005-03-02 06:33:29 UTC
Created attachment 9915 [details]
after the patch

You don't have to know Chinese to see the difference;) The first two charactor
is the same since the font is embeded in the file. other is different because
it use external font configed in xpdfrc. Latin charactor do not have this kind
of problem, you can see it from the snapshot.
Comment 6 LuRan 2005-03-02 06:36:49 UTC
You can find some more information in bugs.gentoo.org, bug #42161
Comment 7 Albert Astals Cid 2005-03-08 10:10:55 UTC
CVS commit by aacid: 

 * Use fontconfig for searching CID Fonts too if no font is found the xpdf way
 * Don't parse "MS-Micho" to fontname "MS" and style "Mincho"
 * Apply patch given at 100551 that fixes crash on 101032 when the font was found, thanks LuRan for providing the patch
 * Stephan can you try it does not crashes there and then send a screenshot to the SuSe reported to see if what we display is the correct thing
 * Will backport when i'm sure the introduced patch does not causes any side effect
BUGS: 101032, 100551


  M +4 -0      CharCodeToUnicode.h   1.2
  M +3 -0      GlobalParams.cc   1.9
  M +45 -6     SplashOutputDev.cc   1.2


--- kdegraphics/kpdf/xpdf/xpdf/CharCodeToUnicode.h  #1.1:1.2
@@ -68,4 +68,8 @@ public:
   int mapToUnicode(CharCode c, Unicode *u, int size);
 
+  // Return the mapping's length, i.e., one more than the max char
+  // code supported by the mapping.
+  CharCode getLength() { return mapLen; }
+
 private:
 

--- kdegraphics/kpdf/xpdf/xpdf/GlobalParams.cc  #1.8:1.9
@@ -1047,4 +1047,6 @@ FILE *GlobalParams::findToUnicodeFile(GS
 void parseStyle(QString& name, int& weight, int& slant)
 {
+  if (name.find("MS-") == 0) name = "MS " + name.remove(0,3);
+
   if (!name.contains('-') && !name.contains(',')) return;
   QString type = name.section(QRegExp("[-,]"),-1);
@@ -1107,4 +1109,5 @@ DisplayFontParam *GlobalParams::getDispl
   }
   unlockGlobalParams;
+  if (!dfp) dfp = getDisplayFont(fontName);
   return dfp;
 }

--- kdegraphics/kpdf/xpdf/xpdf/SplashOutputDev.cc  #1.1:1.2
@@ -498,8 +498,10 @@ void SplashOutputDev::updateFont(GfxStat
   Gushort *codeToGID;
   DisplayFontParam *dfp;
+  CharCodeToUnicode *ctu;
   double m11, m12, m21, m22, w1, w2;
   SplashCoord mat[4];
   const char *name;
-  int c, substIdx, n, code;
+  Unicode uBuf[8];
+  int c, substIdx, n, code, cmap;
 
   needFontUpdate = gFalse;
@@ -545,5 +547,4 @@ void SplashOutputDev::updateFont(GfxStat
 
       // look for a display font mapping or a substitute font
-      dfp = NULL;
       if (gfxFont->isCIDFont()) {
         if (((GfxCIDFont *)gfxFont)->getCollection()) {
@@ -651,8 +652,46 @@ void SplashOutputDev::updateFont(GfxStat
       break;
     case fontCIDType2:
+      codeToGID = NULL;
+      n = 0;
+      if (dfp) {
+        // create a CID-to-GID mapping, via Unicode
+        if ((ctu = ((GfxCIDFont *)gfxFont)->getToUnicode())) {
+          if ((ff = FoFiTrueType::load(fileName->getCString()))) {
+            // look for a Unicode cmap
+            for (cmap = 0; cmap < ff->getNumCmaps(); ++cmap) {
+              if ((ff->getCmapPlatform(cmap) == 3 &&
+                   ff->getCmapEncoding(cmap) == 1) ||
+                  ff->getCmapPlatform(cmap) == 0) {
+                break;
+              }
+            }
+            if (cmap < ff->getNumCmaps()) {
+              // map CID -> Unicode -> GID
+              n = ctu->getLength();
+              codeToGID = (Gushort *)gmalloc(n * sizeof(Gushort));
+              for (code = 0; code < n; ++code) {
+                if (ctu->mapToUnicode(code, uBuf, 8) > 0) {
+                  codeToGID[code] = ff->mapCodeToGID(cmap, uBuf[0]);
+                } else {
+                  codeToGID[code] = 0;
+                }
+              }
+            }
+            delete ff;
+          }
+          ctu->decRefCnt();
+        } else {
+          error(-1, "Couldn't find a mapping to Unicode for font '%s'",
+                gfxFont->getName() ? gfxFont->getName()->getCString()
+                                   : "(unnamed)");
+        }
+      } else {
+        if (((GfxCIDFont *)gfxFont)->getCIDToGID()) {
       n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
       codeToGID = (Gushort *)gmalloc(n * sizeof(Gushort));
       memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
              n * sizeof(Gushort));
+        }
+      }
       if (!(fontFile = fontEngine->loadTrueTypeFont(
                            id,