Start making [draw], a "workflow"-based drawing macro.

This commit is contained in:
be5invis 2016-01-03 23:04:34 +08:00
parent f53369c7c9
commit 68ebc2ba2a
3 changed files with 85 additions and 31 deletions

View File

@ -136,6 +136,20 @@ define [includeGlyphPart cg gs nm] : begin
if [not gs.(nm)] : throw : new Error "Glyph \(nm) is not defined, which is used for \(cg.name)."
return : cg.include.apply cg [{gs.(nm)}.concat [{}.slice.call arguments 3]]
###### Canvas-based mechanism
define-macro draw : syntax-rules
`[draw @::steps] : begin
if [not externEnv.$nWFGlyphs$] : set externEnv.$nWFGlyphs$ 0
inc externEnv.$nWFGlyphs$
dirty `[[lambda [currentGlyph] [begin \\
if [not currentGlyph] : return nothing
if [glyphList.(glyphList.length - 1).name === @{".quote" (".WF" + externEnv.$nWFGlyphs$)}] : glyphList.pop
begin @::[steps.map formOf]
set dependencyProfile.(currentGlyph.name) : getDependencyProfile currentGlyph
return nothing
]] [create-glyph @{".quote" (".WF" + externEnv.$nWFGlyphs$)} [lambda]]]
define-macro save : syntax-rules
`[save @::args] : dirty `[$save$.call currentGlyph @::args]
### COMMON FUNCTIONS
define [mix a b p] : a + (b - a) * p
@ -385,6 +399,17 @@ export as build : define [buildFont para recursive recursiveCodes] : begin
glyphObject.gizmo = globalTransform
actions.call glyphObject
return glyphObject
define [$save$ name unicode] : begin
local t this
local g : create-glyph name [lambda]
if g : begin
g.include t AS_BASE
if name : set dependencyProfile.(name) : getDependencyProfile g
if (g && unicode) : begin
g.assign-unicode unicode
set unicodeGlyphs.(g.unicode.((g.unicode.length - 1))) g
return g
### Spiro constructions
# Basic knots

View File

@ -523,12 +523,25 @@ define [refair g] : begin
set g.contours.(j) : fairify g.contours.(j) globalTransform g.dense
return nothing
define [Fork gs params] : begin
local p : Object.create params
local shouldBuildList {}
foreach glyphid [items-of gs] : set shouldBuildList : shouldBuildList.concat {glyphid :: dependencyProfile.(glyphid)}
set shouldBuildList : shouldBuildList.filter : [x] -> [not [not x]]
# BFS construct ShouldBuildList
local sbh {.}
local found true
local PENDING 1
local CHECKED 2
foreach [glyphid : items-of gs] : set sbh.(glyphid) PENDING
while found : begin
set found false
foreach [glyphid : items-of : Object.keys sbh] : if (sbh.(glyphid) === PENDING) : begin
set sbh.(glyphid) CHECKED
if dependencyProfile.(glyphid) : foreach [k : items-of dependencyProfile.(glyphid)] : if [not sbh.(k)] : begin
set sbh.(k) PENDING
set found true
local shouldBuildList : Object.keys sbh :.filter ([x] -> [not [not x]])
local shouldBuildUnicodes : shouldBuildList.map ([x] -> [if (glyphs.(x) && glyphs.(x).unicode) glyphs.(x).unicode.0 nothing])
:.filter ([x] -> [not [not x]])
local p : Object.create params
try : begin
local forkFont : buildFont.call [TempFont] p shouldBuildList shouldBuildUnicodes
: ex

View File

@ -1723,14 +1723,23 @@ symbol-block 'g'
### O and o
symbol-block 'O'
create-glyph 'O' : glyph-construction
set-width WIDTH
assign-unicode 'O'
draw
include capitalMarks
include : OShape CAP 0 SB RIGHTSB nothing SMOOTHA SMOOTHB
alias 'Omicron' 0x39F 'O'
alias 'cyrO' 0x41E 'O'
save 'O' 'O'
save 'Omicron' 0x39F
save 'cyrO' 0x41E
# create-glyph 'O' : glyph-construction
# set-width WIDTH
# assign-unicode 'O'
# include capitalMarks
#
# include : OShape CAP 0 SB RIGHTSB nothing SMOOTHA SMOOTHB
# alias 'Omicron' 0x39F 'O'
# alias 'cyrO' 0x41E 'O'
create-glyph 'o' : glyph-construction
set-width WIDTH
@ -2419,11 +2428,15 @@ define {LongSShape} : symbol-block 'f'
curl MIDDLE (top - hooky)
straight.right.end (MIDDLE + hookx) (top - w / 2 - fovershoot)
create-glyph 'longs.italic' : glyph-construction
set-width WIDTH
draw 'esh'
include ifMarks
include : LongSShape CAP (-HOOK) HOOKX HOOK
save 'longs.italic'
save 'esh' 0x283
include : HOverlayBar (MIDDLE - LONGJUT * 0.6) (MIDDLE + LONGJUT * 0.6) (XH * 0.25)
save 'eshbar' 0x284
create-glyph 'longs' : glyph-construction
set-width WIDTH
assign-unicode 0x17F
@ -2431,16 +2444,7 @@ define {LongSShape} : symbol-block 'f'
if (para.isItalic)
then : include glyphs.'longs.italic' AS_BASE
else : include glyphs.'longs.upright' AS_BASE
create-glyph 'esh' : glyph-construction
assign-unicode 0x283
include glyphs.'longs.italic' AS_BASE
create-glyph 'eshbar' : glyph-construction
assign-unicode 0x284
include glyphs.esh AS_BASE
include : HOverlayBar (MIDDLE - LONGJUT * 0.6) (MIDDLE + LONGJUT * 0.6) (XH * 0.25)
create-glyph 'eshcurlytail' : glyph-construction
assign-unicode 0x286
include ifMarks
@ -2603,13 +2607,25 @@ define {SmallEShape} : symbol-block 'e'
g4 (RIGHTSB - OX * [if para.isItalic 0 0.5]) AHOOK
include : HBarBottom (SB + (stroke / 2) + OX) (RIGHTSB - (stroke / 2) - OX) barbottom stroke
create-glyph 'e' : glyph-construction
set-width WIDTH
assign-unicode 'e'
draw
include eMarks
include : SmallEShape XH STROKE
alias 'cyrie' 0x435 'e'
save 'e' 'e'
save 'cyrie' 0x435
#
include : FlipAround MIDDLE (XH / 2)
save 'turne' 0x1DD
save 'schwa' 0x259
save 'cyrschwa' 0x4D9
#create-glyph 'e' : glyph-construction
# set-width WIDTH
# assign-unicode 'e'
# include eMarks
#
# include : SmallEShape XH STROKE
#alias 'cyrie' 0x435 'e'
create-glyph 'turnSmallE' : glyph-construction
assign-unicode 0x18F
@ -2617,10 +2633,10 @@ define {SmallEShape} : symbol-block 'e'
include : SmallEShape CAP STROKE
include : FlipAround MIDDLE (CAP / 2)
turned nothing 0x1DD 'e' MIDDLE (XH / 2)
turned 'schwa' 0x259 'e' MIDDLE (XH / 2)
#turned nothing 0x1DD 'e' MIDDLE (XH / 2)
#turned 'schwa' 0x259 'e' MIDDLE (XH / 2)
alias 'cyrSchwa' 0x4D8 'turnSmallE'
alias 'cyrschwa' 0x4D9 'schwa'
#alias 'cyrschwa' 0x4D9 'schwa'
define [RevSmallEShape top stroke barpos] : glyph-construction
local barbottom (top * [fallback barpos EBARPOS] - HALFSTROKE)