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"
12 LY_DEFINE (ly_stencil_set_extent_x,"ly:stencil-set-extent!", 3 , 0, 0,
13 (SCM stil, SCM axis, SCM np),
14 "Set the extent of @var{stil} "
15 "(@var{extent} must be a pair of numbers) "
16 "in @var{axis} direction (0 or 1 for x- and y-axis respectively).")
18 Stencil *s = unsmob_stencil (stil);
19 SCM_ASSERT_TYPE (s, stil, 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 s->dim_[Axis (gh_scm2int (axis))] = iv;
29 LY_DEFINE (ly_translate_stencil_axis,"ly:stencil-translate-axis", 3, 0, 0,
30 (SCM stil, SCM amount, SCM axis),
31 "Return a @var{stil}, "
32 "but translated by @var{amount} in @var{axis} direction.")
34 Stencil *s = unsmob_stencil (stil);
35 SCM_ASSERT_TYPE (s, stil, 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");
40 q.translate_axis (gh_scm2double (amount), Axis (gh_scm2int (axis)));
42 return q.smobbed_copy();
45 LY_DEFINE (ly_translate_stencil,"ly:stencil-translate", 2, 0, 0,
46 (SCM stil, SCM offset),
47 "Return a @var{stil}, "
48 "but translated by @var{offset} (a pair of numbers).")
50 Stencil *s = unsmob_stencil (stil);
51 SCM_ASSERT_TYPE (s, stil, 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_expr,
61 "ly:stencil-get-expr", 1 , 0, 0, (SCM stil),
62 "Return the expression of @var{stil}.")
64 Stencil *s = unsmob_stencil (stil);
65 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
66 return s->get_expr ();
69 LY_DEFINE (ly_stencil_get_extent,
70 "ly:stencil-get-extent", 2 , 0, 0, (SCM stil, SCM axis),
71 "Return a pair of numbers signifying the extent of @var{stil} in "
72 "@var{axis} direction (0 or 1 for x and y axis respectively).")
74 Stencil *s = unsmob_stencil (stil);
75 SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil");
76 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
78 return ly_interval2scm (s->extent (Axis (gh_scm2int (axis))));
81 LY_DEFINE (ly_stencil_combined_at_edge,
82 "ly:stencil-combine-at-edge",
83 4, 2, 0, (SCM first, SCM axis, SCM direction,
87 "Construct a stencil by putting @var{second} next to @var{first}. "
88 "@var{axis} can be 0 (x-axis) or 1 (y-axis), "
89 "@var{direction} can be -1 (left or down) or 1 (right or up). "
90 "The stencils are juxtaposed with @var{padding} as extra space. "
91 "If this puts the reference points closer than @var{minimum}, "
92 "they are moved by the latter amount.")
94 Stencil *s1 = unsmob_stencil (first);
95 Stencil *s2 = unsmob_stencil (second);
98 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG3, __FUNCTION__, "axis");
99 SCM_ASSERT_TYPE (is_direction (direction), direction, SCM_ARG4, __FUNCTION__, "dir");
102 if (padding != SCM_UNDEFINED)
104 SCM_ASSERT_TYPE(gh_number_p (padding), padding, SCM_ARG5, __FUNCTION__, "number");
105 p = gh_scm2double (padding);
108 if (minimum != SCM_UNDEFINED)
110 SCM_ASSERT_TYPE(gh_number_p (minimum), minimum, SCM_ARG6, __FUNCTION__, "number");
111 m = gh_scm2double (minimum);
117 result.add_at_edge (Axis (gh_scm2int (axis)),
118 Direction (gh_scm2int (direction)), *s2, p, m);
120 return result.smobbed_copy ();
123 /* FIXME: support variable number of arguments. */
124 LY_DEFINE (ly_stencil_add ,
125 "ly:stencil-add", 0, 0, 1, (SCM args),
126 "Combine stencils. Takes any number of arguments.")
128 #define FUNC_NAME __FUNCTION__
129 SCM_VALIDATE_REST_ARGUMENT (args);
133 while (!SCM_NULLP (args))
135 Stencil *s = unsmob_stencil (gh_car (args));
137 SCM_ASSERT_TYPE (s, gh_car (args), SCM_ARGn, __FUNCTION__, "Stencil");
139 result.add_stencil (*s);
140 args = gh_cdr (args);
143 return result.smobbed_copy ();
146 LY_DEFINE (ly_make_stencil,
147 "ly:make-stencil", 3, 0, 0, (SCM expr, SCM xext, SCM yext),
149 "Stencils are a device independent output expressions."
150 "They carry two pieces of information: \n\n"
151 "1: a specification of how to print this object. "
152 "This specification is processed by the output backends, "
153 " for example @file{scm/output-tex.scm}.\n\n"
154 "2: the vertical and horizontal extents of the object.\n\n")
156 SCM_ASSERT_TYPE (is_number_pair (xext), xext, SCM_ARG2, __FUNCTION__, "number pair");
157 SCM_ASSERT_TYPE (is_number_pair (yext), yext, SCM_ARG3, __FUNCTION__, "number pair");
159 Box b (ly_scm2interval (xext), ly_scm2interval(yext));
161 return s.smobbed_copy ();
165 fontify_atom (Font_metric const *met, SCM f)
170 return scm_list_n (ly_symbol2scm ("fontify"),
171 ly_quote_scm (met->description_), f, SCM_UNDEFINED);
174 LY_DEFINE (ly_fontify_atom,"ly:fontify-atom", 2, 0, 0,
176 "Add a font selection command for the font metric @var{met} "
179 SCM_ASSERT_TYPE(unsmob_metrics (met), met, SCM_ARG1, __FUNCTION__, "font metric");
181 return fontify_atom (unsmob_metrics (met), f);
184 LY_DEFINE (ly_align_to_x,"ly:stencil-align-to!", 3, 0, 0,
185 (SCM stil, SCM axis, SCM dir),
186 "Align @var{stil} using its own extents. "
187 "@var{dir} is a number -1, 1 are left and right respectively. "
188 "Other values are interpolated (so 0 means the center. ")
190 SCM_ASSERT_TYPE (unsmob_stencil (stil), stil, SCM_ARG1, __FUNCTION__, "stencil");
191 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
192 SCM_ASSERT_TYPE (gh_number_p (dir), dir, SCM_ARG3, __FUNCTION__, "number");
194 unsmob_stencil (stil)->align_to ((Axis)gh_scm2int (axis),
195 gh_scm2double (dir));
197 return SCM_UNDEFINED;