public static void Load(FontParser parser,int offset,FontFace font,out int numberOfGlyphs){ // Seek: parser.Position=offset; // version float version=parser.ReadVersion(); // Italic angle. For some reason it's inverted in the spec - negative means a slope to the right. int frac; int dec=parser.ReadFixed(out frac); if(frac!=0){ // Figure it out: float angle=(float)dec/(float)frac; // Apply it (un-inverted): font.SetItalicAngle(-angle); } // underlinePosition parser.ReadInt16(); // underlineThickness parser.ReadInt16(); // isFixedPitch parser.ReadUInt32(); // minMemType42 parser.ReadUInt32(); // maxMemType42 parser.ReadUInt32(); // minMemType1 parser.ReadUInt32(); // maxMemType1 parser.ReadUInt32(); if(version==2f){ numberOfGlyphs = parser.ReadUInt16(); /* string[] glyphNames=new string[numberOfGlyphs]; for (int i = 0; i < numberOfGlyphs; i++) { // Read the index: int index = parser.ReadUInt16(); if(index >= StandardNames.Length){ // Read the name: glyphNames[i]=parser.ReadString(parser.ReadByte()); }else{ // Grab the std name: glyphNames[i]=StandardNames[index]; } } */ }else if(version==2.5f){ numberOfGlyphs = parser.ReadUInt16(); /* byte[] offsets = new byte[numberOfGlyphs]; for (int i = 0; i < post.numberOfGlyphs; i++){ offsets[i] = parser.ReadByte(); } */ }else{ numberOfGlyphs=-1; } }
//--------------------------------------
public static bool Load(FontParser parser, FontFace font, bool full) { font.RequiresLoad = !full; font.Parser = parser; // Read the version: int dec; int version = parser.ReadFixed(out dec); if (version == 1 && dec == 0) { // TTF outline format. } else { // Reset to start: parser.Position = 0; // OpenType. Read the tag (right at the start): string openTypeVersion = parser.ReadTag(); if (openTypeVersion == "OTTO") { // CFF outline format. } else { // Unsupported format. return(false); } } // Table count: int numTables = parser.ReadUInt16(); // Move to p12: parser.Position = 12; for (int i = 0; i < numTables; i++) { // Read the tables tag: string tag = parser.ReadTag(); // Move parser along: parser.Position += 4; // Read the offset: int offset = (int)parser.ReadUInt32(); // Grab the position - this allows the tables to mess it up: int basePosition = parser.Position; switch (tag) { case "cmap": parser.CmapOffset = offset; break; case "head": // Load the header: if (!HeaderTables.Load(parser, offset, font, out parser.IndexToLocFormat)) { return(false); } break; case "hhea": parser.HheaOffset = offset; break; case "hmtx": parser.HmtxOffset = offset; break; case "maxp": // Maxp table: MaxpTables.Load(parser, offset, font, out parser.GlyphCount); break; case "name": // General meta: NameTables.Load(parser, offset, font); break; case "OS/2": // OS2 table: OS2Tables.Load(parser, offset, font); break; case "post": // Postscript info table: parser.PostOffset = offset; break; case "glyf": parser.GlyfOffset = offset; break; case "loca": parser.LocaOffset = offset; break; case "GSUB": // Gsub(stitute) table. Ligatures fall through here. GsubTables.Load(parser, offset, font); break; case "CFF ": parser.CffOffset = offset; break; case "kern": parser.KernOffset = offset; break; case "GPOS": parser.GposOffset = offset; break; } // Skip meta: parser.Position = basePosition + 4; } if (full) { return(ReadTables(parser, font)); } return(true); }
public static void Load(FontParser parser, int offset, FontFace font, out int numberOfGlyphs) { // Seek: parser.Position = offset; // version float version = parser.ReadVersion(); // Italic angle. For some reason it's inverted in the spec - negative means a slope to the right. int frac; int dec = parser.ReadFixed(out frac); if (frac != 0) { // Figure it out: float angle = (float)dec / (float)frac; // Apply it (un-inverted): font.SetItalicAngle(-angle); } // underlinePosition parser.ReadInt16(); // underlineThickness parser.ReadInt16(); // isFixedPitch parser.ReadUInt32(); // minMemType42 parser.ReadUInt32(); // maxMemType42 parser.ReadUInt32(); // minMemType1 parser.ReadUInt32(); // maxMemType1 parser.ReadUInt32(); if (version == 2f) { numberOfGlyphs = parser.ReadUInt16(); /* * string[] glyphNames=new string[numberOfGlyphs]; * * for (int i = 0; i < numberOfGlyphs; i++) { * * // Read the index: * int index = parser.ReadUInt16(); * * if(index >= StandardNames.Length){ * * // Read the name: * glyphNames[i]=parser.ReadString(parser.ReadByte()); * * }else{ * * // Grab the std name: * glyphNames[i]=StandardNames[index]; * * } * * } */ } else if (version == 2.5f) { numberOfGlyphs = parser.ReadUInt16(); /* * byte[] offsets = new byte[numberOfGlyphs]; * * for (int i = 0; i < post.numberOfGlyphs; i++){ * * offsets[i] = parser.ReadByte(); * * } */ } else { numberOfGlyphs = -1; } }