multiple sections and `page-side-start` attribute (closes #26)

main
Matthew Butterick 5 years ago
parent 8651cd1441
commit 4604b1148b

@ -4,4 +4,4 @@
'(q ((break "section")))
'(q ((page-width "5in")(page-height "3in")) "Second")
'(q ((page-width "5in")(page-height "5in")(page-number-start "5")(page-side-start "right")) "Second")

@ -444,6 +444,13 @@ The @tech{Q-expression} @racketresult['#,para-break]. Used to denote the start o
}
@defthing[section-break qexpr?]{
The @tech{Q-expression} @racketresult['#,section-break]. Used to denote the start of a new section.
A section is a contiguous series of pages. Each section has its own @secref{Page-level_attributes}. A document without any explicit section breaks still has one section (that includes all the pages).
}
@subsection{Attributes}
These are the attributes that can be used inside a @tech{Q-expression} passed to @racketmodname[quadwriter]. Inside a Q-expression, every attribute is a @tech[#:doc '(lib "scribblings/guide/guide.scrbl")]{symbol}, and every attribute value is a @tech[#:doc '(lib "scribblings/guide/guide.scrbl")]{string}.
@ -481,7 +488,11 @@ Inset values from the page edges. Value is given as a @tech{dimension string}. D
}
@defthing[#:kind "attribute" page-number-start symbol?]{
First page number used in document.
First page number used. Default is @racket[1].
}
@defthing[#:kind "attribute" page-side-start symbol?]{
Side that first page appears on. Can be @racket['left] or @racket['right]. A blank page will be inserted if necessary. Default is @racket['right].
}
@deftogether[(@defthing[#:kind "attribute" column-count symbol?]

@ -147,7 +147,9 @@ Naming guidelines
page-height
page-size ; e.g., "letter"
page-orientation ; only applies to page-size dimensions
page-number-start ; 1
page-side-start ; 'right
page-margin-top
page-margin-bottom

@ -10,6 +10,8 @@
(define current-doc (make-parameter #false))
(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-page-count (make-parameter 0))
(define quadwriter-test-mode (make-parameter #f)) ; used during rackunit to suppress nondeterministic elements, like timestamp in header
(define draw-debug? (make-parameter #true))
@ -32,6 +34,8 @@
(define current-doc (make-parameter #false))
(define current-pdf (make-parameter #false))
(define current-line-wrap (make-parameter #f))
(define current-page-count (make-parameter 0))
(define quadwriter-test-mode (make-parameter #f))
(define draw-debug? (make-parameter #false))

@ -169,7 +169,8 @@
(define (setup-column-gap qs)
(or (debug-column-gap) (quad-ref (car qs) :column-gap default-column-gap)))
(define/contract (render-pdf qx-arg pdf-path-arg [base-dir-arg #f]
(define/contract (render-pdf qx-arg pdf-path-arg
[base-dir-arg #false]
#:replace [replace-existing-file? #t]
#:compress [compress? #t])
((qexpr? (or/c #false path? path-string?))
@ -194,6 +195,7 @@
;; set `current-directory` so that ops like `path->complete-path`
;; will be handled relative to the original directory
[current-directory base-dir]
[current-page-count 0]
[verbose-quad-printing? #false])
(define qs (time-log setup-qs (setup-qs qx-arg pdf-path)))
(define sections
@ -216,9 +218,24 @@
(define page-quad-prototype (struct-copy quad q:page
[shift (pt left-margin top-margin)]
[size (pt line-wrap-size printable-height)]))
(define page-qs (time-log page-wrap (page-wrap column-qs printable-width page-quad-prototype)))
(struct-copy quad q:section [elems page-qs])))
(define next-page-side (if (even? (add1 (current-page-count))) 'left 'right))
(define insert-blank-page?
(and (pair? qs)
(let ([section-starting-side (string->symbol (quad-ref (car qs) :page-side-start "right"))])
;; if we need a 'left page and will get 'right (or vice versa) then insert page
(not (eq? section-starting-side next-page-side)))))
(define page-qs
(match (time-log page-wrap (page-wrap column-qs printable-width page-quad-prototype))
[ps #:when insert-blank-page?
(define blank-page (struct-copy quad (car ps) [elems null]))
(cons blank-page ps)]
[ps ps]))
(begin0
(struct-copy quad q:section [elems page-qs])
(current-page-count (+ (current-page-count) (length page-qs))))))
(define doc (time-log position (position (struct-copy quad q:doc [elems sections]))))
(time-log draw (draw doc (current-pdf))))

Loading…
Cancel
Save