public static void Load(FontParser parser, int offset, FontFace font, out int hmMetricCount) { // Seek there: parser.Position = offset; // Version: parser.ReadVersion(); // Ascender: float ascender = (float)parser.ReadInt16() / font.UnitsPerEmF; // Descender: float descender = (float)parser.ReadInt16() / font.UnitsPerEmF; // Line gap: float lineGap = (float)parser.ReadInt16() / font.UnitsPerEmF; if (lineGap < 0f) { // Negative line gaps are treated as meaning 0. lineGap = 0f; } parser.HheaAscender = ascender; parser.HheaDescender = descender; parser.HheaLineGap = lineGap; // Advance width max: font.MaxAdvanceWidth = (float)parser.ReadUInt16() / font.UnitsPerEmF; // Min left side bearing: font.MinLeftSideBearing = (float)parser.ReadInt16() / font.UnitsPerEmF; // Min right side bearing: font.MinRightSideBearing = (float)parser.ReadInt16() / font.UnitsPerEmF; // Max x extent: font.MaxXExtent = (float)parser.ReadInt16() / font.UnitsPerEmF; // Caret slope rise: float caretRise = (float)parser.ReadInt16(); // Caret slope run: float caretRun = (float)parser.ReadInt16(); font.CaretAngle = (float)Math.Atan2(caretRise, caretRun); // Caret offset: font.CaretOffset = (float)parser.ReadInt16() / font.UnitsPerEmF; // Skip: parser.Position += 8; // Metric format: parser.ReadInt16(); // Metric count: hmMetricCount = parser.ReadUInt16(); }
public static void Load(FontParser parser,int offset,FontFace font,out int glyphCount){ // Seek: parser.Position=offset; // Table version: float version=parser.ReadVersion(); // Glyph count: glyphCount=parser.ReadUInt16(); if (version == 1f){ // Max points: parser.ReadUInt16(); // Max contours: parser.ReadUInt16(); // Max composite points: parser.ReadUInt16(); // Max composite contours: parser.ReadUInt16(); // Max zones: parser.ReadUInt16(); // Max twilight points: parser.ReadUInt16(); // Max storage: parser.ReadUInt16(); // Max function defs: parser.ReadUInt16(); // Max instruction defs: parser.ReadUInt16(); // Max stack elements: parser.ReadUInt16(); // Max instruction size: parser.ReadUInt16(); // Max component elements: parser.ReadUInt16(); // Max component depth: parser.ReadUInt16(); } }
public static void Load(FontParser parser, int offset, FontFace font, out int glyphCount) { // Seek: parser.Position = offset; // Table version: float version = parser.ReadVersion(); // Glyph count: glyphCount = parser.ReadUInt16(); if (version == 1f) { // Max points: parser.ReadUInt16(); // Max contours: parser.ReadUInt16(); // Max composite points: parser.ReadUInt16(); // Max composite contours: parser.ReadUInt16(); // Max zones: parser.ReadUInt16(); // Max twilight points: parser.ReadUInt16(); // Max storage: parser.ReadUInt16(); // Max function defs: parser.ReadUInt16(); // Max instruction defs: parser.ReadUInt16(); // Max stack elements: parser.ReadUInt16(); // Max instruction size: parser.ReadUInt16(); // Max component elements: parser.ReadUInt16(); // Max component depth: parser.ReadUInt16(); } }
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,int offset,FontFace font,out int locFormatIndex){ // Seek there now: parser.Position=offset; // Version: parser.ReadVersion(); // Revision: parser.ReadRevision(); // Checksum adjustment: parser.ReadUInt32(); // Magic number: if(parser.ReadUInt32()!=0x5F0F3CF5){ locFormatIndex=0; return false; } // Flags: parser.ReadUInt16(); // Units per em: font.UnitsPerEm = parser.ReadUInt16(); font.UnitsPerEmF = (float)font.UnitsPerEm; // Skip created and modified: parser.ReadTime(); parser.ReadTime(); // X min: parser.ReadInt16(); // Y min: parser.ReadInt16(); // X max: parser.ReadInt16(); // Y max: parser.ReadInt16(); // Mac style: parser.ReadUInt16(); // Lowest Rec PPEM: parser.ReadUInt16(); // Font direction hint: parser.ReadInt16(); // Index for the loc format: locFormatIndex = parser.ReadInt16(); // 50 // Glyph data format: parser.ReadInt16(); return true; }
public static void Load(FontParser parser, int offset, FontFace font) { // Seek there: parser.Position = offset; // Version: parser.ReadVersion(); // Script list (directed by UI Language setting): int scriptList = parser.ReadUInt16(); // Feature list: int featList = parser.ReadUInt16(); // Lookup list: int lookList = parser.ReadUInt16(); // Goto script list: int objectOffset = scriptList + offset; parser.Position = objectOffset; /* * // How many language scripts? * int scriptCount=parser.ReadUInt16(); * * for(int i=0;i<scriptCount;i++){ * * // Read the script code: * string scrName=parser.ReadString(4); * * // And it's offset: * int scriptOffset=parser.ReadUInt16()+objectOffset; * * int retPosition=parser.Position; * * // Seek and load it right away: * parser.Position=scriptOffset; * * // What's the default lang? * int defaultLangOffset=parser.ReadUInt16(); * * // How many languages? * int langCount=parser.ReadUInt16(); * * for(int l=0;l<langCount;l++){ * * // Read the lang code: * string langName=parser.ReadString(4); * * // And it's offset - points to list of features: * int langOffset=parser.ReadUInt16()+objectOffset; * * } * * parser.Position=retPosition; * * } */ // Create lookup set: LookupList lookups = new LookupList(parser, lookList + offset); // Goto feature list: objectOffset = featList + offset; parser.Position = objectOffset; // How many features? int featureCount = parser.ReadUInt16(); for (int i = 0; i < featureCount; i++) { // Read the feature code: string featureName = parser.ReadString(4); // Table offset: int featTable = parser.ReadUInt16(); // Create the feature ref: FontFeature feature = new FontFeature(); feature.Name = featureName; feature.Offset = objectOffset + featTable; feature.Parser = parser; feature.Face = font; feature.List = lookups; // Add to font: font.Features[featureName] = feature; } }
public static void Load(FontParser parser,int offset,FontFace font,out int hmMetricCount){ // Seek there: parser.Position=offset; // Version: parser.ReadVersion(); // Ascender: float ascender=(float)parser.ReadInt16()/font.UnitsPerEmF; // Descender: float descender=(float)parser.ReadInt16()/font.UnitsPerEmF; // Line gap: float lineGap=(float)parser.ReadInt16()/font.UnitsPerEmF; if(!Fonts.UseOS2Metrics || !parser.ReadOS2){ if(lineGap<0f){ lineGap=-lineGap; } float halfGap=lineGap/2f; font.Ascender=ascender + halfGap; font.Descender=halfGap-descender; font.LineGap=font.Ascender + font.Descender; } // Advance width max: font.MaxAdvanceWidth=(float)parser.ReadUInt16()/font.UnitsPerEmF; // Min left side bearing: font.MinLeftSideBearing=(float)parser.ReadInt16()/font.UnitsPerEmF; // Min right side bearing: font.MinRightSideBearing=(float)parser.ReadInt16()/font.UnitsPerEmF; // Max x extent: font.MaxXExtent=(float)parser.ReadInt16()/font.UnitsPerEmF; // Caret slope rise: float caretRise=(float)parser.ReadInt16(); // Caret slope run: float caretRun=(float)parser.ReadInt16(); font.CaretAngle=(float)Math.Atan2(caretRise,caretRun); // Caret offset: font.CaretOffset=(float)parser.ReadInt16()/font.UnitsPerEmF; // Skip: parser.Position += 8; // Metric format: parser.ReadInt16(); // Metric count: hmMetricCount = parser.ReadUInt16(); }
public static void Load(FontParser parser, int offset, FontFace font) { // Seek there: parser.Position = offset; // Version: parser.ReadVersion(); // Script list (directed by UI Language setting): int scriptList = parser.ReadUInt16(); // Feature list: int featList = parser.ReadUInt16(); // Lookup list: int lookList = parser.ReadUInt16(); // Goto script list: int objectOffset = scriptList + offset; parser.Position = objectOffset; /* * // How many language scripts? * int scriptCount=parser.ReadUInt16(); * * for(int i=0;i<scriptCount;i++){ * * // Read the script code: * string scrName=parser.ReadString(4); * * // And it's offset: * int scriptOffset=parser.ReadUInt16()+objectOffset; * * int retPosition=parser.Position; * * // Seek and load it right away: * parser.Position=scriptOffset; * * // What's the default lang? * int defaultLangOffset=parser.ReadUInt16(); * * // How many languages? * int langCount=parser.ReadUInt16(); * * for(int l=0;l<langCount;l++){ * * // Read the lang code: * string langName=parser.ReadString(4); * * // And it's offset - points to list of features: * int langOffset=parser.ReadUInt16()+objectOffset; * * } * * parser.Position=retPosition; * * } */ // Goto lookup list: objectOffset = lookList + offset; // Seek there: parser.Position = objectOffset; // Load each one: int lookCount = parser.ReadUInt16(); // Create: LigatureLookupTable[] lookupTables = new LigatureLookupTable[lookCount]; for (int i = 0; i < lookCount; i++) { // Create the table: LigatureLookupTable table = new LigatureLookupTable(); // Load it: int tableOffset = parser.ReadUInt16(); // Cache the position: int seekPos = parser.Position; // Head over to the table: parser.Position = objectOffset + tableOffset; // Load it now: table.Load(parser); // Add to set: lookupTables[i] = table; // Restore position: parser.Position = seekPos; } // Goto feature list: objectOffset = featList + offset; parser.Position = objectOffset; // How many features? For now, "liga" is the main feature we're after here. int featureCount = parser.ReadUInt16(); for (int i = 0; i < featureCount; i++) { // Read the feature code: string feature = parser.ReadString(4); // Table offset: int featTable = parser.ReadUInt16(); switch (feature) { case "locl": case "liga": AddToFont(feature, parser, featTable + objectOffset, font, lookupTables); break; } } }
public static void Load(FontParser parser, int offset, FontFace font, out int hmMetricCount) { // Seek there: parser.Position = offset; // Version: parser.ReadVersion(); // Ascender: float ascender = (float)parser.ReadInt16() / font.UnitsPerEmF; // Descender: float descender = (float)parser.ReadInt16() / font.UnitsPerEmF; // Line gap: float lineGap = (float)parser.ReadInt16() / font.UnitsPerEmF; if (!Fonts.UseOS2Metrics || !parser.ReadOS2) { if (lineGap < 0f) { lineGap = -lineGap; } float halfGap = lineGap / 2f; font.Ascender = ascender + halfGap; font.Descender = halfGap - descender; font.LineGap = font.Ascender + font.Descender; } // Advance width max: font.MaxAdvanceWidth = (float)parser.ReadUInt16() / font.UnitsPerEmF; // Min left side bearing: font.MinLeftSideBearing = (float)parser.ReadInt16() / font.UnitsPerEmF; // Min right side bearing: font.MinRightSideBearing = (float)parser.ReadInt16() / font.UnitsPerEmF; // Max x extent: font.MaxXExtent = (float)parser.ReadInt16() / font.UnitsPerEmF; // Caret slope rise: float caretRise = (float)parser.ReadInt16(); // Caret slope run: float caretRun = (float)parser.ReadInt16(); font.CaretAngle = (float)Math.Atan2(caretRise, caretRun); // Caret offset: font.CaretOffset = (float)parser.ReadInt16() / font.UnitsPerEmF; // Skip: parser.Position += 8; // Metric format: parser.ReadInt16(); // Metric count: hmMetricCount = parser.ReadUInt16(); }
public static bool Load(FontParser parser, int offset, FontFace font, out int locFormatIndex) { // Seek there now: parser.Position = offset; // Version: parser.ReadVersion(); // Revision: parser.ReadRevision(); // Checksum adjustment: parser.ReadUInt32(); // Magic number: if (parser.ReadUInt32() != 0x5F0F3CF5) { locFormatIndex = 0; return(false); } // Flags: parser.ReadUInt16(); // Units per em: font.UnitsPerEm = parser.ReadUInt16(); font.UnitsPerEmF = (float)font.UnitsPerEm; // Skip created and modified: parser.ReadTime(); parser.ReadTime(); // X min: parser.ReadInt16(); // Y min: parser.ReadInt16(); // X max: parser.ReadInt16(); // Y max: parser.ReadInt16(); // Mac style: parser.ReadUInt16(); // Lowest Rec PPEM: parser.ReadUInt16(); // Font direction hint: parser.ReadInt16(); // Index for the loc format: locFormatIndex = parser.ReadInt16(); // 50 // Glyph data format: parser.ReadInt16(); 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; } }
public static void Load(FontParser parser,int offset,FontFace font){ // Seek there: parser.Position=offset; // Version: parser.ReadVersion(); // Script list (directed by UI Language setting): int scriptList=parser.ReadUInt16(); // Feature list: int featList=parser.ReadUInt16(); // Lookup list: int lookList=parser.ReadUInt16(); // Goto script list: int objectOffset=scriptList+offset; parser.Position=objectOffset; /* // How many language scripts? int scriptCount=parser.ReadUInt16(); for(int i=0;i<scriptCount;i++){ // Read the script code: string scrName=parser.ReadString(4); // And it's offset: int scriptOffset=parser.ReadUInt16()+objectOffset; int retPosition=parser.Position; // Seek and load it right away: parser.Position=scriptOffset; // What's the default lang? int defaultLangOffset=parser.ReadUInt16(); // How many languages? int langCount=parser.ReadUInt16(); for(int l=0;l<langCount;l++){ // Read the lang code: string langName=parser.ReadString(4); // And it's offset - points to list of features: int langOffset=parser.ReadUInt16()+objectOffset; } parser.Position=retPosition; } */ // Goto lookup list: objectOffset=lookList+offset; // Seek there: parser.Position=objectOffset; // Load each one: int lookCount=parser.ReadUInt16(); // Create: LigatureLookupTable[] lookupTables=new LigatureLookupTable[lookCount]; for(int i=0;i<lookCount;i++){ // Create the table: LigatureLookupTable table=new LigatureLookupTable(); // Load it: int tableOffset=parser.ReadUInt16(); // Cache the position: int seekPos=parser.Position; // Head over to the table: parser.Position=objectOffset+tableOffset; // Load it now: table.Load(parser); // Add to set: lookupTables[i]=table; // Restore position: parser.Position=seekPos; } // Goto feature list: objectOffset=featList+offset; parser.Position=objectOffset; // How many features? For now, "liga" is the main feature we're after here. int featureCount=parser.ReadUInt16(); for(int i=0;i<featureCount;i++){ // Read the feature code: string feature=parser.ReadString(4); // Table offset: int featTable=parser.ReadUInt16(); switch(feature){ case "locl": case "liga": AddToFont(feature,parser,featTable+objectOffset,font,lookupTables); break; } } }