private static string[] GetGlyphNamesByFormat(TrueTypeDataBytes data, BasicMaximumProfileTable maximumProfileTable, float formatType) { string[] glyphNames; if (Math.Abs(formatType - 1) < float.Epsilon) { glyphNames = new string[WindowsGlyphList4.NumberOfMacGlyphs]; Array.Copy(WindowsGlyphList4.MacGlyphNames, glyphNames, WindowsGlyphList4.NumberOfMacGlyphs); } else if (Math.Abs(formatType - 2) < float.Epsilon) { glyphNames = GetFormat2GlyphNames(data); } else if (Math.Abs(formatType - 2.5) < float.Epsilon) { var glyphNameIndex = new int[maximumProfileTable?.NumberOfGlyphs ?? 0]; for (var i = 0; i < glyphNameIndex.Length; i++) { var offset = data.ReadSignedByte(); glyphNameIndex[i] = i + 1 + offset; } glyphNames = new string[glyphNameIndex.Length]; for (var i = 0; i < glyphNames.Length; i++) { var name = WindowsGlyphList4.MacGlyphNames[glyphNameIndex[i]]; if (name != null) { glyphNames[i] = name; } } } else if (Math.Abs(formatType - 3) < float.Epsilon) { glyphNames = new string[0]; } else { throw new InvalidOperationException($"Format type {formatType} is not supported for the PostScript table."); } return(glyphNames); }
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 static IndexToLocationTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, HeaderTable headerTable, BasicMaximumProfileTable maximumProfileTable) { const short shortFormat = 0; const short longFormat = 1; data.Seek(table.Offset); var format = headerTable.IndexToLocFormat; var glyphCount = maximumProfileTable.NumberOfGlyphs + 1; var offsets = new long[glyphCount]; switch (format) { case shortFormat: { // The local offset divided by 2 is stored. for (int i = 0; i < glyphCount; i++) { offsets[i] = data.ReadUnsignedShort() * 2; } break; } case longFormat: { // The actual offset is stored. data.ReadUnsignedIntArray(offsets, glyphCount); break; } default: throw new InvalidOperationException($"The format {format} was invalid for the index to location (loca) table."); } return(new IndexToLocationTable(table, offsets)); }