From 6ccf2fe7e91f647339f1cd85462aeb8cd5d5241e Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 15 Jan 2020 14:58:35 -0800 Subject: [PATCH] introduce font-case attribute --- quad/quad/scribblings/quad.scrbl | 4 ++++ quad/quadwriter/attrs.rkt | 1 + quad/quadwriter/layout.rkt | 20 +++++++++++++------- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/quad/quad/scribblings/quad.scrbl b/quad/quad/scribblings/quad.scrbl index 844770e3..9ee322a5 100644 --- a/quad/quad/scribblings/quad.scrbl +++ b/quad/quad/scribblings/quad.scrbl @@ -662,6 +662,10 @@ Space between characters. Value is a @tech{dimension string}. Vertical offset of font baseline (positive values move the baseline up, negative down). Value is a @tech{dimension string}. } +@defthing[#:kind "attribute" font-case symbol?]{ +Case transformation of string. Possibilities are @racket["upper"], @racket["lower"], or @racket["title"]. +} + @deftogether[(@defthing[#:kind "attribute" line-height symbol?] @defthing[#:kind "attribute" line-height-adjust symbol?])]{ Two ways of setting the distance between baselines. @racket[line-height] takes a @tech{dimension string}. @racket[line-height-adjust] takes a string representing a percentage (like @racket["120%"]) and sets the line height to the line height of the parent, multiplied by the percentage. diff --git a/quad/quadwriter/attrs.rkt b/quad/quadwriter/attrs.rkt index 26a1db36..865b2d11 100644 --- a/quad/quadwriter/attrs.rkt +++ b/quad/quadwriter/attrs.rkt @@ -74,6 +74,7 @@ Naming guidelines font-bold font-tracking font-baseline-shift + font-case bg link href diff --git a/quad/quadwriter/layout.rkt b/quad/quadwriter/layout.rkt index cf9afc66..354ff18e 100644 --- a/quad/quadwriter/layout.rkt +++ b/quad/quadwriter/layout.rkt @@ -87,11 +87,11 @@ [str (font-size pdf (quad-ref q :font-size default-font-size)) (font pdf (path->string (quad-ref q font-path-key default-font-face))) - (define ft-value (quad-ref q :font-tracking 0)) + (define tracking-val (quad-ref q :font-tracking 0)) (match str - ["\u00AD" ft-value] + ["\u00AD" tracking-val] [_ (+ (string-width pdf str - #:tracking ft-value + #:tracking tracking-val #:features (quad-ref q :font-features default-font-features)))])] [else 0])) (list string-size (quad-ref q :line-height default-line-height)))) @@ -148,13 +148,19 @@ (and (line-break-quad? q) q)) (define (do-string-quad q) + ;; need to handle casing here so that it's reflected in sizing ops + (define cased-str ((match (quad-ref q :font-case) + [(or "upper" "uppercase") string-upcase] + [(or "lower" "lowercase" "down" "downcase") string-downcase] + [(or "title" "titlecase") string-titlecase] + [_ values]) (unsafe-car (quad-elems q)))) (struct-copy string-quad q:string [attrs #:parent quad (let ([attrs (quad-attrs q)]) (hash-ref! attrs :font-size default-font-size) attrs)] - [elems #:parent quad (quad-elems q)] - [size #:parent quad (make-size-promise q)])) + [elems #:parent quad (list cased-str)] + [size #:parent quad (make-size-promise q cased-str)])) (define (generic->typed-quad q) (or @@ -533,8 +539,8 @@ (fill-color doc default-font-color) (text doc (or (quad-ref q :footer-text) (format "~a ยท ~a at ~a" (quad-ref q :page-number 0) - (if (quadwriter-test-mode) "test" (quad-ref q :doc-title "untitled")) - (date->string (if (quadwriter-test-mode) (seconds->date 0 #f) (current-date)) #t))) + (if (quadwriter-test-mode) "test" (quad-ref q :doc-title "untitled")) + (date->string (if (quadwriter-test-mode) (seconds->date 0 #f) (current-date)) #t))) x y)) (define (make-footer-quad col-q page-idx path)