Skip to content

Commit

Permalink
Make basic operations to produce less closures
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Aug 21, 2024
1 parent 78b0df7 commit 4fdd2ac
Show file tree
Hide file tree
Showing 10 changed files with 262 additions and 190 deletions.
46 changes: 20 additions & 26 deletions packages/font-glyphs/src/common/shapes.ptl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ $$include '../meta/macros.ptl'

import [mix linreg clamp fallback boole boolePn] from "@iosevka/util"
import [Transform] from "@iosevka/geometry/transform"
import [Interpolator WithKnotProxy] from "@iosevka/geometry/spiro-control"
import [FunctionInterpolator WithKnotProxy AfCombine] from "@iosevka/geometry/spiro-control"
import [RadicalGeometry StrokeGeometry RemoveHolesGeometry] from "@iosevka/geometry"
import [CMixCoord CopyBackKnotProxy] from "@iosevka/font-kits/derived-coordinates"

Expand Down Expand Up @@ -133,7 +133,6 @@ glyph-block CommonShapes : begin
local mx ((l + r) / 2)
currentGlyph.gizmo = [if transformShiftOnly [Transform.Id] giz]
include : dispiro
begin [lambda : set this.gizmo currentGlyph.gizmo]
widths.rhs [fallback s Stroke]
g4 mx d [heading Leftward]
archv
Expand Down Expand Up @@ -168,7 +167,6 @@ glyph-block CommonShapes : begin
local mx ((l + r) / 2)
currentGlyph.gizmo = [if transformShiftOnly [Transform.Id] giz]
include : spiro-outline
begin [lambda : set this.gizmo currentGlyph.gizmo]
g4 mx d
archv 32 2.0
g4 l my
Expand Down Expand Up @@ -463,22 +461,16 @@ glyph-block CommonShapes : begin
local depth : v + skew0 * sw - sw
local shallowLimit : sw / 2
local skew : clamp 0 (1 / 2) : skew0 + [clamp 0 shallowLimit (shallowLimit - depth)] / rad
local faf toFinish.af
if doSwash
: then : begin
set toFinish.af : lambda [] : begin
if faf : faf.apply this arguments
if this.headsTo : this.headsTo {
.x (Contrast / [Math.hypot 1 skew] * [if dtu (-1) 1])
.y (skew / [Math.hypot 1 skew] * [if ltr 1 (-1)])
}
: else : begin
set toFinish.af : lambda [] : begin
if faf : faf.apply this arguments
if this.headsTo : this.headsTo{
.x (Contrast * [if dtu (-1) 1])
.y 0
}

local headDirection : if doSwash
object
x (Contrast / [Math.hypot 1 skew] * [if dtu (-1) 1])
y (skew / [Math.hypot 1 skew] * [if ltr 1 (-1)])
object
x (Contrast * [if dtu (-1) 1])
y 0

set toFinish.af : new AfCombine toFinish.af [heading headDirection]

# Create the arc knots
local segBefore {}
Expand All @@ -487,14 +479,14 @@ glyph-block CommonShapes : begin
local fraction : j / nHookSegments
local mixRatioAdjust : Math.max (1 / 2) : (1 / 2) + [if doSwash 1 (1 / 8)] * (mixRatio - (1 / 2))
local fractionAfter : fraction * (1 - mixRatioAdjust) / mixRatioAdjust
local myfinal : _SuperXY ((1 - mixRatioAdjust) / mixRatioAdjust) superness
local myfinal : 1 - [archv.yFromX ((1 - mixRatioAdjust) / mixRatioAdjust) superness]
segBefore.push : g4
mix mx toStraight.x fraction
mix y toStraight.y (1 - [_SuperXY fraction superness])
mix y toStraight.y [archv.yFromX fraction superness]
begin unimportant
segAfter.push : g4
mix mx toFinish.x fraction
mix y toFinish.y ((1 - [_SuperXY fractionAfter superness]) / (1 - myfinal))
mix y toFinish.y ([archv.yFromX fractionAfter superness] / (1 - myfinal))
begin unimportant

if isStart
Expand Down Expand Up @@ -525,7 +517,7 @@ glyph-block CommonShapes : begin
local-parameter : noSwash -- false
local-parameter : o -- O
local args : object [yRef y] sw swTerminal isTail noSwash [overshoot o]
return : WithKnotProxy [hookProxy args] : Interpolator hookStartBlender args
return : WithKnotProxy [hookProxy args] : new FunctionInterpolator hookStartBlender args

glyph-block-export hookend
define flex-params [hookend] : begin
Expand All @@ -536,7 +528,7 @@ glyph-block CommonShapes : begin
local-parameter : noSwash -- false
local-parameter : o -- O
local args : object [yRef y] sw swTerminal isTail noSwash [overshoot o]
return : WithKnotProxy [hookProxy args] : Interpolator hookEndBlender args
return : WithKnotProxy [hookProxy args] : new FunctionInterpolator hookEndBlender args

glyph-block-export arch
define arch : namespace
Expand Down Expand Up @@ -638,7 +630,8 @@ glyph-block CommonShapes : begin
local-parameter : blendPre -- [if anglePre nothing [arcvh]]
local-parameter : blendPost -- [if anglePost nothing [archv]]
local args : object [lhs true] y p sw compact o swBefore swAfter mockPre mockPost blendPre blendPost anglePre anglePost
return : WithKnotProxy [archBlenderProxy args] : Interpolator archBlender args
return : WithKnotProxy [archBlenderProxy args]
new FunctionInterpolator archBlender args

export : define flex-params [rhs] : begin
local-parameter : y
Expand All @@ -655,7 +648,8 @@ glyph-block CommonShapes : begin
local-parameter : blendPre -- [if anglePre nothing [arcvh]]
local-parameter : blendPost -- [if anglePost nothing [archv]]
local args : object [lhs false] y p sw compact o swBefore swAfter mockPre mockPost blendPre blendPost anglePre anglePost
return : WithKnotProxy [archBlenderProxy args] : Interpolator archBlender args
return : WithKnotProxy [archBlenderProxy args]
new FunctionInterpolator archBlender args

foreach side {lhs rhs} : begin
set side.centerAt : object
Expand Down
19 changes: 12 additions & 7 deletions packages/font-glyphs/src/letter-like/fraktur/common.ptl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import [mix fallback] from "@iosevka/util"
import [SpiroPenGeometry] from "@iosevka/geometry"
import [Vec2] from "@iosevka/geometry/point"
import [Box] from "@iosevka/geometry/box"
import [Interpolator] from "@iosevka/geometry/spiro-control"
import [AfBase FunctionInterpolator] from "@iosevka/geometry/spiro-control"
import [PenKnotCollector] from "@iosevka/geometry/spiro-pen-expand"

glyph-module
Expand Down Expand Up @@ -61,8 +61,13 @@ glyph-block LetterLike-Fraktur-Common : begin

# Directive to change the profile
glyph-block-export change-pen
define [change-pen newPen] : function : begin
this.setProfile : newPen.getPenShape this.gizmo
define [change-pen newPen] : new AfChangePen newPen

class AfChangePen : inherits AfBase
public [new newPen] : begin
this.newPen = newPen
public [applyTo target] : begin
target.setProfile : this.newPen.getPenShape target.gizmo

# A pen profile describes a virtual flat-tip pen. We use a 45-degree arrangement to
# simplify the math.
Expand Down Expand Up @@ -152,26 +157,26 @@ glyph-block LetterLike-Fraktur-Common : begin
export : define DepthX : 1 * DecoSizeX
export : define LTDecoSize : 0.75 * DecoSizeX

export : define [h o] : Interpolator hBlender [object o]
export : define [h o] : new FunctionInterpolator hBlender [object o]
define [hBlender before after args] : begin
return : list
g2 [mix before.x after.x 0.375] (after.y + [fallback args.o 0])
g2 [mix before.x after.x 0.625] (before.y - [fallback args.o 0])

export : define [vc waveDepth] : Interpolator vcBlender [object waveDepth]
export : define [vc waveDepth] : new FunctionInterpolator vcBlender [object waveDepth]
define [vcBlender before after args] : begin
local [object waveDepth] args
return : list
g2 (before.x + 0.5 * waveDepth) [mix before.y after.y 0.375]
g2 (after.x - 0.5 * waveDepth) [mix before.y after.y 0.625]

export : define [v] : Interpolator vBlender
export : define [v] : new FunctionInterpolator vBlender
define [vBlender before after] : begin
return : list
g2 after.x [mix before.y after.y 0.375]
g2 before.x [mix before.y after.y 0.625]

export : define [vDistAfter d] : Interpolator vDistAfterBlender [object d]
export : define [vDistAfter d] : new FunctionInterpolator vDistAfterBlender [object d]
define [vDistAfterBlender before after args] : begin
return : list
g2 after.x [mix before.y after.y 0.375]
Expand Down
2 changes: 1 addition & 1 deletion packages/font-glyphs/src/letter/latin/lower-e.ptl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ glyph-block Letter-Latin-Lower-E : begin
dispiro
g4 lastKnot.x lastKnot.y [widths.rhs fine]
g4 (lastKnot.x - beginCoSlope * TINY) (lastKnot.y - TINY)
alsoThruThem.fromTWithOffset {(1/3) (2/3)} : object
alsoThruThem.computed { (1/3) (2/3) } : object
rx : function [rt] rt
deltaX : function [rt] 0
ry : function [rt] : 1/24 + rt + (1/2 - rt) * (3/8)
Expand Down
6 changes: 3 additions & 3 deletions packages/font-glyphs/src/letter/shared.ptl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$$include '../meta/macros.ptl'

import [mix clamp fallback] from "@iosevka/util"
import [Interpolator] from "@iosevka/geometry/spiro-control"
import [FunctionInterpolator] from "@iosevka/geometry/spiro-control"
import [Dotless CvDecompose] from "@iosevka/glyph/relation"
import [RightDependentTrigger RightDependentLink DependentSelector] from "@iosevka/glyph/relation"
import [DesignParameters] from "../meta/aesthetics.mjs"
Expand Down Expand Up @@ -211,7 +211,7 @@ glyph-block Letter-Shared-Shapes : begin
local-parameter : swBefore -- Stroke
local-parameter : terminalSlopeAdj -- 0.5

return : Interpolator normalBlender
return : new FunctionInterpolator normalBlender
object [flat false] fine bottom xOuter x2 y2 yLoopTop swBefore terminalSlopeAdj

export : define flex-params [f] : begin
Expand All @@ -223,7 +223,7 @@ glyph-block Letter-Shared-Shapes : begin
local-parameter : swBefore -- Stroke
local-parameter : terminalSlopeAdj -- 0.5

return : Interpolator normalBlender
return : new FunctionInterpolator normalBlender
object [flat true] fine bottom xOuter x2 yLoopTop swBefore terminalSlopeAdj

glyph-block-export HCurlyTail
Expand Down
6 changes: 1 addition & 5 deletions packages/font-glyphs/src/meta/aesthetics.ptl
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,6 @@ export : define [calculateMetrics para] : begin
define GeometryStroke : AdviceStroke 4
define ShoulderFine : Math.min (Stroke * para.shoulderFineMin) [AdviceStroke 16]

define [_SuperXY x superness] : Math.pow
1 - [Math.pow x [fallback superness DesignParameters.superness]]
1 / [fallback superness DesignParameters.superness]

define [AdviceGlottalStopArchDepth y sign] : begin
return : ((y - Stroke) * 0.24 + Stroke * 0.625) + sign * TanSlope * SmoothAdjust

Expand All @@ -199,7 +195,7 @@ export : define [calculateMetrics para] : begin
EssUpper EssLower EssQuestion HalfStroke RightSB Middle DotRadius PeriodRadius SideJut
ArchDepthA ArchDepthB SmallArchDepthA SmallArchDepthB CorrectionOMidX CorrectionOMidS
compositeBaseAnchors AdviceStroke AdviceStroke2 OverlayStroke OperatorStroke GeometryStroke
ShoulderFine _SuperXY AdviceGlottalStopArchDepth StrokeWidthBlend ArchDepthAOf ArchDepthBOf
ShoulderFine AdviceGlottalStopArchDepth StrokeWidthBlend ArchDepthAOf ArchDepthBOf
SmoothAdjust MidJutSide MidJutCenter YSmoothMidR YSmoothMidL HSwToV NarrowUnicodeT
WideUnicodeT VERY-FAR TINY]

Expand Down
8 changes: 4 additions & 4 deletions packages/font-glyphs/src/meta/macros.ptl
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,10 @@ define-macro glyph-block : syntax-rules
WideWidth2 WideWidth3 WideWidth4 EssUpper EssLower EssQuestion HalfStroke RightSB
Middle DotRadius PeriodRadius SideJut ArchDepthA ArchDepthB SmallArchDepthA
SmallArchDepthB CorrectionOMidX CorrectionOMidS AdviceStroke AdviceStroke2
OverlayStroke OperatorStroke GeometryStroke ShoulderFine _SuperXY
AdviceGlottalStopArchDepth StrokeWidthBlend ArchDepthAOf ArchDepthBOf SmoothAdjust
MidJutSide MidJutCenter compositeBaseAnchors YSmoothMidR YSmoothMidL HSwToV
NarrowUnicodeT WideUnicodeT VERY-FAR TINY]
OverlayStroke OperatorStroke GeometryStroke ShoulderFine AdviceGlottalStopArchDepth
StrokeWidthBlend ArchDepthAOf ArchDepthBOf SmoothAdjust MidJutSide MidJutCenter
compositeBaseAnchors YSmoothMidR YSmoothMidL HSwToV NarrowUnicodeT WideUnicodeT
VERY-FAR TINY]
define spiroFnImports `[g4 g2 corner flat curl virt close end straight g2c cg2 flatc ccurl
widths disable-contrast heading unimportant important alsoThru alsoThruThem bezControls
quadControls archv arcvh dispiro spiro-outline spiro-collect]
Expand Down
Loading

0 comments on commit 4fdd2ac

Please sign in to comment.