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>
9 #include "font-metric.hh"
13 LY_DEFINE (ly_stencil_set_extent_x,"ly:stencil-set-extent!",
14 3, 0, 0, (SCM stil, SCM axis, SCM np),
15 "Set the extent of @var{stil} "
16 "(@var{extent} must be a pair of numbers) "
17 "in @var{axis} direction (0 or 1 for x- and y-axis respectively).")
19 Stencil *s = unsmob_stencil (stil);
20 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
21 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
22 SCM_ASSERT_TYPE (is_number_pair (np), np, SCM_ARG3, __FUNCTION__, "number pair");
24 Interval iv = ly_scm2interval (np);
25 s->dim_[Axis (gh_scm2int (axis))] = iv;
30 LY_DEFINE (ly_translate_stencil_axis, "ly:stencil-translate-axis",
31 3, 0, 0, (SCM stil, SCM amount, SCM axis),
32 "Return a @var{stil}, "
33 "but translated by @var{amount} in @var{axis} direction.")
35 Stencil *s = unsmob_stencil (stil);
36 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
37 SCM_ASSERT_TYPE (gh_number_p (amount), amount, SCM_ARG2, __FUNCTION__, "number pair");
38 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",
47 2, 0, 0, (SCM stil, SCM offset),
48 "Return a @var{stil}, "
49 "but translated by @var{offset} (a pair of numbers).")
51 Stencil *s = unsmob_stencil (stil);
52 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
53 SCM_ASSERT_TYPE (is_number_pair (offset), offset, SCM_ARG2, __FUNCTION__, "number pair");
54 Offset o = ly_scm2offset (offset);
58 return q.smobbed_copy ();
61 LY_DEFINE (ly_stencil_get_expr, "ly:stencil-get-expr",
63 "Return the expression of @var{stil}.")
65 Stencil *s = unsmob_stencil (stil);
66 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
67 return s->get_expr ();
70 LY_DEFINE (ly_stencil_get_extent,
71 "ly:stencil-get-extent", 2 , 0, 0, (SCM stil, SCM axis),
72 "Return a pair of numbers signifying the extent of @var{stil} in "
73 "@var{axis} direction (0 or 1 for x and y axis respectively).")
75 Stencil *s = unsmob_stencil (stil);
76 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
77 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
79 return ly_interval2scm (s->extent (Axis (gh_scm2int (axis))));
82 LY_DEFINE (ly_stencil_combined_at_edge,
83 "ly:stencil-combine-at-edge",
84 4, 2, 0, (SCM first, SCM axis, SCM direction,
88 "Construct a stencil by putting @var{second} next to @var{first}. "
89 "@var{axis} can be 0 (x-axis) or 1 (y-axis), "
90 "@var{direction} can be -1 (left or down) or 1 (right or up). "
91 "The stencils are juxtaposed with @var{padding} as extra space. "
92 "If this puts the reference points closer than @var{minimum}, "
93 "they are moved by the latter amount.")
95 Stencil *s1 = unsmob_stencil (first);
96 Stencil *s2 = unsmob_stencil (second);
99 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
100 SCM_ASSERT_TYPE (is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
103 if (padding != SCM_UNDEFINED)
105 SCM_ASSERT_TYPE (gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
106 p = gh_scm2double (padding);
109 if (minimum != SCM_UNDEFINED)
111 SCM_ASSERT_TYPE (gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
112 m = gh_scm2double (minimum);
118 result.add_at_edge (Axis (gh_scm2int (axis)),
119 Direction (gh_scm2int (direction)), *s2, p, m);
121 return result.smobbed_copy ();
124 /* FIXME: support variable number of arguments. */
125 LY_DEFINE (ly_stencil_add ,
126 "ly:stencil-add", 0, 0, 1, (SCM args),
127 "Combine stencils. Takes any number of arguments.")
129 #define FUNC_NAME __FUNCTION__
130 SCM_VALIDATE_REST_ARGUMENT (args);
134 while (!SCM_NULLP (args))
136 Stencil *s = unsmob_stencil (gh_car (args));
138 SCM_ASSERT_TYPE (s, gh_car (args), SCM_ARGn, __FUNCTION__, "Stencil");
140 result.add_stencil (*s);
141 args = gh_cdr (args);
144 return result.smobbed_copy ();
147 LY_DEFINE (ly_make_stencil,
148 "ly:make-stencil", 3, 0, 0, (SCM expr, SCM xext, SCM yext),
150 "Stencils are a device independent output expressions."
151 "They carry two pieces of information: \n\n"
152 "1: a specification of how to print this object. "
153 "This specification is processed by the output backends, "
154 " for example @file{scm/output-tex.scm}.\n\n"
155 "2: the vertical and horizontal extents of the object.\n\n")
157 SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair");
158 SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair");
160 Box b (ly_scm2interval (xext), ly_scm2interval (yext));
162 return s.smobbed_copy ();
166 fontify_atom (Font_metric const *met, SCM f)
171 return scm_list_n (ly_symbol2scm ("fontify"),
172 ly_quote_scm (met->description_), f, SCM_UNDEFINED);
175 LY_DEFINE (ly_fontify_atom,"ly:fontify-atom", 2, 0, 0,
177 "Add a font selection command for the font metric @var{met} "
180 SCM_ASSERT_TYPE (unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric");
182 return fontify_atom (unsmob_metrics (met), f);
185 LY_DEFINE (ly_align_to_x, "ly:stencil-align-to!",
186 3, 0, 0, (SCM stil, SCM axis, SCM dir),
187 "Align @var{stil} using its own extents. "
188 "@var{dir} is a number -1, 1 are left and right respectively. "
189 "Other values are interpolated (so 0 means the center. ")
191 SCM_ASSERT_TYPE (unsmob_stencil (stil), stil, SCM_ARG1, __FUNCTION__, "stencil");
192 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
193 SCM_ASSERT_TYPE (gh_number_p (dir), dir, SCM_ARG3, __FUNCTION__, "number");
195 unsmob_stencil (stil)->align_to ((Axis)gh_scm2int (axis),
196 gh_scm2double (dir));
197 return SCM_UNDEFINED;