Exemple #1
0
        public static Format4SubTable Read(ushort format, BinaryReader reader)
        {
            var instance = new Format4SubTable
            {
                Format     = format,
                Length     = reader.ReadUInt16BigEndian(),
                Language   = reader.ReadUInt16BigEndian(),
                SegCountX2 = reader.ReadUInt16BigEndian()
            };

            int segCount = instance.SegCountX2 / 2;

            instance.SearchRange   = reader.ReadUInt16BigEndian();
            instance.EntrySelector = reader.ReadUInt16BigEndian();
            instance.RangeShift    = reader.ReadUInt16BigEndian();
            instance.EndCode       = reader.ReadUInt16BigEndianArray(segCount);
            instance.ReservedPad   = reader.ReadUInt16BigEndian();
            instance.StartCode     = reader.ReadUInt16BigEndianArray(segCount);
            instance.IdDelta       = reader.ReadInt16BigEndianArray(segCount);
            instance.IdRangeOffset = reader.ReadUInt16BigEndianArray(segCount);

            var glyphIdArrayLength = (instance.Length - (16 + segCount * 8)) / 2;

            instance.GlyphIdArray = reader.ReadUInt16BigEndianArray(glyphIdArrayLength);

            return(instance);
        }
Exemple #2
0
        public static CharacterMapTable Read(BinaryReader reader)
        {
            var tableOffset = reader.BaseStream.Position;

            var instance = new CharacterMapTable
            {
                Version         = reader.ReadUInt16BigEndian(),
                NumTables       = reader.ReadUInt16BigEndian(),
                EncodingRecords = new List <EncodingRecord>()
            };

            for (int i = 0; i < instance.NumTables; i++)
            {
                instance.EncodingRecords.Add(EncodingRecord.Read(reader));
            }

            instance.EncodingFormats = new Dictionary <EncodingRecord, int>();
            instance.Encodings       = new Dictionary <EncodingRecord, FormatSubTableBase>();
            for (int i = 0; i < instance.EncodingRecords.Count; i++)
            {
                var encodingRecord = instance.EncodingRecords[i];
                reader.BaseStream.Seek(tableOffset + encodingRecord.Offset, SeekOrigin.Begin);
                var format = reader.ReadUInt16BigEndian();
                instance.EncodingFormats[encodingRecord] = format;

                if (format == 4)
                {
                    instance.Encodings[encodingRecord] = Format4SubTable.Read(format, reader);
                }
                else
                {
                    //throw new FontReaderException($"Unsupported cmap Format Table format {format}");
                }
            }

            return(instance);
        }