main
Matthew Butterick 9 years ago
parent 41cdc8d676
commit ee85254a77

@ -12,6 +12,7 @@
[(symbol? x) ($hard empty-attrs x #f)]
[(string? x)
;; consolidate consecutive whitespaces into single word space
;; todo: hyphenate here? then they are in the quad stream
(for/list ([c (in-string x)])
(cons ($hard empty-attrs #f #f)
;; todo: is it feasible to box or otherwise object-ize a char

@ -1,14 +1,14 @@
#lang quad/text #:fit 300 150
Produces a list of three-element lists, where each three-element list represents a set of consecutive code points for which the Unicode standard specifies character properties. Each three-element list contains two integers and a boolean; the first integer is a starting code-point value (inclusive), the second integer is an ending code-point value (inclusive), and the boolean is #t when all characters in the code-point range have identical results for all of the character predicates above. The three-element lists are ordered in the overall result list such that later lists represent larger code-point values, and all three-element lists are separated from every other by at least one code-point value that is not specified by Unicode.
One morning, when Gregor Samsa woke from troubled dreams, he found
@quad[(make-attrs #:size 7)]{One morning, when Gregor Samsa woke from troubled dreams, he found
himself transformed in his bed into a horrible vermin. He lay on
his armour-like back, and if he lifted his head a little he could
see his brown belly, slightly domed and divided by arches into stiff
sections. The bedding was hardly able to cover it and seemed ready
to slide off any moment. His many legs, pitifully thin compared
with the size of the rest of him, waved about helplessly as he
looked.
looked.}
"What's happened to me?" he thought. It wasn't a dream. His room,
a proper human room although a little too small, lay peacefully

@ -4,10 +4,10 @@
(define (measure! q)
(quad-dim-set! q
(cond
[(or ($black? q) ($soft? q))
(* (measure-char (quad-font q) (quad-val q)) (quad-font-size q))]
[else 0])))
(cond
[(or ($black? q) ($soft? q))
(* (measure-char (quad-font q) (quad-val q)) (quad-font-size q))]
[else 0])))
(module+ test
(require rackunit)
@ -23,7 +23,10 @@
[ft-face-cache (make-hash)])
(λ (font-pathstring char)
(define (do-measure)
(define ft-face (hash-ref! ft-face-cache font-pathstring (λ () (FT_New_Face ft-library font-pathstring 0))))
(define ft-face (hash-ref! ft-face-cache font-pathstring
(λ () (unless (file-exists? font-pathstring)
(error 'measure-char (format "font path ~v does not exist" font-pathstring)))
(FT_New_Face ft-library font-pathstring 0))))
(define width
(let ([glyph-idx (hash-ref! glyph-idx-cache (cons char font-pathstring)
(λ () (FT_Get_Char_Index ft-face (char->integer char))))])

@ -35,6 +35,8 @@ measure (line width)
(define (merge-strings xs)
;; merge consecutive strings
;; todo: only trim remove space between string and a hard break.
;; space between a string and a subquad is ok
(let loop ([xs xs])
(cond
[(empty? xs) empty]

Loading…
Cancel
Save