]> git.donarmstrong.com Git - lilypond.git/blob - scm/titling.scm
b5f8b1bb8a64218a5d3e4dbbdb186a5a1100d986
[lilypond.git] / scm / titling.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2004--2012 Jan Nieuwenhuizen <janneke@gnu.org>
4 ;;;;          Han-Wen Nienhuys <hanwen@xs4all.nl>
5 ;;;;
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
10 ;;;;
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;;; GNU General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19 (define-public (layout-extract-page-properties layout)
20   (list (append `((line-width . ,(ly:paper-get-number
21                                   layout 'line-width)))
22                 (ly:output-def-lookup layout 'text-font-defaults))))
23
24 ;;;;;;;;;;;;;;;;;;
25
26 (define-public ((marked-up-headfoot what-odd what-even)
27                 layout scopes page-number is-last-bookpart is-bookpart-last-page)
28   "Read variables @var{what-odd}, @var{what-even} from @var{layout},
29 and interpret them as markup.  The @var{props} argument will include
30 variables set in @var{scopes} and @code{page:is-bookpart-last-page},
31 @code{page:is-last-bookpart}, @code{page:page-number-string}, and
32 @code{page:page-number}."
33
34   (define (get sym)
35     (ly:output-def-lookup layout sym))
36
37   (define (interpret-in-page-env potential-markup)
38     (if (markup? potential-markup)
39         (let* ((alists (map ly:module->alist scopes))
40                (prefixed-alists
41                 (map (lambda (alist)
42                        (map (lambda (entry)
43                               (cons
44                                (string->symbol
45                                 (string-append
46                                  "header:"
47                                  (symbol->string (car entry))))
48                                (cdr entry)))
49                             alist))
50                      alists))
51                (pgnum-alist
52                 (list
53                  (cons 'header:tagline
54                        (ly:modules-lookup scopes 'tagline
55                                           (ly:output-def-lookup layout 'tagline)))
56                  (cons 'page:is-last-bookpart is-last-bookpart)
57                  (cons 'page:is-bookpart-last-page is-bookpart-last-page)
58                  (cons 'page:page-number-string
59                        (number->string page-number))
60                  (cons 'page:page-number page-number)))
61                (props (append
62                        (list pgnum-alist)
63                        prefixed-alists
64                        (layout-extract-page-properties layout))))
65           (interpret-markup layout props potential-markup))
66
67         empty-stencil))
68
69   (interpret-in-page-env
70    (if (and (even? page-number)
71             (markup? (get what-even)))
72        (get what-even)
73        (get what-odd))))
74
75 (define-public ((marked-up-title what) layout scopes)
76   "Read variables @var{what} from @var{scopes}, and interpret it as markup.
77 The @var{props} argument will include variables set in @var{scopes} (prefixed
78 with `header:'."
79
80   (define (get sym)
81     (let ((x (ly:modules-lookup scopes sym)))
82       (if (markup? x) x #f)))
83
84   (let* ((alists (map ly:module->alist scopes))
85          (prefixed-alist
86           (map (lambda (alist)
87                  (map (lambda (entry)
88                         (cons
89                          (string->symbol
90                           (string-append
91                            "header:"
92                            (symbol->string (car entry))))
93                          (cdr entry)))
94                       alist))
95                alists))
96          (props (append prefixed-alist
97                         (layout-extract-page-properties layout)))
98
99          (markup (ly:output-def-lookup layout what)))
100
101     (if (markup? markup)
102         (interpret-markup layout props markup)
103         empty-stencil)))