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