]> git.donarmstrong.com Git - lilypond.git/blob - scm/titling.scm
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scm / titling.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; Copyright (C) 2004--2015 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 ((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                (number-type (get 'page-number-type))
52                (pgnum-alist
53                 (list
54                  (cons 'header:tagline
55                        (ly:modules-lookup scopes 'tagline
56                                           (ly:output-def-lookup layout 'tagline)))
57                  (cons 'page:is-last-bookpart is-last-bookpart)
58                  (cons 'page:is-bookpart-last-page is-bookpart-last-page)
59                  (cons 'page:page-number-string
60                        (number-format number-type page-number))
61                  (cons 'page:page-number page-number)))
62                (props (append
63                        (list pgnum-alist)
64                        prefixed-alists
65                        (layout-extract-page-properties layout))))
66           (interpret-markup layout props potential-markup))
67
68         empty-stencil))
69
70   (interpret-in-page-env
71    (if (and (even? page-number)
72             (markup? (get what-even)))
73        (get what-even)
74        (get what-odd))))
75 (export marked-up-headfoot)
76
77 (define ((marked-up-title what) layout scopes)
78   "Read variables @var{what} from @var{scopes}, and interpret it as markup.
79 The @var{props} argument will include variables set in @var{scopes} (prefixed
80 with `header:'."
81
82   (define (get sym)
83     (let ((x (ly:modules-lookup scopes sym)))
84       (if (markup? x) x #f)))
85
86   (let* ((alists (map ly:module->alist scopes))
87          (prefixed-alist
88           (map (lambda (alist)
89                  (map (lambda (entry)
90                         (cons
91                          (string->symbol
92                           (string-append
93                            "header:"
94                            (symbol->string (car entry))))
95                          (cdr entry)))
96                       alist))
97                alists))
98          (props (append prefixed-alist
99                         (layout-extract-page-properties layout)))
100
101          (markup (ly:output-def-lookup layout what)))
102
103     (if (markup? markup)
104         (interpret-markup layout props markup)
105         empty-stencil)))
106 (export marked-up-title)