]> git.donarmstrong.com Git - lilypond.git/blob - scm/document-backend.scm
(Determining a grob
[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                     (sort 
75                      (map symbol->string
76                           (hashq-ref iface->grob-table (car interface) '() ))
77                      string<?)
78                     
79                     )))
80
81       )))
82
83 (define (grob-alist->texi alist)
84   (let*
85       ((uprops (filter (lambda (x) (not (object-property x 'backend-internal)))
86                        (map car alist))))
87
88     (description-list->texi
89      (map (lambda (y) (property->texi 'backend y alist))
90           uprops)
91      )))
92
93
94 (define (grob-doc description)
95   "Given a property alist DESCRIPTION, make a documentation
96 node."
97   
98   (let*
99       (
100        (metah (assoc 'meta description))
101        (meta (cdr metah))
102        (name (cdr (assoc 'name meta)))
103        (ifaces (map lookup-interface (cdr (assoc 'interfaces meta))))
104        (ifacedoc (map (lambda (iface)
105                         (ref-ify (symbol->string (car iface)))
106                         )
107                       (reverse ifaces)))
108        (engravers (filter
109                    (lambda (x) (engraver-makes-grob? name x)) all-engravers-list))
110        (namestr (symbol->string name))
111        (engraver-names (map symbol->string (map ly:translator-name engravers)))
112        )
113
114     (make <texi-node>
115       #:name namestr
116       #:text
117       (string-append
118        namestr " objects are created by: "
119        (human-listify (map ref-ify
120                            (map engraver-name engraver-names)))
121        "\n\nStandard settings: \n\n"
122        (grob-alist->texi description)
123        "\n\nThis object supports the following interfaces: \n"
124        (human-listify ifacedoc)
125        ))
126     ))
127
128 (define (all-grobs-doc)
129   (make <texi-node>
130     #:name "All layout objects"
131     #:desc "Description and defaults for all Grobs"
132     #:children
133     (map (lambda (x) (grob-doc (cdr x)))  all-grob-descriptions)))
134
135 (define interface-description-alist
136   (hash-fold
137    (lambda (key val prior)
138      (cons (cons key val)  prior)
139      )
140    '() (ly:all-grob-interfaces)))
141
142 (set! interface-description-alist (sort interface-description-alist alist<?))
143
144
145 ;;;;;;;;;; check for dangling backend properties.
146 (define (mark-interface-properties entry)
147   (map (lambda (x) (set-object-property! x  'iface-marked #t)) (caddr (cdr entry)))
148   )
149
150 (map mark-interface-properties interface-description-alist)
151
152 (define (check-dangling-properties prop)
153   (if (not (object-property prop 'iface-marked))
154       (error  "\ndefine-grob-properties.scm: Can't find interface for property:" prop)))
155
156 (map check-dangling-properties all-backend-properties)
157
158 ;;;;;;;;;;;;;;;;
159
160 (define (lookup-interface name)
161   (let*  (
162           (entry  (hashq-ref (ly:all-grob-interfaces) name '() ))
163           )
164
165     (if (equal? entry #f)
166         (error "Unknown interface" name))
167     
168     entry
169 ))
170
171 (define (all-interfaces-doc)
172   (make <texi-node>
173     #:name "Graphical Object Interfaces"
174     #:desc "Building blocks of graphical objects"
175     #:children
176     (map interface-doc interface-description-alist)
177     ))
178
179 (define (backend-properties-doc-string lst)
180   (let*
181       (
182        (ps (sort (map symbol->string lst) string<?))
183        (descs (map (lambda (prop)
184                      (property->texi 'backend (string->symbol prop)  '()))
185                    ps))
186        (texi (description-list->texi descs))
187        )
188     texi))
189
190   
191 ;(dump-node (grob-doc (cdadr all-grob-descriptions))  (current-output-port) 0 )
192 (define (backend-doc-node)
193   (make <texi-node>
194     #:name "Backend"
195     #:desc "Reference for the layout engine"
196     #:children
197     (list
198      (all-grobs-doc)
199      (all-interfaces-doc)
200     (make <texi-node>
201       #:name "User backend properties"
202       #:desc "All tunable properties in a big list"
203       #:text (backend-properties-doc-string all-user-grob-properties))
204     (make <texi-node>
205       #:name "Internal backend properties"
206       #:desc "All internal layout properties in a big list"
207       #:text (backend-properties-doc-string all-internal-grob-properties))
208   )))