|
|
|
@ -126,9 +126,9 @@
|
|
|
|
|
(define indented-qs (insert-first-line-indents typed-quads))
|
|
|
|
|
indented-qs)
|
|
|
|
|
|
|
|
|
|
(define (setup-margins qs pdf)
|
|
|
|
|
(define default-side-margin (min (* 72 1.5) (floor (* .20 (pdf-width pdf)))))
|
|
|
|
|
(define default-top-margin (min 72 (floor (* .10 (pdf-height pdf)))))
|
|
|
|
|
(define (setup-margins qs page-width page-height)
|
|
|
|
|
(define default-side-margin (min (* 72 1.5) (floor (* .20 page-width))))
|
|
|
|
|
(define default-top-margin (min 72 (floor (* .10 page-height))))
|
|
|
|
|
|
|
|
|
|
;; if only left or right margin is provided, copy other value in preference to default margin
|
|
|
|
|
(define left
|
|
|
|
@ -169,21 +169,22 @@
|
|
|
|
|
(and (pair? qs) (match (quad-ref (car qs) k)
|
|
|
|
|
[#false #false]
|
|
|
|
|
[val (inexact->exact (floor val))]))))
|
|
|
|
|
(resolve-page-size! the-pdf
|
|
|
|
|
(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? #t]
|
|
|
|
|
#:replace [replace-existing-file? #t]
|
|
|
|
|
#:compress [compress? #t])
|
|
|
|
|
((qexpr? (or/c #false path? path-string?)) (#:replace any/c
|
|
|
|
|
#:compress any/c) . ->* . (or/c void? bytes?))
|
|
|
|
|
|
|
|
|
|
(define pdf-path (setup-pdf-path pdf-path-arg))
|
|
|
|
|
(when (and (not replace?) (file-exists? pdf-path))
|
|
|
|
|
(raise-argument-error 'render-pdf "path that doesn't exist" pdf-path))
|
|
|
|
|
(unless replace-existing-file?
|
|
|
|
|
(when (file-exists? pdf-path)
|
|
|
|
|
(raise-argument-error 'render-pdf "path that doesn't exist" pdf-path)))
|
|
|
|
|
|
|
|
|
|
(define the-pdf (make-pdf #:compress compress?
|
|
|
|
|
#:auto-first-page #false
|
|
|
|
@ -192,11 +193,13 @@
|
|
|
|
|
[verbose-quad-printing? #false])
|
|
|
|
|
(define qs (time-log setup-qs (setup-qs qx-arg pdf-path)))
|
|
|
|
|
|
|
|
|
|
(set-page-size! the-pdf qs)
|
|
|
|
|
|
|
|
|
|
(match-define (list left-margin top-margin right-margin bottom-margin) (setup-margins qs (current-pdf)))
|
|
|
|
|
(define printable-width (- (pdf-width (current-pdf)) left-margin right-margin))
|
|
|
|
|
(define printable-height (- (pdf-height (current-pdf)) top-margin bottom-margin))
|
|
|
|
|
(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 left-margin top-margin right-margin bottom-margin)
|
|
|
|
|
(setup-margins qs page-width page-height))
|
|
|
|
|
(define printable-width (- page-width left-margin right-margin))
|
|
|
|
|
(define printable-height (- page-height top-margin bottom-margin))
|
|
|
|
|
(define column-count (setup-column-count qs))
|
|
|
|
|
(define column-gap (setup-column-gap qs))
|
|
|
|
|
|
|
|
|
@ -213,7 +216,7 @@
|
|
|
|
|
(define page-qs (time-log page-wrap (page-wrap column-qs printable-width page-quad-prototype)))
|
|
|
|
|
|
|
|
|
|
(define positioned-qs (time-log position (position (struct-copy quad q:doc [elems page-qs]))))
|
|
|
|
|
(time-log draw (draw positioned-qs (current-pdf))))
|
|
|
|
|
(time-log draw (draw positioned-qs (current-pdf)))))
|
|
|
|
|
|
|
|
|
|
(if pdf-path-arg
|
|
|
|
|
(log-quadwriter-info (format "wrote PDF to ~a" pdf-path))
|
|
|
|
|