Correct left text alignment of DynamicTextSpanner.
[lilypond.git] / lily / stencil-interpret.cc
blob8afc330d6f8bd63fcd75f3b6b8f074ffb7b9f2fc
1 /*
2 stencil-interpret.cc -- implement Stencil expression interpreting
4 source file of the GNU LilyPond music typesetter
6 (c) 2005--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "stencil.hh"
11 void
12 interpret_stencil_expression (SCM expr,
13 void (*func) (void *, SCM),
14 void *func_arg,
15 Offset o)
17 while (1)
19 if (!scm_is_pair (expr))
20 return;
22 SCM head = scm_car (expr);
24 if (head == ly_symbol2scm ("delay-stencil-evaluation"))
26 interpret_stencil_expression (scm_force (scm_cadr (expr)), func, func_arg, o);
27 return;
29 if (head == ly_symbol2scm ("translate-stencil"))
31 o += ly_scm2offset (scm_cadr (expr));
32 expr = scm_caddr (expr);
34 else if (head == ly_symbol2scm ("combine-stencil"))
37 for (SCM x = scm_cdr (expr); scm_is_pair (x); x = scm_cdr (x))
38 interpret_stencil_expression (scm_car (x), func, func_arg, o);
39 return;
41 else if (head == ly_symbol2scm ("grob-cause"))
43 SCM grob = scm_cadr (expr);
45 (*func) (func_arg, scm_list_3 (head,
46 ly_quote_scm (ly_offset2scm (o)), grob));
47 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
48 (*func) (func_arg, scm_list_1 (ly_symbol2scm ("no-origin")));
49 return;
51 else if (head == ly_symbol2scm ("color"))
53 SCM color = scm_cadr (expr);
54 SCM r = scm_car (color);
55 SCM g = scm_cadr (color);
56 SCM b = scm_caddr (color);
58 (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setcolor"), r, g, b));
59 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
60 (*func) (func_arg, scm_list_1 (ly_symbol2scm ("resetcolor")));
62 return;
64 else if (head == ly_symbol2scm ("rotate-stencil"))
66 SCM args = scm_cadr (expr);
67 SCM angle = scm_car (args);
68 Offset tmp = o + robust_scm2offset (scm_cadr (args), Offset (0.0, 0.0));
70 SCM offset = ly_offset2scm (tmp);
71 SCM x = scm_car (offset);
72 SCM y = scm_cdr (offset);
74 (*func) (func_arg, scm_list_4 (ly_symbol2scm ("setrotation"), angle, x, y));
75 interpret_stencil_expression (scm_caddr (expr), func, func_arg, o);
76 (*func) (func_arg, scm_list_4 (ly_symbol2scm ("resetrotation"), angle, x, y));
78 return;
80 else
82 (*func) (func_arg,
83 scm_list_4 (ly_symbol2scm ("placebox"),
84 scm_from_double (o[X_AXIS]),
85 scm_from_double (o[Y_AXIS]),
86 expr));
87 return;
92 struct Font_list
94 SCM fonts_;
97 static void
98 find_font_function (void *fs, SCM x)
100 Font_list *me = (Font_list *) fs;
102 if (scm_car (x) == ly_symbol2scm ("placebox"))
104 SCM args = scm_cdr (x);
105 SCM what = scm_caddr (args);
107 if (scm_is_pair (what))
109 SCM head = scm_car (what);
110 if (ly_symbol2scm ("text") == head)
111 me->fonts_ = scm_cons (scm_cadr (what), me->fonts_);
112 else if (head == ly_symbol2scm ("char"))
113 me->fonts_ = scm_cons (scm_cadr (what), me->fonts_);
119 find_expression_fonts (SCM expr)
121 Font_list fl;
123 fl.fonts_ = SCM_EOL;
125 interpret_stencil_expression (expr, &find_font_function,
126 (void *) & fl, Offset (0, 0));
128 return fl.fonts_;