public TtfTableOS2(BinaryReader file, OffsetEntry table) { if (file == null) { throw new ArgumentNullException(nameof(file)); } file.Seek(table.Offset); // See https://docs.microsoft.com/en-gb/typography/opentype/spec/os2 // See https://github.com/fontforge/fontforge/blob/master/fontforge/ttf.h#L467 Version = file.GetUint16(); switch (Version) { case 5: ReadVersion5(file); break; case 2: case 3: case 4: ReadVersion4(file); break; default: throw new Exception("OS/2 version not supported: " + Version); } }
public TtfTableName(BinaryReader file, OffsetEntry table) { file.Seek(table.Offset); TableBase = table.Offset; // See https://docs.microsoft.com/en-gb/typography/opentype/spec/name Format = file.GetUint16(); switch (Format) { case 0: case 1: // format 1 has extra info, but starts the same as zero ReadFormatZero(file); break; default: break; } }
private Dictionary <string, OffsetEntry> ReadOffsetTables() { var tables = new Dictionary <string, OffsetEntry>(); // DO NOT REARRANGE CALLS! _scalarType = _file.GetUint32(); var numTables = _file.GetUint16(); _searchRange = _file.GetUint16(); _entrySelector = _file.GetUint16(); _rangeShift = _file.GetUint16(); for (int i = 0; i < numTables; i++) { var tag = _file.GetString(4); if (string.IsNullOrEmpty(tag)) { break; // malformatted? End of file? } var entry = new OffsetEntry { Checksum = _file.GetUint32(), Offset = _file.GetUint32(), Length = _file.GetUint32() }; if (tables.ContainsKey(tag)) { Console.WriteLine($"duplicate tag: {tag}"); } else { tables.Add(tag, entry); } /* if (tag != "head") { * if (CalculateTableChecksum(file, tables[tag].Offset, tables[tag].Length) != tables[tag].Checksum) * throw new Exception("Bad file format: checksum fail in offset tables"); * }*/ } return(tables); }
public Ttf_HorizontalMetricsTable(BinaryReader file, OffsetEntry table, Ttf_HorizontalHeaderTable header, Ttf_MaximumProfileTable profile) { file.Seek(table.Offset); TableBase = table.Offset; int numMetrics = header.NumberOfHMetrics; int extraLeftSideBearings = profile.NumGlyphs - numMetrics; _advanceWidths = new List <ushort>(numMetrics); _leftSideBearings = new List <short>(numMetrics + extraLeftSideBearings); for (int idx = 0; idx < numMetrics; idx++) { _advanceWidths.Add(file.GetUint16()); _leftSideBearings.Add(file.GetInt16()); } for (int idx = 0; idx < extraLeftSideBearings; idx++) { _leftSideBearings.Add(file.GetInt16()); } }