2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2005--2015 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/>.
23 interpret_stencil_expression (SCM expr,
24 SCM (*func) (void *, SCM),
30 if (!scm_is_pair (expr))
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);
40 if (head == ly_symbol2scm ("transparent-stencil"))
42 if (head == ly_symbol2scm ("footnote"))
44 if (head == ly_symbol2scm ("translate-stencil"))
46 o += ly_scm2offset (scm_cadr (expr));
47 expr = scm_caddr (expr);
49 else if (head == ly_symbol2scm ("combine-stencil"))
52 for (SCM x = scm_cdr (expr); scm_is_pair (x); x = scm_cdr (x))
53 interpret_stencil_expression (scm_car (x), func, func_arg, o);
56 else if (head == ly_symbol2scm ("grob-cause"))
58 SCM grob = scm_cadr (expr);
62 scm_list_3 (head, ly_quote_scm (ly_offset2scm (o)), grob));
63 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
64 if (scm_is_true (link))
65 (*func) (func_arg, scm_list_1 (ly_symbol2scm ("no-origin")));
68 else if (head == ly_symbol2scm ("color"))
70 SCM color = scm_cadr (expr);
71 SCM r = scm_car (color);
72 SCM g = scm_cadr (color);
73 SCM b = scm_caddr (color);
75 (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setcolor"), r, g, b));
76 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
77 (*func) (func_arg, scm_list_1 (ly_symbol2scm ("resetcolor")));
81 else if (head == ly_symbol2scm ("id"))
83 SCM id = scm_cadr (expr);
85 (*func) (func_arg, scm_list_2 (ly_symbol2scm ("start-enclosing-id-node"), id));
86 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
87 (*func) (func_arg, scm_list_1 (ly_symbol2scm ("end-enclosing-id-node")));
91 else if (head == ly_symbol2scm ("rotate-stencil"))
93 SCM args = scm_cadr (expr);
94 SCM angle = scm_car (args);
95 Offset tmp = o + robust_scm2offset (scm_cadr (args), Offset (0.0, 0.0));
97 SCM offset = ly_offset2scm (tmp);
98 SCM x = scm_car (offset);
99 SCM y = scm_cdr (offset);
101 (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setrotation"), angle, x, y));
102 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
103 (*func) (func_arg, scm_list_4 (ly_symbol2scm ("resetrotation"), angle, x, y));
107 else if (head == ly_symbol2scm ("scale-stencil"))
109 SCM args = scm_cadr (expr);
110 SCM x_scale = scm_car (args);
111 SCM y_scale = scm_cadr (args);
112 Offset unscaled = o.scale (Offset (1 / scm_to_double (x_scale),
113 1 / scm_to_double (y_scale)));
115 (*func) (func_arg, scm_list_3 (ly_symbol2scm ("setscale"), x_scale,
117 interpret_stencil_expression (scm_caddr (expr), func, func_arg,
119 (*func) (func_arg, scm_list_1 (ly_symbol2scm ("resetscale")));
126 scm_list_4 (ly_symbol2scm ("placebox"),
127 scm_from_double (o[X_AXIS]),
128 scm_from_double (o[Y_AXIS]),
141 find_font_function (void *fs, SCM x)
143 Font_list *me = (Font_list *) fs;
145 if (scm_car (x) == ly_symbol2scm ("placebox"))
147 SCM args = scm_cdr (x);
148 SCM what = scm_caddr (args);
150 if (scm_is_pair (what))
152 SCM head = scm_car (what);
153 if (ly_symbol2scm ("text") == head)
154 me->fonts_ = scm_cons (scm_cadr (what), me->fonts_);
155 else if (head == ly_symbol2scm ("char"))
156 me->fonts_ = scm_cons (scm_cadr (what), me->fonts_);
163 find_expression_fonts (SCM expr)
169 interpret_stencil_expression (expr, &find_font_function,
170 (void *) & fl, Offset (0, 0));