]> git.donarmstrong.com Git - lilypond.git/blob - scm/titling.scm
added printpagenumber
[lilypond.git] / scm / titling.scm
1 ;;;; titling.scm -- titling functions
2 ;;;;
3 ;;;;  source file of the GNU LilyPond music typesetter
4 ;;;;
5 ;;;; (c) 2004--2005 Jan Nieuwenhuizen <janneke@gnu.org>
6 ;;;;          Han-Wen Nienhuys <hanwen@cs.uu.nl>
7
8 (define-public (layout-extract-page-properties layout)
9   (list (append `((linewidth . ,(ly:paper-get-number
10                                  layout 'linewidth)))
11                 (ly:output-def-lookup layout 'text-font-defaults))))
12
13 ;;;;;;;;;;;;;;;;;;
14
15 (define-public ((marked-up-headfoot what-odd what-even) layout scopes page-number last?)
16
17   "Read variables WHAT-ODD, WHAT-EVEN from LAYOUT, and interpret them
18 as markup. The PROPS argument will include variables set in SCOPES and
19 page:last?, page:page-number-string and page:page-number
20
21
22   (define (get sym)
23     (ly:output-def-lookup layout sym))
24
25   (define (interpret-in-page-env potential-markup)
26     (if (markup? potential-markup)
27         (let* ((alists (map ly:module->alist scopes))
28                (prefixed-alists
29                 (map (lambda (alist)
30                        (map (lambda (entry)
31                               (cons
32                                (string->symbol
33                                 (string-append
34                                  "header:"
35                                  (symbol->string (car entry))))
36                                (cdr entry)))
37                             alist))
38                      alists))
39                (tagline (ly:modules-lookup scopes 'tagline)) 
40                (default-tagline (ly:output-def-lookup layout 'tagline)) 
41
42                (pgnum-alist
43                 (list
44                  (cons 'header:tagline
45                        (cond
46                         ((markup? tagline) tagline)
47                         ((markup? default-tagline) default-tagline)
48                         (else "")))
49                  (cons 'page:last? last?)
50                  (cons 'page:page-number-string
51            (if (ly:output-def-lookup layout 'printpagenumber)
52                (number->string page-number)
53                ""))
54                  (cons 'page:page-number page-number)))
55                (props (append
56                        (list pgnum-alist)
57                        prefixed-alists
58                        (layout-extract-page-properties layout))))
59
60           (interpret-markup layout props potential-markup))
61
62         empty-stencil))
63
64   (interpret-in-page-env
65    (if (and (even? page-number)
66             (markup? (get what-even)))
67        (get what-even)
68        (get what-odd))))
69
70 (define-public ((marked-up-title what) layout scopes)
71   "Read variables WHAT from SCOPES, and interpret it as markup. The
72 PROPS argument will include variables set in SCOPES (prefixed with
73 `header:'
74 "
75   
76   (define (get sym)
77     (let ((x (ly:modules-lookup scopes sym)))
78       (if (markup? x) x #f)))
79
80   (let* ((alists (map ly:module->alist scopes))
81          (prefixed-alist
82           (map (lambda (alist)
83                  (map (lambda (entry)
84                         (cons
85                          (string->symbol
86                           (string-append
87                            "header:"
88                            (symbol->string (car entry))))
89                          (cdr entry)))
90                       alist))
91                alists))
92          (props (append prefixed-alist
93                         (layout-extract-page-properties layout)))
94
95          (markup (ly:output-def-lookup layout what)))
96
97     (if (markup? markup)
98         (interpret-markup layout props markup)
99         (ly:make-stencil '() '(1 . -1) '(1 . -1)))))