Refactor of y

This commit is contained in:
be5invis 2023-10-11 00:33:22 -07:00
parent cd6c43efe8
commit aab298f771

View file

@ -20,6 +20,12 @@ glyph-block Letter-Latin-Lower-Y : begin
define SLAB-MOTION { false false true } define SLAB-MOTION { false false true }
define SLAB-CURSIVE-MOTION { true true true } define SLAB-CURSIVE-MOTION { true true true }
define TS-NONE 0
define TS-HOOKTOP 1
define SHRINK-NONE 0
define SHRINK-INNER 1
define BS-STRAIGHT 0 define BS-STRAIGHT 0
define BS-TURN 1 define BS-TURN 1
define BS-LOOP 2 define BS-LOOP 2
@ -33,209 +39,233 @@ glyph-block Letter-Latin-Lower-Y : begin
local slabCurlyNoTurnB : doSlabBottom && !straightBar && !bottomShape local slabCurlyNoTurnB : doSlabBottom && !straightBar && !bottomShape
local bottomIsNotVertical : doSlabBottom || useStraightBottom || bottomShape local bottomIsNotVertical : doSlabBottom || useStraightBottom || bottomShape
local px1 0.84 define yBottomJut : Jut * 1.25
local py1 : [StrokeWidthBlend 0.8 0.76] * [if slabCurly [StrokeWidthBlend 1 0.9] 1] define slabysize : yBottomJut * (Width / UPM) + Stroke
local px2 : if slabCurlyNoTurnB px1 0.95
local py2VertBot : 0.88 * [if slabCurly [StrokeWidthBlend 1 0.9] 1]
local py2 : if slabCurlyNoTurnB py1 : if bottomIsNotVertical 0.97 py2VertBot
local pds 0.1
local pds2 0.01
local dpy1 : (1 - [linreg (1 - px2) (1 - py2) px1 py1 1]) / (1 - py1)
local dpy2 : (1 - [linreg (1 - px1) (1 - py1) px2 py2 1]) / (1 - py2)
local yrstrokel0 : Middle - Width * 0.1
local yrstrokel : Middle - Width * 0.1 + ([HSwToV Stroke] * [if bottomIsNotVertical (2 / 3) (1 / 3)] * [if slabCurly [StrokeWidthBlend 0.95 0.97] 1])
local yrstroker : Width - SB * [if straightBar DesignParameters.straightSmallYShapeSbShrink 1]
local yshrink : [StrokeWidthBlend 1 0.85] * [if straightBar ([AdviceStroke 3.25] / Stroke) 1]
local yBottomJut : Jut * 1.25
local slabysize : Jut * 1.25 * (Width / UPM) + Stroke
local slabyvx 0.625
define [CalcDS top bottom] : begin define [CalcDS top bottom] : begin
local pds 0.1
local pds2 0.01
local slabyvx 0.625
local ds0 : (top - bottom) * pds local ds0 : (top - bottom) * pds
local ds20 : (top - bottom) * pds2 local ds20 : (top - bottom) * pds2
local ds : if slabCurly [Math.max [AdviceStroke2 3 6 (top - bottom)] ds0] ds0 local ds : if slabCurly [Math.max [AdviceStroke2 3 6 (top - bottom)] ds0] ds0
local ds2 : if slabCurlyNoTurnB ds : ds20 + [if bottomIsNotVertical (slabysize * slabyvx) 0] local ds2 : if slabCurlyNoTurnB ds : ds20 + [if bottomIsNotVertical (slabysize * slabyvx) 0]
return {ds ds2} return {ds ds2}
define [yDiagCor dy] : DiagCor dy (yrstroker - yrstrokel) 0 0 define [Metrics ts kShrink] : namespace
define pxHookTopOffset : [StrokeWidthBlend (0.5 * TailX) (0.375 * TailX)] / (RightSB - SB)
export : define px1 : 0.84 - [if (ts == TS-HOOKTOP) pxHookTopOffset 0]
export : define py1 : [StrokeWidthBlend 0.8 0.76] * [if slabCurly [StrokeWidthBlend 1 0.9] 1]
export : define px2 : if slabCurlyNoTurnB px1 0.95
export : define py2VertBot : 0.88 * [if slabCurly [StrokeWidthBlend 1 0.9] 1]
export : define py2 : if slabCurlyNoTurnB py1 : if bottomIsNotVertical 0.97 py2VertBot
export : define dpy1 : (1 - [linreg (1 - px2) (1 - py2) px1 py1 1]) / (1 - py1)
export : define dpy2 : (1 - [linreg (1 - px1) (1 - py1) px2 py2 1]) / (1 - py2)
define [yTopKnots x top bottom ds dir] : begin define yrstrokel0 : Middle - Width * 0.1
local hs : HalfStroke * [if straightBar [yDiagCor (top - bottom)] 1] export : define yrstrokel : Middle - Width * 0.1 + ([HSwToV Stroke] * [if bottomIsNotVertical (2 / 3) (1 / 3)] * [if slabCurly [StrokeWidthBlend 0.95 0.97] 1])
local hl : hs - hs * dir export : define yrstroker : Width - SB * [if straightBar DesignParameters.straightSmallYShapeSbShrink 1]
local hr : hs + hs * dir
if straightBar : return : list
flat x top [widths.heading hl hr Downward]
: else : return : list
flat x top [widths.heading hl hr Downward]
curl x (top - ds) [widths.heading hl hr Downward]
quadControls 0 dpy1 16
define [yOgonekAttach top bottom shrink hooktop] : glyph-proc export : define yshrink : mix 1 ([StrokeWidthBlend 1 0.85] * [if straightBar ([AdviceStroke 3.25] / Stroke) 1]) kShrink
define {ds ds2} : CalcDS top bottom
define coJoinX : if (straightBar && (! hooktop)) yrstroker [mix yrstrokel yrstroker px1]
define coJoinY : if (straightBar && (! hooktop)) top [mix (bottom + ds2) (top - ds) py1]
define joinX : mix yrstrokel yrstroker (1 - px2)
define joinY : mix (bottom + ds2) (top - ds) (1 - py2)
define anchorX : mix coJoinX joinX ((0 - coJoinY) / (joinY - coJoinY)) export : define [diagCor dy] : DiagCor dy (yrstroker - yrstrokel) 0 0
set-base-anchor 'trailing' anchorX 0
OgonekTrY.set currentGlyph
define [px1HooktopAdj hooktop] : begin export : define [yJoinProportion x] : linreg
return : px1 - [if hooktop ([StrokeWidthBlend (0.5 * TailX) (0.375 * TailX)] / (RightSB - SB)) 0] 1 - px2
1 - py2
if (straightBar && ts != TS-HOOKTOP) 1 px1
if (straightBar && ts != TS-HOOKTOP) 1 py1
(x - yrstrokel) / (yrstroker - yrstrokel)
define [yBaseKnots top bottom shrink hooktop] : begin export : define [yJoinHeight top bottom] : begin
define {ds ds2} : CalcDS top bottom local {ds ds2} : CalcDS top bottom
return : mix (bottom + ds2) (top - ds) [yJoinProportion Middle]
define coJoinX : mix yrstrokel yrstroker [px1HooktopAdj hooktop] export : define [createSplitMask top bottom dir elev] : begin
define coJoinY : mix (bottom + ds2) (top - ds) py1 local {ds ds2} : CalcDS top bottom
define joinX : mix yrstrokel yrstroker (1 - px2) local jp0 : yJoinProportion (Width / 2 - Width / 2 * dir)
define joinY : mix (bottom + ds2) (top - ds) (1 - py2) local jp1 : yJoinProportion (Width / 2 + Width / 2 * dir)
define [ConnectZ shrink] : curl joinX joinY [widths.rhs : Stroke * shrink] local hs : 0.75 * Stroke
local yLeft : [mix (bottom + ds2) (top - ds) jp1] + hs - [fallback elev 0]
local yRight : [mix (bottom + ds2) (top - ds) jp0] + hs - [fallback elev 0]
local yMin : Math.min bottom yLeft yRight
return : spiro-outline
corner Width yMin
corner Width yRight
corner 0 yLeft
corner 0 yMin
define [RightHalf ts kShrink] : namespace
local me : Metrics ts kShrink
return : list export : define [topKnots top bottom] : begin
if (straightBar && !hooktop) local {ds} : CalcDS top bottom
then : list return : piecewise
else : list [flat coJoinX coJoinY] (ts == TS-HOOKTOP) : list
straight.left.start ([mix me.yrstrokel me.yrstroker me.px1] - HalfStroke + 0.875 * TailX) (top - Stroke - O) [widths.rhs]
piecewise alsoThruThem {{[StrokeWidthBlend 0.58 0.65] 0.2} {[StrokeWidthBlend 0.78 0.85] 0.5}} important
useStraightBottom : list straightBar : list
ConnectZ shrink flat me.yrstroker top [widths.rhs.heading ([me.diagCor (top - bottom)] * Stroke) Downward]
curl [mix yrstroker joinX ((top - bottom) / (top - joinY))] bottom [widths.heading 0 (Stroke * [yDiagCor (top - bottom)]) Downward]
(bottomShape == BS-LOOP) : begin
local joinHeight1 : yJoinHeight ds ds2 top bottom false
local k : 1 / [Math.sin : Math.atan2 (joinX - Middle) (joinY - joinHeight1)] - 0.25
local joinHeight3 : [Math.abs k] * Stroke + joinHeight1
local deltaX : Math.max yBottomJut [HSwToV : 1.2 * Stroke]
local fine : AdviceStroke 3
local xLoopLeft : Math.max (SB * -0.25) [mix joinX (yrstrokel - deltaX) 2]
local xCenter : mix xLoopLeft joinX 0.5
list
ConnectZ shrink
g4.left.mid ([Math.min (yrstrokel - deltaX) xCenter] + CorrectionOMidS) bottom [widths.rhs]
archv
g4.up.mid xLoopLeft [mix bottom joinHeight3 0.5] [widths.rhs.heading fine Upward]
arcvh
flat xCenter joinHeight3 [heading Rightward]
curl Middle joinHeight3 [heading Rightward]
(bottomShape == BS-TURN) : list
ConnectZ shrink
flat (yrstrokel - slabysize) bottom [widths.rhs]
curl [Math.min (yrstrokel - slabysize - 0.1) (yrstrokel - Stroke - yBottomJut)] bottom
true : list true : list
ConnectZ 1 flat me.yrstroker top [widths.rhs.heading Stroke Downward]
quadControls 1 (1 - dpy2) 16 curl me.yrstroker (top - ds) [heading Downward]
flat yrstrokel (bottom + ds2) [widths.heading 0 Stroke Downward] quadControls 0 me.dpy1 16
curl yrstrokel bottom [widths.heading 0 Stroke Downward]
define [yBaseSerif top bottom] : glyph-proc export : define [baseKnots top bottom] : begin
local {ds ds2} : CalcDS top bottom define {ds ds2} : CalcDS top bottom
define joinX : mix yrstrokel yrstroker (1 - px2)
define joinY : mix (bottom + ds2) (top - ds) (1 - py2)
if bottomShape : return nothing define coJoinX : mix me.yrstrokel me.yrstroker me.px1
if (useStraightBottom) : begin define coJoinY : mix (bottom + ds2) (top - ds) me.py1
local xBaseKnot : mix yrstroker joinX ((top - bottom) / (top - joinY)) define joinX : mix me.yrstrokel me.yrstroker (1 - me.px2)
include : HSerif.lb (xBaseKnot - [HSwToV HalfStroke]) bottom yBottomJut define joinY : mix (bottom + ds2) (top - ds) (1 - me.py2)
: else : begin define [ConnectZ shrink] : curl joinX joinY [widths.rhs : Stroke * shrink]
include : HSerif.lb (yrstrokel - [HSwToV HalfStroke]) bottom yBottomJut
define [yJoinProportion hooktop x] : linreg return : list
1 - px2 if (straightBar && ts != TS-HOOKTOP)
1 - py2 then : list
if (straightBar && !hooktop) 1 [px1HooktopAdj hooktop] else : list [flat coJoinX coJoinY]
if (straightBar && !hooktop) 1 py1
(x - yrstrokel) / (yrstroker - yrstrokel)
define [yJoinHeight ds ds2 top bottom hooktop] : begin piecewise
return : mix (bottom + ds2) (top - ds) [yJoinProportion hooktop Middle] useStraightBottom : list
ConnectZ me.yshrink
curl [mix me.yrstroker joinX ((top - bottom) / (top - joinY))] bottom [widths.rhs.heading ([me.diagCor (top - bottom)] * Stroke) Downward]
(bottomShape == BS-LOOP) : begin
local joinHeight1 : me.yJoinHeight top bottom
local k : 1 / [Math.sin : Math.atan2 (joinX - Middle) (joinY - joinHeight1)] - 0.25
local joinHeight3 : [Math.abs k] * Stroke + joinHeight1
local deltaX : Math.max yBottomJut [HSwToV : 1.2 * Stroke]
local fine : AdviceStroke 3
local xLoopLeft : Math.max (SB * -0.25) [mix joinX (me.yrstrokel - deltaX) 2]
local xCenter : mix xLoopLeft joinX 0.5
list
ConnectZ me.yshrink
g4.left.mid ([Math.min (me.yrstrokel - deltaX) xCenter] + CorrectionOMidS) bottom [widths.rhs]
archv
g4.up.mid xLoopLeft [mix bottom joinHeight3 0.5] [widths.rhs.heading fine Upward]
arcvh
flat xCenter joinHeight3 [heading Rightward]
curl Middle joinHeight3 [heading Rightward]
(bottomShape == BS-TURN) : list
ConnectZ me.yshrink
flat (me.yrstrokel - slabysize) bottom [widths.rhs]
curl [Math.min (me.yrstrokel - slabysize - 0.1) (me.yrstrokel - Stroke - yBottomJut)] bottom
true : list
ConnectZ 1
quadControls 1 (1 - me.dpy2) 16
flat me.yrstrokel (bottom + ds2) [widths.heading 0 Stroke Downward]
curl me.yrstrokel bottom [widths.heading 0 Stroke Downward]
define [yJoinKnots ds ds2 top bottom hooktop] : begin export : define [baseSerif top bottom] : glyph-proc
return : list local {ds ds2} : CalcDS top bottom
if straightBar : then : list define joinX : mix me.yrstrokel me.yrstroker (1 - me.px2)
: else : list define joinY : mix (bottom + ds2) (top - ds) (1 - me.py2)
flat
mix (Width - yrstrokel) (Width - yrstroker) px1
mix (bottom + ds2) (top - ds) py1
curl Middle
yJoinHeight ds ds2 top bottom hooktop
widths.lhs (Stroke * yshrink)
define [SmallYStrokeSplitMask top bottom hooktop dir elev] : begin if bottomShape : return nothing
local {ds ds2} : CalcDS top bottom if (useStraightBottom) : begin
local jp0 : yJoinProportion hooktop (Width / 2 - Width / 2 * dir) local xBaseKnot : mix me.yrstroker joinX ((top - bottom) / (top - joinY))
local jp1 : yJoinProportion hooktop (Width / 2 + Width / 2 * dir) include : HSerif.lb (xBaseKnot - [HSwToV HalfStroke]) bottom yBottomJut
local hs : 0.75 * Stroke : else : begin
local yLeft : [mix (bottom + ds2) (top - ds) jp1] + hs - [fallback elev 0] include : HSerif.lb (me.yrstrokel - [HSwToV HalfStroke]) bottom yBottomJut
local yRight : [mix (bottom + ds2) (top - ds) jp0] + hs - [fallback elev 0]
local yMin : Math.min bottom yLeft yRight export : define [ogonekAttach top bottom] : glyph-proc
return : spiro-outline define {ds ds2} : CalcDS top bottom
corner Width yMin define coJoinX : if (straightBar && ts != TS-HOOKTOP) me.yrstroker [mix me.yrstrokel me.yrstroker me.px1]
corner Width yRight define coJoinY : if (straightBar && ts != TS-HOOKTOP) top [mix (bottom + ds2) (top - ds) me.py1]
corner 0 yLeft define joinX : mix me.yrstrokel me.yrstroker (1 - me.px2)
corner 0 yMin define joinY : mix (bottom + ds2) (top - ds) (1 - me.py2)
define anchorX : mix coJoinX joinX ((0 - coJoinY) / (joinY - coJoinY))
set-base-anchor 'trailing' anchorX 0
OgonekTrY.set currentGlyph
export : define [splitMask top bottom elev] : me.createSplitMask top bottom (-1) elev
define [LeftHalf ts kShrink] : namespace
local me : Metrics ts kShrink
export : define [topKnots top bottom] : begin
local {ds} : CalcDS top bottom
if straightBar
: then : return : list
flat (Width - me.yrstroker) top [widths.lhs.heading ([me.diagCor (top - bottom)] * Stroke) Downward]
: else : return : list
flat (Width - me.yrstroker) top [widths.lhs.heading Stroke Downward]
curl (Width - me.yrstroker) (top - ds) [heading Downward]
quadControls 0 me.dpy1 16
export : define [joinKnots top bottom] : begin
local {ds ds2} : CalcDS top bottom
return : list
if straightBar : then : list
: else : list
flat
mix (Width - me.yrstrokel) (Width - me.yrstroker) me.px1
mix (bottom + ds2) (top - ds) me.py1
curl Middle
me.yJoinHeight top bottom
widths.lhs (Stroke * me.yshrink)
export : define [splitMask top bottom elev] : me.createSplitMask top bottom (+1) elev
export : define [SmallYShape top bottom] : glyph-proc export : define [SmallYShape top bottom] : glyph-proc
local {ds ds2} : CalcDS top bottom local right : RightHalf TS-NONE SHRINK-NONE
local rightSh : RightHalf TS-NONE SHRINK-INNER
local left : LeftHalf TS-NONE SHRINK-INNER
include : yOgonekAttach top bottom yshrink include : right.ogonekAttach top bottom
include : union
intersection
dispiro
right.topKnots top bottom
right.baseKnots top bottom
left.splitMask top bottom
include : intersection difference
SmallYStrokeSplitMask top bottom false 1 dispiro
dispiro right.topKnots top bottom
yTopKnots yrstroker top bottom ds 1 rightSh.baseKnots top bottom
yBaseKnots top bottom 1 left.splitMask top bottom
include : difference difference
dispiro dispiro
yTopKnots yrstroker top bottom ds 1 left.topKnots top bottom
yBaseKnots top bottom yshrink left.joinKnots top bottom
SmallYStrokeSplitMask top bottom false 1 1 right.splitMask top bottom
Rect (bottom + HalfStroke) (bottom - top) 0 Width
include : difference
dispiro
yTopKnots (Width - yrstroker) top bottom ds (-1)
yJoinKnots ds ds2 top bottom
SmallYStrokeSplitMask top bottom false (-1)
Rect (bottom + HalfStroke) (bottom - top) 0 Width
if doSlabTop : include : let [sf : SerifFrame.fromDf [DivFrame 1] top bottom] if doSlabTop : include : let [sf : SerifFrame.fromDf [DivFrame 1] top bottom]
composite-proc sf.lt.full sf.rt.full composite-proc sf.lt.full sf.rt.full
if doSlabBottom : include : yBaseSerif top bottom if doSlabBottom : include : right.baseSerif top bottom
if doSlabMotion : include : HSerif.lt SB top SideJut if doSlabMotion : include : HSerif.lt SB top SideJut
export : define [SmallYHookTopShape top bottom] : glyph-proc export : define [SmallYHookTopShape top bottom] : glyph-proc
local {ds ds2} : CalcDS top bottom local right : RightHalf TS-HOOKTOP SHRINK-NONE
local rightSh : RightHalf TS-HOOKTOP SHRINK-INNER
local left : LeftHalf TS-NONE SHRINK-INNER
include : yOgonekAttach top bottom yshrink true include : right.ogonekAttach top bottom
include : union
intersection
dispiro
right.topKnots top bottom
right.baseKnots top bottom
left.splitMask top bottom
local startX : [mix yrstrokel yrstroker px1] - HalfStroke + [StrokeWidthBlend 0.5 0.75] * TailX difference
local startY : top - Stroke - O dispiro
right.topKnots top bottom
rightSh.baseKnots top bottom
left.splitMask top bottom
local [rightStroke shrink] : dispiro difference
straight.left.start startX startY [widths.rhs] dispiro
alsoThruThem {{[StrokeWidthBlend 0.58 0.65] 0.2} {[StrokeWidthBlend 0.78 0.85] 0.5}} important left.topKnots top bottom
yBaseKnots top bottom shrink true left.joinKnots top bottom
right.splitMask top bottom
Rect (bottom + HalfStroke) (bottom - top) 0 Width
include : intersection if doSlabTop : include : let [sf : SerifFrame.fromDf [DivFrame 1] top bottom] sf.lt.full
rightStroke 1 if doSlabBottom : include : right.baseSerif top bottom
SmallYStrokeSplitMask top bottom true 1
include : difference
rightStroke yshrink
SmallYStrokeSplitMask top bottom true 1 1
include : difference
dispiro
widths.center
yTopKnots (Width - yrstroker) top bottom ds (-1)
yJoinKnots ds ds2 top bottom true
SmallYStrokeSplitMask top bottom true (-1)
Rect (bottom + HalfStroke) (bottom - top) 0 Width
if doSlabTop : include : let [sf : SerifFrame.fromDf [DivFrame 1] top bottom] sf.lt.full
if doSlabBottom : include : yBaseSerif top bottom
if doSlabMotion : include : HSerif.lt SB top SideJut if doSlabMotion : include : HSerif.lt SB top SideJut
export : define [SmallLambdaShape top bottom] : union : glyph-proc export : define [SmallLambdaShape top bottom] : union : glyph-proc