|
|
|
@ -158,7 +158,7 @@
|
|
|
|
|
;; ok to put back absolute quads at end, because it doesn't affect their layout
|
|
|
|
|
(append other-qs absolute-qs))])])]))
|
|
|
|
|
|
|
|
|
|
(define (make-paragraph-spacer maybe-first-line-q key default-val)
|
|
|
|
|
(define (make-paragraph-spacer maybe-first-line-q key default-val)
|
|
|
|
|
(define arbitrary-width 20)
|
|
|
|
|
(make-quad #:type line-spacer-quad
|
|
|
|
|
#:size (pt arbitrary-width (cond
|
|
|
|
@ -170,7 +170,7 @@
|
|
|
|
|
#:draw-start (if (draw-debug-line?) draw-debug void)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define ((line-wrap-finish line-prototype-q default-block-id) wrap-qs q-before q-after idx)
|
|
|
|
|
(define ((line-wrap-finish line-prototype-q default-block-id) wrap-qs q-before q-after idx)
|
|
|
|
|
;; we curry line-q so that the wrap size can be communicated to this operation
|
|
|
|
|
;; remove unused soft hyphens so they don't affect final shaping
|
|
|
|
|
(define wrap-qs-printing (for/list ([wq (in-list wrap-qs)]
|
|
|
|
@ -246,27 +246,29 @@
|
|
|
|
|
[_ null]))) ; hard line break
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define softies (map string '(#\space #\- #\u00AD)))
|
|
|
|
|
(define softies (map string '(#\space #\- #\u00AD)))
|
|
|
|
|
|
|
|
|
|
(define (soft-break-for-line? q)
|
|
|
|
|
(define (soft-break-for-line? q)
|
|
|
|
|
(and (pair? (quad-elems q))
|
|
|
|
|
(member (unsafe-car (quad-elems q)) softies)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (line-wrap qs wrap-size [debug #false])
|
|
|
|
|
(unless (positive? wrap-size)
|
|
|
|
|
(raise-argument-error 'line-wrap "positive number" wrap-size))
|
|
|
|
|
(match qs
|
|
|
|
|
[(cons q _)
|
|
|
|
|
(define line-q (quad-copy line-quad q:line [size (pt wrap-size (quad-ref q :line-height default-line-height))]))
|
|
|
|
|
(define permitted-justify-overfill
|
|
|
|
|
(define (permitted-justify-overfill q)
|
|
|
|
|
(match (quad-ref q :line-align)
|
|
|
|
|
;; allow justified lines to go wider,
|
|
|
|
|
;; and then fill-wrap will tighten thes word spaces
|
|
|
|
|
;; this makes justified paragraphs more even, becuase
|
|
|
|
|
;; some lines are a little tight, as opposed to all of them being loose
|
|
|
|
|
;; this has to be based on a certain quad, not set globally for the line-wrap operation,
|
|
|
|
|
;; because different paragraphs might have different alignment settings.
|
|
|
|
|
["justify" 1.04]
|
|
|
|
|
[_ 1]))
|
|
|
|
|
|
|
|
|
|
(define (line-wrap qs wrap-size [debug #false])
|
|
|
|
|
(unless (positive? wrap-size)
|
|
|
|
|
(raise-argument-error 'line-wrap "positive number" wrap-size))
|
|
|
|
|
(match qs
|
|
|
|
|
[(cons q _)
|
|
|
|
|
(define line-q (quad-copy line-quad q:line [size (pt wrap-size (quad-ref q :line-height default-line-height))]))
|
|
|
|
|
;; group lines into sublists separated by para-breaks, but then omit the para-breaks themselves
|
|
|
|
|
;; because they've served their purpose (leave the others, to be expressed later)
|
|
|
|
|
;; however, leave line-breaks in, because they will be handled by wrap.
|
|
|
|
@ -290,9 +292,8 @@
|
|
|
|
|
(* (- wrap-size
|
|
|
|
|
(quad-ref pq :inset-left 0)
|
|
|
|
|
(quad-ref pq :inset-right 0))
|
|
|
|
|
permitted-justify-overfill)
|
|
|
|
|
(permitted-justify-overfill pq))
|
|
|
|
|
debug
|
|
|
|
|
|
|
|
|
|
;; during wrap, anchored qs are treated as having distance 0
|
|
|
|
|
;; so they can staty in right place, so that relative queries will work.
|
|
|
|
|
;; but they won't affect where lines break
|
|
|
|
@ -310,4 +311,3 @@
|
|
|
|
|
res]
|
|
|
|
|
[_ null]))
|
|
|
|
|
|
|
|
|
|
|