public ushort LookupIndex(int codepoint, int nextCodepoint = 0) { // https://www.microsoft.com/typography/OTSPEC/cmap.htm // "character codes that do not correspond to any glyph in the font should be mapped to glyph index 0." ushort ret = 0; if (!_codepointToGlyphs.TryGetValue(codepoint, out ret)) { foreach (CharacterMap cmap in _charMaps) { ushort gid = cmap.CharacterToGlyphIndex(codepoint); //https://www.microsoft.com/typography/OTSPEC/cmap.htm //...When building a Unicode font for Windows, the platform ID should be 3 and the encoding ID should be 1 if (ret == 0 || (gid != 0 && cmap.PlatformId == 3 && cmap.EncodingId == 1)) { ret = gid; } } _codepointToGlyphs[codepoint] = ret; } // If there is a second codepoint, we are asked whether this is an UVS sequence // -> if true, return a glyph ID // -> otherwise, return 0 if (nextCodepoint > 0) { foreach (CharacterMap cmap in _charMaps) { if (cmap is CharMapFormat14) { CharMapFormat14 cmap14 = cmap as CharMapFormat14; ushort gid = cmap14.CharacterPairToGlyphIndex(codepoint, ret, nextCodepoint); if (gid > 0) { return(gid); } } } return(0); } return(ret); }
private static CharacterMap ReadCharacterMap(BinaryReader input) { ushort format = input.ReadUInt16(); switch (format) { default: Utils.WarnUnimplemented("cmap subtable format {0}", format); return(new NullCharMap()); case 0: return(ReadFormat_0(input)); case 2: return(ReadFormat_2(input)); case 4: return(ReadFormat_4(input)); case 6: return(ReadFormat_6(input)); case 12: return(ReadFormat_12(input)); case 14: return(CharMapFormat14.Create(input)); } }