Beispiel #1
0
        private string GetVersion(TrueTypeReader reader)
        {
            reader.Seek(0);

            var versionBuf = reader.ReadFixed();

            return(BitConverter.ToString(versionBuf).Replace("-", ""));
        }
Beispiel #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();
        }