(all-grob-descriptions): remove gap from
[lilypond.git] / lily / stencil-scheme.cc
blob79ab518636e0b29bf2e4d2cc8c70ad35a8e95f8e
1 /*
2 stencil-scheme.cc -- implement Stencil scheme accessors
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "font-metric.hh"
10 #include "stencil.hh"
13 TODO: naming add/combine.
16 UMGH. junkme!
19 LY_DEFINE (ly_stencil_set_extent_x, "ly:stencil-set-extent!",
20 3, 0, 0, (SCM stil, SCM axis, SCM np),
21 "Set the extent of @var{stil} "
22 "(@var{extent} must be a pair of numbers) "
23 "in @var{axis} direction (0 or 1 for x- and y-axis respectively).")
25 Stencil *s = unsmob_stencil (stil);
26 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
27 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
28 SCM_ASSERT_TYPE (is_number_pair (np), np, SCM_ARG3, __FUNCTION__,
29 "number pair");
31 Interval iv = ly_scm2interval (np);
32 s->dim_[Axis (gh_scm2int (axis))] = iv;
34 return SCM_UNDEFINED;
37 LY_DEFINE (ly_translate_stencil_axis, "ly:stencil-translate-axis",
38 3, 0, 0, (SCM stil, SCM amount, SCM axis),
39 "Return a copy of @var{stil} but translated by @var{amount} in @var{axis} direction.")
41 Stencil *s = unsmob_stencil (stil);
42 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
43 SCM_ASSERT_TYPE (gh_number_p (amount), amount, SCM_ARG2, __FUNCTION__, "number pair");
44 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
46 SCM new_s = s->smobbed_copy ();
47 Stencil *q = unsmob_stencil (new_s);
48 q->translate_axis (gh_scm2double (amount), Axis (gh_scm2int (axis)));
49 return new_s;
53 LY_DEFINE (ly_translate_stencil, "ly:stencil-translate",
54 2, 0, 0, (SCM stil, SCM offset),
55 "Return a @var{stil}, "
56 "but translated by @var{offset} (a pair of numbers).")
58 Stencil *s = unsmob_stencil (stil);
59 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
60 SCM_ASSERT_TYPE (is_number_pair (offset), offset, SCM_ARG2, __FUNCTION__, "number pair");
61 Offset o = ly_scm2offset (offset);
63 SCM new_s = s->smobbed_copy ();
64 Stencil *q =unsmob_stencil (new_s);
65 q->translate (o);
66 return new_s;
69 LY_DEFINE (ly_stencil_get_expr, "ly:stencil-get-expr",
70 1, 0, 0, (SCM stil),
71 "Return the expression of @var{stil}.")
73 Stencil *s = unsmob_stencil (stil);
74 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
75 return s->get_expr ();
78 LY_DEFINE (ly_stencil_get_extent, "ly:stencil-extent",
79 2, 0, 0, (SCM stil, SCM axis),
80 "Return a pair of numbers signifying the extent of @var{stil} in "
81 "@var{axis} direction (0 or 1 for x and y axis respectively).")
83 Stencil *s = unsmob_stencil (stil);
84 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
85 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
87 return ly_interval2scm (s->extent (Axis (gh_scm2int (axis))));
90 LY_DEFINE (ly_stencil_moved_to_edge, "ly:stencil-moved-to-edge",
91 4, 2, 0, (SCM first, SCM axis, SCM direction, SCM second,
92 SCM padding, SCM minimum),
93 "Similar to @code{ly:stencil-combine-edge}, but returns "
94 "@var{second} positioned to be next to @var{first}. ")
97 C&P from combine-at-edge.
99 Stencil *s1 = unsmob_stencil (first);
100 Stencil *s2 = unsmob_stencil (second);
101 Stencil first_stencil;
103 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
104 SCM_ASSERT_TYPE (is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
106 Real p = 0.0;
107 if (padding != SCM_UNDEFINED)
109 SCM_ASSERT_TYPE (gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
110 p = gh_scm2double (padding);
112 Real m = 0.0;
113 if (minimum != SCM_UNDEFINED)
115 SCM_ASSERT_TYPE (gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
116 m = gh_scm2double (minimum);
119 if (s1)
120 first_stencil = *s1;
122 if (s2)
123 return first_stencil.moved_to_edge (Axis (gh_scm2int (axis)),
124 Direction (gh_scm2int (direction)),
125 *s2, p, m).smobbed_copy ();
126 else
127 return Stencil().smobbed_copy ();
132 LY_DEFINE (ly_stencil_combine_at_edge, "ly:stencil-combine-at-edge",
133 4, 2, 0, (SCM first, SCM axis, SCM direction,
134 SCM second,
135 SCM padding,
136 SCM minimum),
137 "Construct a stencil by putting @var{second} next to @var{first}. "
138 "@var{axis} can be 0 (x-axis) or 1 (y-axis), "
139 "@var{direction} can be -1 (left or down) or 1 (right or up). "
140 "The stencils are juxtaposed with @var{padding} as extra space. "
141 "If this puts the reference points closer than @var{minimum}, "
142 "they are moved by the latter amount.")
144 Stencil *s1 = unsmob_stencil (first);
145 Stencil *s2 = unsmob_stencil (second);
146 Stencil result;
148 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
149 SCM_ASSERT_TYPE (is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
151 Real p = 0.0;
152 if (padding != SCM_UNDEFINED)
154 SCM_ASSERT_TYPE (gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
155 p = gh_scm2double (padding);
157 Real m = 0.0;
158 if (minimum != SCM_UNDEFINED)
160 SCM_ASSERT_TYPE (gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
161 m = gh_scm2double (minimum);
164 if (s1)
165 result = *s1;
166 if (s2)
167 result.add_at_edge (Axis (gh_scm2int (axis)),
168 Direction (gh_scm2int (direction)), *s2, p, m);
170 return result.smobbed_copy ();
173 LY_DEFINE (ly_stencil_add , "ly:stencil-add",
174 0, 0, 1, (SCM args),
175 "Combine stencils. Takes any number of arguments.")
177 #define FUNC_NAME __FUNCTION__
178 SCM_VALIDATE_REST_ARGUMENT (args);
180 Stencil result;
182 while (!SCM_NULLP (args))
184 Stencil *s = unsmob_stencil (gh_car (args));
185 if (!s)
186 SCM_ASSERT_TYPE (s, gh_car (args), SCM_ARGn, __FUNCTION__, "Stencil");
188 result.add_stencil (*s);
189 args = gh_cdr (args);
192 return result.smobbed_copy ();
195 LY_DEFINE (ly_make_stencil, "ly:make-stencil",
196 3, 0, 0, (SCM expr, SCM xext, SCM yext),
197 " \n"
198 "Stencils are a device independent output expressions."
199 "They carry two pieces of information: \n\n"
200 "1: a specification of how to print this object. "
201 "This specification is processed by the output backends, "
202 " for example @file{scm/output-tex.scm}.\n\n"
203 "2: the vertical and horizontal extents of the object.\n\n")
205 SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair");
206 SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair");
208 Box b (ly_scm2interval (xext), ly_scm2interval (yext));
209 Stencil s (b, expr);
210 return s.smobbed_copy ();
214 fontify_atom (Font_metric const *met, SCM f)
216 if (f == SCM_EOL)
217 return f;
218 else
219 return scm_list_n (ly_symbol2scm ("fontify"),
220 ly_quote_scm (met->description_), f, SCM_UNDEFINED);
223 LY_DEFINE (ly_fontify_atom,"ly:fontify-atom",
224 2, 0, 0, (SCM met, SCM f),
225 "Add a font selection command for the font metric @var{met} "
226 "to @var{f}.")
228 SCM_ASSERT_TYPE (unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric");
230 return fontify_atom (unsmob_metrics (met), f);
233 LY_DEFINE (ly_align_to_x, "ly:stencil-align-to!",
234 3, 0, 0, (SCM stil, SCM axis, SCM dir),
235 "Align @var{stil} using its own extents. "
236 "@var{dir} is a number -1, 1 are left and right respectively. "
237 "Other values are interpolated (so 0 means the center. ")
239 SCM_ASSERT_TYPE (unsmob_stencil (stil), stil, SCM_ARG1, __FUNCTION__, "stencil");
240 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
241 SCM_ASSERT_TYPE (gh_number_p (dir), dir, SCM_ARG3, __FUNCTION__, "number");
243 unsmob_stencil (stil)->align_to ((Axis)gh_scm2int (axis),
244 gh_scm2double (dir));
245 return SCM_UNDEFINED;