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"
17 LY_DEFINE (ly_stencil_set_extent_x,"ly:stencil-set-extent!",
18 3, 0, 0, (SCM stil, SCM axis, SCM np),
19 "Set the extent of @var{stil} "
20 "(@var{extent} must be a pair of numbers) "
21 "in @var{axis} direction (0 or 1 for x- and y-axis respectively).")
23 Stencil *s = unsmob_stencil (stil);
24 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
25 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
26 SCM_ASSERT_TYPE (is_number_pair (np), np, SCM_ARG3, __FUNCTION__, "number pair");
28 Interval iv = ly_scm2interval (np);
29 s->dim_[Axis (gh_scm2int (axis))] = iv;
34 LY_DEFINE (ly_translate_stencil_axis, "ly:stencil-translate-axis",
35 3, 0, 0, (SCM stil, SCM amount, SCM axis),
36 "Return a @var{stil}, "
37 "but translated by @var{amount} in @var{axis} direction.")
39 Stencil *s = unsmob_stencil (stil);
40 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
41 SCM_ASSERT_TYPE (gh_number_p (amount), amount, SCM_ARG2, __FUNCTION__, "number pair");
42 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
45 q.translate_axis (gh_scm2double (amount), Axis (gh_scm2int (axis)));
47 return q.smobbed_copy ();
50 LY_DEFINE (ly_translate_stencil,"ly:stencil-translate",
51 2, 0, 0, (SCM stil, SCM offset),
52 "Return a @var{stil}, "
53 "but translated by @var{offset} (a pair of numbers).")
55 Stencil *s = unsmob_stencil (stil);
56 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
57 SCM_ASSERT_TYPE (is_number_pair (offset), offset, SCM_ARG2, __FUNCTION__, "number pair");
58 Offset o = ly_scm2offset (offset);
62 return q.smobbed_copy ();
65 LY_DEFINE (ly_stencil_get_expr, "ly:stencil-get-expr",
67 "Return the expression of @var{stil}.")
69 Stencil *s = unsmob_stencil (stil);
70 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
71 return s->get_expr ();
74 LY_DEFINE (ly_stencil_get_extent,
75 "ly:stencil-extent", 2 , 0, 0, (SCM stil, SCM axis),
76 "Return a pair of numbers signifying the extent of @var{stil} in "
77 "@var{axis} direction (0 or 1 for x and y axis respectively).")
79 Stencil *s = unsmob_stencil (stil);
80 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
81 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
83 return ly_interval2scm (s->extent (Axis (gh_scm2int (axis))));
86 LY_DEFINE (ly_stencil_combined_at_edge,
87 "ly:stencil-combine-at-edge",
88 4, 2, 0, (SCM first, SCM axis, SCM direction,
92 "Construct a stencil by putting @var{second} next to @var{first}. "
93 "@var{axis} can be 0 (x-axis) or 1 (y-axis), "
94 "@var{direction} can be -1 (left or down) or 1 (right or up). "
95 "The stencils are juxtaposed with @var{padding} as extra space. "
96 "If this puts the reference points closer than @var{minimum}, "
97 "they are moved by the latter amount.")
99 Stencil *s1 = unsmob_stencil (first);
100 Stencil *s2 = unsmob_stencil (second);
103 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
104 SCM_ASSERT_TYPE (is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
107 if (padding != SCM_UNDEFINED)
109 SCM_ASSERT_TYPE (gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
110 p = gh_scm2double (padding);
113 if (minimum != SCM_UNDEFINED)
115 SCM_ASSERT_TYPE (gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
116 m = gh_scm2double (minimum);
122 result.add_at_edge (Axis (gh_scm2int (axis)),
123 Direction (gh_scm2int (direction)), *s2, p, m);
125 return result.smobbed_copy ();
128 /* FIXME: support variable number of arguments. */
129 LY_DEFINE (ly_stencil_add ,
130 "ly:stencil-add", 0, 0, 1, (SCM args),
131 "Combine stencils. Takes any number of arguments.")
133 #define FUNC_NAME __FUNCTION__
134 SCM_VALIDATE_REST_ARGUMENT (args);
138 while (!SCM_NULLP (args))
140 Stencil *s = unsmob_stencil (gh_car (args));
142 SCM_ASSERT_TYPE (s, gh_car (args), SCM_ARGn, __FUNCTION__, "Stencil");
144 result.add_stencil (*s);
145 args = gh_cdr (args);
148 return result.smobbed_copy ();
151 LY_DEFINE (ly_make_stencil,
152 "ly:make-stencil", 3, 0, 0, (SCM expr, SCM xext, SCM yext),
154 "Stencils are a device independent output expressions."
155 "They carry two pieces of information: \n\n"
156 "1: a specification of how to print this object. "
157 "This specification is processed by the output backends, "
158 " for example @file{scm/output-tex.scm}.\n\n"
159 "2: the vertical and horizontal extents of the object.\n\n")
161 SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair");
162 SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair");
164 Box b (ly_scm2interval (xext), ly_scm2interval (yext));
166 return s.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} "
184 SCM_ASSERT_TYPE (unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric");
186 return fontify_atom (unsmob_metrics (met), f);
189 LY_DEFINE (ly_align_to_x, "ly:stencil-align-to!",
190 3, 0, 0, (SCM stil, SCM axis, SCM dir),
191 "Align @var{stil} using its own extents. "
192 "@var{dir} is a number -1, 1 are left and right respectively. "
193 "Other values are interpolated (so 0 means the center. ")
195 SCM_ASSERT_TYPE (unsmob_stencil (stil), stil, SCM_ARG1, __FUNCTION__, "stencil");
196 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
197 SCM_ASSERT_TYPE (gh_number_p (dir), dir, SCM_ARG3, __FUNCTION__, "number");
199 unsmob_stencil (stil)->align_to ((Axis)gh_scm2int (axis),
200 gh_scm2double (dir));
201 return SCM_UNDEFINED;