]> git.donarmstrong.com Git - lilypond.git/blob - lily/stencil-interpret.cc
Update source file headers. Fixes using standard GNU package conventions.
[lilypond.git] / lily / stencil-interpret.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2005--2009 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
20 #include "stencil.hh"
21
22 void
23 interpret_stencil_expression (SCM expr,
24                               void (*func) (void *, SCM),
25                               void *func_arg,
26                               Offset o)
27 {
28   while (1)
29     {
30       if (!scm_is_pair (expr))
31         return;
32
33       SCM head = scm_car (expr);
34
35       if (head == ly_symbol2scm ("delay-stencil-evaluation"))
36         {
37           interpret_stencil_expression (scm_force (scm_cadr (expr)), func, func_arg, o);
38           return;
39         }
40       if (head == ly_symbol2scm ("translate-stencil"))
41         {
42           o += ly_scm2offset (scm_cadr (expr));
43           expr = scm_caddr (expr);
44         }
45       else if (head == ly_symbol2scm ("combine-stencil"))
46         {
47
48           for (SCM x = scm_cdr (expr); scm_is_pair (x); x = scm_cdr (x))
49             interpret_stencil_expression (scm_car (x), func, func_arg, o);
50           return;
51         }
52       else if (head == ly_symbol2scm ("grob-cause"))
53         {
54           SCM grob = scm_cadr (expr);
55
56           (*func) (func_arg, scm_list_3 (head,
57                                          ly_quote_scm (ly_offset2scm (o)), grob));
58           interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
59           (*func) (func_arg, scm_list_1 (ly_symbol2scm ("no-origin")));
60           return;
61         }
62       else if (head == ly_symbol2scm ("color"))
63         {
64           SCM color = scm_cadr (expr);
65           SCM r = scm_car (color);
66           SCM g = scm_cadr (color);
67           SCM b = scm_caddr (color);
68
69           (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setcolor"), r, g, b));
70           interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
71           (*func) (func_arg, scm_list_1 (ly_symbol2scm ("resetcolor")));
72
73           return;
74         }
75       else if (head == ly_symbol2scm ("rotate-stencil"))
76         {
77           SCM args = scm_cadr (expr);
78           SCM angle = scm_car (args);
79           Offset tmp = o + robust_scm2offset (scm_cadr (args), Offset (0.0, 0.0));
80
81           SCM offset = ly_offset2scm (tmp);
82           SCM x = scm_car (offset);
83           SCM y = scm_cdr (offset);
84
85           (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setrotation"), angle, x, y));
86           interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
87           (*func) (func_arg, scm_list_4 (ly_symbol2scm ("resetrotation"), angle, x, y));
88
89           return;
90         }
91       else
92         {
93           (*func) (func_arg,
94                    scm_list_4 (ly_symbol2scm ("placebox"),
95                                scm_from_double (o[X_AXIS]),
96                                scm_from_double (o[Y_AXIS]),
97                                expr));
98           return;
99         }
100     }
101 }
102
103 struct Font_list
104 {
105   SCM fonts_;
106 };
107
108 static void
109 find_font_function (void *fs, SCM x)
110 {
111   Font_list *me = (Font_list *) fs;
112
113   if (scm_car (x) == ly_symbol2scm ("placebox"))
114     {
115       SCM args = scm_cdr (x);
116       SCM what = scm_caddr (args);
117
118       if (scm_is_pair (what))
119         {
120           SCM head = scm_car (what);
121           if (ly_symbol2scm ("text") == head)
122             me->fonts_ = scm_cons (scm_cadr (what), me->fonts_);
123           else if (head == ly_symbol2scm ("char"))
124             me->fonts_ = scm_cons (scm_cadr (what), me->fonts_);
125         }
126     }
127 }
128
129 SCM
130 find_expression_fonts (SCM expr)
131 {
132   Font_list fl;
133
134   fl.fonts_ = SCM_EOL;
135
136   interpret_stencil_expression (expr, &find_font_function,
137                                 (void *) & fl, Offset (0, 0));
138
139   return fl.fonts_;
140 }