1 ;; As an excercise, do it with records.
2 ;; Should use GOOPS, really.
6 ;; lookup-font should be written in C.
8 ;; should dump tree to .texi as internal documentation
10 ;; * should extract design sizes from fonts.
12 (define font-tree-record
15 '(qualifier default children)))
17 (define-public font-tree-node?
18 (record-predicate font-tree-record))
19 (define-public font-tree-default
20 (record-accessor font-tree-record 'default))
21 (define-public font-tree-qualifier
22 (record-accessor font-tree-record 'qualifier))
23 (define-public font-tree-children
24 (record-accessor font-tree-record 'children))
27 (define (make-font-tree-node
29 ((record-constructor font-tree-record)
32 (make-hash-table 11))) ;ugh. hardcoded.
34 (define default-qualifier-order
35 '(font-encoding font-family font-shape font-series))
38 (define-public (add-font node fprops size-family)
39 (define (assoc-delete key alist)
40 (assoc-remove! (list-copy alist) key))
41 (define (make-node fprops size-family)
45 ((qual (next-qualifier default-qualifier-order fprops)))
46 (make-font-tree-node qual
47 (assoc-get qual fprops)))
49 (define (next-qualifier order props)
51 ((and (null? props) (null? order))
53 ((null? props) (car order))
54 ((null? order) (caar props))
56 (if (assoc-get (car order) props)
58 (next-qualifier (cdr order) props))
61 (if (font-tree-node? node)
63 ((q (font-tree-qualifier node))
64 (d (font-tree-default node))
65 (v (assoc-get q fprops d))
66 (new-fprops (assoc-delete q fprops))
67 (child (hashq-ref (font-tree-children node)
73 (set! child (make-node new-fprops size-family))
74 (hashq-set! (font-tree-children node) v child)))
76 (add-font child new-fprops size-family))
77 (if (not (equal? size-family node))
78 (throw 'invalid-font props size-family)))
81 (define-public (display-font-node node . rest)
83 ((port (if (pair? rest) (car rest) (current-output-port)))
86 ((font-tree-node? node)
92 "Font_node { \nqual: "
93 (font-tree-qualifier node)
95 (font-tree-default node)
100 (display (car x) port)
102 (display-font-node (cdr x) port))
103 (hash-table->alist (font-tree-children node)))
107 (display node port))))
110 (define-public (lookup-font node alist-chain)
112 ((font-tree-node? node)
114 ((qual (font-tree-qualifier node))
115 (def (font-tree-default node))
116 (val (chain-assoc-get qual alist-chain def))
117 (desired-font (lookup-font
118 (hashq-ref (font-tree-children node)
120 (font (if desired-font
122 (lookup-font (hashq-ref (font-tree-children node)
128 (define-public (make-font-tree factor)
130 ((n (make-font-tree-node 'font-encoding 'music))
136 (list (cons 'font-encoding (car x)))
137 (cons (* factor (cadr x))
140 #((3.82 . "feta-nummer4")
141 (5.5 . "feta-nummer6")
142 (8.0 . "feta-nummer8")
143 (10.0 . "feta-nummer10")
144 (12.0 . "feta-nummer12")
145 (16.0 . "feta-nummer16")))
146 (dynamic 14.0 #((6.0 . "feta-din6")
148 (10.0 . "feta-din10")
149 (12.0 . "feta-din12")
150 (14.0 . "feta-din14")
151 (17.0 . "feta-din17")
153 (math 10 #((10.0 . "msam10")))
155 #((11.22 . ("feta11" "parmesan11"))
156 (12.60 . ("feta13" "parmesan13"))
157 (14.14 . ("feta14" "parmesan14"))
158 (15.87 . ("feta16" "parmesan16"))
159 (17.82 . ("feta18" "parmesan18"))
160 (20.0 . ("feta20" "parmesan20"))
161 (22.45 . ("feta23" "parmesan23"))
162 (25.20 . ("feta26" "parmesan26"))
164 (braces 10 #((10.0 . ("feta-braces00"
179 `((font-encoding . text)
180 (font-series . ,(vector-ref (car x) 2))
181 (font-shape . ,(vector-ref (car x) 1))
182 (font-family . ,(vector-ref (car x) 0)))
183 (cons (* factor (cadr x))
186 '((#(roman upright medium) .
187 (10.0 . #((6.0 . "cmr6")
193 (#(roman upright bold) .
194 (10.0 . #((6.0 . "cmbx6")
200 (#(roman italic medium) .
201 (10.0 . #((7.0 . "cmti7")
205 (#(roman italic bold) .
206 (10.0 . #((8.0 . "cmbxti8")
211 (#(roman caps medium) .
212 (10.0 . #((10.0 . "cmcsc10"))))
214 (#(roman upright bold-narrow ) .
215 (10.0 . #((10.0 . "cmb10")
218 (#(sans upright medium) .
219 (10.0 . #((8.0 . "cmss8")
224 (#(typewriter upright medium) .
225 (10.0 . #((8.0 . "cmtt8")
232 (define-public (magstep x)
233 (exp (* (/ x 6) (log 2))))