Fix \deadNotesOff.
[lilypond/mpolesky.git] / lily / stencil-interpret.cc
blob509c89aba42e13ff82f6e675df48897ac499bfa3
1 /*
2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
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.
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.
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/>.
20 #include "stencil.hh"
22 void
23 interpret_stencil_expression (SCM expr,
24 void (*func) (void *, SCM),
25 void *func_arg,
26 Offset o)
28 while (1)
30 if (!scm_is_pair (expr))
31 return;
33 SCM head = scm_car (expr);
35 if (head == ly_symbol2scm ("delay-stencil-evaluation"))
37 interpret_stencil_expression (scm_force (scm_cadr (expr)), func, func_arg, o);
38 return;
40 if (head == ly_symbol2scm ("translate-stencil"))
42 o += ly_scm2offset (scm_cadr (expr));
43 expr = scm_caddr (expr);
45 else if (head == ly_symbol2scm ("combine-stencil"))
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;
52 else if (head == ly_symbol2scm ("grob-cause"))
54 SCM grob = scm_cadr (expr);
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;
62 else if (head == ly_symbol2scm ("color"))
64 SCM color = scm_cadr (expr);
65 SCM r = scm_car (color);
66 SCM g = scm_cadr (color);
67 SCM b = scm_caddr (color);
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")));
73 return;
75 else if (head == ly_symbol2scm ("rotate-stencil"))
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));
81 SCM offset = ly_offset2scm (tmp);
82 SCM x = scm_car (offset);
83 SCM y = scm_cdr (offset);
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));
89 return;
91 else
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;
103 struct Font_list
105 SCM fonts_;
108 static void
109 find_font_function (void *fs, SCM x)
111 Font_list *me = (Font_list *) fs;
113 if (scm_car (x) == ly_symbol2scm ("placebox"))
115 SCM args = scm_cdr (x);
116 SCM what = scm_caddr (args);
118 if (scm_is_pair (what))
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_);
130 find_expression_fonts (SCM expr)
132 Font_list fl;
134 fl.fonts_ = SCM_EOL;
136 interpret_stencil_expression (expr, &find_font_function,
137 (void *) & fl, Offset (0, 0));
139 return fl.fonts_;