fewer assumptions

main
Matthew Butterick 4 years ago
parent 6cbb96f823
commit 550260e9c9

@ -379,23 +379,21 @@
(define (correct-line-alignment doc) (define (correct-line-alignment doc)
;; correct lines with inner / outer alignment ;; correct lines with inner / outer alignment
(for* ([(page page-idx) (in-indexed (for*/list ([section (in-list (quad-elems doc))] ;; all inner / outer lines are initially filled as if they were right-aligned
[page (in-list (quad-elems section))]) ;; on odd (right-hand) pages, inner becomes 0 (and on left-hand, outer becomes 0)
page))] (for* ([section (in-list (quad-elems doc))]
#:when (page-quad? page) [(page page-idx) (in-indexed (quad-elems section))]
;; all inner / outer lines are initially filled as if they were right-aligned #:when (page-quad? page))
[zero-filler-side (in-value (if (odd? (add1 page-idx)) "inner" "outer"))] (define right-side? (odd? (add1 page-idx)))
[col (in-list (quad-elems page))] (define zero-filler-side (if right-side? "inner" "outer"))
#:when (column-quad? col) (let loop ([x page])
[block (in-list (quad-elems col))] (cond
#:when (block-quad? block) [(and (line-quad? x)
[line (in-list (quad-elems block))] (equal? zero-filler-side (quad-ref x :line-align))
#:when (line-quad? line)) (filler-quad? (car (quad-elems x))))
(when (equal? zero-filler-side (quad-ref line :line-align)) ;; collapse the filler quad by setting size to 0
(match (quad-elems line) (set-quad-size! (car (quad-elems x)) (pt 0 0))]
;; collapse the filler quad by setting size to 0 [(quad? x) (for-each loop (quad-elems x))])))
[(cons (? filler-quad? fq) _) (set-quad-size! fq (pt 0 0))]
[_ (void)])))
doc) doc)
(define/contract (render-pdf qx-arg (define/contract (render-pdf qx-arg

Loading…
Cancel
Save