private byte[] buildHeadTable() { using (var bos = new MemoryStream()) using (var output = new BinaryWriter(bos)) { HeaderTable h = ttf.Header; WriteFixed(output, h.Version); WriteFixed(output, h.FontRevision); WriteUint32(output, 0); // h.CheckSumAdjustment() WriteUint32(output, h.MagicNumber); WriteUint16(output, h.Flags); WriteUint16(output, h.UnitsPerEm); WriteLongDateTime(output, h.Created); WriteLongDateTime(output, h.Modified); WriteSInt16(output, h.XMin); WriteSInt16(output, h.YMin); WriteSInt16(output, h.XMax); WriteSInt16(output, h.YMax); WriteUint16(output, h.MacStyle); WriteUint16(output, h.LowestRecPPEM); WriteSInt16(output, h.FontDirectionHint); // force long format of 'loca' table WriteSInt16(output, (short)1); // h.IndexToLocFormat() WriteSInt16(output, h.GlyphDataFormat); output.Flush(); return(bos.ToArray()); } }
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); }
/** * Parse all tables and check if all needed tables are present. * * @param font the TrueTypeFont instance holding the parsed data. * @ If there is an error parsing the TrueType font. */ private void ParseTables(TrueTypeFont font) { foreach (TTFTable table in font.Tables) { if (!table.Initialized) { font.ReadTable(table); } } bool isPostScript = AllowCFF && font.TableMap.ContainsKey(CFFTable.TAG); HeaderTable head = font.Header; if (head == null) { throw new IOException("head is mandatory"); } HorizontalHeaderTable hh = font.HorizontalHeader; if (hh == null) { throw new IOException("hhead is mandatory"); } MaximumProfileTable maxp = font.MaximumProfile; if (maxp == null) { throw new IOException("maxp is mandatory"); } PostScriptTable post = font.PostScript; if (post == null && !isEmbedded) { // in an embedded font this table is optional throw new IOException("post is mandatory"); } if (!isPostScript) { IndexToLocationTable loc = font.IndexToLocation; if (loc == null) { throw new IOException("loca is mandatory"); } if (font.Glyph == null) { throw new IOException("glyf is mandatory"); } } if (font.Naming == null && !isEmbedded) { throw new IOException("name is mandatory"); } if (font.HorizontalMetrics == null) { throw new IOException("hmtx is mandatory"); } if (!isEmbedded && font.Cmap == null) { throw new IOException("cmap is mandatory"); } }