From 522f882d76081dcea06120fd0c89b18ef1de1276 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 21 Feb 2015 16:13:14 -0800 Subject: [PATCH] pause point --- quad/wrap-typed.rkt | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/quad/wrap-typed.rkt b/quad/wrap-typed.rkt index 732b4d28..0b454ff7 100644 --- a/quad/wrap-typed.rkt +++ b/quad/wrap-typed.rkt @@ -319,9 +319,9 @@ (define/typed (measure-potential-line ps) ((Listof Quad) . -> . Flonum) (cast (for*/sum : (U Flonum Zero) - ([rendered-piece (in-list (render-pieces ps))] - [piece-quad (in-list (quad-list rendered-piece))]) - (quad-width (cast piece-quad Quad))) Flonum)) + ([rendered-piece (in-list (render-pieces ps))] + [piece-quad (in-list (quad-list rendered-piece))]) + (quad-width (cast piece-quad Quad))) Flonum)) (define/typed (vector-break-at vec bps) @@ -336,10 +336,10 @@ ;; makes a wrap function by combining component functions. (define/typed (make-wrap-proc - make-pieces-proc - measure-quad-proc - compose-line-proc - find-breakpoints-proc) + make-pieces-proc + measure-quad-proc + compose-line-proc + find-breakpoints-proc) ((Procedure Procedure Procedure Procedure) () . ->* . Procedure) (λ(qs [measure #f]) (let* ([measure (fl+ (fl (or measure (quad-attr-ref/parameter (car qs) world:measure-key))) 0.0)] @@ -369,3 +369,21 @@ (quad-attr-set* p 'bb-width before-break-width 'nb-width no-break-width)) +(define/typed (make-piece-vectors pieces) + ((Vectorof Quad) . -> . (values (Vectorof Flonum) (Vectorof Flonum))) + (define pieces-measured + (for/list : (Vector Flonum Flonum Flonum) ([p (in-vector pieces)]) + (define wb (quad-attr-ref p world:word-break-key #f)) + (vector + (apply + (for/list ([q (in-list (quad-list p))]) + (define str (quad->string q)) + (if (equal? str "") + (fl (quad-attr-ref q world:width-key 0.0)) + (apply measure-text (quad->string q) (font-attributes-with-defaults q))))) + (if wb (apply measure-text (quad-attr-ref wb world:no-break-key) (font-attributes-with-defaults wb)) 0.0) + (if wb (apply measure-text (quad-attr-ref wb world:before-break-key) (font-attributes-with-defaults wb)) 0.0)))) + (values + (for/vector : Flonum ([p (in-list pieces-measured)]) + (fl+ (vector-ref p 0) (vector-ref p 1))) ; first = word length, second = nb length + (for/vector : Flonum ([p (in-list pieces-measured)]) + (fl+ (vector-ref p 0) (vector-ref p 2))))) ; first = word length, third = bb length \ No newline at end of file