start named quads

main
Matthew Butterick 5 years ago
parent 04a111f478
commit fd2818b853

@ -94,9 +94,9 @@
(define-syntax-rule (quad-copy QID [K V] ...)
(struct-copy quad QID [K V] ...))
(struct quad-attr (key default-val) #:transparent)
#;(struct quad-attr (key default-val) #:transparent)
(define (make-quad-attr key [default-val #f])
#;(define (make-quad-attr key [default-val #f])
(quad-attr key default-val))
(define (quad-ref q key-arg [default-val-arg #f])

@ -657,6 +657,7 @@
#:attrs attrs
#:from-parent 'sw
#:to 'nw
#:elems (or null (hash-ref (current-named-quads) "foo"))
#:shift (pt 0 (* 1.5 default-line-height))
#:printable #true
#:draw-start (λ (q doc)

@ -11,6 +11,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 section-pages-used (make-parameter 0))
(define current-named-quads (make-parameter #false))
(define quadwriter-test-mode (make-parameter #f)) ; used during rackunit to suppress nondeterministic elements, like timestamp in header
@ -35,6 +36,7 @@
(define current-pdf (make-parameter #false))
(define current-line-wrap (make-parameter #f))
(define section-pages-used (make-parameter 0))
(define current-named-quads (make-parameter #false))
(define quadwriter-test-mode (make-parameter #f))

@ -135,6 +135,13 @@
;; so if we invoke that style first, we will get a page break.
(dropf qs break-quad?))
(define (extract-defined-quads qs)
(define (get-define-val q) (quad-ref q 'define))
(define-values (dqs not-dqs) (partition get-define-val qs))
(for ([dq-group (in-list (group-by get-define-val dqs))])
(hash-set! (current-named-quads) (get-define-val (car dq-group)) dq-group))
not-dqs)
(define default-line-height-multiplier 1.42)
(define (setup-qs qx-arg base-dir)
;; convert our input Q-expression into a useful form.
@ -164,6 +171,7 @@
[qs (time-log hyphenate (apply append (map handle-hyphenate qs)))]
[qs (map generic->typed-quad qs)]
[qs (drop-leading-breaks qs)]
[qs (extract-defined-quads qs)]
[qs (insert-first-line-indents qs)])
qs))
@ -388,7 +396,8 @@
;; a lot of operations need to look at pages used so it's easier to
;; make it a parameter than endlessly pass it around as an argument.
[section-pages-used 0]
[verbose-quad-printing? #false]) ; for ease of debugging; not mandatory
[verbose-quad-printing? #false]
[current-named-quads (make-hash)]) ; for ease of debugging; not mandatory
(define qs (time-log setup-qs (setup-qs qx-arg base-dir)))
(setup-pdf-metadata! qs (current-pdf))
;; all the heavy lifting happens inside `make-sections`

Loading…
Cancel
Save