main
Matthew Butterick 6 years ago
parent 94cf078315
commit e5284a6d76

@ -34,11 +34,11 @@
(define fontsize (string->number (hash-ref (attrs q) 'fontsize "12"))) (define fontsize (string->number (hash-ref (attrs q) 'fontsize "12")))
(define str (car (elems q))) (define str (car (elems q)))
(send* (current-doc) (send* (current-doc)
[fontSize fontsize] [font-size fontsize]
[font (path->string charter)]) [font (path->string charter)])
(list (list
(send (current-doc) widthOfString str) (send (current-doc) string-width str)
(send (current-doc) currentLineHeight))) (send (current-doc) current-line-height)))
'printable? (case (car (elems q)) 'printable? (case (car (elems q))
[(" " #\u00AD) (λ (sig) (memq sig '(end)))] [(" " #\u00AD) (λ (sig) (memq sig '(end)))]
[(" " #\space) (λ (sig) (not (memq sig '(start end))))] [(" " #\space) (λ (sig) (not (memq sig '(start end))))]
@ -46,7 +46,7 @@
'draw (λ (q doc) 'draw (λ (q doc)
(set! draw-counter (add1 draw-counter )) (set! draw-counter (add1 draw-counter ))
#;(draw-debug q doc) #;(draw-debug q doc)
(send doc fontSize (string->number (hash-ref (attrs q) 'fontsize "12"))) (send doc font-size (string->number (hash-ref (attrs q) 'fontsize "12")))
(let ([str (car (elems q))]) (let ([str (car (elems q))])
(cond (cond
[(hash-has-key? (attrs q) 'link) [(hash-has-key? (attrs q) 'link)
@ -95,9 +95,9 @@
(define (as-link doc str url-str [x 0] [y 0]) (define (as-link doc str url-str [x 0] [y 0])
(send doc save) (send doc save)
(send doc fillColor "blue") (send doc fill-color "blue")
(define width (send doc widthOfString str)) (define width (send doc string-width str))
(define height (send doc currentLineHeight)) (define height (send doc current-line-height))
(send doc text str x y) (send doc text str x y)
(send doc link x y width height url-str) (send doc link x y width height url-str)
(send doc restore)) (send doc restore))
@ -105,8 +105,8 @@
(define pb ($break (hasheq 'printable? #f (define pb ($break (hasheq 'printable? #f
'size '(0 0) 'size '(0 0)
'draw (λ (q doc) 'draw (λ (q doc)
(send doc addPage) (send doc add-page)
(send doc fontSize 10) (send doc font-size 10)
(define str (string-append "page " (number->string page-count))) (define str (string-append "page " (number->string page-count)))
;; page number ;; page number
(as-link doc str "https://practicaltypography.com" 10 10) (as-link doc str "https://practicaltypography.com" 10 10)
@ -141,16 +141,20 @@
(parameterize ([current-doc doc]) (parameterize ([current-doc doc])
(time-name config-doc (time-name config-doc
(send* doc (send* doc
[pipe (open-output-file path #:exists 'replace)] #;[pipe (open-output-file path #:exists 'replace)]
[font (path->string charter)] [font (path->string charter)]
[fontSize 12])) [font-size 12]))
;; 181127: with layout caching, draw takes about 1.5x linebreak; without, about 2x ;; 181127: with layout caching, draw takes about 1.5x linebreak; without, about 2x
(parameterize ([current-layout-caching #true]) ; from fontland/font (parameterize ([current-layout-caching #true]) ; from fontland/font
(define q (typeset qin)) (define q (typeset qin))
(report draw-counter) (report draw-counter)
(time-name draw (draw q doc)) (time-name draw
(report draw-counter) (with-output-to-file path
(time-name end-doc (send doc end))))) (λ ()
(draw q doc)
(send doc end))
#:exists 'replace))
(report draw-counter))))
(define-macro (mb . ARGS) (define-macro (mb . ARGS)
(with-syntax ([PS (syntax-property #'ARGS 'ps)] (with-syntax ([PS (syntax-property #'ARGS 'ps)]

Loading…
Cancel
Save