-
Notifications
You must be signed in to change notification settings - Fork 556
/
aesthetics.ptl
341 lines (297 loc) · 14.5 KB
/
aesthetics.ptl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
import '../support/point' as Point
import '../support/transform' as Transform
import [mix linreg clamp fallback] from '../support/utils'
import '../support/anchor' as Anchor
# Parameter generation
export : define [calculateMetrics para] : begin
define UPM 1000
define HalfUPM : UPM / 2
# Key metrics
define Width : Math.round para.width
define SB para.sb
define CAP para.cap
define XH para.xheight
define Descender : fallback para.descender (XH - CAP)
define Contrast : fallback para.contrast 1
# Key metrics for symbols
define SymbolMid : fallback para.SymbolMid (XH * 0.65)
define ParenTop : SymbolMid + para.parenSize / 2
define ParenBot : SymbolMid - para.parenSize / 2
define OperTop : SymbolMid + para.operSize * (Width - SB * 2)
define OperBot : SymbolMid - para.operSize * (Width - SB * 2)
define TackTop : SymbolMid + para.tackSize * (Width - SB * 2)
define TackBot : SymbolMid - para.tackSize * (Width - SB * 2)
define PlusTop : SymbolMid + para.plusSize * (Width - SB * 2)
define PlusBot : SymbolMid - para.plusSize * (Width - SB * 2)
define PictTop : SymbolMid + para.pictSize * (Width - SB * 2)
define PictBot : SymbolMid - para.pictSize * (Width - SB * 2)
define BgOpTop : SymbolMid + para.bgopSize * (Width - SB * 2)
define BgOpBot : SymbolMid - para.bgopSize * (Width - SB * 2)
# Transform constructors
define [Italify angle shift] : begin
local slope [Math.tan ([fallback angle para.slopeAngle] / 180 * Math.PI)]
return : new Transform 1 slope 0 1 [fallback shift : -slope * SymbolMid] 0
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 [Rotate angle] : new Transform [Math.cos angle] (-[Math.sin angle]) [Math.sin angle] [Math.cos angle] 0 0
define GlobalTransform : Italify para.slopeAngle
define TanSlope GlobalTransform.yx
define SinSlope : Math.sin (para.slopeAngle / 180 * Math.PI)
define CosSlope : Math.cos (para.slopeAngle / 180 * Math.PI)
define HVContrast : Contrast * CosSlope + SinSlope * TanSlope
# Orient parameters
define Upward : new Point (-HVContrast) 0
define Downward : new Point HVContrast 0
define Rightward : new Point TanSlope 1
define Leftward : new Point (- TanSlope) (-1)
define [UpwardT] : new Point (-HVContrast) 0
define [DownwardT] : new Point HVContrast 0
define [RightwardT] : new Point this.gizmo.yx 1
define [LeftwardT] : new Point (- this.gizmo.yx) (-1)
# Style parameters
define O para.overshoot
define OX para.overshootx
define OXHook para.oxhook
define Hook para.hook
define AHook para.ahook
define SHook para.shook
define RHook para.rhook
define JHook para.jhook
define FHook para.fhook
define HookX para.hookx
define Smooth para.smooth
define SmallSmooth para.smallsmooth
# Weight Control
# We will estimate blackness using lower-case 'e'
define DarknessMockWidth : if (Width < HalfUPM) (HalfUPM * [Math.pow (Width / HalfUPM) 0.5]) Width
define DarknessMockWidth2 : HalfUPM * [Math.pow (Width / HalfUPM) 0.5]
define BaseFillRate : 1 / 2 + para.stroke / ([Math.max HalfUPM DarknessMockWidth2] - SB * 2)
define [InverseCrowdedness c] : [Math.tanh c] / c
define [adviceBlackness crowdedness div mul] : begin
local gap : DarknessMockWidth * [fallback div 1] - SB * 2
local shrink : BaseFillRate * [InverseCrowdedness crowdedness]
return : Math.min para.stroke ([fallback mul 1] * gap * shrink)
define [adviceBlackness2 cowX cowY refH div] : Math.min
adviceBlackness cowX (refH / DarknessMockWidth2)
adviceBlackness cowY div
define Stroke : adviceBlackness 2
define DotSize : fallback para.dotsize Stroke
define PeriodSize : fallback para.periodsize DotSize
define HBarPos : designParameters.hBarPos - 0.09 * Stroke / CAP
define OverlayPos designParameters.overlayPos
define Jut para.jut
define LongJut para.longjut
define MidJutSide : Math.max Jut : mix (0.5 * Stroke * HVContrast) LongJut 0.5
define MidJutCenter : Math.max Jut : mix (0.5 * Stroke * HVContrast) LongJut 0.6
define VJut para.vjut
define Accent para.accent
define AccentX para.accentx
define CThin : fallback para.cthin 0.75
define CThinB : fallback para.cthinb 0.5
define SLAB para.slab
define TailAdjX : Width * 0.2
define TailAdjY : XH * 0.25
define LBalance : LongJut * 0.04
define IBalance : fallback para.ibalance (LongJut * 0.04)
define LBalance2 : LongJut * 0.14
define IBalance2 : fallback para.ibalance (LongJut * 0.14)
define JBalance : fallback para.jbalance 0
define JBalance2 : fallback para.jbalance2 (Stroke * 0.25 + LBalance)
define TBalance : fallback para.tbalance JBalance
define TBalance2 : fallback para.tbalance2 TBalance
define RBalance : fallback para.rbalance (JBalance * 0.3)
define RBalance2 : fallback para.rbalance2 0
define FBalance : fallback para.fbalance 0
define OneBalance : fallback para.onebalance 0
# derived metrics
define MONOSPACE : para.diversityM == 1 && para.diversityF == 1 && para.diversityI == 1 && para.diversityII == 1
define WideWidth0 : if MONOSPACE (Width * 2) UPM
define WideWidth1 : if (para.spacing >= 1) WideWidth0 Width
define WideWidth2 : if (para.spacing >= 2) WideWidth0 Width
define Ess : Stroke * [fallback para.essx Contrast]
define EssQuestion : Stroke * [fallback para.essxq Contrast]
define HalfStroke : Stroke / 2
define RightSB : Width - SB
define Middle : Width / 2
define CapMiddle : CAP / 2
define DotRadius : DotSize / 2
define PeriodRadius : PeriodSize / 2
define SideJut : Jut - HalfStroke * HVContrast
define [StrokeWidthBlend min max sw] : linreg 18 min 126 max [fallback sw Stroke]
define SmoothAdjust : StrokeWidthBlend 80 144
define [SmoothAOf smooth width] : smooth - TanSlope * SmoothAdjust / Width * width
define [SmoothBOf smooth width] : smooth + TanSlope * SmoothAdjust / Width * width
define [YSmoothMidR top bot sma smb] : begin
local delta : (smb - sma) / 2
local smOfSma : sma + delta
local smOfSmb : smb - delta
local yNotAdjusted : mix top bot (smOfSmb / (smOfSma + smOfSmb))
return : yNotAdjusted - delta
define [YSmoothMidL top bot sma smb] : begin
local delta : (smb - sma) / 2
local smOfSma : sma + delta
local smOfSmb : smb - delta
local yNotAdjusted : mix top bot (smOfSma / (smOfSma + smOfSmb))
return : yNotAdjusted + delta
define SmoothA : Smooth - TanSlope * SmoothAdjust
define SmoothB : Smooth + TanSlope * SmoothAdjust
define SmallSmoothA : SmallSmooth - TanSlope * SmoothAdjust
define SmallSmoothB : SmallSmooth + TanSlope * SmoothAdjust
define CorrectionOMidX : TanSlope * 0.9 * [StrokeWidthBlend 1.3 0.9]
define CorrectionOMidS : Stroke * CorrectionOMidX
define [MVertStrokeD hPack div] : adviceBlackness [Math.max designParameters.lllcrowdedness hPack] div
define MVertStroke : MVertStrokeD 3 1
define OverlayStroke : adviceBlackness 3.75
define OperatorStroke : adviceBlackness 3
define GeometryStroke : adviceBlackness 4.5
define ShoulderFine : Math.min (Stroke * para.shoulderfineMin) [adviceBlackness 16]
define [superXY x superness] : Math.pow (1 - [Math.pow x [fallback superness designParameters.superness]]) (1 / [fallback superness designParameters.superness])
define [adviceSSmooth y sign _stroke] : begin
# Handle with extreme care.
local stroke : fallback _stroke Stroke
local strokeFactor : stroke * [clamp 1 2 : linreg 126 1 137 1.025 stroke] * [clamp 0 1 : Math.pow (Width / HalfUPM) 0.5]
local widthFactor : RightSB - SB
local ss : y * 0.21 + 0.375 * strokeFactor + 0.035 * widthFactor
return : ss + sign * TanSlope * (SmoothAdjust + 0.75 * stroke)
define [adviceGlottalStopSmooth y sign] : begin
return : ((y - Stroke) * 0.24 + Stroke * 0.625) + sign * TanSlope * SmoothAdjust
define [shoulderMidSlope _fine _stroke _dir] : begin
local stroke : fallback _stroke Stroke
local fine : fallback _fine ShoulderFine
local dir : fallback _dir 1
return : 0.5 * HVContrast * (stroke - fine) / stroke + dir * TanSlope
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
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 Ess EssQuestion
HalfStroke RightSB Middle CapMiddle DotRadius PeriodRadius SideJut SmoothA
SmoothB SmallSmoothA SmallSmoothB CorrectionOMidX CorrectionOMidS compositeBaseAnchors
adviceBlackness adviceBlackness2 MVertStroke MVertStrokeD OverlayStroke OperatorStroke
GeometryStroke ShoulderFine superXY adviceSSmooth adviceGlottalStopSmooth
shoulderMidSlope StrokeWidthBlend SmoothAOf SmoothBOf SmoothAdjust MidJutSide MidJutCenter YSmoothMidR YSmoothMidL]
export : define [setFontMetrics para metrics fm] : begin
define [object CAP Descender XH Width] metrics
define leading : Math.round para.leading
define asc : Math.round : leading * CAP / (CAP - Descender)
define desc : Math.round : leading * Descender / (CAP - Descender)
define descenderPad : Math.round : fallback para.descenderPad 0
define winMetricAscenderPad : Math.round : fallback para.winMetricAscenderPad 0
define winMetricDescenderPad : Math.round : fallback para.winMetricDescenderPad 0
set fm.OS_2.xAvgCharWidth Width
set fm.head.unitsPerEm 1000
set fm.hhea.ascender asc
set fm.OS_2.usWinAscent (asc + winMetricAscenderPad)
set fm.OS_2.sTypoAscender asc
set fm.hhea.descender (Descender - descenderPad)
set fm.OS_2.usWinDescent ([Math.abs desc] + descenderPad + winMetricDescenderPad)
set fm.OS_2.sTypoDescender (desc - descenderPad)
set fm.hhea.lineGap (leading - asc + Descender)
set fm.OS_2.sTypoLineGap (leading - asc + desc)
set fm.OS_2.sxHeight XH
set fm.OS_2.sCapHeight CAP
set fm.post.italicAngle [Math.round (0 - para.slopeAngle)]
export : define [compositeBaseAnchors] : begin
local h {.}
foreach a [items-of arguments] : foreach k [items-of [Object.keys a.baseAnchors]] : begin
set h.(k) : new Anchor a.baseAnchors.(k).x a.baseAnchors.(k).y a.baseAnchors.(k).type a.baseAnchors.(k).mbx a.baseAnchors.(k).mby
return {.baseAnchors h .isMarkSet true}
export : define [MarksetDiv p sbMul me] : begin
define width : p * me.Width
define middle : p * me.Middle
define rightSB : me.Width * p - me.SB
define [ta anchor] : return : new Anchor
* (anchor.x * me.GlobalTransform.xx + anchor.y * me.TanSlope + me.GlobalTransform.x)
* (anchor.x * me.GlobalTransform.xy + anchor.y * me.GlobalTransform.yy + me.GlobalTransform.y)
define [MarkAbove zone] {.baseAnchors {.above [ta : new Anchor middle zone.top ]}}
define [MarkBelow zone] {.baseAnchors {.below [ta : new Anchor middle zone.bot ]}}
define [MarkTopRight zone] {.baseAnchors {.topright [ta : new Anchor rightSB zone.top ]}}
define [MarkBottomRight zone] {.baseAnchors {.bottomright [ta : new Anchor rightSB zone.bot ]}}
define markTieAbove {.baseAnchors {.tieAbove [ta : new Anchor width (me.XH + me.Accent * 1.38)]}}
define markTieBelow {.baseAnchors {.tieBelow [ta : new Anchor width me.Descender ]}}
define [buildStandardMarkSet zone] : lambda [] : begin
if (this.baseAnchors) : begin
throw : new Error "A mark set is now a function. Please call it before inclusion"
local a : compositeBaseAnchors
MarkAbove zone
MarkBelow zone
MarkTopRight zone
MarkBottomRight zone
begin markTieAbove
begin markTieBelow
set a.baseAnchors.overlay : new Anchor
* [mix a.baseAnchors.below.x a.baseAnchors.above.x me.OverlayPos]
* [mix a.baseAnchors.below.y a.baseAnchors.above.y me.OverlayPos]
set a.baseAnchors.slash : new Anchor
* [mix a.baseAnchors.below.x a.baseAnchors.above.x 0.5]
* [mix a.baseAnchors.below.y a.baseAnchors.above.y 0.5]
return a
return : object
OfZone buildStandardMarkSet
capital : buildStandardMarkSet {.top me.CAP .bot 0}
b : buildStandardMarkSet {.top me.CAP .bot 0}
e : buildStandardMarkSet {.top me.XH .bot 0}
p : buildStandardMarkSet {.top me.XH .bot me.Descender}
oper : buildStandardMarkSet {.top me.OperTop .bot me.OperBot}
tack : buildStandardMarkSet {.top me.TackTop .bot me.TackBot}
plus : buildStandardMarkSet {.top me.PlusTop .bot me.PlusBot}
if : buildStandardMarkSet {.top me.CAP .bot me.Descender}
export : define designParameters : object
# V shape
straightVShapeSbShrink 0.8
straightSmallYShapeSbShrink 0.8
#
equal_wideness 0.075
logic_narrow_shrink 0.75
GeometricLargeX : lambda [mw uw] : (mw + uw / 2) / mw
geometric_very_small_x (2.5 / 7)
geometric_small_x (4 / 7)
geometric_medium_small_x (4.75 / 7)
geometric_medium_x (5.5 / 7)
arrow_size 0.45
# ()
parenOutside 0.2
parenInside 0.9
parenCurliness 0.7
parenOvershoot 0.0375
# []
bracketOutside 0.1
bracketInside 0.95
# {}
braceOutside 0.05
braceInside 0.95
braceCurlyM1 0.6
braceCurlyM2 0.45
braceOvershoot 0.02
# Crosdedness
lllcrowdedness (3 + 1 / 3)
# Bar position
hBarPos 0.525
eBarPos 0.5
fiveBarPos 0.64
overlayPos 0.52
fBarPosToXH 0.91
gBarPos 0.42
upperEBarPos : lambda [slab] : if slab 0.52 0.53
# Fine adjustments
fbarStrokeAdj 0.25
superness 2.275
tightHookSuperness 2.30
export : define [GenDivFrame metrics] : lambda [_div _hPack _sbMul] : begin
local div : fallback _div 1
local hPack : Math.max 2 [fallback _hPack 0]
local sbMul : fallback _sbMul : Math.min 1 : (metrics.Width * div - hPack * [metrics.adviceBlackness hPack div]) / (2 * hPack * metrics.SB)
return : object
div div
width : metrics.Width * div
middle : metrics.Middle * div
sb : metrics.SB * sbMul
leftSB : metrics.SB * sbMul
rightSB : metrics.Width * div - metrics.SB * sbMul
mvs : metrics.MVertStrokeD hPack div
markSet : MarksetDiv div sbMul metrics