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