You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
typesetting/fontland/fontland/path.rkt

45 lines
1.3 KiB
Racket

#lang debug racket
(require sugar/unstable/dict
(for-syntax racket/syntax))
(provide (all-defined-out))
#|
approximates
https://github.com/mbutterick/fontkit/blob/master/src/glyph/Path.js
|#
#|
/**
* Path objects are returned by glyphs and represent the actual
* vector outlines for each glyph in the font. Paths can be converted
* to SVG path data strings, or to functions that can be applied to
* render the path to a graphics context.
*/
|#
(struct Path$ (commands _bbox _cbox) #:transparent #:mutable)
(define (Path [commands null] [_bbox #false] [_cbox #false])
(Path$ commands _bbox _cbox))
(define-syntax (define-command stx)
(syntax-case stx ()
[(_ COMMAND)
(with-syntax [(ID (format-id #'COMMAND (format "path-~a" (syntax-e #'COMMAND))))]
#'(define (ID this . args)
(set-Path$-_bbox! this #false)
(set-Path$-_cbox! this #false)
(set-Path$-commands! this
(append
(Path$-commands this)
(list
(dictify
'command 'COMMAND
'args args))))
this))]))
(define-command moveTo)
(define-command lineTo)
(define-command quadraticCurveTo)
(define-command bezierCurveTo)
(define-command closePath)