diff --git a/quad/qtest/fark.rkt b/quad/qtest/fark.rkt index 3419f884..d6fbbb46 100644 --- a/quad/qtest/fark.rkt +++ b/quad/qtest/fark.rkt @@ -1,5 +1,5 @@ #lang qtest/markdown -hello +x -> world \ No newline at end of file +y \ No newline at end of file diff --git a/quad/qtest/markdown.rkt b/quad/qtest/markdown.rkt index 4c388802..80d97564 100644 --- a/quad/qtest/markdown.rkt +++ b/quad/qtest/markdown.rkt @@ -442,7 +442,7 @@ naive approach works but: ;; could do it after, but it would require going back inside each page quad ;; which seems overly interdependent, because `insert-blocks` is used to determine break locations. ;; `page-wrap` should emit quads that are complete. - (wrap #R xs vertical-height + (wrap xs vertical-height #:soft-break (λ (q) #true) #:no-break (λ (q) (quad-ref q 'no-pbr)) #:distance (λ (q dist-so-far wrap-qs) diff --git a/quad/quad/wrap.rkt b/quad/quad/wrap.rkt index fc0eb56d..8a5545b2 100644 --- a/quad/quad/wrap.rkt +++ b/quad/quad/wrap.rkt @@ -181,6 +181,8 @@ previous-wrap-ender other-qs)])])]))) +(define last-line-can-be-short? #t) +(define mega-penalty 1e8) (define (wrap-best qs max-distance-proc debug hard-break? soft-break? finish-wrap wrap-count distance-func initial-wrap-idx) (struct $penalty (val idx) #:transparent) (define (penalty i j) @@ -190,9 +192,9 @@ (define out-of-bounds-signal (- i)) ($penalty out-of-bounds-signal last-idx)] [else - (define would-be-wrap-qs (pieces-sublist i j)) (define last-q (last (vector-ref pieces (sub1 j)))) (define wrap-idx (wrap-count last-idx last-q)) + (define would-be-wrap-qs (pieces-sublist i j)) (define wrap-distance (for/fold ([last-dist 0]) ([q (in-list would-be-wrap-qs)]) (distance-func q last-dist would-be-wrap-qs))) @@ -200,11 +202,13 @@ (define underflow (- measure wrap-distance)) ($penalty (+ last-val ; include penalty so far - (if (negative? underflow) - ;; overfull line: huge penalty prevents break; multiplier is essential for monotonicity. - (* 1e8 (- underflow)) - ;; standard penalty - (expt underflow 2))) + (* wrap-idx mega-penalty) ; new line penalty + (cond + ;; overfull line: huge penalty prevents break; multiplier is essential for monotonicity. + [(negative? underflow) (* mega-penalty (- underflow))] + ;; standard penalty + [((if last-line-can-be-short? < <=) j (vector-length pieces)) (expt underflow 2)] + [else 0])) wrap-idx)])) (define ocm (make-ocm penalty ($penalty 0 (sub1 initial-wrap-idx)) $penalty-val))