(names, ltag)
| 5958 | } |
| 5959 | |
| 5960 | function makeNameTable(names, ltag) { |
| 5961 | var nameID; |
| 5962 | var nameIDs = []; |
| 5963 | |
| 5964 | var namesWithNumericKeys = {}; |
| 5965 | var nameTableIds = reverseDict(nameTableNames); |
| 5966 | for (var key in names) { |
| 5967 | var id = nameTableIds[key]; |
| 5968 | if (id === undefined) { |
| 5969 | id = key; |
| 5970 | } |
| 5971 | |
| 5972 | nameID = parseInt(id); |
| 5973 | namesWithNumericKeys[nameID] = names[key]; |
| 5974 | nameIDs.push(nameID); |
| 5975 | } |
| 5976 | |
| 5977 | var macLanguageIds = reverseDict(macLanguages); |
| 5978 | var windowsLanguageIds = reverseDict(windowsLanguages); |
| 5979 | |
| 5980 | var nameRecords = []; |
| 5981 | var stringPool = []; |
| 5982 | |
| 5983 | for (var i = 0; i < nameIDs.length; i++) { |
| 5984 | nameID = nameIDs[i]; |
| 5985 | var translations = namesWithNumericKeys[nameID]; |
| 5986 | for (var lang in translations) { |
| 5987 | var text = translations[lang]; |
| 5988 | |
| 5989 | // For MacOS, we try to emit the name in the form that was introduced |
| 5990 | // in the initial version of the TrueType spec (in the late 1980s). |
| 5991 | // However, this can fail for various reasons: the requested BCP 47 |
| 5992 | // language code might not have an old-style Mac equivalent; |
| 5993 | // we might not have a codec for the needed character encoding; |
| 5994 | // or the name might contain characters that cannot be expressed |
| 5995 | // in the old-style Macintosh encoding. In case of failure, we emit |
| 5996 | // the name in a more modern fashion (Unicode encoding with BCP 47 |
| 5997 | // language tags) that is recognized by MacOS 10.5, released in 2009. |
| 5998 | // If fonts were only read by operating systems, we could simply |
| 5999 | // emit all names in the modern form; this would be much easier. |
| 6000 | // However, there are many applications and libraries that read |
| 6001 | // 'name' tables directly, and these will usually only recognize |
| 6002 | // the ancient form (silently skipping the unrecognized names). |
| 6003 | var macPlatform = 1; // Macintosh |
| 6004 | var macLanguage = macLanguageIds[lang]; |
| 6005 | var macScript = macLanguageToScript[macLanguage]; |
| 6006 | var macEncoding = getEncoding(macPlatform, macScript, macLanguage); |
| 6007 | var macName = encode.MACSTRING(text, macEncoding); |
| 6008 | if (macName === undefined) { |
| 6009 | macPlatform = 0; // Unicode |
| 6010 | macLanguage = ltag.indexOf(lang); |
| 6011 | if (macLanguage < 0) { |
| 6012 | macLanguage = ltag.length; |
| 6013 | ltag.push(lang); |
| 6014 | } |
| 6015 | |
| 6016 | macScript = 4; // Unicode 2.0 and later |
| 6017 | macName = encode.UTF16(text); |
nothing calls this directly
no test coverage detected