no more percentages

main
Matthew Butterick 4 years ago
parent e1157db843
commit e90ba9204f

@ -4,4 +4,4 @@
'(q ((column-count "2")(font-size "18")(line-height "2em")) "The lines in both columns should be vertically aligned. The column on the left is font size 18pt with line height 2em, or 36pt. The right column is font size 50%, or 9pt, with line height 4em, or 36pt."
(q ((break "column")))
(q ((break "para")))
(q ((font-size "50%")(line-height "4em")) "The lines in both columns should be vertically aligned. The column on the left is font size 18pt with line height 2em, or 36pt. The right column is font size 50%, or 9pt, with line height 4em, or 36pt."))
(q ((font-size "0.5em")(line-height "4em")) "The lines in both columns should be vertically aligned. The column on the left is font size 18pt with line height 2em, or 36pt. The right column is font size 50%, or 9pt, with line height 4em, or 36pt."))

@ -5,8 +5,6 @@
'(q ((font-size "20")(font-tracking "5")) "we have the same tracking you see")
'(q ((break "para")))
'(q ((font-size "20")(font-tracking "25%")) "we have the same tracking you see")
'(q ((break "para")))
'(q ((font-size "20")(font-tracking "0.25em")) "we have the same tracking you see")
'(q ((break "para")))
@ -17,6 +15,4 @@
'(q ((font-size "20")(font-tracking "5")(line-align "justify")) "we have the same tracking you see")
'(q ((break "para")))
'(q ((font-size "20")(font-tracking "25%")(line-align "justify")) "we have the same tracking you see")
'(q ((break "para")))
'(q ((font-size "20")(font-tracking "0.25em")(line-align "justify")) "we have the same tracking you see")

@ -627,7 +627,7 @@ Sets the display type. Value is a string. Supply @racket["block"] as a value of
}
@defthing[#:kind "attribute" font-size symbol?]{
Sets the point size for text. Value is a @tech{dimension string}, a string representing a percentage (like @racket["120%"]), or an em size (like @racket["1.2em"]). If a percentage or em size is provided, the font size is the size of the parent multiplied by the percentage (or em).
Sets the point size for text. Value is a @tech{dimension string} or an em size (like @racket["1.2em"]). If an em size is provided, the font size is the size of the parent multiplied by the em.
}
@defthing[#:kind "attribute" font-family symbol?]{
@ -654,7 +654,7 @@ Sets OpenType layout features. @racket[font-features] takes a @deftech{feature s
@defthing[#:kind "attribute" font-tracking symbol?]{
Space between characters. Value is a @tech{dimension string}, a string representing a percentage (like @racket["15%"]), or an em size (like @racket["0.15em"]). If a percentage or em size is provided, the font tracking is the current font size multiplied by the percentage (or em).
Space between characters. Value is a @tech{dimension string} or an em size (like @racket["0.15em"]). If an em size is provided, the font tracking is the current font size multiplied by the em.
}
@defthing[#:kind "attribute" font-baseline-shift symbol?]{
@ -667,7 +667,7 @@ Case transformation of string. Possibilities are @racket["uppercase"], @racket["
@defthing[#:kind "attribute" line-height symbol?]{
Sets the distance between baselines. Value is a @tech{dimension string}, a string representing a percentage (like @racket["120%"]), or an em size (like @racket["1.2em"]). If a percentage or em size is provided, the line height is the current font size multiplied by the percentage (or em).
Sets the distance between baselines. Value is a @tech{dimension string} or an em size (like @racket["1.2em"]). If an em size is provided, the line height is the current font size multiplied by em.
}
TK: OT feature attributes, bullet attributes

@ -87,20 +87,23 @@
(string-suffix? pstr suffix)
(string->number (string-trim pstr suffix))))
(define (parse-em str)
(parse-adjustment str "em"))
(define (parse-percentage pstr)
(match (parse-adjustment pstr "%")
[#false #false]
[res (/ res 100.0)]))
(define (parse-percentage-or-em str)
(or (parse-percentage str) (parse-adjustment str "em")))
(or (parse-percentage str) (parse-em str)))
(define (resolve-font-size! attrs)
;; convert font-size attributes into a simple font size
;; we stashed the previous size in private key 'font-size-previous
(define prev-font-size-key 'font-size-previous)
(define val (hash-ref attrs :font-size default-font-size))
(define adjustment (parse-percentage-or-em val))
(define adjustment (parse-em val))
;; if our value represents an adjustment, we apply the adjustment to the previous value
;; otherwise we use our value directly
(define base-size (if adjustment (hash-ref attrs prev-font-size-key default-font-size) val))
@ -112,13 +115,20 @@
(hash-set! attrs prev-font-size-key base-size-adjusted))
(define ((make-updater-based-on-font-size attrs) val)
(define adjustment (parse-percentage-or-em val))
(define base-height (if adjustment (hash-ref attrs :font-size) val))
(and base-height (* base-height (or adjustment 1))))
(define em-adjustment (parse-em val))
(define base-height (if em-adjustment (hash-ref attrs :font-size) val))
(and base-height (* base-height (or em-adjustment 1))))
(define (resolve-em attrs key)
(match (hash-ref attrs key #f)
[#false (void)]
[val
(define updater (make-updater-based-on-font-size attrs))
(hash-set! attrs key (updater val))]))
(define (resolve-line-height! attrs)
;; convert line-height attributes into a simple line height
(hash-update! attrs :line-height (make-updater-based-on-font-size attrs) default-line-height))
(resolve-em attrs :line-height))
(define (resolve-font-tracking! attrs)
(hash-update! attrs :font-tracking (make-updater-based-on-font-size attrs) 0))
(resolve-em attrs :font-tracking))

@ -25,7 +25,7 @@
[_ (qexpr (append (list->attrs
:keep-first-lines "2"
:keep-last-lines "3"
:font-size "100%"
:font-size "1em"
:hyphenate "true"
:display (symbol->string (gensym)))
attrs) exprs)]))
@ -77,7 +77,7 @@
(define-tag-function (strong attrs exprs)
(qexpr (append (list->attrs
:font-bold "true"
:font-size "100%")
:font-size "1em")
attrs) exprs))
(define b strong)
@ -91,7 +91,7 @@
(qexpr (append
(list->attrs
:font-italic "true"
:font-size "100%") attrs) exprs))
:font-size "1em") attrs) exprs))
(define i em)

Loading…
Cancel
Save