per-page sizing

main
Matthew Butterick 5 years ago
parent 4b8e4c2992
commit 79b11ea75e

@ -472,8 +472,26 @@
(make-nobreak! ln)]))
(cons ln reversed-lines)))
(define default-page-size "letter")
(define default-page-orientation "tall")
(define (parse-page-size q)
;; page size can be specified by name, or measurements.
;; explicit measurements from page-height and page-width supersede those from page-size.
(match-define (list page-width page-height)
(for/list ([k (list :page-width :page-height)])
(and (quad? q) (match (quad-ref q k)
[#false #false]
[val (inexact->exact (floor val))]))))
(resolve-page-size
(or (debug-page-width) page-width)
(or (debug-page-height) page-height)
(quad-ref q :page-size default-page-size)
(quad-ref q :page-orientation default-page-orientation)))
(define (page-draw-start q doc)
(add-page doc)
(match-define (list page-width page-height) (parse-page-size q))
(add-page doc page-width page-height)
(scale doc (zoom-factor) (zoom-factor))
(draw-debug q doc "aliceblue" "aliceblue" 3))
@ -643,7 +661,10 @@
(match (quad-ref (car cols) :footer-display #true)
[(or #false "none") (from-parent cols 'nw)]
[_ (cons (make-footer-quad (car cols) page-idx path) (from-parent cols 'nw))]))
(list (quad-copy page-quad [elems elems])))
(list (quad-copy page-quad
[elems elems]
[attrs (copy-block-attrs (quad-attrs (car cols))
(hash-copy (quad-attrs page-quad)))])))
(define (page-wrap qs width [page-quad q:page])
(unless (positive? width)
@ -658,7 +679,7 @@
#:finish-wrap (page-finish-wrap page-quad (pdf-output-path (current-pdf)))))
(define (section-wrap qs)
qs)
(list qs))
(define (insert-blocks lines)
(define groups-of-lines (contiguous-group-by (λ (x) (quad-ref x :display)) lines))

@ -21,8 +21,7 @@
"log.rkt")
(provide (all-defined-out))
(define default-page-size "letter")
(define default-page-orientation "tall")
(define (setup-pdf-path pdf-path-arg)
(define fallback-path (build-path (find-system-path 'temp-dir) "quadwriter-temp.pdf"))
@ -161,20 +160,6 @@
(define (setup-column-gap qs)
(or (debug-column-gap) (quad-ref (car qs) :column-gap default-column-gap)))
(define (set-page-size! the-pdf qs)
;; page size can be specified by name, or measurements.
;; explicit measurements from page-height and page-width supersede those from page-size.
(match-define (list page-width page-height)
(for/list ([k (list :page-width :page-height)])
(and (pair? qs) (match (quad-ref (car qs) k)
[#false #false]
[val (inexact->exact (floor val))]))))
(resolve-page-size
(or (debug-page-width) page-width)
(or (debug-page-height) page-height)
(quad-ref (car qs) :page-size default-page-size)
(quad-ref (car qs) :page-orientation default-page-orientation)))
(define/contract (render-pdf qx-arg pdf-path-arg
#:replace [replace-existing-file? #t]
#:compress [compress? #t])
@ -195,7 +180,7 @@
(define sections (time-log section-wrap (section-wrap qs)))
(for ([qs (in-list sections)])
(match-define (list page-width page-height) (set-page-size! the-pdf qs))
(match-define (list page-width page-height) (parse-page-size (and (pair? qs) (car qs))))
(match-define (list left-margin top-margin right-margin bottom-margin)
(setup-margins qs page-width page-height))
(define printable-width (- page-width left-margin right-margin))

Loading…
Cancel
Save