Iosevka/font.patel
2015-07-20 21:56:19 +08:00

264 lines
7.7 KiB
Plaintext

define font [require './empty.json']
exports.font = font
define glyphList font.glyf
define glyphs (.'.notdef' glyphList.0)
define Glyph [require './support/glyph'].Glyph
define Stroke [require './support/stroke'].Stroke
define para_regular (
.width 500
.stroke 80
.dotsize 125
.sb 50
.cap 771
.xheight 560
.hook 145
.ahook 135
.shook 100
.rhook 75
.smooth 192
.smallsmooth 242
.smoothadjust 100
.o [-8]
.oxhook 0
.descender [-178]
.kappa 0.515
.italicangle 0
.barpos 0.44
.gbarpos 0.37
.longserif 175
.accent 175
.tbalance 90
.tbalance2 30
)
define para_bold : Object.create para_regular
para_bold.stroke = 120
para_bold.dotsize = 160
para_bold.barpos = 0.42
para_bold.hook = 150
para_bold.ahook = 100
para_bold.oxhook = 0
para_bold.kappa_hook = 0.7
para_bold.kappa_ahook = 0.60
para_bold.jbalance = 60
define para_italic : Object.create para_regular
para_italic.italicangle = 10
define para_bolditalic : Object.create para_bold
para_bolditalic.italicangle = 10
para = para_bolditalic
define variantSelector (
.zero 'slashed'
)
define globalTransform (
.xx 1
.yx [Math.tan [para.italicangle / 180 * Math.PI]]
.xy 0
.yy 1
.x 0
.y 0
)
define ITALICCOR : 1 / [Math.sqrt [1 - globalTransform.yx * globalTransform.yx]]
define UPWARD (.x [-ITALICCOR] .y 0)
define DOWNWARD (.x ITALICCOR .y 0)
define RIGHTWARD (.x globalTransform.yx .y 1)
define LEFTWARD (.x [- globalTransform.yx] .y [-1])
# metrics
define DESCENDER para.descender
define WIDTH para.width
define CAP para.cap
define XH para.xheight
define O para.o
define OXHOOK para.oxhook
define SB para.sb
define HOOK para.hook
define AHOOK para.ahook
define SHOOK para.shook
define RHOOK para.rhook
define SMOOTH para.smooth
define SMALLSMOOTH para.smallsmooth
define STROKE para.stroke
define DOTSIZE para.dotsize
define BARPOS para.barpos
define GBARPOS para.gbarpos
define LONGSERIF para.longserif
define ACCENT para.accent
# derived metrics
define XO : XH - O
define CAPO : CAP - O
define HALFSTROKE : STROKE / 2
define RIGHTSB : WIDTH - SB
define MIDDLE : WIDTH / 2
define CAPMIDDLE : CAP / 2
define CAP_SMOOTH : CAP - SMOOTH
define DOTRADIUS : para.dotsize / 2
define SMOOTHA : SMOOTH - globalTransform.yx * para.smoothadjust
define SMOOTHB : SMOOTH + globalTransform.yx * para.smoothadjust
define SMALLSMOOTHA : SMALLSMOOTH - globalTransform.yx * para.smoothadjust
define SMALLSMOOTHB : SMALLSMOOTH + globalTransform.yx * para.smoothadjust
define ITALICCORS : STROKE * globalTransform.yx
# style parameters
define KAPPA para.kappa
define COKAPPA : 1 - KAPPA
define BKAPPA : KAPPA + 0.1
define COBKAPPA : 1 - BKAPPA
define KAPPA_HOOK : para.kappa_hook || 0.7
define KAPPA_AHOOK : para.kappa_ahook || KAPPA_HOOK
define TAILADJX : WIDTH * 0.2
define TAILADJY : XH * 0.25
define TAILADJKAPPA 0.75
define TAILADJSX : WIDTH * 0.2
define TAILADJSY 0
define TAILADJSKAPPA 0.75
define ILBALANCE : LONGSERIF * 0.04
define JBALANCE : para.jbalance || HALFSTROKE + ILBALANCE
define TBALANCE : para.tbalance || JBALANCE
define TBALANCE2 : para.tbalance2 || TBALANCE
# Anchor parameters
define BASE 'base'
define MARK 'mark'
define MARKBASE 'markbase'
define [tm anchor] : return (
.x [anchor.x * globalTransform.xx + anchor.y * globalTransform.yx + globalTransform.x]
.y [anchor.x * globalTransform.xy + anchor.y * globalTransform.yy + globalTransform.y]
.type anchor.type
)
define markAboveLower (.anchors (.above [tm (.x MIDDLE .y XH .type BASE)]))
define markAboveCap (.anchors (.above [tm (.x MIDDLE .y CAP .type BASE)]))
define markBelowLower (.anchors (.below [tm (.x MIDDLE .y DESCENDER .type BASE)]))
define markBelowZero (.anchors (.below [tm (.x MIDDLE .y 0 .type BASE)]))
define capitalMarks (.anchors (.above markAboveCap.anchors.above .below markBelowZero.anchors.below))
define bMarks (.anchors (.above markAboveCap.anchors.above .below markBelowZero.anchors.below))
define eMarks (.anchors (.above markAboveLower.anchors.above .below markBelowZero.anchors.below))
define pMarks (.anchors (.above markAboveLower.anchors.above .below markBelowLower.anchors.below))
define ifMarks (.anchors (.above markAboveCap.anchors.above .below markBelowLower.anchors.below))
Stroke.bindParameters para
### Useful shapes
define [Ring u d l r] : begin {
local my [[u + d] / 2]
local mx [[l + r] / 2]
local s : new Stroke
:.set-transform globalTransform
:.start-from mx d
:.cubic-to [mx + [l - mx] * BKAPPA] d l [my + [d - my] * BKAPPA] l my
:.cubic-to l [my + [u - my] * BKAPPA] [mx + [l - mx] * BKAPPA] u mx u
:.cubic-to [mx + [r - mx] * BKAPPA] u r [my + [u - my] * BKAPPA] r my
:.cubic-to r [my + [d - my] * BKAPPA] [mx + [r - mx] * BKAPPA] d mx d
return s.points
}
define [ORing u d l r smooth] : begin {
local myu [u - smooth]
local myd [d + smooth]
local mx [[l + r] / 2]
local s : new Stroke
:.set-transform globalTransform
:.start-from mx d
:.cubic-to [mx + [l - mx] * BKAPPA] d l [myd + [d - myd] * BKAPPA] l myd
:.line-to l myu
:.cubic-to l [myu + [u - myu] * BKAPPA] [mx + [l - mx] * BKAPPA] u mx u
:.cubic-to [mx + [r - mx] * BKAPPA] u r [myu + [u - myu] * BKAPPA] r myu
:.line-to r myd
:.cubic-to r [myd + [d - myd] * BKAPPA] [mx + [r - mx] * BKAPPA] d mx d
return s.points
}
define [leftwardTopSerif x y length] : begin {
return : new Stroke
:.set-transform globalTransform
:.start-from [x + HALFSTROKE] y
:.heads-to LEFTWARD
:.set-width STROKE 0
:.line-to [x - length - globalTransform.yx * STROKE] y
:.to-outline
}
define [leftwardBottomSerif x y length] : begin {
return : new Stroke
:.set-transform globalTransform
:.start-from [x + HALFSTROKE] y
:.heads-to LEFTWARD
:.set-width 0 STROKE
:.line-to [x - length + globalTransform.yx * STROKE] y
:.to-outline
}
define [rightwardTopSerif x y length] : begin {
return : new Stroke
:.set-transform globalTransform
:.start-from [x - HALFSTROKE] y
:.heads-to RIGHTWARD
:.set-width 0 STROKE
:.line-to [x + length - globalTransform.yx * STROKE] y
:.to-outline
}
define [rightwardBottomSerif x y length] : begin {
return : new Stroke
:.set-transform globalTransform
:.start-from [x - HALFSTROKE] y
:.heads-to RIGHTWARD
:.set-width STROKE 0
:.line-to [x + length + globalTransform.yx * STROKE] y
:.to-outline
}
define-macro glyph-construction : syntax-rules {
@`[glyph-construction @::steps] ('.syntactic-closure' @`[lambda [] [begin {
local set-width : this.set-width.bind this
local assign-unicode : this.assign-unicode.bind this
local start-from : this.start-from.bind this
local line-to : this.line-to.bind this
local curve-to : this.curve-to.bind this
local cubic-to : this.cubic-to.bind this
local put-shapes : this.put-shapes.bind this
local reverse-last : this.reverse-last.bind this
local include : this.include.bind this
local create-stroke : this.create-stroke.bind this
local set-anchor : this.set-anchor.bind this
this.gizmo = globalTransform
this.set-width WIDTH
begin @::[steps.map formOf]
return nothing
}]] env)
}
define [create-glyph name actions] : begin {
define glyphObject [new Glyph name]
glyphList.push glyphObject
glyphs`name = glyphObject
actions.call glyphObject
return glyphObject
}
###### SYMBOLS
create-glyph 'space' : glyph-construction {
set-width WIDTH
assign-unicode ' '
}
create-glyph 'bar' : glyph-construction {
set-width WIDTH
assign-unicode '|'
put-shapes : create-stroke :.start-from MIDDLE [DESCENDER / 2]
:.set-width [STROKE / 2] [STROKE / 2]
:.line-to MIDDLE [CAP - DESCENDER / 2]
:.to-outline
}