/// <summary> /// Read the header table from the data stream. /// </summary> public static HeaderTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table) { data.Seek(table.Offset); var version = data.Read32Fixed(); var fontRevision = data.Read32Fixed(); var checkSumAdjustment = data.ReadUnsignedInt(); var magicNumber = data.ReadUnsignedInt(); if (magicNumber != 0x5F0F3CF5) { throw new InvalidOperationException("The magic number for this TrueType font was incorrect. Value was: " + magicNumber); } var flags = data.ReadUnsignedShort(); var unitsPerEm = data.ReadUnsignedShort(); if (unitsPerEm < 16 || unitsPerEm > 16384) { throw new InvalidOperationException($"The units per em for this TrueType font was incorrect, value should be between 16 and 16384 but found {unitsPerEm} istead."); } DateTime created; try { created = data.ReadInternationalDate(); } catch (InvalidFontFormatException) { created = DateTime.MinValue; } DateTime modified; try { modified = data.ReadInternationalDate(); } catch (InvalidFontFormatException) { modified = DateTime.MinValue; } var xMin = data.ReadSignedShort(); var yMin = data.ReadSignedShort(); var xMax = data.ReadSignedShort(); var yMax = data.ReadSignedShort(); var macStyle = data.ReadUnsignedShort(); var lowestRecPpem = data.ReadUnsignedShort(); var fontDirectionHint = data.ReadSignedShort(); var indexToLocFormat = (IndexToLocationTable.EntryFormat)data.ReadSignedShort(); var glyphDataFormat = data.ReadSignedShort(); return(new HeaderTable(table, version, fontRevision, checkSumAdjustment, magicNumber, flags, unitsPerEm, created, modified, xMin, yMin, xMax, yMax, macStyle, lowestRecPpem, fontDirectionHint, indexToLocFormat, glyphDataFormat)); }
public TrueTypeFont Parse(TrueTypeDataBytes data) { var version = (decimal)data.Read32Fixed(); int numberOfTables = data.ReadUnsignedShort(); // Read these data points to move to the correct data location. // ReSharper disable UnusedVariable int searchRange = data.ReadUnsignedShort(); int entrySelector = data.ReadUnsignedShort(); int rangeShift = data.ReadUnsignedShort(); // ReSharper restore UnusedVariable var tables = new Dictionary <string, TrueTypeHeaderTable>(); for (var i = 0; i < numberOfTables; i++) { var table = ReadTable(data); if (table.HasValue) { tables[table.Value.Tag] = table.Value; } } var result = ParseTables(version, tables, data); return(result); }
public static BasicMaximumProfileTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table) { data.Seek(table.Offset); var version = data.Read32Fixed(); var numberOfGlyphs = data.ReadUnsignedShort(); if (Math.Abs(version - 0.5) < float.Epsilon) { return(new BasicMaximumProfileTable(table, version, numberOfGlyphs)); } var maxPoints = data.ReadUnsignedShort(); var maxContours = data.ReadUnsignedShort(); var maxCompositePoints = data.ReadUnsignedShort(); var maxCompositeContours = data.ReadUnsignedShort(); var maxZones = data.ReadUnsignedShort(); var maxTwilightPoints = data.ReadUnsignedShort(); var maxStorage = data.ReadUnsignedShort(); var maxFunctionDefs = data.ReadUnsignedShort(); var maxInstructionDefs = data.ReadUnsignedShort(); var maxStackElements = data.ReadUnsignedShort(); var maxSizeOfInstructions = data.ReadUnsignedShort(); var maxComponentElements = data.ReadUnsignedShort(); var maxComponentDepth = data.ReadUnsignedShort(); return(new MaximumProfileTable(table, version, numberOfGlyphs, maxPoints, maxContours, maxCompositePoints, maxCompositeContours, maxZones, maxTwilightPoints, maxStorage, maxFunctionDefs, maxInstructionDefs, maxStackElements, maxSizeOfInstructions, maxComponentElements, maxComponentDepth)); }
internal static NameTable GetNameTable(TrueTypeDataBytes data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } // Read these data points to move to the correct data location. data.Read32Fixed(); int numberOfTables = data.ReadUnsignedShort(); data.ReadUnsignedShort(); data.ReadUnsignedShort(); data.ReadUnsignedShort(); TrueTypeHeaderTable?name = null; for (var i = 0; i < numberOfTables; i++) { var tableHeader = ReadTable(data); if (tableHeader.HasValue && tableHeader.Value.Tag == TrueTypeHeaderTable.Name) { name = tableHeader; break; } } if (!name.HasValue) { return(null); } return(TableParser.Parse <NameTable>(name.Value, data, new TableRegister.Builder())); }
public static PostScriptTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, BasicMaximumProfileTable maximumProfileTable) { data.Seek(table.Offset); var formatType = data.Read32Fixed(); var italicAngle = data.Read32Fixed(); var underlinePosition = data.ReadSignedShort(); var underlineThickness = data.ReadSignedShort(); var isFixedPitch = data.ReadUnsignedInt(); var minMemType42 = data.ReadUnsignedInt(); var maxMemType42 = data.ReadUnsignedInt(); var mimMemType1 = data.ReadUnsignedInt(); var maxMemType1 = data.ReadUnsignedInt(); var glyphNames = GetGlyphNamesByFormat(data, maximumProfileTable, formatType); return(new PostScriptTable(table, (decimal)formatType, (decimal)italicAngle, underlinePosition, underlineThickness, isFixedPitch, minMemType42, maxMemType42, mimMemType1, maxMemType1, glyphNames)); }
public TrueTypeFont Parse(TrueTypeDataBytes data) { var version = (decimal)data.Read32Fixed(); int numberOfTables = data.ReadUnsignedShort(); int searchRange = data.ReadUnsignedShort(); int entrySelector = data.ReadUnsignedShort(); int rangeShift = data.ReadUnsignedShort(); var tables = new Dictionary <string, TrueTypeHeaderTable>(); for (var i = 0; i < numberOfTables; i++) { var table = ReadTable(data); if (table.HasValue) { tables[table.Value.Tag] = table.Value; } } var result = ParseTables(version, tables, data); return(result); }