Sorry, I slipped to attache the patches.

Regards,
mpsuzuki

On Tue, 27 Mar 2012 01:09:24 +0900
[email protected] wrote:

>Hi,
>
>On Tue, 27 Mar 2012 00:32:30 +0900
>[email protected] wrote:
>>Also I fixed Korean entry by changing "kana" to "hang",
>>but Batang (bundled to Microsoft Windows) have other
>>problems, and I will submit another set of patches.
>
>The problems in Batang (a Korean font bundled to Microsoft
>Windows) are following.
>
>1) entries in OpenType lookup table are sorted by source GID?
>
>FoFiTrueType assumes the entries in lookup table are
>sorted by source GID. If it finds a GID greater than
>source GID, the lookup process is finished as "not
>found in the table".
>
>In Batang, the entries in the lookup subtable for
>"vert" feature is not sorted by source GID, so some
>substitution rule could not be found. So all entries
>should be scanned to use Batang.
>
>attached "fixOTLookupForUnsortedTable_20120326.diff"
>is a workaround patch for this issue.
>
>
>
>2) default language system or not?
>
>FoFiTrueType assumes the vertical layout feature is
>defined in default language system, for specified
>script. FoFiTrueType::setupGSUB() takes only script
>name. It is true for SimSun, MingLiU, MS-Mincho, but
>false for Batang. In Batang, "hang" script supports
>"KOR " language system (in "KOR " language system,
>"vert" is defined), but default language system is
>not "KOR " and it has no layout feature.
>
>attached "addSetupGSUBWithLang_20120326.diff" is a
>patch to add new variant of FoFiTrueType::setupGSUB()
>taking both of "script" and "language". By giving both
>of "hang" and "KOR ", the vertical layout feature of
>Batang can be activated. Original method is kept as
>a thin wrapper of new method.
>
>attached "useSetupGSUBWithLang_20120326.diff" is a
>patch to modify GfxCIDFont::getCodeToGIDMap() to use
>new variant of FoFiTrueType::setupGSUB(script, lang).
>
>--
>
>If more detailed analysis and testing PDF are required,
>I will post.
>
>Regards,
>mpsuzuki
>_______________________________________________
>poppler mailing list
>[email protected]
>http://lists.freedesktop.org/mailman/listinfo/poppler
diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index 431910d..7a1380d 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -2281,7 +2281,7 @@ int FoFiTrueType::setupGSUB(const char *tagName)
 
   /* read LangSys table */
   if (langSys == 0) {
-    /* no ldefault LangSys */
+    /* no default LangSys */
     return 0;
   }
 
@@ -2453,6 +2453,9 @@ int FoFiTrueType::checkGIDInCoverage(Guint coverage, Guint orgGID)
   case 1:
     count = getU16BE(pos,&parsedOk);
     pos += 2;
+    // In some poor CJK fonts, key GIDs are not sorted,
+    // thus we cannot finish checking even when the range
+    // including orgGID seems to have already passed.
     for (i = 0;i < count;i++) {
       Guint gid;
 
@@ -2462,9 +2465,6 @@ int FoFiTrueType::checkGIDInCoverage(Guint coverage, Guint orgGID)
         /* found */
         index = i;
         break;
-      } else if (gid > orgGID) {
-        /* not found */
-        break;
       }
     }
     break;
@@ -2481,13 +2481,13 @@ int FoFiTrueType::checkGIDInCoverage(Guint coverage, Guint orgGID)
       pos += 2;
       startIndex = getU16BE(pos,&parsedOk);
       pos += 2;
+      // In some poor CJK fonts, key GIDs are not sorted,
+      // thus we cannot finish checking even when the range
+      // including orgGID seems to have already passed.
       if (startGID <= orgGID && orgGID <= endGID) {
         /* found */
         index = startIndex+orgGID-startGID;
         break;
-      } else if (orgGID <= endGID) {
-        /* not found */
-        break;
       }
     }
     break;
diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index 7a1380d..f112189 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -2219,7 +2219,17 @@ Guint FoFiTrueType::charToTag(const char *tagName)
   setup GSUB table data
   Only supporting vertical text substitution.
 */
-int FoFiTrueType::setupGSUB(const char *tagName)
+int FoFiTrueType::setupGSUB(const char *scriptName)
+{
+  return setupGSUB(scriptName, NULL);
+}
+
+/*
+  setup GSUB table data
+  Only supporting vertical text substitution.
+*/
+int FoFiTrueType::setupGSUB(const char *scriptName,
+                            const char *languageName)
 {
   Guint gsubTable;
   unsigned int i;
@@ -2236,11 +2246,11 @@ int FoFiTrueType::setupGSUB(const char *tagName)
   int x;
   Guint pos;
 
-  if (tagName == 0) {
+  if (scriptName == 0) {
     gsubFeatureTable = 0;
     return 0;
   }
-  scriptTag = charToTag(tagName);
+  scriptTag = charToTag(scriptName);
   /* read GSUB Header */
   if ((x = seekTable("GSUB")) < 0) {
     return 0; /* GSUB table not found */
@@ -2277,7 +2287,21 @@ int FoFiTrueType::setupGSUB(const char *tagName)
   /* read script table */
   /* use default language system */
   pos = gsubTable+scriptList+scriptTable;
-  langSys = getU16BE(pos,&parsedOk);/* default language system */
+  langSys = 0;
+  if (languageName) {
+    Guint langTag = charToTag(languageName);
+    Guint langCount = getU16BE(pos+2,&parsedOk);
+    for (i = 0;i < langCount && langSys == 0;i++) {
+      tag = getU32BE(pos+4+i*(4+2),&parsedOk);
+      if (tag == langTag) {
+        langSys = getU16BE(pos+4+i*(4+2)+4,&parsedOk);
+      }
+    }
+  }
+  if (langSys == 0) {
+    /* default language system */
+    langSys = getU16BE(pos,&parsedOk);
+  }
 
   /* read LangSys table */
   if (langSys == 0) {
diff --git a/fofi/FoFiTrueType.h b/fofi/FoFiTrueType.h
index c2d7bd4..2f3ed22 100644
--- a/fofi/FoFiTrueType.h
+++ b/fofi/FoFiTrueType.h
@@ -165,7 +165,12 @@ public:
   // Otherwise returns false.  (Only useful for OpenType CFF fonts).
   GBool getCFFBlock(char **start, int *length);
 
-  int setupGSUB(const char *tagName);
+  // setup vert/vrt2 GSUB for default lang
+  int setupGSUB(const char *scriptName);
+
+  // setup vert/vrt2 GSUB for specified lang
+  int setupGSUB(const char *scriptName, const char* languageName);
+
 private:
 
   FoFiTrueType(char *fileA, int lenA, GBool freeFileDataA, int faceIndexA);
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index fe908b7..536ae5a 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -2232,36 +2232,37 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
   static struct CMapListEntry {
     const char *collection;
     const char *scriptTag;
+    const char *languageTag;
     const char *toUnicodeMap;
     const char **CMaps;
   } CMapList[] = {
     {
       "Adobe-CNS1",
-      "hani",
+      "hani", "CHN ",
       "Adobe-CNS1-UCS2",
       adobe_cns1_cmaps,
     },
     {
       "Adobe-GB1",
-      "hani",
+      "hani", "CHN ",
       "Adobe-GB1-UCS2",
       adobe_gb1_cmaps,
     },
     {
       "Adobe-Japan1",
-      "kana",
+      "kana", "JAN ",
       "Adobe-Japan1-UCS2",
       adobe_japan1_cmaps,
     },
     {
       "Adobe-Japan2",
-      "kana",
+      "kana", "JAN ",
       "Adobe-Japan2-UCS2",
       adobe_japan2_cmaps,
     },
     {
       "Adobe-Korea1",
-      "hang",
+      "hang", "KOR ",
       "Adobe-Korea1-UCS2",
       adobe_korea1_cmaps,
     },
@@ -2359,7 +2360,7 @@ int *GfxCIDFont::getCodeToGIDMap(FoFiTrueType *ff, int *mapsizep) {
 	cMap->decRefCnt();
       }
     }
-    ff->setupGSUB(lp->scriptTag);
+    ff->setupGSUB(lp->scriptTag, lp->languageTag);
   } else {
     error(errSyntaxError, -1, "Unknown character collection {0:t}\n",
       getCollection());
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler

Reply via email to