// Reads through the header information of the cmap format 6 table private CmapFormat6Header ParseCmapFormat6Header(byte[] source, ref uint offset) { CmapFormat6Header header = new CmapFormat6Header(); header.format = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); Debug.Assert(header.format == 6); header.length = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); header.language = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); header.firstCode = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); header.entryCount = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); return(header); }
// Parses the format 6 cmap table // Refer to https://www.microsoft.com/typography/otspec/cmap.htm to learn about how this format is organized private void ParseFormat6(byte[] source, ref uint offset, List <GlyphModel> allChars) { CmapFormat6Header header = ParseCmapFormat6Header(source, ref offset); for (uint i = 0; i < header.entryCount; i++) { ushort gID = ReadDataAndIncreaseIndex <ushort>(source, ref offset, sizeof(ushort)); if (gID != 0) { GlyphModel newChar = new GlyphModel(); newChar.CodePoint = i; newChar.GlyphID = gID; byte[] byteI = BitConverter.GetBytes(i); newChar.Definition = Encoding.UTF32.GetString(byteI); if (!allChars.Contains(newChar)) { allChars.Add(newChar); } } } }