2 stencil-scheme.cc -- implement Stencil
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "font-metric.hh"
12 LY_DEFINE(ly_stencil_set_extent_x,"ly:stencil-set-extent!", 3 , 0, 0,
13 (SCM mol, SCM axis, SCM np),
14 "Set the extent (@var{extent} must be a pair of numbers) of @var{mol} in \n"
15 "@var{axis} direction (0 or 1 for x- and y-axis respectively).\n"
18 Stencil* m = unsmob_stencil (mol);
19 SCM_ASSERT_TYPE (m, mol, SCM_ARG1, __FUNCTION__, "stencil");
20 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
21 SCM_ASSERT_TYPE (is_number_pair (np), np, SCM_ARG3, __FUNCTION__, "number pair");
23 Interval iv = ly_scm2interval (np);
24 m->dim_[Axis (gh_scm2int (axis))] = iv;
30 LY_DEFINE(ly_translate_stencil_axis,"ly:stencil-translate-axis", 3, 0, 0,
31 (SCM mol, SCM amount, SCM axis),
32 "Return a @var{mol}, but translated by @var{amount} in @var{axis} direction")
34 Stencil* m = unsmob_stencil (mol);
35 SCM_ASSERT_TYPE (m, mol, SCM_ARG1, __FUNCTION__, "stencil");
36 SCM_ASSERT_TYPE (gh_number_p (amount), amount, SCM_ARG2, __FUNCTION__, "number pair");
37 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
41 q.translate_axis (gh_scm2double (amount), Axis (gh_scm2int (axis)));
43 return q.smobbed_copy();
46 LY_DEFINE(ly_translate_stencil,"ly:stencil-translate", 2, 0, 0,
47 (SCM mol, SCM offset),
48 "Return a @var{mol}, but translated by @var{offset} (a pair of numbers).")
50 Stencil* m = unsmob_stencil (mol);
51 SCM_ASSERT_TYPE (m, mol, SCM_ARG1, __FUNCTION__, "stencil");
52 SCM_ASSERT_TYPE (is_number_pair (offset), offset, SCM_ARG2, __FUNCTION__, "number pair");
53 Offset o = ly_scm2offset (offset);
57 return q.smobbed_copy();
60 LY_DEFINE(ly_stencil_get_extent,
61 "ly:stencil-get-extent", 2 , 0, 0, (SCM mol, SCM axis),
62 "Return a pair of numbers signifying the extent of @var{mol} in "
63 "@var{axis} direction (0 or 1 for x and y axis respectively)."
66 Stencil *m = unsmob_stencil (mol);
67 SCM_ASSERT_TYPE (m, mol, SCM_ARG1, __FUNCTION__, "stencil");
68 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
70 return ly_interval2scm (m->extent (Axis (gh_scm2int (axis))));
74 LY_DEFINE(ly_stencil_combined_at_edge,
75 "ly:stencil-combine-at-edge",
76 4, 2, 0, (SCM first, SCM axis, SCM direction,
80 "Construct a stencil by putting @var{second} next to "
81 "@var{first}. @var{axis} can be 0 (x-axis) or 1 (y-axis), @var{direction} can be "
82 "-1 (left or down) or 1 (right or up). "
83 "The stencils are juxtaposed with @var{padding} as extra space. If "
84 "this puts the reference points closer than @var{minimum}, they are moved "
85 "by the latter amount.")
88 Stencil * m1 = unsmob_stencil (first);
89 Stencil * m2 = unsmob_stencil (second);
93 SCM_ASSERT_TYPE(is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
94 SCM_ASSERT_TYPE(is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
97 if (padding != SCM_UNDEFINED)
99 SCM_ASSERT_TYPE(gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
100 p = gh_scm2double (padding);
103 if (minimum != SCM_UNDEFINED)
105 SCM_ASSERT_TYPE(gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
106 m = gh_scm2double (minimum);
112 result.add_at_edge (Axis (gh_scm2int (axis)), Direction (gh_scm2int (direction)),
115 return result.smobbed_copy ();
119 FIXME: support variable number of arguments.
122 LY_DEFINE(ly_stencil_add ,
123 "ly:stencil-add", 0, 0, 1, (SCM args),
124 "Combine stencils. Takes any number of arguments."
127 #define FUNC_NAME __FUNCTION__
128 SCM_VALIDATE_REST_ARGUMENT (args);
132 while (!SCM_NULLP (args))
134 Stencil * m = unsmob_stencil (gh_car (args));
137 SCM_ASSERT_TYPE(m, gh_car (args), SCM_ARGn, __FUNCTION__,
140 result.add_stencil (*m);
142 args = gh_cdr (args);
145 return result.smobbed_copy ();
148 LY_DEFINE(ly_make_stencil,
149 "ly:make-stencil", 3, 0, 0, (SCM expr, SCM xext, SCM yext),
151 "Stencils are a device independent output expressions."
152 "They carry two pieces of information: \n\n"
153 "1: a specification of how to print this object. "
154 "This specification is processed by the output backends, for example "
155 "@file{scm/output-tex.scm}.\n\n"
156 "2: the vertical and horizontal extents of the object.\n\n"
160 SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair");
161 SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair");
163 Box b (ly_scm2interval (xext), ly_scm2interval(yext));
165 return m.smobbed_copy ();
170 fontify_atom (Font_metric const * met, SCM f)
175 return scm_list_n (ly_symbol2scm ("fontify"),
176 ly_quote_scm (met->description_), f, SCM_UNDEFINED);
179 LY_DEFINE(ly_fontify_atom,"ly:fontify-atom", 2, 0, 0,
181 "Add a font selection command for the font metric @var{met} to @var{f}.")
183 SCM_ASSERT_TYPE(unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric");
185 return fontify_atom (unsmob_metrics (met), f);
187 LY_DEFINE(ly_align_to_x,"ly:stencil-align-to!", 3, 0, 0, (SCM mol, SCM axis, SCM dir),
189 "Align @var{mol} using its own extents. @var{dir} is a number -1, 1 are "
190 " left and right respectively. Other values are interpolated (so 0 means "
193 SCM_ASSERT_TYPE(unsmob_stencil (mol), mol, SCM_ARG1, __FUNCTION__, "stencil");
194 SCM_ASSERT_TYPE(is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
195 SCM_ASSERT_TYPE(gh_number_p (dir), dir, SCM_ARG3, __FUNCTION__, "number");
197 unsmob_stencil (mol)->align_to ((Axis)gh_scm2int (axis),
198 gh_scm2double (dir));
200 return SCM_UNDEFINED;