private static TrueTypeFont ParseTables(decimal version, IReadOnlyDictionary <string, TrueTypeHeaderTable> tables, TrueTypeDataBytes data) { var isPostScript = tables.ContainsKey(TrueTypeHeaderTable.Cff); var tableRegister = new TableRegister(); if (!tables.TryGetValue(TrueTypeHeaderTable.Head, out var table)) { throw new InvalidOperationException($"The {TrueTypeHeaderTable.Head} table is required."); } // head tableRegister.HeaderTable = HeaderTable.Load(data, table); if (!tables.TryGetValue(TrueTypeHeaderTable.Hhea, out var hHead)) { throw new InvalidOperationException("The horizontal header table is required."); } // hhea tableRegister.HorizontalHeaderTable = HorizontalHeaderTable.Load(data, hHead); if (!tables.TryGetValue(TrueTypeHeaderTable.Maxp, out var maxHeaderTable)) { throw new InvalidOperationException("The maximum profile table is required."); } // maxp tableRegister.MaximumProfileTable = BasicMaximumProfileTable.Load(data, maxHeaderTable); // post if (tables.TryGetValue(TrueTypeHeaderTable.Post, out var postscriptHeaderTable)) { tableRegister.PostScriptTable = PostScriptTable.Load(data, table, tableRegister.MaximumProfileTable); } if (!isPostScript) { if (!tables.TryGetValue(TrueTypeHeaderTable.Loca, out var indexToLocationHeaderTable)) { throw new InvalidOperationException("The location to index table is required for non-PostScript fonts."); } // loca tableRegister.IndexToLocationTable = IndexToLocationTable.Load(data, indexToLocationHeaderTable, tableRegister); if (!tables.TryGetValue(TrueTypeHeaderTable.Glyf, out var glyphHeaderTable)) { throw new InvalidOperationException("The glpyh table is required for non-PostScript fonts."); } // glyf tableRegister.GlyphDataTable = GlyphDataTable.Load(data, glyphHeaderTable, tableRegister); OptionallyParseTables(tables, data, tableRegister); } return(new TrueTypeFont(version, tables, tableRegister)); }
private static TrueTypeFont ParseTables(float version, IReadOnlyDictionary <string, TrueTypeHeaderTable> tables, TrueTypeDataBytes data) { var isPostScript = tables.ContainsKey(TrueTypeHeaderTable.Cff); var builder = new TableRegister.Builder(); if (!tables.TryGetValue(TrueTypeHeaderTable.Head, out var table)) { throw new InvalidFontFormatException($"The {TrueTypeHeaderTable.Head} table is required."); } // head builder.HeaderTable = HeaderTable.Load(data, table); if (!tables.TryGetValue(TrueTypeHeaderTable.Hhea, out var hHead)) { throw new InvalidFontFormatException("The horizontal header table is required."); } // hhea builder.HorizontalHeaderTable = TableParser.Parse <HorizontalHeaderTable>(hHead, data, builder); if (!tables.TryGetValue(TrueTypeHeaderTable.Maxp, out var maxHeaderTable)) { throw new InvalidFontFormatException("The maximum profile table is required."); } // maxp builder.MaximumProfileTable = BasicMaximumProfileTable.Load(data, maxHeaderTable); // post if (tables.TryGetValue(TrueTypeHeaderTable.Post, out var postscriptHeaderTable)) { builder.PostScriptTable = PostScriptTable.Load(data, postscriptHeaderTable, builder.MaximumProfileTable); } if (tables.TryGetValue(TrueTypeHeaderTable.Name, out var nameTable)) { builder.NameTable = TableParser.Parse <NameTable>(nameTable, data, builder); } if (tables.TryGetValue(TrueTypeHeaderTable.Os2, out var os2Table)) { builder.Os2Table = TableParser.Parse <Os2Table>(os2Table, data, builder); } if (!isPostScript) { if (!tables.TryGetValue(TrueTypeHeaderTable.Loca, out var indexToLocationHeaderTable)) { throw new InvalidFontFormatException("The location to index table is required for non-PostScript fonts."); } // loca builder.IndexToLocationTable = IndexToLocationTable.Load(data, indexToLocationHeaderTable, builder); if (!tables.TryGetValue(TrueTypeHeaderTable.Glyf, out var glyphHeaderTable)) { throw new InvalidFontFormatException("The glyph table is required for non-PostScript fonts."); } // glyf builder.GlyphDataTable = GlyphDataTable.Load(data, glyphHeaderTable, builder); OptionallyParseTables(tables, data, builder); } return(new TrueTypeFont(version, tables, builder.Build())); }