From 20f5bc5ef22fcc7e780f0906c9f925886b6fb1b9 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 13 Mar 2019 15:05:52 -0700 Subject: [PATCH] toSVG --- fontland/fontland/path.rkt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/fontland/fontland/path.rkt b/fontland/fontland/path.rkt index fe6e52ce..97c28c44 100644 --- a/fontland/fontland/path.rkt +++ b/fontland/fontland/path.rkt @@ -22,6 +22,20 @@ https://github.com/mbutterick/fontkit/blob/master/src/glyph/Path.js (define (Path [commands null] [_bbox #false] [_cbox #false]) (Path$ commands _bbox _cbox)) +(define SVG_COMMANDS (hasheq 'moveTo "M" + 'lineTo "L" + 'quadraticCurveTo "Q" + 'bezierCurveTo "C" + 'closePath "Z")) + +(define (toSVG this) + (define cmds (for/list ([c (in-list (Path$-commands this))]) + (define args (for/list ([arg (in-list (dict-ref c 'args))]) + (round (/ (* arg 100) 100)))) + (format "~a~a" (hash-ref SVG_COMMANDS (dict-ref c 'command)) + (string-join (map ~a args) " ")))) + (string-join cmds "")) + (define-syntax (define-command stx) (syntax-case stx () [(_ COMMAND)