]> git.donarmstrong.com Git - lilypond.git/blob - scm/document-backend.scm
* lily/grob.cc: edit doc string.
[lilypond.git] / scm / document-backend.scm
1 ;;; backend-documentation-lib.scm -- Functions for backend documentation
2 ;;;
3 ;;; source file of the GNU LilyPond music typesetter
4 ;;; 
5 ;;; (c)  2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
6 ;;; Jan Nieuwenhuizen <janneke@gnu.org>
7
8
9 (define (interface-doc-string interface grob-description)
10   (let*
11       ((name (car interface))
12        (desc (cadr interface))
13        (props (sort (caddr interface) symbol<?))
14        (docfunc (lambda (pr)
15                   (property->texi
16                     'backend pr grob-description)))
17        (iprops (filter (lambda (x) (object-property x 'backend-internal) ) props))
18        (uprops (filter (lambda (x) (not (object-property x 'backend-internal)) ) props))
19        (user-propdocs (map docfunc uprops))
20        (internal-propdocs (map docfunc iprops)))
21
22        (string-append
23         desc
24
25         (if (pair? uprops)
26             (string-append
27             "\n\n@unnumberedsubsubsec User settable properties:\n"
28             (description-list->texi user-propdocs))
29             "")
30
31         (if (pair? iprops)
32             (string-append
33              "\n\n@unnumberedsubsubsec Internal properties: \n"
34              (description-list->texi internal-propdocs)
35              )
36             "")
37         )
38     ))
39
40
41 (define iface->grob-table (make-vector 61 '()))
42 ;; extract ifaces, and put grob into the hash table.
43 (map
44  (lambda (x)
45    (let*
46        (
47         (metah (assoc 'meta (cdr x)))
48         (meta (cdr metah))
49         (ifaces (cdr (assoc 'interfaces meta)))
50         )
51
52      (map (lambda (iface)
53             (hashq-set!
54              iface->grob-table iface
55              (cons (car x)
56                    (hashq-ref iface->grob-table iface '())
57                    )))
58           ifaces)
59      ))
60  all-grob-descriptions)
61
62 ;; First level Interface description
63 (define (interface-doc interface)
64   (let ((name (symbol->string (car interface))))
65     (make <texi-node>
66       #:name name
67       #:text (string-append
68               (interface-doc-string (cdr interface) '())
69               "\n\n"
70               "This grob interface is used in the following graphical objects: "
71
72               (human-listify
73                (map ref-ify
74                     (map symbol->string
75                          (hashq-ref iface->grob-table (car interface) '() )))))
76
77       )))
78
79 (define (grob-alist->texi alist)
80   (let*
81       ((uprops (filter (lambda (x) (not (object-property x 'backend-internal)))
82                        (map car alist))))
83
84     (description-list->texi
85      (map (lambda (y) (property->texi 'backend y alist))
86           uprops)
87      )))
88
89
90 (define (grob-doc description)
91   "Given a property alist DESCRIPTION, make a documentation
92 node."
93   
94   (let*
95       (
96        (metah (assoc 'meta description))
97        (meta (cdr metah))
98        (name (cdr (assoc 'name meta)))
99        (ifaces (map lookup-interface (cdr (assoc 'interfaces meta))))
100        (ifacedoc (map (lambda (iface)
101                         (ref-ify (symbol->string (car iface)))
102                         )
103                       (reverse ifaces)))
104        (engravers (filter
105                    (lambda (x) (engraver-makes-grob? name x)) all-engravers-list))
106        (namestr (symbol->string name))
107        (engraver-names (map symbol->string (map ly:translator-name engravers)))
108        )
109
110     (make <texi-node>
111       #:name namestr
112       #:text
113       (string-append
114        namestr " grobs are created by: "
115        (human-listify (map ref-ify
116                            (map engraver-name engraver-names)))
117        "\n\nStandard settings: \n\n"
118        (grob-alist->texi description)
119        "\n\nThis object supports the following interfaces: \n"
120        (human-listify ifacedoc)
121        ))
122     ))
123
124 (define (all-grobs-doc)
125   (make <texi-node>
126     #:name "All layout objects"
127     #:desc "Description and defaults for all Grobs"
128     #:children
129     (map (lambda (x) (grob-doc (cdr x)))  all-grob-descriptions)))
130
131 (define interface-description-alist
132   (hash-fold
133    (lambda (key val prior)
134      (cons (cons key val)  prior)
135      )
136    '() (ly:all-grob-interfaces)))
137
138 (set! interface-description-alist (sort interface-description-alist alist<?))
139
140
141 ;;;;;;;;;; check for dangling backend properties.
142 (define (mark-interface-properties entry)
143   (map (lambda (x) (set-object-property! x  'iface-marked #t)) (caddr (cdr entry)))
144   )
145
146 (map mark-interface-properties interface-description-alist)
147
148 (define (check-dangling-properties prop)
149   (if (not (object-property prop 'iface-marked))
150       (error  "\ndefine-grob-properties.scm: Can't find interface for property:" prop)))
151
152 (map check-dangling-properties all-backend-properties)
153
154 ;;;;;;;;;;;;;;;;
155
156 (define (lookup-interface name)
157   (let*  (
158           (entry  (hashq-ref (ly:all-grob-interfaces) name '() ))
159           )
160
161     (if (equal? entry #f)
162         (error "Unknown interface" name))
163     
164     entry
165 ))
166
167 (define (all-interfaces-doc)
168   (make <texi-node>
169     #:name "Graphical Object Interfaces"
170     #:desc "Building blocks of graphical objects"
171     #:children
172     (map interface-doc interface-description-alist)
173     ))
174
175 (define (backend-properties-doc-string lst)
176   (let*
177       (
178        (ps (sort (map symbol->string lst) string<?))
179        (descs (map (lambda (prop)
180                      (property->texi 'backend (string->symbol prop)  '()))
181                    ps))
182        (texi (description-list->texi descs))
183        )
184     texi))
185
186   
187 ;(dump-node (grob-doc (cdadr all-grob-descriptions))  (current-output-port) 0 )
188 (define (backend-doc-node)
189   (make <texi-node>
190     #:name "Backend"
191     #:desc "Reference for the layout engine"
192     #:children
193     (list
194      (all-grobs-doc)
195      (all-interfaces-doc)
196     (make <texi-node>
197       #:name "User backend properties"
198       #:desc "All tunable properties in a big list"
199       #:text (backend-properties-doc-string all-user-grob-properties))
200     (make <texi-node>
201       #:name "Internal backend properties"
202       #:desc "All internal layout properties in a big list"
203       #:text (backend-properties-doc-string all-internal-grob-properties))
204   )))