From d0862e25eb28c07981c15e610aaa24e632079d3b Mon Sep 17 00:00:00 2001 From: be5invis Date: Sat, 27 Feb 2021 21:10:44 -0800 Subject: [PATCH] re-enable complexity measurement --- font-src/gen/finalize/glyphs.js | 9 --------- font-src/glyphs/index.ptl | 3 +-- font-src/support/geometry.js | 28 +++++++++++++++++++++++++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/font-src/gen/finalize/glyphs.js b/font-src/gen/finalize/glyphs.js index b24ee38d5..c48669360 100644 --- a/font-src/gen/finalize/glyphs.js +++ b/font-src/gen/finalize/glyphs.js @@ -7,7 +7,6 @@ const util = require("util"); module.exports = finalizeGlyphs; function finalizeGlyphs(para, glyphStore) { - suppressNaN(glyphStore); const skew = Math.tan(((para.slopeAngle || 0) / 180) * Math.PI); regulateGlyphStore(skew, glyphStore); return glyphStore; @@ -15,14 +14,6 @@ function finalizeGlyphs(para, glyphStore) { /////////////////////////////////////////////////////////////////////////////////////////////////// -function suppressNaN(glyphStore) { - for (const g of glyphStore.glyphs()) { - // if (g.geometry) g.geometry.suppressNaN(); - } -} - -/////////////////////////////////////////////////////////////////////////////////////////////////// - function regulateGlyphStore(skew, glyphStore) { for (const g of glyphStore.glyphs()) { if (g.geometry.isEmpty()) continue; diff --git a/font-src/glyphs/index.ptl b/font-src/glyphs/index.ptl index 51eb27cc3..6cbd80fde 100644 --- a/font-src/glyphs/index.ptl +++ b/font-src/glyphs/index.ptl @@ -83,8 +83,7 @@ export all : define [buildGlyphs para recursive recursiveCodes] : begin return glyphObject define [warnAboutBrokenGlyph g ensuredGlyphName saveGlyphName] : begin - local complexity 0 - # if g.geometry : set complexity : g.geometry.suppressNaN + local complexity : g.geometry.measureComplexity if ([not recursive] && complexity > 4096) : begin console.log 'Possible broken shape found in' ensuredGlyphName 'Complexity' complexity diff --git a/font-src/support/geometry.js b/font-src/support/geometry.js index 9e25b9e29..f01a9f17e 100644 --- a/font-src/support/geometry.js +++ b/font-src/support/geometry.js @@ -16,12 +16,18 @@ class GeometryBase { isEmpty() { return true; } + measureComplexity() { + return 0; + } } class ContourGeometry extends GeometryBase { constructor(points) { super(); - this.m_points = points; + this.m_points = []; + for (const z of points) { + this.m_points.push(Point.from(z.type, z)); + } } asContours() { if (this.isEmpty()) return []; @@ -36,6 +42,9 @@ class ContourGeometry extends GeometryBase { isEmpty() { return !this.m_points.length; } + measureComplexity() { + return this.m_points.length; + } } class ReferenceGeometry extends GeometryBase { @@ -43,8 +52,8 @@ class ReferenceGeometry extends GeometryBase { super(); if (!glyph || !glyph.geometry) throw new TypeError("Invalid glyph"); this.m_glyph = glyph; - this.m_x = x; - this.m_y = y; + this.m_x = x || 0; + this.m_y = y || 0; } unwrap() { return new TransformedGeometry( @@ -68,6 +77,9 @@ class ReferenceGeometry extends GeometryBase { if (!this.m_glyph || !this.m_glyph.geometry) return true; return this.m_glyph.geometry.isEmpty(); } + measureComplexity() { + return this.m_glyph.geometry.measureComplexity(); + } } class TaggedGeometry extends GeometryBase { @@ -89,6 +101,9 @@ class TaggedGeometry extends GeometryBase { isEmpty() { return this.m_geom.isEmpty(); } + measureComplexity() { + return this.m_geom.measureComplexity(); + } } class TransformedGeometry extends GeometryBase { @@ -122,6 +137,9 @@ class TransformedGeometry extends GeometryBase { isEmpty() { return this.m_geom.isEmpty(); } + measureComplexity() { + return this.m_geom.measureComplexity(); + } } class CombineGeometry extends GeometryBase { @@ -168,6 +186,10 @@ class CombineGeometry extends GeometryBase { for (const part of this.m_parts) if (!part.isEmpty()) return false; return true; } + measureComplexity() { + let s = 0; + for (const part of this.m_parts) s += part.measureComplexity(); + } } function combineWith(a, b) {