uahgi2/expander.rkt

62 lines
2 KiB
Racket
Raw Normal View History

2025-09-29 22:12:15 +08:00
2025-10-07 01:37:09 +08:00
(module uahgi2 racket/base
(require racket/dict)
(define main-config (make-hash
'(["paper-width". 2480]
["paper-height". 3508]
2025-10-07 02:41:00 +08:00
["lang" . #f]
2025-10-07 01:37:09 +08:00
["font-family" . "FreeSerif"]
["font-family-CJK" . "Noto Sans CJK TC"]
["font-size" . 14]
["font-weight" . "regular"]
["font-style" . "normal"]
)))
(define main-frame (make-hash
'(["id" . 1]
["font-family" . (dict-ref main-config "font-family")]
["class" . frame]
["width" . 2000]
["height" . 3000]
["x" . 200]
["y" . 250]
["content" . #f])))
(define (set-main-config attr val)
(dict-set! main-config attr val))
(define (main-text txt)
2025-10-07 02:41:00 +08:00
(begin
(dict-set! main-frame "content" txt)
(for/list ([p plugin-list])
[if (memq (dict-ref p "lang") (dict-ref main-config "lang"))
[let ([tmp ((dict-ref p "body") (dict-ref main-frame "content"))])
(dict-set! main-frame "content" tmp)] #f])))
2025-10-07 01:37:09 +08:00
(define-syntax text-series
(syntax-rules ()
[(_ x ...)
; delete the beginning newline
(if (eq? (caar `(x ...)) "\n")
`('text ,(cdar `(x ...)))
2025-10-07 02:41:00 +08:00
`('text ,(caar `(x ...)) ,(cdar `(x ...))))]))
(define plugin-list '())
(define plugin-test (make-hash `(["lang" . "zh"]
["body" . ,(lambda (x) "result:foo")])))
(set! plugin-list (reverse (cons plugin-test (reverse plugin-list))))
2025-10-07 01:37:09 +08:00
(provide text-series main-text main-frame main-config set-main-config set!
(all-from-out racket/base) (all-from-out racket/dict)
#%module-begin #%app #%datum #%expression #%top)
2025-10-07 02:41:00 +08:00
)