store global attrs in param

main
Matthew Butterick 4 years ago
parent 7aa542f286
commit 22610a8e17

Binary file not shown.

@ -57,15 +57,18 @@
(define (make-footer-quad col-q page-idx path)
(define-values (dir name _) (split-path (path-replace-extension path #"")))
(define attrs (let ([attrs (make-hasheq)])
(define attrs (let ([attrs (make-hasheq)]
[cltq (current-top-level-quad)])
(hash-set*! attrs
:footer-text (quad-ref col-q :footer-text)
:page-number (+ (quad-ref col-q :page-number-start (add1 (section-pages-used))) (sub1 page-idx))
:doc-title (string-titlecase (path->string name))
:font-size (* 0.8 (quad-ref col-q :font-size default-font-size))
:line-height (quad-ref col-q :line-height default-line-height)
:font-family "text")
(resolve-font-path! attrs)
;; we get font & line-height from cltq
;; because these are not block attrs
;; so they are not propagated upward from col-q
:font-size (* 0.8 (quad-ref cltq :font-size))
:line-height (quad-ref cltq :line-height)
:font-path (quad-ref cltq :font-path))
attrs))
(make-quad #:size (pt 50 default-line-height)
#:attrs attrs

@ -4,6 +4,7 @@
(define current-pdf (make-parameter #false))
(define current-line-wrap (make-parameter #f)) ; because kp is slow and maybe we want to disable for "draft" mode
(define current-top-level-quad (make-parameter #f))
(define section-pages-used (make-parameter 0))
(define quadwriter-test-mode (make-parameter #f)) ; used during rackunit to suppress nondeterministic elements, like timestamp in header

@ -172,10 +172,20 @@
;; convert our input Q-expression into a useful form.
;; some typographic niceties
(define qexpr (decode qx-arg
(define qexpr
(let ([qx (decode qx-arg
#:string-proc (compose1 smart-ellipses smart-dashes)
#:txexpr-proc smart-quotes))
#:txexpr-proc smart-quotes)])
(match qx
[(list tag attrs elements ...)
;; we insert a dummy element "◊" (irrelevant what it is)
;; to get a sample of the global attrs
;; which we will strip off after atomization
;; but keep the attrs around in case anyone needs to use them
;; for instance, quads added to the layout like footers
;; won't have another way of getting this
(list* tag attrs (cons "" elements))])))
;; apply some default styling attributes.
;; These will only be used if the underlying q-expression hasn't specified its own values,
;; which will naturally override these.
@ -194,6 +204,10 @@
#:emoji "fallback-emoji"
#:math "fallback-math"
#:font-path-resolver resolve-font-path!)]
[qs (let ()
;; store the dummy element and discard
(current-top-level-quad (car qs))
(cdr qs))]
[qs (time-log hyphenate (apply append (map handle-hyphenate qs)))]
[qs (map generic->typed-quad qs)]
[qs (drop-leading-breaks qs)]

Loading…
Cancel
Save