//Checks the presence of the CFF table to decide whether the font file has or not PostScript outlines protected bool IsPostScript() { DirectoryEntry de_cff = GetDirectoryEntry("CFF "); Table_CFF cffTable = (Table_CFF)GetTable("CFF "); if (de_cff != null && cffTable != null) { return(true); } return(false); }
static int Main(string[] args) { verbose = 0; if (args.Length == 0) { Console.WriteLine("CFFInfo [-v] [-v] [-v] fontfile"); return(0); } OTFile f = new OTFile(); Table_CFF tCFF = null; string filename = null; verbose = 0; for (int i = 0; i < args.Length; i++) { if ("-v" == args[i]) { verbose++; } else { filename = args[i]; } } if (!f.open(filename)) { Console.WriteLine("Error: Cannot open {0} as font file", filename); return(0); } if (f.GetNumFonts() != 1) { Console.WriteLine("{0} contains {1} member fonts", filename, f.GetNumFonts()); } for (uint iFont = 0; iFont < f.GetNumFonts(); iFont++) { OTFont fn = f.GetFont(iFont); tCFF = (Table_CFF)fn.GetTable("CFF "); Console.WriteLine("{0} CFF table: {1}", filename, (tCFF == null) ? "Absent" : "Present"); if (tCFF == null) { continue; } /* header */ /* INDEX's */ Console.WriteLine("Name:\tcount={0}\tsize={1}", tCFF.Name.count, tCFF.Name.size); Console.WriteLine("TopDICT:\tcount={0}\tsize={1}", tCFF.TopDICT.count, tCFF.TopDICT.size); Console.WriteLine("String:\tcount={0}\tsize={1}", tCFF.String.count, tCFF.String.size); Console.WriteLine("GlobalSubr:\tcount={0}\tsize={1}", tCFF.GlobalSubr.count, tCFF.GlobalSubr.size); /* INDEX success */ var overlap = new DataOverlapDetector(); overlap.CheckForNoOverlap(0, tCFF.hdrSize); overlap.CheckForNoOverlap(tCFF.Name.begin, tCFF.Name.size); overlap.CheckForNoOverlap(tCFF.TopDICT.begin, tCFF.TopDICT.size); overlap.CheckForNoOverlap(tCFF.String.begin, tCFF.String.size); overlap.CheckForNoOverlap(tCFF.GlobalSubr.begin, tCFF.GlobalSubr.size); if (verbose > 1) { Console.WriteLine("Region-hdr :\t{0}\t{1}", 0, tCFF.hdrSize); Console.WriteLine("Region-Name :\t{0}\t{1}", tCFF.Name.begin, tCFF.Name.size); Console.WriteLine("Region-TopDICT :\t{0}\t{1}", tCFF.TopDICT.begin, tCFF.TopDICT.size); Console.WriteLine("Region-String :\t{0}\t{1}", tCFF.String.begin, tCFF.String.size); Console.WriteLine("Region-GlobalSubr :\t{0}\t{1}", tCFF.GlobalSubr.begin, tCFF.GlobalSubr.size); } for (uint i = 0; i < tCFF.Name.count; i++) { Console.WriteLine("Name: " + tCFF.Name.GetString(i)); } try{ for (uint i = 0; i < tCFF.String.count; i++) { var a = tCFF.String.GetString(i); if (verbose > 0) { Console.WriteLine("String #{0}: {1}", i, a); } } } catch (DecoderFallbackException) { for (uint i = 0; i < tCFF.String.count; i++) { var a = tCFF.String.GetUTFString(i); if (verbose > 0) { Console.WriteLine("String #{0}: {1}", i, a); } } } for (uint iDICT = 0; iDICT < tCFF.TopDICT.count; iDICT++) { var curTopDICT = tCFF.GetTopDICT(iDICT); Console.WriteLine("FullName in TopDICT: " + curTopDICT.FullName); overlap.CheckForNoOverlap((uint)curTopDICT.offsetPrivate, (uint)curTopDICT.sizePrivate); if (verbose > 1) { Console.WriteLine("Region-Private :\t{0}\t{1}", curTopDICT.offsetPrivate, curTopDICT.sizePrivate); } Console.WriteLine("Offset to Charset:\t" + curTopDICT.offsetCharset); Console.WriteLine("Offset to Encoding:\t" + curTopDICT.offsetEncoding); Table_CFF.DICTData topPrivateDict = null; try { topPrivateDict = tCFF.GetPrivate(curTopDICT); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Broken Private Dict:" + e.Message); } if (topPrivateDict != null && topPrivateDict.Subrs != 0) { var topPrivSubrs = tCFF.GetINDEX(curTopDICT.offsetPrivate + topPrivateDict.Subrs); overlap.CheckForNoOverlap(topPrivSubrs.begin, topPrivSubrs.size); if (verbose > 1) { Console.WriteLine("Region-PrivSubrs :\t{0}\t{1}", topPrivSubrs.begin, topPrivSubrs.size); } } var CharStrings = tCFF.GetINDEX(curTopDICT.offsetCharStrings); Console.WriteLine("CharStrings count: " + CharStrings.count); overlap.CheckForNoOverlap(CharStrings.begin, CharStrings.size); if (verbose > 1) { Console.WriteLine("Region-CharStrings:\t{0}\t{1}", CharStrings.begin, CharStrings.size); } if (curTopDICT.ROS != null) { Console.WriteLine("CID ROS: " + curTopDICT.ROS); Console.WriteLine("Offset to CID FDSelect:\t" + curTopDICT.offsetFDSelect); } if (curTopDICT.offsetFDArray > 0) { var FDArray = tCFF.GetINDEX(curTopDICT.offsetFDArray); overlap.CheckForNoOverlap(FDArray.begin, FDArray.size); if (verbose > 1) { Console.WriteLine("Region-FDArray :\t{0}\t{1}", FDArray.begin, FDArray.size); } for (uint i = 0; i < FDArray.count; i++) { var FDict = tCFF.GetDICT(FDArray.GetData(i)); Console.WriteLine("CID FontDict #{0}: {1}", i, FDict.FontName); overlap.CheckForNoOverlap((uint)FDict.offsetPrivate, (uint)FDict.sizePrivate); if (verbose > 1) { Console.WriteLine("Region-CID FontDict #{2} :\t{0}\t{1}", FDict.offsetPrivate, FDict.sizePrivate, i); } Table_CFF.DICTData FDictPrivate = null; try { FDictPrivate = tCFF.GetPrivate(FDict); } catch (ArgumentOutOfRangeException e) { Console.WriteLine("Broken CID FD Private Dict #{0}:{1}", i, e.Message); } if (FDictPrivate != null && FDictPrivate.Subrs != 0) { var PrivSubrs = tCFF.GetINDEX(FDict.offsetPrivate + FDictPrivate.Subrs); overlap.CheckForNoOverlap(PrivSubrs.begin, PrivSubrs.size); if (verbose > 1) { Console.WriteLine("Region-CID PrivSubrs #{2} :\t{0}\t{1}", PrivSubrs.begin, PrivSubrs.size, i); } } } } } Console.WriteLine("Tested region: {0} of {1}", overlap.Occupied, tCFF.GetLength()); if (overlap.ends != tCFF.GetLength()) { } } return(0); }
/************************ * public methods */ public bool Validate(Validator v, OTFontVal fontOwner) { bool bRet = true; if (v.PerformTest(T.maxp_TableVersion)) { uint val = TableVersionNumber.GetUint(); Table_CFF CFFTable = (Table_CFF)fontOwner.GetTable("CFF "); Table_glyf glyfTable = (Table_glyf)fontOwner.GetTable("glyf"); if (val == 0x00005000) { if (CFFTable != null && glyfTable == null) { v.Pass(T.maxp_TableVersion, P.maxp_P_VERSION_0_5, m_tag); } else if (CFFTable == null) { v.Error(T.maxp_TableVersion, E.maxp_E_VERSION_0_5_NOCFF, m_tag); bRet = false; } else if (glyfTable != null) { v.Error(T.maxp_TableVersion, E.maxp_E_VERSION_0_5_glyf, m_tag); bRet = false; } } else if (val == 0x00010000) { if (CFFTable == null && glyfTable != null) { v.Pass(T.maxp_TableVersion, P.maxp_P_VERSION_1_0, m_tag); } else if (glyfTable == null) { v.Error(T.maxp_TableVersion, E.maxp_E_VERSION_1_0_NOglyf, m_tag); bRet = false; } else if (CFFTable != null) { v.Error(T.maxp_TableVersion, E.maxp_E_VERSION_1_0_CFF, m_tag); bRet = false; } } else { v.Error(T.maxp_TableVersion, E.maxp_E_VERSION_INVALID, m_tag, "0x" + val.ToString("x8")); bRet = false; } } if (v.PerformTest(T.maxp_TableLength)) { uint val = TableVersionNumber.GetUint(); if (val == 0x00005000) { if (m_bufTable.GetLength() == 6) { v.Pass(T.maxp_TableLength, P.maxp_P_LENGTH_0_5, m_tag); } else { v.Error(T.maxp_TableLength, E.maxp_E_LENGTH_0_5, m_tag, m_bufTable.GetLength().ToString()); bRet = false; } } else if (val == 0x00010000) { if (m_bufTable.GetLength() == 32) { v.Pass(T.maxp_TableLength, P.maxp_P_LENGTH_1_0, m_tag); } else { v.Error(T.maxp_TableLength, E.maxp_E_LENGTH_1_0, m_tag, m_bufTable.GetLength().ToString()); bRet = false; } } } if (v.PerformTest(T.maxp_NumGlyphsMatchLoca)) { if (TableVersionNumber.GetUint() == 0x00010000) { Table_loca locaTable = (Table_loca)fontOwner.GetTable("loca"); if (locaTable != null) { // locaTable.NumEntry returns (-1) on failure if (locaTable.NumEntry(fontOwner) == NumGlyphs + 1) { v.Pass(T.maxp_NumGlyphsMatchLoca, P.maxp_P_NumGlyphsMatchLoca, m_tag, "numGlyphs = " + NumGlyphs); } else { v.Error(T.maxp_NumGlyphsMatchLoca, E.maxp_E_NumGlyphsMatchLoca, m_tag, "numGlyphs = " + NumGlyphs); bRet = false; } } else { v.Error(T.maxp_NumGlyphsMatchLoca, E._TEST_E_TableMissing, m_tag, "loca"); bRet = false; } } else { v.Info(T.maxp_NumGlyphsMatchLoca, I._TEST_I_TableVersion, m_tag, "test = maxp_NumGlyphsMatchLoca"); } } if (v.PerformTest(T.maxp_GlyphStats)) { if (TableVersionNumber.GetUint() == 0x00010000) { Table_glyf glyfTable = (Table_glyf)fontOwner.GetTable("glyf"); if (glyfTable == null) { v.Error(T.maxp_GlyphStats, E._TEST_E_TableMissing, m_tag, "glyf"); bRet = false; } else { bool bGlyphStatsOk = true; if (ComputeMaxpStats(glyfTable, fontOwner)) { if (maxPoints != maxPointsCalc) { String sDetails = "maxPoints = " + maxPoints + ", calculated = " + maxPointsCalc; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; bGlyphStatsOk = false; } if (maxContours != maxContoursCalc) { String sDetails = "maxContours = " + maxContours + ", calculated = " + maxContoursCalc; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; bGlyphStatsOk = false; } if (maxCompositePoints != maxCompositePointsCalc) { String sDetails = "maxCompositePoints = " + maxCompositePoints + ", calculated = " + maxCompositePointsCalc; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; bGlyphStatsOk = false; } if (maxCompositeContours != maxCompositeContoursCalc) { String sDetails = "maxCompositeContours = " + maxCompositeContours + ", calculated = " + maxCompositeContoursCalc; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; bGlyphStatsOk = false; } // Bug 2168. // Case 1: Same as max size from glyf table. Info. // Case 2: Same as max size from glyf table + // size(fpgm) + size(prep). Info message. // Case 3: Smaller than max size from glyf table. // Error // Case 4: Neither 1 nor 2. Warning. DirectoryEntry dePrep = fontOwner.GetDirectoryEntry("prep"); uint prepLength = 0; if (null != dePrep) { prepLength = dePrep.length; } DirectoryEntry deFpgm = fontOwner.GetDirectoryEntry("fpgm"); uint fpgmLength = 0; if (null != deFpgm) { fpgmLength = deFpgm.length; } if (maxSizeOfInstructions == maxSizeOfInstructionsCalc) { // Case 1: String sDetails = "maxSizeOfInstructions=" + maxSizeOfInstructions + ", computed " + "from the glyf table"; v.Info(T.maxp_GlyphStats, I.maxp_I_Calculation_Method1, m_tag, sDetails); } else if (maxSizeOfInstructions == (maxSizeOfInstructionsCalc + prepLength + fpgmLength)) { // Case 2: String sDetails = "maxp maxSizeOfInstructions is " + maxSizeOfInstructions + ", which is " + "glyf maxSizeOfInstructions (" + maxSizeOfInstructionsCalc + ") + prep size (" + prepLength + ") + fpgm size (" + fpgmLength + ")"; v.Info(T.maxp_GlyphStats, I.maxp_I_Calculation_Method2, m_tag, sDetails); } else if (maxSizeOfInstructions < maxSizeOfInstructionsCalc) { // Case 3 String sDetails = "maxp maxSizeOfInstructions is " + maxSizeOfInstructions + ", which is smaller than the " + "size of instuctions (" + maxSizeOfInstructionsCalc + ") found" + " for some glyph in the glyf table."; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; } else { // Case 4 String sDetails = "glyf maxSizeOfInstructions=" + maxSizeOfInstructionsCalc + ", prep size=" + prepLength + ", fpgm size=" + fpgmLength + ", whereas maxp maxSizeOfInstruction " + "is " + maxSizeOfInstructions; v.Warning(T.maxp_GlyphStats, W.maxp_W_Calculation_Unclear, m_tag, sDetails); bGlyphStatsOk = false; } if (maxComponentElements != maxComponentElementsCalc) { String sDetails = "maxComponentElements = " + maxComponentElements + ", calculated = " + maxComponentElementsCalc; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; bGlyphStatsOk = false; } if (maxComponentDepth != maxComponentDepthCalc) { String sDetails = "maxComponentDepth = " + maxComponentDepth + ", calculated = " + maxComponentDepthCalc; v.Error(T.maxp_GlyphStats, E.maxp_E_Calculation, m_tag, sDetails); bRet = false; bGlyphStatsOk = false; } if (bGlyphStatsOk) { v.Pass(T.maxp_GlyphStats, P.maxp_P_Calculation, m_tag); } } else { v.Warning(T.maxp_GlyphStats, W._TEST_W_ErrorInAnotherTable, m_tag, "Errors in the glyf table are preventing validation of maxPoints, maxContours, maxCompositePoints, maxCompositeContours, maxSizeofInstructions, maxComponentElements, and maxComponentDepth"); } } } else { v.Info(T.maxp_GlyphStats, I._TEST_I_TableVersion, m_tag, "test = maxp_GlyphStats"); } } return(bRet); }