From fdff7dbb60e13b4a8ed651a6563eef3c7fea6ec6 Mon Sep 17 00:00:00 2001 From: be5invis Date: Tue, 2 Feb 2021 01:56:43 -0800 Subject: [PATCH] Add apparent translate mechanism to improve component sharing --- font-src/glyphs/common/shapes.ptl | 9 +- .../letter/latin-ext/bidental-percussive.ptl | 4 +- font-src/glyphs/letter/latin/lower-d.ptl | 5 +- font-src/glyphs/letter/latin/lower-h.ptl | 12 +- font-src/glyphs/letter/latin/lower-l.ptl | 4 +- font-src/glyphs/letter/latin/lower-q.ptl | 8 +- font-src/glyphs/letter/latin/lower-r.ptl | 8 +- font-src/glyphs/letter/latin/s.ptl | 4 +- font-src/glyphs/letter/latin/upper-l.ptl | 4 +- font-src/glyphs/letter/latin/w.ptl | 4 +- font-src/glyphs/letter/shared.ptl | 4 +- font-src/glyphs/marks/index.ptl | 36 +-- font-src/glyphs/symbol/math/arith.ptl | 4 +- font-src/glyphs/symbol/math/relation.ptl | 28 +-- font-src/glyphs/symbol/punctuation.ptl | 10 +- font-src/meta/aesthetics.ptl | 7 +- font-src/meta/macros.ptl | 2 +- font-src/support/glyph.js | 226 +++++++++--------- 18 files changed, 154 insertions(+), 225 deletions(-) diff --git a/font-src/glyphs/common/shapes.ptl b/font-src/glyphs/common/shapes.ptl index 3174a6201..81b08da48 100644 --- a/font-src/glyphs/common/shapes.ptl +++ b/font-src/glyphs/common/shapes.ptl @@ -607,14 +607,9 @@ glyph-block CommonShapes : begin include : Italify define ScaleAround FlipAround - define [Realign x y sx sy] : glyph-proc - include : Upright - include : Translate (-x) (-y) - include : Translate sx sy - include : Italify + define [Realign x y sx sy] : ApparentTranslate (sx - x) (sy - y) - define [ForceUpright] : glyph-proc - set this.gizmo : Translate 0 0 + define [ForceUpright] : glyph-proc [set this.gizmo : Translate 0 0] define [CreateWaveShape dist sw _phaesShift] : begin define WaveResolution 64 diff --git a/font-src/glyphs/letter/latin-ext/bidental-percussive.ptl b/font-src/glyphs/letter/latin-ext/bidental-percussive.ptl index ad6c2a2d1..865c5321a 100644 --- a/font-src/glyphs/letter/latin-ext/bidental-percussive.ptl +++ b/font-src/glyphs/letter/latin-ext/bidental-percussive.ptl @@ -16,7 +16,5 @@ glyph-block Letter-Latin-Bidental-Percussive : begin include : VBarLeft SB (CAP * 0.1) (CAP * 0.4) include : VBarRight RightSB (CAP * 0.1) (CAP * 0.4) include g - include : Upright - include : Translate 0 (CAP / 2) - include : Italify + include : ApparentTranslate 0 (CAP / 2) include g diff --git a/font-src/glyphs/letter/latin/lower-d.ptl b/font-src/glyphs/letter/latin/lower-d.ptl index dcc06c697..22496a320 100644 --- a/font-src/glyphs/letter/latin/lower-d.ptl +++ b/font-src/glyphs/letter/latin/lower-d.ptl @@ -107,10 +107,7 @@ glyph-block Letter-Latin-Lower-D : begin create-glyph 'dhooktop.tailed' : glyph-proc include : MarkSet.b include : OBarRightShape - include : dispiro - flat RightSB yDHookTopConnect [widths.rhs.heading Stroke Downward] - curl RightSB (Hook * 0.5 + Stroke + O * 2) - g4 (RightSB + Hook * 0.25) (Stroke * 0.75 + O * 2) + include : RightwardTailedBar RightSB 0 yDHookTopConnect include : VerticalHook (RightSB - HalfStroke * HVContrast) yDHookTopConnect HookX (-Hook) if SLAB : include : tagged 'serifRB' : RightwardBottomSerif RightSB 0 SideJut diff --git a/font-src/glyphs/letter/latin/lower-h.ptl b/font-src/glyphs/letter/latin/lower-h.ptl index 5ebd6fef3..239c6a1d3 100644 --- a/font-src/glyphs/letter/latin/lower-h.ptl +++ b/font-src/glyphs/letter/latin/lower-h.ptl @@ -119,9 +119,7 @@ glyph-block Letter-Latin-Lower-H : begin include : VBarLeft SB 0 CAP include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate RightSB (Hook + HalfStroke) - include : Italify + include : ApparentTranslate RightSB (Hook + HalfStroke) include : FlipAround Middle (XH / 2) include : MarkSet.p if SLAB : begin @@ -136,15 +134,11 @@ glyph-block Letter-Latin-Lower-H : begin include : VBarLeft SB 0 (XH - 1) include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate RightSB (Hook + HalfStroke) - include : Italify + include : ApparentTranslate RightSB (Hook + HalfStroke) include : FlipAround Middle (XH / 2) include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate RightSB 0 - include : Italify + include : ApparentTranslate RightSB 0 include : MarkSet.p if SLAB : begin include : LeftwardTopSerif (RightSB - Stroke * HVContrast) XH SideJut diff --git a/font-src/glyphs/letter/latin/lower-l.ptl b/font-src/glyphs/letter/latin/lower-l.ptl index 1f75ee7fe..3fb77b6d3 100644 --- a/font-src/glyphs/letter/latin/lower-l.ptl +++ b/font-src/glyphs/letter/latin/lower-l.ptl @@ -209,9 +209,7 @@ glyph-block Letter-Latin-Lower-L : begin include [refer-glyph 'l.serifed'] AS_BASE ALSO_METRICS include : new-glyph : glyph-proc include : refer-glyph "tildeAboveOverlay" - include : Upright - include : Translate (df.middle - markMiddle) (CAP * 0.525 - [mix aboveMarkBot aboveMarkTop 0.5]) - include : Italify + include : ApparentTranslate (df.middle - markMiddle) (CAP * 0.525 - [mix aboveMarkBot aboveMarkTop 0.5]) define [Belt middle] : glyph-proc local fine : AdviceStroke 4.5 diff --git a/font-src/glyphs/letter/latin/lower-q.ptl b/font-src/glyphs/letter/latin/lower-q.ptl index 6522b0c82..4cde68140 100644 --- a/font-src/glyphs/letter/latin/lower-q.ptl +++ b/font-src/glyphs/letter/latin/lower-q.ptl @@ -135,9 +135,7 @@ glyph-block Letter-Latin-Lower-Q : begin include : VBarRight RightSB 0 CAP include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate RightSB 0 - include : Italify + include : ApparentTranslate RightSB 0 if SLAB : begin include : tagged 'serifRT' : RightwardTopSerif RightSB CAP SideJut @@ -147,9 +145,7 @@ glyph-block Letter-Latin-Lower-Q : begin include : VBarRight RightSB 0 XH include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate RightSB 0 - include : Italify + include : ApparentTranslate RightSB 0 if SLAB : begin include : tagged 'serifRT' : RightwardTopSerif RightSB XH SideJut diff --git a/font-src/glyphs/letter/latin/lower-r.ptl b/font-src/glyphs/letter/latin/lower-r.ptl index c7d8a31e2..8e9ac8be4 100644 --- a/font-src/glyphs/letter/latin/lower-r.ptl +++ b/font-src/glyphs/letter/latin/lower-r.ptl @@ -211,9 +211,7 @@ glyph-block Letter-Latin-Lower-R : begin eject-contour 'serifLB' include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate rbar 0 - include : Italify + include : ApparentTranslate rbar 0 create-glyph 'rrtail.serifless' SmallRRTailShape StandardLowerRShape dfN rStraight 0 create-glyph 'rrtail.topSerifed' @@ -242,9 +240,7 @@ glyph-block Letter-Latin-Lower-R : begin include : FlipAround df.middle (XH / 2) include : new-glyph : glyph-proc include : refer-glyph "rtailBR" - include : Upright - include : Translate (df.rightSB - rbar + df.leftSB + Stroke * HVContrast) 0 - include : Italify + include : ApparentTranslate (df.rightSB - rbar + df.leftSB + Stroke * HVContrast) 0 create-glyph 'turnrrtail.serifless' TurnRRTailShape StandardLowerRShape dfN rStraight 0 diff --git a/font-src/glyphs/letter/latin/s.ptl b/font-src/glyphs/letter/latin/s.ptl index cac9b3905..2126d75a4 100644 --- a/font-src/glyphs/letter/latin/s.ptl +++ b/font-src/glyphs/letter/latin/s.ptl @@ -250,9 +250,7 @@ glyph-block Letter-Latin-S : begin include : new-glyph : glyph-proc local sw : AdviceStroke2 2 3 XH include : refer-glyph "rtailBR" - include : Upright - include : Translate (start.x + sw * HVContrast) 0 - include : Italify + include : ApparentTranslate (start.x + sw * HVContrast) 0 include : VBarLeft start.x 0 start.y diff --git a/font-src/glyphs/letter/latin/upper-l.ptl b/font-src/glyphs/letter/latin/upper-l.ptl index 83d2b2c17..8c28eb090 100644 --- a/font-src/glyphs/letter/latin/upper-l.ptl +++ b/font-src/glyphs/letter/latin/upper-l.ptl @@ -67,9 +67,7 @@ glyph-block Letter-Latin-Upper-L : begin include [refer-glyph src] AS_BASE ALSO_METRICS include : new-glyph : glyph-proc include : refer-glyph "tildeAboveOverlay" - include : Upright - include : Translate (SB * 1.5 + Stroke * HVContrast / 2 - markMiddle) (CAP * 0.525 - [mix aboveMarkBot aboveMarkTop 0.5]) - include : Italify + include : ApparentTranslate (SB * 1.5 + Stroke * HVContrast / 2 - markMiddle) (CAP * 0.525 - [mix aboveMarkBot aboveMarkTop 0.5]) with-related-glyphs 'Ldot' 0x13F 'L' : lambda [src sel] : glyph-proc include [refer-glyph src] AS_BASE diff --git a/font-src/glyphs/letter/latin/w.ptl b/font-src/glyphs/letter/latin/w.ptl index cbb3bf6c5..0fbc03e35 100644 --- a/font-src/glyphs/letter/latin/w.ptl +++ b/font-src/glyphs/letter/latin/w.ptl @@ -195,9 +195,7 @@ glyph-block Letter-Latin-W : begin set-width df.width include : df.markSet.capital include : WshapeImpl df (CAP / 2) bodyType slabType - include : Upright - include : Translate 0 (CAP / 2) - include : Italify + include : ApparentTranslate 0 (CAP / 2) include : WshapeImpl df (CAP / 2) bodyType slabType define [WHooktopShape df top bodyType] : glyph-proc diff --git a/font-src/glyphs/letter/shared.ptl b/font-src/glyphs/letter/shared.ptl index 21a305d6c..4fffaffd1 100644 --- a/font-src/glyphs/letter/shared.ptl +++ b/font-src/glyphs/letter/shared.ptl @@ -25,9 +25,7 @@ glyph-block Letter-Shared : begin define srcGlyph : query-glyph src define commaOffset : (Width / 2) * [Math.pow (srcGlyph.advanceWidth / Width * 2) (2/3)] include : refer-glyph "commaTR" - include : Upright - include : Translate commaOffset 0 - include : Italify + include : ApparentTranslate commaOffset 0 include srcGlyph AS_BASE ALSO_METRICS glyph-block Letter-Blackboard : begin diff --git a/font-src/glyphs/marks/index.ptl b/font-src/glyphs/marks/index.ptl index eef8c97fc..e2c9d8bfb 100644 --- a/font-src/glyphs/marks/index.ptl +++ b/font-src/glyphs/marks/index.ptl @@ -69,9 +69,7 @@ glyph-block Marks : begin include : difference DotAt markMiddle (XH + Accent) radiusOut DotAt markMiddle (XH + Accent) radiusIn - include : Upright - include : Translate 0 (-markFine * 0.75) - include : Italify + include : ApparentTranslate 0 (-markFine * 0.75) create-glyph 'dblRingAbove' 0x1AB2 : glyph-proc set-width 0 @@ -314,14 +312,10 @@ glyph-block Marks : begin local shift : (ttop - tbot) * 1.2 include : addTilde - include : Upright - include : Translate 0 shift - include : Italify + include : ApparentTranslate 0 shift include : addTilde - include : Upright - include : Translate 0 (-0.5 * shift) - include : Italify + include : ApparentTranslate 0 (-0.5 * shift) create-glyph 'macronAbove' 0x304 : glyph-proc set-width 0 @@ -468,9 +462,7 @@ glyph-block Marks : begin straight.down.start (markMiddle + radius) (aboveMarkTop - radius + commaOvershoot) quadcontrols 0 0.6 g4 [mix markMiddle (markMiddle - radius) 0.2] (aboveMarkBot - radius - commaOvershoot2) - include : Upright - include : Translate 0 (DotRadius * 0.3) - include : Italify + include : ApparentTranslate 0 (DotRadius * 0.3) create-glyph 'turnCommaAbove' 0x312 : glyph-proc set-width 0 @@ -493,9 +485,7 @@ glyph-block Marks : begin straight.down.start (markMiddle - radius) (aboveMarkTop - radius + commaOvershoot) quadcontrols 0 0.6 g4 [mix markMiddle (markMiddle + radius) 0.2] (aboveMarkBot - radius - commaOvershoot2) - include : Upright - include : Translate 0 (DotRadius * 0.3) - include : Italify + include : ApparentTranslate 0 (DotRadius * 0.3) create-glyph 'barAbove' 0x30D : glyph-proc set-width 0 @@ -552,9 +542,7 @@ glyph-block Marks : begin archv g4.up.end (markMiddle + radius) yc [heading Upward] include : DotAt markMiddle (XH + Accent) fine - include : Upright - include : Translate 0 (fine * 0.5) - include : Italify + include : ApparentTranslate 0 (fine * 0.5) set-mark-anchor 'above' markMiddle XH markMiddle aboveMarkTop set-base-anchor 'aboveBrace' markMiddle (XH + Accent) @@ -1095,17 +1083,13 @@ glyph-block Marks : begin create-glyph 'dotTR' 0x358 : glyph-proc set-width 0 include : refer-glyph "dotAbove" - include : Upright - include : Translate (RightSB - Middle + DotRadius) 0 - include : Italify + include : ApparentTranslate (RightSB - Middle + DotRadius) 0 set-mark-anchor 'topright' 0 XH 0 aboveMarkTop create-glyph 'commaTR' 0x315 : glyph-proc set-width 0 include : refer-glyph "commaAbove" - include : Upright - include : Translate (RightSB - Middle + DotRadius) 0 - include : Italify + include : ApparentTranslate (RightSB - Middle + DotRadius) 0 set-mark-anchor 'topright' 0 XH 0 aboveMarkTop create-glyph 'rtailBR' 0x322 : glyph-proc @@ -1135,9 +1119,7 @@ glyph-block Marks : begin set-width 0 set-mark-anchor 'overlay' markMiddle (XH / 2) markMiddle (XH / 2) include : refer-glyph "tildeAbove" - include : Upright - include : Translate 0 (XH / 2 - [mix aboveMarkTop aboveMarkBot 0.5]) - include : Italify + include : ApparentTranslate 0 (XH / 2 - [mix aboveMarkTop aboveMarkBot 0.5]) create-glyph 'barOver' 0x335 : glyph-proc set-width 0 diff --git a/font-src/glyphs/symbol/math/arith.ptl b/font-src/glyphs/symbol/math/arith.ptl index 3f4ebf6ed..b69a8b14c 100644 --- a/font-src/glyphs/symbol/math/arith.ptl +++ b/font-src/glyphs/symbol/math/arith.ptl @@ -43,9 +43,7 @@ glyph-block Symbol-Math-Arith : begin local sbSquash 0.5 local delta : Math.max 0 : Width / 2 - DotRadius - SB * sbSquash - include : Upright - include : Translate (+delta) (SymbolMid - XH / 2) - include : Italify + include : ApparentTranslate (+delta) (SymbolMid - XH / 2) include : HBar (SB * sbSquash) (RightSB - DotSize) SymbolMid OperatorStroke diff --git a/font-src/glyphs/symbol/math/relation.ptl b/font-src/glyphs/symbol/math/relation.ptl index 6bca6865d..6d482120c 100644 --- a/font-src/glyphs/symbol/math/relation.ptl +++ b/font-src/glyphs/symbol/math/relation.ptl @@ -108,9 +108,7 @@ glyph-block Symbol-Math-Relation : begin include : refer-glyph "xhDot" local delta : Math.max 0 : Width / 2 - DotRadius - SB * ColonEqSbSquash - include : Upright - include : Translate (+delta) (SymbolMid - XH / 2) - include : Italify + include : ApparentTranslate (+delta) (SymbolMid - XH / 2) include : EqualShape (SB * ColonEqSbSquash) (RightSB - DotSize) @@ -119,9 +117,7 @@ glyph-block Symbol-Math-Relation : begin include : refer-glyph "xhDot" local delta : Math.max 0 : Width / 2 - DotRadius - SB * ColonEqSbSquash - include : Upright - include : Translate (-delta) (SymbolMid - XH / 2) - include : Italify + include : ApparentTranslate (-delta) (SymbolMid - XH / 2) create-glyph 'colonEq' 0x2254 : glyph-proc include : ColonEqColonShape @@ -467,24 +463,18 @@ glyph-block Symbol-Math-Relation : begin create-glyph 'barSym' 0x2242 : glyph-proc include [refer-glyph 'sym'] AS_BASE - include : Upright - include : Translate 0 (-approxDist / 2) - include : Italify + include : ApparentTranslate 0 (-approxDist / 2) include : HBar SB RightSB (SymbolMid + approxDist / 2) OperatorStroke create-glyph 'symEq' 0x2243 : glyph-proc include [refer-glyph 'sym'] AS_BASE - include : Upright - include : Translate 0 (approxDist / 2) - include : Italify + include : ApparentTranslate 0 (approxDist / 2) include : HBar SB RightSB (SymbolMid - approxDist / 2) OperatorStroke create-glyph 'symEqEq' 0x2245 : glyph-proc local sympShift : approxDist + EqualHalfSpace * 1.5 include [refer-glyph 'sym'] AS_BASE - include : Upright - include : Translate 0 (sympShift / 2) - include : Italify + include : ApparentTranslate 0 (sympShift / 2) include : HBar SB RightSB (SymbolMid - sympShift / 2 + EqualHalfSpace * 1.5) OperatorStroke include : HBar SB RightSB (SymbolMid - sympShift / 2) OperatorStroke @@ -494,17 +484,13 @@ glyph-block Symbol-Math-Relation : begin create-glyph 'flipSymEq' 0x22CD : glyph-proc include [refer-glyph 'flipSym'] AS_BASE - include : Upright - include : Translate 0 (approxDist / 2) - include : Italify + include : ApparentTranslate 0 (approxDist / 2) include : HBar SB RightSB (SymbolMid - approxDist / 2) OperatorStroke create-glyph 'flipSymEqEq' 0x224C : glyph-proc local sympShift : approxDist + EqualHalfSpace * 1.5 include [refer-glyph 'flipSym'] AS_BASE - include : Upright - include : Translate 0 (sympShift / 2) - include : Italify + include : ApparentTranslate 0 (sympShift / 2) include : HBar SB RightSB (SymbolMid - sympShift / 2 + EqualHalfSpace * 1.5) OperatorStroke include : HBar SB RightSB (SymbolMid - sympShift / 2) OperatorStroke diff --git a/font-src/glyphs/symbol/punctuation.ptl b/font-src/glyphs/symbol/punctuation.ptl index e23d7b5ac..8d7513f98 100644 --- a/font-src/glyphs/symbol/punctuation.ptl +++ b/font-src/glyphs/symbol/punctuation.ptl @@ -376,9 +376,7 @@ glyph-block Symbol-Punctuation-Small : begin include : refer-glyph "xhPeriod" create-derived 'colon.mid' : glyph-proc - include : Upright - include : Translate 0 (SymbolMid - XH / 2) - include : Italify + include : ApparentTranslate 0 (SymbolMid - XH / 2) create-glyph 'hollowColon' 0x2982 : glyph-proc define sw : AdviceStroke 5 @@ -1417,10 +1415,8 @@ glyph-block Symbol-Punctuation-Ellipsis : begin include : DotAt (MosaicWidth / 2) radius (radius - O) include : DotAt right radius (radius - O) - create-derived [MangleName 'mathCDots'] [MangleUnicode 0x22EF] : glyph-proc - include : Upright - include : Translate 0 (SymbolMid - radius) - include : Italify + create-derived [MangleName 'mathCDots'] [MangleUnicode 0x22EF] + ApparentTranslate 0 (SymbolMid - radius) create-glyph : glyph-proc set-width MosaicWidth diff --git a/font-src/meta/aesthetics.ptl b/font-src/meta/aesthetics.ptl index 20974c9b6..e67eac92c 100644 --- a/font-src/meta/aesthetics.ptl +++ b/font-src/meta/aesthetics.ptl @@ -39,6 +39,7 @@ export : define [calculateMetrics para] : begin define [Upright angle shift] [Italify angle shift :.inverse] define [Scale sx sy] : new Transform sx 0 0 [fallback sy sx] 0 0 define [Translate x y] : new Transform 1 0 0 1 x y + define [ApparentTranslate x y] : Translate (x + TanSlope * y) y define [Rotate angle] : new Transform [Math.cos angle] (-[Math.sin angle]) [Math.sin angle] [Math.cos angle] 0 0 define GlobalTransform : Italify para.slopeAngle @@ -195,9 +196,9 @@ export : define [calculateMetrics para] : begin return [object UPM HalfUPM Width SB CAP XH Descender Contrast SymbolMid ParenTop ParenBot OperTop OperBot TackTop TackBot PlusTop PlusBot PictTop PictBot BgOpTop BgOpBot Italify Upright Scale - Translate Rotate GlobalTransform TanSlope HVContrast Upward Downward Rightward Leftward - UpwardT DownwardT LeftwardT RightwardT O OX OXHook Hook AHook SHook RHook JHook FHook HookX - Smooth SmallSmooth Stroke DotSize PeriodSize HBarPos OverlayPos + Translate ApparentTranslate Rotate GlobalTransform TanSlope HVContrast Upward Downward + Rightward Leftward UpwardT DownwardT LeftwardT RightwardT O OX OXHook Hook AHook SHook RHook + JHook FHook HookX Smooth SmallSmooth Stroke DotSize PeriodSize HBarPos OverlayPos LongJut Jut VJut Accent AccentX CThin CThinB SLAB TailAdjX TailAdjY LBalance IBalance LBalance2 IBalance2 JBalance JBalance2 TBalance TBalance2 RBalance RBalance2 FBalance OneBalance WideWidth0 WideWidth1 WideWidth2 WideWidth3 WideWidth4 Ess EssQuestion diff --git a/font-src/meta/macros.ptl b/font-src/meta/macros.ptl index 83db1cec3..72c536315 100644 --- a/font-src/meta/macros.ptl +++ b/font-src/meta/macros.ptl @@ -205,7 +205,7 @@ define-macro glyph-block : syntax-rules buildGlyphs tagged DivFrame fontMetrics $assignUnicodeImpl$] define metricImports `[UPM HalfUPM Width SB CAP XH Descender Contrast SymbolMid ParenTop ParenBot OperTop OperBot TackTop TackBot PlusTop PlusBot PictTop PictBot BgOpTop BgOpBot - Italify Upright Scale Translate Rotate GlobalTransform TanSlope + Italify Upright Scale Translate ApparentTranslate Rotate GlobalTransform TanSlope HVContrast Upward Downward Rightward Leftward UpwardT DownwardT LeftwardT RightwardT O OX OXHook Hook AHook SHook RHook JHook FHook HookX Smooth SmallSmooth Stroke DotSize PeriodSize HBarPos OverlayPos LongJut Jut VJut diff --git a/font-src/support/glyph.js b/font-src/support/glyph.js index 8fffa5c22..7cf434f12 100644 --- a/font-src/support/glyph.js +++ b/font-src/support/glyph.js @@ -4,102 +4,6 @@ const Transform = require("./transform"); const Point = require("./point"); const Anchor = require("./anchor"); -class GeometryStore { - constructor() { - this.m_contours = []; - this.m_references = []; - } - - addContour(c) { - this.m_contours.push(c); - } - addReference(glyph, x, y) { - this.m_references.push({ glyph, x, y }); - } - asContours() { - let result = []; - for (const c of this.m_contours) { - const c1 = [...c]; - if (c.tag) c1.tag = c.tag; - result.push(c1); - } - for (const r of this.m_references) { - for (const c of r.glyph.geometry.asContours()) { - let c1 = []; - for (const z of c) c1.push(Point.fromXY(z.type, z.x + r.x, z.y + r.y)); - if (c.tag) c1.tag = c.tag; - result.push(c1); - } - } - return result; - } - asReferences() { - if (this.m_contours && this.m_contours.length) return null; - if (!this.m_references.length) return null; - return this.m_references; - } - - applyTranslate(shiftX, shiftY) { - for (const c of this.m_contours) { - for (let k = 0; k < c.length; k++) { - c[k] = Point.translated(c[k], shiftX, shiftY); - } - } - for (const r of this.m_references) { - r.x += shiftX; - r.y += shiftY; - } - } - applyTransform(tfm) { - const cs = this.asContours(); - for (const c of cs) { - for (let k = 0; k < c.length; k++) { - c[k] = Point.transformed(tfm, c[k]); - } - } - this.m_contours = cs; - this.m_references.length = 0; - } - - reTagContour(oldTag, newTag) { - for (const c of this.m_contours) { - if (c.tag === oldTag) c.tag = newTag; - } - } - ejectContour(tag) { - const cs = this.asContours(); - let i = 0, - j = 0; - for (; i < cs.length; i++) if (!cs[i].tag || cs[i].tag !== tag) cs[j++] = cs[i]; - cs.length = j; - this.m_contours = cs; - this.m_references = []; - } - - suppressNaN() { - let broken = false, - complexity = 0; - for (const c of this.m_contours) { - for (const z of c) { - complexity++; - if (!isFinite(z.x)) { - broken = true; - z.x = 0; - } - if (!isFinite(z.y)) { - broken = true; - z.y = 0; - } - } - } - return broken ? 0xffff : complexity; - } - - isEmpty() { - return !this.m_contours.length && !this.m_references.length; - } -} - module.exports = class Glyph { constructor(_identifier) { this._m_identifier = _identifier; @@ -216,23 +120,6 @@ module.exports = class Glyph { } } - combineAnchor(shift, baseThis, markThat, basesThat) { - if (!baseThis || !markThat) return; - shift.x = baseThis.x - markThat.x; - shift.y = baseThis.y - markThat.y; - if (basesThat) { - for (const bk in basesThat) { - this.baseAnchors[bk] = new Anchor( - shift.x + basesThat[bk].x, - shift.y + basesThat[bk].y - ); - } - } - } - copyAnchors(g) { - if (g.markAnchors) for (const k in g.markAnchors) this.markAnchors[k] = g.markAnchors[k]; - if (g.baseAnchors) for (const k in g.baseAnchors) this.baseAnchors[k] = g.baseAnchors[k]; - } applyTransform(tfm, alsoAnchors) { if (Transform.isTranslate(tfm)) { this.geometry.applyTranslate(tfm.x, tfm.y); @@ -275,6 +162,23 @@ module.exports = class Glyph { } // Anchors + combineAnchor(shift, baseThis, markThat, basesThat) { + if (!baseThis || !markThat) return; + shift.x = baseThis.x - markThat.x; + shift.y = baseThis.y - markThat.y; + if (basesThat) { + for (const bk in basesThat) { + this.baseAnchors[bk] = new Anchor( + shift.x + basesThat[bk].x, + shift.y + basesThat[bk].y + ); + } + } + } + copyAnchors(g) { + if (g.markAnchors) for (const k in g.markAnchors) this.markAnchors[k] = g.markAnchors[k]; + if (g.baseAnchors) for (const k in g.baseAnchors) this.baseAnchors[k] = g.baseAnchors[k]; + } setBaseAnchor(id, x, y) { this.baseAnchors[id] = new Anchor(x, y).transform(this.gizmo); } @@ -291,3 +195,99 @@ module.exports = class Glyph { delete this.markAnchors[id]; } }; + +class GeometryStore { + constructor() { + this.m_contours = []; + this.m_references = []; + } + + addContour(c) { + this.m_contours.push(c); + } + addReference(glyph, x, y) { + this.m_references.push({ glyph, x, y }); + } + asContours() { + let result = []; + for (const c of this.m_contours) { + const c1 = [...c]; + if (c.tag) c1.tag = c.tag; + result.push(c1); + } + for (const r of this.m_references) { + for (const c of r.glyph.geometry.asContours()) { + let c1 = []; + for (const z of c) c1.push(Point.fromXY(z.type, z.x + r.x, z.y + r.y)); + if (c.tag) c1.tag = c.tag; + result.push(c1); + } + } + return result; + } + asReferences() { + if (this.m_contours && this.m_contours.length) return null; + if (!this.m_references.length) return null; + return this.m_references; + } + + applyTranslate(shiftX, shiftY) { + for (const c of this.m_contours) { + for (let k = 0; k < c.length; k++) { + c[k] = Point.translated(c[k], shiftX, shiftY); + } + } + for (const r of this.m_references) { + r.x += shiftX; + r.y += shiftY; + } + } + applyTransform(tfm) { + const cs = this.asContours(); + for (const c of cs) { + for (let k = 0; k < c.length; k++) { + c[k] = Point.transformed(tfm, c[k]); + } + } + this.m_contours = cs; + this.m_references.length = 0; + } + + reTagContour(oldTag, newTag) { + for (const c of this.m_contours) { + if (c.tag === oldTag) c.tag = newTag; + } + } + ejectContour(tag) { + const cs = this.asContours(); + let i = 0, + j = 0; + for (; i < cs.length; i++) if (!cs[i].tag || cs[i].tag !== tag) cs[j++] = cs[i]; + cs.length = j; + this.m_contours = cs; + this.m_references = []; + } + + suppressNaN() { + let broken = false, + complexity = 0; + for (const c of this.m_contours) { + for (const z of c) { + complexity++; + if (!isFinite(z.x)) { + broken = true; + z.x = 0; + } + if (!isFinite(z.y)) { + broken = true; + z.y = 0; + } + } + } + return broken ? 0xffff : complexity; + } + + isEmpty() { + return !this.m_contours.length && !this.m_references.length; + } +}