[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#280791: patch (Re: kpdf: failes to display 16-bit TrueType fonts (such as Japanese).)



Pardon me.  The patch file was missing.   Attached is it.  Here you go.

Thanks,
Haru
diff -Nru kdegraphics-3.3.1/kpdf/xpdf/SplashOutputDev.cc kdegraphics-patched/kpdf/xpdf/SplashOutputDev.cc
--- kdegraphics-3.3.1/kpdf/xpdf/SplashOutputDev.cc	2004-11-03 14:56:59.000000000 +0900
+++ kdegraphics-patched/kpdf/xpdf/SplashOutputDev.cc	2004-11-03 22:03:37.000000000 +0900
@@ -497,15 +497,18 @@
   FILE *tmpFile;
   Gushort *codeToGID;
   DisplayFontParam *dfp;
+  CharCodeToUnicode *ctu;
   double m11, m12, m21, m22, w1, w2;
   SplashCoord mat[4];
-  const char *name;
-  int c, substIdx, n, code;
+  const char *name;
+  Unicode uBuf[8];
+  int c, substIdx, n, code, cmap;
 
   needFontUpdate = gFalse;
   font = NULL;
   tmpFileName = NULL;
   substIdx = -1;
+  dfp = NULL;
 
   if (!(gfxFont = state->getFont())) {
     goto err1;
@@ -544,7 +547,6 @@
     } else if (!(fileName = gfxFont->getExtFontFile())) {
 
       // look for a display font mapping or a substitute font
-      dfp = NULL;
       if (gfxFont->isCIDFont()) {
 	if (((GfxCIDFont *)gfxFont)->getCollection()) {
 	  dfp = globalParams->
@@ -650,10 +652,48 @@
       }
       break;
     case fontCIDType2:
-      n = ((GfxCIDFont *)gfxFont)->getCIDToGIDLen();
-      codeToGID = (Gushort *)gmalloc(n * sizeof(Gushort));
-      memcpy(codeToGID, ((GfxCIDFont *)gfxFont)->getCIDToGID(),
-	     n * sizeof(Gushort));
+      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,
 			   fileName->getCString(),
diff -Nru kdegraphics-3.3.1/kpdf/xpdf/CharCodeToUnicode.h kdegraphics-patched/kpdf/xpdf/CharCodeToUnicode.h
--- kdegraphics-3.3.1/kpdf/xpdf/CharCodeToUnicode.h	2004-11-03 22:03:37.000000000 +0900
+++ kdegraphics-patched/kpdf/xpdf/CharCodeToUnicode.h	2004-11-04 19:09:01.000000000 +0900
@@ -67,6 +67,10 @@
   // Map a CharCode to Unicode.
   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:
 
   void parseCMap1(int (*getCharFunc)(void *), void *data, int nBits);
diff -Nru kdegraphics-3.3.1/kpdf/splash/SplashFTFont.cc kdegraphics-patched/kpdf/splash/SplashFTFont.cc
--- kdegraphics-3.3.1/kpdf/splash/SplashFTFont.cc	2004-11-06 03:13:13.000000000 +0900
+++ kdegraphics-patched/kpdf/splash/SplashFTFont.cc	2004-11-03 22:03:37.000000000 +0900
@@ -225,6 +225,9 @@
   if (FT_Get_Glyph(slot, &glyph)) {
     return NULL;
   }
+  if (glyph->format != FT_GLYPH_FORMAT_OUTLINE) {
+    return NULL;
+  }
   path = new SplashPath();
   FT_Outline_Decompose(&((FT_OutlineGlyph)glyph)->outline,
 		       &outlineFuncs, path);

Reply to: