fix handling of justified spacers

these are new quads added the line so they need to observe the same line-height logic as the rest of the line. That means we don't just look at the line height of the line-quad prototype.
main
Matthew Butterick 3 years ago
parent 1c0b091b8d
commit c5555653fe

@ -75,13 +75,19 @@
(define (sum-sum-x qss) (define (sum-sum-x qss)
(for/sum ([qs (in-list qss)]) (for/sum ([qs (in-list qss)])
(sum-x qs))) (sum-x qs)))
(define (tracking-adjustment q) (define (tracking-adjustment q)
(match q (match q
[(? string-quad?) (/ (quad-ref q :font-tracking 0) 2.0)] [(? string-quad?) (/ (quad-ref q :font-tracking 0) 2.0)]
[_ 0])) [_ 0]))
(define (line-height-from-qs qs)
;; line height is the max 'line-height value or the natural height of q:line
(match (filter-map (λ (q) (or (quad-ref q :line-height) (pt-y (size q)))) qs)
[(? null?) #false]
[line-heights (apply max line-heights)]))
(define (fill-line-wrap all-qs line-prototype last-line-in-paragraph?) (define (fill-line-wrap all-qs line-prototype last-line-in-paragraph?)
;; happens during the finish of a line wrap, before consolidation of runs ;; happens during the finish of a line wrap, before consolidation of runs
(unless (pair? all-qs) (unless (pair? all-qs)
@ -134,12 +140,12 @@
;; which amounts to shrinking the word spaces till the line fits ;; which amounts to shrinking the word spaces till the line fits
(and line-overfull? (> nonspacess-count 1)))) (and line-overfull? (> nonspacess-count 1))))
(define justified-space-width (/ empty-hspace (sub1 nonspacess-count))) (define justified-space-width (/ empty-hspace (sub1 nonspacess-count)))
(cons (make-left-edge-filler) (define justified-spacer (make-quad
(apply append (add-between hung-nonspacess (list (make-quad #:from 'bo
#:from 'bo #:to 'bi
#:to 'bi #:draw-end q:string-draw-end
#:draw-end q:string-draw-end #:size (pt justified-space-width (or (line-height-from-qs (append* hung-nonspacess)) line-prototype-height))))
#:size (pt justified-space-width line-prototype-height))))))] (cons (make-left-edge-filler) (apply append (add-between hung-nonspacess (list justified-spacer))))]
[else [else
(define space-multiplier (match align-value (define space-multiplier (match align-value
["center" 0.5] ["center" 0.5]
@ -175,7 +181,7 @@
;; remove unused soft hyphens so they don't affect final shaping ;; remove unused soft hyphens so they don't affect final shaping
(define wrap-qs-printing (for/list ([wq (in-list wrap-qs)] (define wrap-qs-printing (for/list ([wq (in-list wrap-qs)]
#:unless (equal? (quad-elems wq) '("\u00AD"))) #:unless (equal? (quad-elems wq) '("\u00AD")))
wq)) wq))
(define new-lines (define new-lines
(cond (cond
[(empty? wrap-qs-printing) null] [(empty? wrap-qs-printing) null]
@ -200,10 +206,7 @@
(hash-ref! h :display default-block-id) (hash-ref! h :display default-block-id)
h)] h)]
;; line width is static ;; line width is static
;; line height is the max 'line-height value or the natural height of q:line [size (pt line-width (or (line-height-from-qs pcs) line-height))]
[size (pt line-width (match (filter-map (λ (q) (or (quad-ref q :line-height) (pt-y (size q)))) pcs)
[(? null?) line-height]
[line-heights (apply max line-heights)]))]
;; handle list indexes. drop new quad into line to hold list index ;; handle list indexes. drop new quad into line to hold list index
;; could also use this for line numbers ;; could also use this for line numbers
[elems [elems
@ -283,34 +286,34 @@
(define res (define res
(apply append (apply append
(for/list ([para-qs (in-list para-qss)]) (for/list ([para-qs (in-list para-qss)])
(define block-id (gensym)) (define block-id (gensym))
(match para-qs (match para-qs
[(? break-quad? bq) (list bq)] [(? break-quad? bq) (list bq)]
[(cons pq _) [(cons pq _)
(define line-q-for-this-paragraph (define line-q-for-this-paragraph
(quad-copy line-quad (quad-copy line-quad
q:line q:line
[size (pt wrap-size (quad-ref pq :line-height default-line-height))])) [size (pt wrap-size (quad-ref pq :line-height default-line-height))]))
(wrap para-qs (wrap para-qs
(* (- wrap-size (* (- wrap-size
(quad-ref pq :inset-left 0) (quad-ref pq :inset-left 0)
(quad-ref pq :inset-right 0)) (quad-ref pq :inset-right 0))
(permitted-justify-overfill pq)) (permitted-justify-overfill pq))
debug debug
;; during wrap, anchored qs are treated as having distance 0 ;; during wrap, anchored qs are treated as having distance 0
;; so they can staty in right place, so that relative queries will work. ;; so they can staty in right place, so that relative queries will work.
;; but they won't affect where lines break ;; but they won't affect where lines break
#:distance (λ (q last-dist wrap-qs) #:distance (λ (q last-dist wrap-qs)
(+ last-dist (cond (+ last-dist (cond
[(quad-ref q :parent) 0] [(quad-ref q :parent) 0]
[(printable? q) (distance q)] [(printable? q) (distance q)]
[else 0]))) [else 0])))
#:nicely (match (or (current-line-wrap) (quad-ref pq :line-wrap)) #:nicely (match (or (current-line-wrap) (quad-ref pq :line-wrap))
[(or "best" "kp") #true] [(or "best" "kp") #true]
[_ #false]) [_ #false])
#:hard-break line-break-quad? #:hard-break line-break-quad?
#:soft-break soft-break-for-line? #:soft-break soft-break-for-line?
#:finish-wrap (line-wrap-finish line-q-for-this-paragraph block-id))])))) #:finish-wrap (line-wrap-finish line-q-for-this-paragraph block-id))]))))
res] res]
[_ null])) [_ null]))

Loading…
Cancel
Save