Hi all.

Mac OS X 10.11 El Capitan provides many new CJK fonts as OpenType Collection 
(but extension is .ttc).
LuaTeX 0.81.0 can handle these new fonts (see rev 5330).
However, luaotfload still cannot embed several fonts, e.g. HiraginoSans-W1, 
with "Invalid TTC index number" error.

The cause of the problem is that this font does not have subfonts whose 
PostScript name is same as "fontname" of the font file.
For HiraginoSans-W1, luatex fontloader returns:

...
 ["familyname"]="Hiragino Sans W1",
 ["fontname"]="HiraKakuProN-W1",
 ["fontstyle_id"]=0,
 ["fullname"]="HiraKakuProN-W1",
...

This font file has two subfonts. Their PostScript name are:

...
     ["family"]=".Hiragino Kaku Gothic Interface",
     ["fullname"]=".Hiragino Kaku Gothic Interface W1",
     ["manufacturer"]="SCREEN Graphic and Precision Solutions Co., Ltd.",
     ["postscriptname"]=".HiraKakuInterface-W1",
     ["preffamilyname"]=".Hiragino Kaku Gothic Interface",
...
     ["family"]="Hiragino Sans W1",
     ["fullname"]="Hiragino Sans W1",
     ["manufacturer"]="SCREEN Graphic and Precision Solutions Co., Ltd.",
     ["postscriptname"]="HiraginoSans-W1",
     ["preffamilyname"]="Hiragino Sans",
...

There is no subfont whose postscriptname is "HiraKakuProN-W1".
But luaotfload sets fontname "HiraKakuProN-W1" to psname, and causes "Invalid 
TTC index number" error.


I attach a patch to luaotfload (or font-otf.lua).
This code reads postscriptname, writes it to font cache as metadata.psname, and 
sets it to psname.
After applying this patch, you will be able to embed all the new CJK fonts.


Best regards
Kazuki Maeda
diff --git a/src/fontloader/runtime/fontloader-reference.lua b/src/fontloader/runtime/fontloader-reference.lua
index d8095a2..dc46fa5 100644
--- a/src/fontloader/runtime/fontloader-reference.lua
+++ b/src/fontloader/runtime/fontloader-reference.lua
@@ -7566,6 +7566,16 @@ function otf.load(filename,sub,featurefile)
         stoptiming(packtime)
       end
       report_otf("saving %a in cache",filename)
+      if fontdata.names then
+         local englishnames = {}
+         for _, raw_namedata in next, fontdata.names do
+            if raw_namedata.lang == "English (US)" then
+               englishnames = raw_namedata.names or {}
+               break
+            end
+         end
+         data.metadata.psname = englishnames.postscriptname
+      end
       data=containers.write(otf.cache,hash,data)
       if cleanup>1 then
         collectgarbage("collect")
@@ -9164,7 +9174,7 @@ local function copytotfm(data,cache_id)
     local filename=constructors.checkedfilename(resources)
     local fontname=metadata.fontname
     local fullname=metadata.fullname or fontname
-    local psname=fontname or fullname
+    local psname=metadata.psname or fontname or fullname
     local units=metadata.units_per_em or 1000
     if units==0 then 
       units=1000 

Reply via email to