main
Matthew Butterick 5 years ago
parent 1ea67cbecb
commit 573804651d

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -71,6 +71,7 @@
draw-end ; func called at the end of every draw event (for teardown ops)
id
)
#:mutable
#:transparent
#:property prop:custom-write
(λ (q p w?) (display

@ -246,11 +246,17 @@
(define (space-quad? q) (equal? (quad-elems q) (list " ")))
(define (fill-wrap qs ending-q line-q)
(match (and (pair? qs) (quad-ref (car qs) (if ending-q
(define (fill-line-wrap qs ending-q line-q)
(let loop ([align-value (and (pair? qs)
(quad-ref (car qs) (if ending-q
:line-align
:line-align-last) "left"))
[align-value
:line-align-last) "left"))])
(match align-value
;; for inner & outer: pretend we're on right-side page now,
;; adjust later when actual page side is known
["inner" (loop "left")]
["outer" (loop "right")]
[_
;; words may still be in hyphenated fragments
;; (though soft hyphens would have been removed)
;; so group them (but no need to consolidate — that happens elsewhere)
@ -293,25 +299,30 @@
#:to 'bi
#:draw-end q:string-draw-end
#:size (pt justified-space-width line-height)))))]
[(equal? align-value "left") qs] ; no filling needed
[else
(define space-multiplier (match align-value
["left" 0]
["center" 0.5]
["right" 1]))
;; subtact space-width because that appears between words
;; we only care about redistributing the space on the ends
(define end-hspace (- empty-hspace word-space-width))
; make filler a leading quad, not a parent / grouping quad,
;; make filler a leading quad, not a parent / grouping quad,
;; so that elements can still be reached by consolidate-runs
(list* (make-quad #:type filler-quad
(define fq (make-quad #:type filler-quad
#:id 'line-filler
#:from-parent (quad-from-parent (car qs))
#:from 'bo
#:to 'bi
#:size (pt (* end-hspace space-multiplier) 0)
#:attrs (quad-attrs (car qs)))
(quad-copy (car qs) [from-parent #f])
(cdr qs))])])]))
#:attrs (let ([attrs (quad-attrs (car qs))])
(hash-set! attrs 'end-hspace end-hspace)
attrs)))
(list* fq
(let ([q (car qs)])
(set-quad-from-parent! q #f)
q)
(cdr qs))])])])))
(define-quad offsetter-quad quad ())
@ -344,7 +355,7 @@
(define pcs-with-hyphen (render-hyphen pcs-printing ending-q))
;; fill wrap so that consolidate-runs works properly
;; (justified lines won't be totally consolidated)
(define pcs (fill-wrap pcs-with-hyphen ending-q line-q))
(define pcs (fill-line-wrap pcs-with-hyphen ending-q line-q))
(match (consolidate-runs pcs ending-q)
[(? pair? elems)
(define elem (unsafe-car elems))
@ -628,6 +639,8 @@
;; can be repeated without damage.
[((? null?) _) null]
[((cons q rest) where)
#;(set-quad-from-parent! q (or where (quad-from q)))
#;(cons q rest)
(cons (quad-copy q [from-parent (or where (quad-from q))]) rest)])
(define ((col-finish-wrap col-quad) lns . _)

@ -281,8 +281,23 @@
(cons new-section sections-acc)])
(section-pages-used (+ (section-pages-used) (length section-pages))))))
(define doc (time-log position (position (struct-copy quad q:doc [elems sections]))))
(time-log draw (draw doc (current-pdf))))
(define doc (struct-copy quad q:doc [elems sections]))
#;(for* ([(page page-idx) (in-indexed (for*/list ([section (in-list (quad-elems doc))]
[page (in-list (quad-elems section))])
page))]
[col (in-list (quad-elems page))]
[line (in-list (quad-elems col))])
(define side (if (odd? (add1 page-idx)) 'right 'left))
(when (eq? side 'left)
(match (quad-elems line)
[(cons (? filler-quad? fq) _)
(match (quad-ref line :line-align)
["inner" (set-quad-size! fq (pt (quad-ref fq 'end-hspace) 0))] ;; change filler to right-align
["outer" (set-quad-size! fq (pt 0 0))] ;; change filler to 0
[_ (void)])]
[_ (void)])))
(define positioned-doc (time-log position (position doc)))
(time-log draw (draw positioned-doc (current-pdf))))
(if pdf-path-arg
(log-quadwriter-info (format "wrote PDF to ~a" pdf-path))

Loading…
Cancel
Save