// Parses the format 12 cmap table // Refer to https://www.microsoft.com/typography/otspec/cmap.htm to learn about how this format is organized private void ParseFormat12(byte[] source, ref uint offset, List <GlyphModel> allChars) { CmapFormat12Header header = ParseCmapFormat12Header(source, ref offset); for (int i = 0; i < header.nGroups; i++) { uint startCharCode = ReadDataAndIncreaseIndex <uint>(source, ref offset, sizeof(uint)); uint endCharCode = ReadDataAndIncreaseIndex <uint>(source, ref offset, sizeof(uint)); uint startGlyphID = ReadDataAndIncreaseIndex <uint>(source, ref offset, sizeof(uint)); for (uint j = startCharCode; j <= endCharCode; j++) { GlyphModel newChar = new GlyphModel(); newChar.CodePoint = j; newChar.GlyphID = (ushort)startGlyphID; startGlyphID++; byte[] byteJ = BitConverter.GetBytes(j); newChar.Definition = Encoding.UTF32.GetString(byteJ); if (!allChars.Contains(newChar)) { allChars.Add(newChar); } } } }
// Reads through the header information of the cmap format 12 table private CmapFormat12Header ParseCmapFormat12Header(byte[] source, ref uint offset) { CmapFormat12Header header = new CmapFormat12Header(); header.format = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); Debug.Assert(header.format == 12); header.reserved = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); header.length = ReadDataAndIncreaseIndex <uint>(source, ref offset, sizeof(uint)); header.language = ReadDataAndIncreaseIndex <uint>(source, ref offset, sizeof(uint)); header.nGroups = ReadDataAndIncreaseIndex <uint>(source, ref offset, sizeof(uint)); return(header); }