private void GetCompositeGlyphStats(Table_glyf.CompositeGlyph cg, ref short nContours, ref ushort nPoints, ref ushort nInstructions, ref ushort nComponentElements, ref ushort nComponentDepth, OTFont fontOwner, Table_glyf glyfTable) { ushort nPointsTemp = 0; short nContoursTemp = 0; ushort nInstructionsTemp = 0; short TotalContours = 0; ushort TotalPoints = 0; ushort maxInstructions = 0; nComponentDepth++; int nCompositeGlyphs = 0; while (cg != null) { nCompositeGlyphs++; nInstructions = Math.Max(nInstructions, cg.GetNumInstructions()); Table_glyf.header glyfHeader = glyfTable.GetGlyphHeader(cg.glyphIndex, fontOwner); if (glyfHeader != null) { if (glyfHeader.numberOfContours >= 0) { nContoursTemp = glyfHeader.numberOfContours; Table_glyf.SimpleGlyph sg = glyfHeader.GetSimpleGlyph(); nPointsTemp = (ushort)(sg.GetEndPtOfContour((uint)glyfHeader.numberOfContours - 1) + 1); nInstructionsTemp = sg.instructionLength; } else { Table_glyf.CompositeGlyph EmbeddedCG = glyfHeader.GetCompositeGlyph(); GetCompositeGlyphStats(EmbeddedCG, ref nContoursTemp, ref nPointsTemp, ref nInstructionsTemp, ref nComponentElements, ref nComponentDepth, fontOwner, glyfTable); } TotalContours += nContoursTemp; TotalPoints += nPointsTemp; maxInstructions = Math.Max(maxInstructions, nInstructionsTemp); } cg = cg.GetNextCompositeGlyph(); } nComponentElements = (ushort)Math.Max(nComponentElements, nCompositeGlyphs); nContours = TotalContours; nPoints = TotalPoints; nInstructions = maxInstructions; }
private bool ComputeMaxpStats(Table_glyf glyfTable, OTFont fontOwner) { bool bRet = true; try { maxPointsCalc = 0; maxContoursCalc = 0; maxCompositePointsCalc = 0; maxCompositeContoursCalc = 0; maxSizeOfInstructionsCalc = 0; maxComponentElementsCalc = 0; maxComponentDepthCalc = 0; for (uint iGlyph = 0; iGlyph < NumGlyphs; iGlyph++) { Table_glyf.header glyfHeader = glyfTable.GetGlyphHeader(iGlyph, fontOwner); if (glyfHeader != null) { if (glyfHeader.numberOfContours >= 0) { Table_glyf.SimpleGlyph sg = glyfHeader.GetSimpleGlyph(); maxPointsCalc = (ushort)Math.Max(maxPointsCalc, sg.GetEndPtOfContour((uint)glyfHeader.numberOfContours - 1) + 1); maxContoursCalc = (ushort)Math.Max(maxContoursCalc, glyfHeader.numberOfContours); maxSizeOfInstructionsCalc = Math.Max(maxSizeOfInstructionsCalc, sg.instructionLength); } else { ushort nPointsTemp = 0; short nContoursTemp = 0; ushort nInstructionsTemp = 0; ushort nCompElementsTemp = 0; ushort nCompDepthTemp = 0; Table_glyf.CompositeGlyph cg = glyfHeader.GetCompositeGlyph(); GetCompositeGlyphStats(cg, ref nContoursTemp, ref nPointsTemp, ref nInstructionsTemp, ref nCompElementsTemp, ref nCompDepthTemp, fontOwner, glyfTable); maxCompositePointsCalc = Math.Max(maxCompositePointsCalc, nPointsTemp); maxCompositeContoursCalc = Math.Max(maxCompositeContoursCalc, nContoursTemp); maxSizeOfInstructionsCalc = Math.Max(maxSizeOfInstructionsCalc, nInstructionsTemp); maxComponentElementsCalc = Math.Max(maxComponentElementsCalc, nCompElementsTemp); maxComponentDepthCalc = Math.Max(maxComponentDepthCalc, nCompDepthTemp); } } } } catch { maxPointsCalc = 0; maxContoursCalc = 0; maxCompositePointsCalc = 0; maxCompositeContoursCalc = 0; maxSizeOfInstructionsCalc = 0; maxComponentElementsCalc = 0; maxComponentDepthCalc = 0; bRet = false; } return(bRet); }