/** * This will read the required data from the stream. * * @param ttf The font that is being read. * @param data The stream to read the data from. * @ If there is an error reading the data. */ public override void Read(TrueTypeFont ttf, TTFDataStream data) { VerticalHeaderTable vHeader = ttf.VerticalHeader; if (vHeader == null) { throw new IOException("Could not get vhea table"); } numVMetrics = vHeader.NumberOfVMetrics; int numGlyphs = ttf.NumberOfGlyphs; int bytesRead = 0; advanceHeight = new int[numVMetrics]; topSideBearing = new short[numVMetrics]; for (int i = 0; i < numVMetrics; i++) { advanceHeight[i] = data.ReadUnsignedShort(); topSideBearing[i] = data.ReadSignedShort(); bytesRead += 4; } if (bytesRead < Length) { int numberNonVertical = numGlyphs - numVMetrics; // handle bad fonts with too many vmetrics if (numberNonVertical < 0) { numberNonVertical = numGlyphs; } additionalTopSideBearing = new short[numberNonVertical]; for (int i = 0; i < numberNonVertical; i++) { if (bytesRead < Length) { additionalTopSideBearing[i] = data.ReadSignedShort(); bytesRead += 2; } } } initialized = true; }
private TTFTable ReadTableDirectory(TrueTypeFont font, TTFDataStream raf) { TTFTable table; string tag = raf.ReadString(4); switch (tag) { case CmapTable.TAG: table = new CmapTable(font); break; case GlyphTable.TAG: table = new GlyphTable(font); break; case HeaderTable.TAG: table = new HeaderTable(font); break; case HorizontalHeaderTable.TAG: table = new HorizontalHeaderTable(font); break; case HorizontalMetricsTable.TAG: table = new HorizontalMetricsTable(font); break; case IndexToLocationTable.TAG: table = new IndexToLocationTable(font); break; case MaximumProfileTable.TAG: table = new MaximumProfileTable(font); break; case NamingTable.TAG: table = new NamingTable(font); break; case OS2WindowsMetricsTable.TAG: table = new OS2WindowsMetricsTable(font); break; case PostScriptTable.TAG: table = new PostScriptTable(font); break; case DigitalSignatureTable.TAG: table = new DigitalSignatureTable(font); break; case KerningTable.TAG: table = new KerningTable(font); break; case VerticalHeaderTable.TAG: table = new VerticalHeaderTable(font); break; case VerticalMetricsTable.TAG: table = new VerticalMetricsTable(font); break; case VerticalOriginTable.TAG: table = new VerticalOriginTable(font); break; case GlyphSubstitutionTable.TAG: table = new GlyphSubstitutionTable(font); break; default: table = ReadTable(font, tag); break; } table.Tag = tag; table.CheckSum = raf.ReadUnsignedInt(); table.Offset = raf.ReadUnsignedInt(); table.Length = raf.ReadUnsignedInt(); // skip tables with zero length (except glyf) if (table.Length == 0 && !tag.Equals(GlyphTable.TAG, StringComparison.Ordinal)) { return(null); } return(table); }