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: fonts should
11 ;; be read off the disk, on demand, something like:
13 ;; cmr -> ((font-load "cmr6") (font-load "cmr8") .. )
16 (define-class <Font-tree-element>
20 (define-class <Font-tree-leaf> (<Font-tree-element>)
21 (default-size #:init-keyword #:default-size)
22 (size-vector #:init-keyword #:size-vector))
24 (define-class <Font-tree-node> (<Font-tree-element>)
25 (qualifier #:init-keyword #:qualifier #:accessor font-qualifier)
26 (default #:init-keyword #:default #:accessor font-default)
27 (children #:init-keyword #:children #:accessor font-children))
29 (define (make-font-tree-leaf size size-font-vector)
30 (make <Font-tree-leaf> #:default-size size #:size-vector size-font-vector))
32 (define (make-font-tree-node
34 (make <Font-tree-node>
37 #:children (make-hash-table 11)))
39 (define-method (display (leaf <Font-tree-leaf>) port)
40 (map (lambda (x) (display x port))
42 "Font-size-family: \n"
43 (slot-ref leaf 'default-size)
44 (slot-ref leaf 'size-vector) )))
46 (define-method (display (node <Font-tree-node>) port)
53 "Font_node { \nqual: "
61 (display (car x) port)
63 (display (cdr x) port))
64 (hash-table->alist (font-children node)))
69 (define default-qualifier-order
70 '(font-encoding font-family font-shape font-series))
72 (define-method (add-font (node <Font-tree-node>) fprops size-family)
73 (define (assoc-delete key alist)
74 (assoc-remove! (list-copy alist) key))
75 (define (make-node fprops size-family)
77 (make-font-tree-leaf (car size-family) (cdr size-family))
79 ((qual (next-qualifier default-qualifier-order fprops)))
80 (make-font-tree-node qual
81 (assoc-get qual fprops)))
83 (define (next-qualifier order props)
85 ((and (null? props) (null? order))
87 ((null? props) (car order))
88 ((null? order) (caar props))
90 (if (assoc-get (car order) props)
92 (next-qualifier (cdr order) props))
96 ((q (font-qualifier node))
97 (d (font-default node))
98 (v (assoc-get q fprops d))
99 (new-fprops (assoc-delete q fprops))
100 (child (hashq-ref (slot-ref node 'children)
106 (set! child (make-node new-fprops size-family))
107 (hashq-set! (slot-ref node 'children) v child)))
108 (if (pair? new-fprops)
109 (add-font child new-fprops size-family))))
112 (define-method (add-font (node <Font-tree-leaf>) fprops size-family)
113 (throw "must add to node, not leaf"))
116 (define-method (g-lookup-font (node <Font-tree-node>) alist-chain)
118 ((qual (font-qualifier node))
119 (def (font-default node))
120 (val (chain-assoc-get qual alist-chain def))
121 (desired-child (hashq-ref (font-children node) val))
125 (g-lookup-font desired-child alist-chain)
126 (g-lookup-font (hashq-ref (font-children node) def) alist-chain)
129 (define-method (g-lookup-font (node <Font-tree-leaf>) alist-chain)
132 ;; two step call is handy for debugging.
133 (define (lookup-font node alist-chain)
134 (g-lookup-font node alist-chain))
138 (define-public (make-font-tree factor)
140 ((n (make-font-tree-node 'font-encoding 'music))
146 (list (cons 'font-encoding (car x)))
147 (cons (* factor (cadr x))
150 #((3.82 . "feta-nummer4")
151 (5.5 . "feta-nummer6")
152 (8.0 . "feta-nummer8")
153 (10.0 . "feta-nummer10")
154 (12.0 . "feta-nummer12")
155 (16.0 . "feta-nummer16")))
156 (dynamic 14.0 #((6.0 . "feta-din6")
158 (10.0 . "feta-din10")
159 (12.0 . "feta-din12")
160 (14.0 . "feta-din14")
161 (17.0 . "feta-din17")
163 (math 10 #((10.0 . "msam10")))
165 #((11.22 . ("feta11" "parmesan11"))
166 (12.60 . ("feta13" "parmesan13"))
167 (14.14 . ("feta14" "parmesan14"))
168 (15.87 . ("feta16" "parmesan16"))
169 (17.82 . ("feta18" "parmesan18"))
170 (20.0 . ("feta20" "parmesan20"))
171 (22.45 . ("feta23" "parmesan23"))
172 (25.20 . ("feta26" "parmesan26"))
174 (braces 10 #((10.0 . ("feta-braces00"
189 `((font-encoding . text)
190 (font-series . ,(vector-ref (car x) 2))
191 (font-shape . ,(vector-ref (car x) 1))
192 (font-family . ,(vector-ref (car x) 0)))
193 (cons (* factor (cadr x))
196 '((#(roman upright medium) .
197 (10.0 . #((6.0 . "cmr6")
203 (#(roman upright bold) .
204 (10.0 . #((6.0 . "cmbx6")
210 (#(roman italic medium) .
211 (10.0 . #((7.0 . "cmti7")
215 (#(roman italic bold) .
216 (10.0 . #((8.0 . "cmbxti8")
221 (#(roman caps medium) .
222 (10.0 . #((10.0 . "cmcsc10"))))
224 (#(roman upright bold-narrow ) .
225 (10.0 . #((10.0 . "cmb10")
228 (#(sans upright medium) .
229 (10.0 . #((8.0 . "cmss8")
234 (#(typewriter upright medium) .
235 (10.0 . #((8.0 . "cmtt8")
242 ; (display (make-font-tree 1.0))
244 (define-public (magstep x)
245 (exp (* (/ x 6) (log 2))))