From 87c921550e6713eaf33037afb753687f344d54db Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 17 Mar 2018 23:18:17 -0700 Subject: [PATCH] fontsize & baseline --- quad/quad/position.rkt | 3 ++- quad/quad/typewriter-test.rkt | 2 +- quad/quad/typewriter.rkt | 16 +++++++++------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/quad/quad/position.rkt b/quad/quad/position.rkt index 76e56332..2de1b445 100644 --- a/quad/quad/position.rkt +++ b/quad/quad/position.rkt @@ -32,7 +32,8 @@ (unitsPerEm (openSync p))) (define (fontsize q) - (hash-ref (attrs q) 'fontsize 0)) + (define val (hash-ref (attrs q) 'fontsize 0)) + ((if (number? val) values string->number) val)) (define/contract (anchor->point q anchor) diff --git a/quad/quad/typewriter-test.rkt b/quad/quad/typewriter-test.rkt index 1d0aaf83..dcfc7869 100644 --- a/quad/quad/typewriter-test.rkt +++ b/quad/quad/typewriter-test.rkt @@ -1,3 +1,3 @@ #lang quad/typewriter -◊quad[#:link "http://beautfifulracket.com"]{An expression that} is not a value can ◊quad[#:fontsize "22"]{always} ◊quad[#:fontsize "7"]{be partitioned} into two parts: a redex, which is the part that changed in a single-step simplification (highlighted), and the continuation, which is the evaluation context surrounding an expression. In (- 4 (+ 1 1)), the redex is (+ 1 1), and the continuation is (- 4 []), where [] takes the place of the redex. That is, the continuation says how to "continue" after the redex is reduced to a value." \ No newline at end of file +◊quad[#:link "http://beautfifulracket.com"]{An expression that} is not a value can ◊quad[#:fontsize "22"]{always} certainly ◊quad[#:fontsize "7"]{be partitioned} into two parts \ No newline at end of file diff --git a/quad/quad/typewriter.rkt b/quad/quad/typewriter.rkt index 60c07b70..18dbe666 100644 --- a/quad/quad/typewriter.rkt +++ b/quad/quad/typewriter.rkt @@ -1,8 +1,12 @@ #lang debug br/quicklang (require racket/promise racket/list sugar/list sugar/debug "quad.rkt" "atomize.rkt" "break.rkt" "qexpr.rkt" "generic.rkt" "position.rkt") (require pitfall/document) +(require hyphenate racket/runtime-path pollen/unstable/typography pollen/tag) (provide (rename-out [mb #%module-begin]) (except-out (all-from-out br/quicklang) #%module-begin)) + +(define-runtime-path fira "fira.ttf") + (define soft-break? (λ (q) (and (quad? q) (memv (car (elems q)) '(#\space #\- #\u00AD))))) (struct $shim $quad () #:transparent) (struct $char $quad () #:transparent) @@ -10,12 +14,13 @@ (define char-sizes (make-hasheqv)) (define (charify q) ($char (hash-set* (attrs q) - 'in 'bi - 'out 'bo + 'in 'nw + 'out 'ne + 'font fira 'size (hash-ref! char-sizes (car (elems q)) (λ () (send util-doc fontSize (string->number (hash-ref (attrs q) 'fontsize "12"))) - (send util-doc font "Courier") + (send util-doc font fira) (list (send util-doc widthOfString (apply string (elems q))) (send util-doc currentLineHeight)))) @@ -102,12 +107,9 @@ (position ($doc (hasheq 'origin '(36 36)) (page-wrap (line-wrap (map charify (atomize qarg)) line-width) lines-per-page)))) -(require hyphenate racket/runtime-path pollen/unstable/typography pollen/tag) - (provide quad) (define quad (default-tag-function 'quad)) -(define-runtime-path fira "fira.ttf") (define-macro (mb . ARGS) (with-pattern ([PS (syntax-property #'ARGS 'ps)]) #'(#%module-begin @@ -120,7 +122,7 @@ (send* doc [pipe (open-output-file PS #:exists 'replace)] [registerFont "Fira" (path->string fira)] - [font "Courier"] + [font "Fira"] [fontSize 12]) (draw q doc) (send doc end))