Esempio n. 1
0
        public override void Process(TrueTypeFont font)
        {
            var reader = new TrueTypeReader(Data);

            Version        = reader.ReadUShort();
            NumberOfTables = reader.ReadUShort();

            Subtables = new List <KerningSubtableBase>(NumberOfTables);

            for (var t = 0; t < NumberOfTables; t++)
            {
                var subtableOffset = reader.Position;
                var version        = reader.ReadUShort();
                var length         = reader.ReadUShort();
                var coverage       = reader.ReadUShort();

                var subtableType = ImplementationTypeAttribute.GetTypeFromEnumValue(typeof(KerningSubtableType), GetSubtypeFromCoverage(coverage));

                var subtable = Activator.CreateInstance(subtableType) as KerningSubtableBase;
                subtable.ReadData(reader, (uint)subtableOffset, length);

                Subtables.Add(subtable);
            }

            ProcessSubtables(font);

            reader.Dispose();
        }
Esempio n. 2
0
        public TrueTypeFont(Stream fontStream)
        {
            var reader = new TrueTypeReader(fontStream);

            Version             = GetVersion(reader);
            this.NumberOfTables = reader.ReadUShort();
            this.SearchRange    = reader.ReadUShort();
            this.EntrySelector  = reader.ReadUShort();
            this.RangeShift     = reader.ReadUShort();

            var tableEntries = new List <FontTableHeaderEntry>();

            for (var i = 0; i < this.NumberOfTables; i++)
            {
                tableEntries.Add(new FontTableHeaderEntry()
                {
                    Type     = (FontTableType)reader.ReadULong(),
                    Checksum = reader.ReadULong(),
                    Offset   = reader.ReadULong(),
                    Length   = reader.ReadULong()
                });
            }

            Tables = new List <FontTableBase>(this.NumberOfTables);
            foreach (var entry in tableEntries)
            {
                var tableType = ImplementationTypeAttribute.GetTypeFromEnumValue(typeof(FontTableType), entry.Type);

                if (tableType == null)
                {
                    continue;
                }

                var table = Activator.CreateInstance(tableType) as FontTableBase;
                table.HeaderEntry = entry;
                table.Checksum    = entry.Checksum;
                table.ReadData(reader, entry.Offset, entry.Length);
                Tables.Add(table);
            }

            reader.Dispose();

            ProcessTables();
        }
Esempio n. 3
0
        public override void Process(TrueTypeFont font)
        {
            var reader = new TrueTypeReader(Data);

            Version            = reader.ReadUShort();
            EncodingTableCount = reader.ReadUShort();

            EncodingTables = new List <EncodingTableEntry>(EncodingTableCount);
            for (var i = 0; i < EncodingTableCount; i++)
            {
                EncodingTables.Add(new EncodingTableEntry()
                {
                    Platform = (Platform)reader.ReadUShort(),
                    Encoding = (Encoding)reader.ReadUShort(),
                    Offset   = reader.ReadULong()
                });
            }

            foreach (var encodingTable in EncodingTables)
            {
                reader.Seek(encodingTable.Offset);

                var format = (CmapSubtableType)reader.ReadUShort();
                var length = reader.ReadUShort();

                var subtableProcessorType = ImplementationTypeAttribute.GetTypeFromEnumValue(typeof(CmapSubtableType), format);

                if (subtableProcessorType == null)
                {
                    continue;
                }

                var subtableProcessor = Activator.CreateInstance(subtableProcessorType) as CharacterToGlyphSubtableBase;
                subtableProcessor.EncodingTableEntry = encodingTable;
                subtableProcessor.ReadData(reader, encodingTable.Offset, length);

                Subtables.Add(subtableProcessor);
            }

            ProcessSubtables(font);

            reader.Dispose();
        }