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 TODO: naming add/combine.
16 UGH. Junk all mutators.
18 LY_DEFINE (ly_stencil_set_extent_x
, "ly:stencil-set-extent!",
19 3, 0, 0, (SCM stil
, SCM axis
, SCM np
),
20 "Set the extent of @var{stil} "
21 "(@var{extent} must be a pair of numbers) "
22 "in @var{axis} direction (0 or 1 for x- and y-axis respectively).")
24 Stencil
*s
= unsmob_stencil (stil
);
25 SCM_ASSERT_TYPE (s
, stil
, SCM_ARG1
, __FUNCTION__
, "stencil");
26 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG2
, __FUNCTION__
, "axis");
27 SCM_ASSERT_TYPE (is_number_pair (np
), np
, SCM_ARG3
, __FUNCTION__
,
30 Interval iv
= ly_scm2interval (np
);
31 s
->dim_
[Axis (ly_scm2int (axis
))] = iv
;
33 return SCM_UNSPECIFIED
;
36 LY_DEFINE (ly_translate_stencil_axis
, "ly:stencil-translate-axis",
37 3, 0, 0, (SCM stil
, SCM amount
, SCM axis
),
38 "Return a copy of @var{stil} but translated by @var{amount} in @var{axis} direction.")
40 Stencil
*s
= unsmob_stencil (stil
);
41 SCM_ASSERT_TYPE (s
, stil
, SCM_ARG1
, __FUNCTION__
, "stencil");
42 SCM_ASSERT_TYPE (ly_c_number_p (amount
), amount
, SCM_ARG2
, __FUNCTION__
, "number pair");
43 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG3
, __FUNCTION__
, "axis");
45 SCM new_s
= s
->smobbed_copy ();
46 Stencil
*q
= unsmob_stencil (new_s
);
47 q
->translate_axis (ly_scm2double (amount
), Axis (ly_scm2int (axis
)));
52 LY_DEFINE (ly_translate_stencil
, "ly:stencil-translate",
53 2, 0, 0, (SCM stil
, SCM offset
),
54 "Return a @var{stil}, "
55 "but translated by @var{offset} (a pair of numbers).")
57 Stencil
*s
= unsmob_stencil (stil
);
58 SCM_ASSERT_TYPE (s
, stil
, SCM_ARG1
, __FUNCTION__
, "stencil");
59 SCM_ASSERT_TYPE (is_number_pair (offset
), offset
, SCM_ARG2
, __FUNCTION__
, "number pair");
60 Offset o
= ly_scm2offset (offset
);
62 SCM new_s
= s
->smobbed_copy ();
63 Stencil
*q
=unsmob_stencil (new_s
);
68 LY_DEFINE (ly_stencil_expr
, "ly:stencil-expr",
70 "Return the expression of @var{stil}.")
72 Stencil
*s
= unsmob_stencil (stil
);
73 SCM_ASSERT_TYPE (s
, stil
, SCM_ARG1
, __FUNCTION__
, "stencil");
77 LY_DEFINE (ly_stencil_get_extent
, "ly:stencil-extent",
78 2, 0, 0, (SCM stil
, SCM axis
),
79 "Return a pair of numbers signifying the extent of @var{stil} in "
80 "@var{axis} direction (0 or 1 for x and y axis respectively).")
82 Stencil
*s
= unsmob_stencil (stil
);
83 SCM_ASSERT_TYPE (s
, stil
, SCM_ARG1
, __FUNCTION__
, "stencil");
84 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG2
, __FUNCTION__
, "axis");
86 return ly_interval2scm (s
->extent (Axis (ly_scm2int (axis
))));
89 LY_DEFINE (ly_stencil_moved_to_edge
, "ly:stencil-moved-to-edge",
90 4, 2, 0, (SCM first
, SCM axis
, SCM direction
, SCM second
,
91 SCM padding
, SCM minimum
),
92 "Similar to @code{ly:stencil-combine-edge}, but returns "
93 "@var{second} positioned to be next to @var{first}. ")
96 C&P from combine-at-edge.
98 Stencil
*s1
= unsmob_stencil (first
);
99 Stencil
*s2
= unsmob_stencil (second
);
100 Stencil first_stencil
;
102 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG3
, __FUNCTION__
, "axis");
103 SCM_ASSERT_TYPE (is_direction (direction
), direction
, SCM_ARG4
, __FUNCTION__
, "dir");
106 if (padding
!= SCM_UNDEFINED
)
108 SCM_ASSERT_TYPE (ly_c_number_p (padding
), padding
, SCM_ARG5
, __FUNCTION__
, "number");
109 p
= ly_scm2double (padding
);
112 if (minimum
!= SCM_UNDEFINED
)
114 SCM_ASSERT_TYPE (ly_c_number_p (minimum
), minimum
, SCM_ARG6
, __FUNCTION__
, "number");
115 m
= ly_scm2double (minimum
);
122 return first_stencil
.moved_to_edge (Axis (ly_scm2int (axis
)),
123 Direction (ly_scm2int (direction
)),
124 *s2
, p
, m
).smobbed_copy ();
126 return Stencil().smobbed_copy ();
131 LY_DEFINE (ly_stencil_combine_at_edge
, "ly:stencil-combine-at-edge",
132 4, 2, 0, (SCM first
, SCM axis
, SCM direction
,
136 "Construct a stencil by putting @var{second} next to @var{first}. "
137 "@var{axis} can be 0 (x-axis) or 1 (y-axis), "
138 "@var{direction} can be -1 (left or down) or 1 (right or up). "
139 "The stencils are juxtaposed with @var{padding} as extra space. "
140 "If this puts the reference points closer than @var{minimum}, "
141 "they are moved by the latter amount."
142 "@var{first} and @var{second} may also be '() or #f.")
144 Stencil
*s1
= unsmob_stencil (first
);
145 Stencil
*s2
= unsmob_stencil (second
);
148 SCM_ASSERT_TYPE (s1
|| first
== SCM_BOOL_F
|| first
== SCM_EOL
,
149 first
, SCM_ARG1
, __FUNCTION__
, "Stencil, #f or ()");
150 SCM_ASSERT_TYPE (s2
|| second
== SCM_BOOL_F
|| second
== SCM_EOL
,
151 second
, SCM_ARG4
, __FUNCTION__
, "Stencil, #f or ()");
152 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG2
, __FUNCTION__
, "axis");
153 SCM_ASSERT_TYPE (is_direction (direction
), direction
, SCM_ARG3
, __FUNCTION__
, "dir");
156 if (padding
!= SCM_UNDEFINED
)
158 SCM_ASSERT_TYPE (ly_c_number_p (padding
), padding
, SCM_ARG5
, __FUNCTION__
, "number");
159 p
= ly_scm2double (padding
);
162 if (minimum
!= SCM_UNDEFINED
)
164 SCM_ASSERT_TYPE (ly_c_number_p (minimum
), minimum
, SCM_ARG6
, __FUNCTION__
, "number");
165 m
= ly_scm2double (minimum
);
172 result
.add_at_edge (Axis (ly_scm2int (axis
)),
173 Direction (ly_scm2int (direction
)), *s2
, p
, m
);
175 return result
.smobbed_copy ();
178 LY_DEFINE (ly_stencil_add
, "ly:stencil-add",
180 "Combine stencils. Takes any number of arguments.")
182 #define FUNC_NAME __FUNCTION__
183 SCM_VALIDATE_REST_ARGUMENT (args
);
187 while (!SCM_NULLP (args
))
189 Stencil
*s
= unsmob_stencil (ly_car (args
));
191 SCM_ASSERT_TYPE (s
, ly_car (args
), SCM_ARGn
, __FUNCTION__
, "Stencil");
193 result
.add_stencil (*s
);
194 args
= ly_cdr (args
);
197 return result
.smobbed_copy ();
200 LY_DEFINE (ly_make_stencil
, "ly:make-stencil",
201 3, 0, 0, (SCM expr
, SCM xext
, SCM yext
),
203 "Stencils are a device independent output expressions."
204 "They carry two pieces of information: \n\n"
205 "1: a specification of how to print this object. "
206 "This specification is processed by the output backends, "
207 " for example @file{scm/output-tex.scm}.\n\n"
208 "2: the vertical and horizontal extents of the object.\n\n")
210 SCM_ASSERT_TYPE (is_number_pair (xext
), xext
, SCM_ARG2
, __FUNCTION__
, "number pair");
211 SCM_ASSERT_TYPE (is_number_pair (yext
), yext
, SCM_ARG3
, __FUNCTION__
, "number pair");
213 Box
b (ly_scm2interval (xext
), ly_scm2interval (yext
));
215 return s
.smobbed_copy ();
219 LY_DEFINE (ly_stencil_align_to_x
, "ly:stencil-align-to!",
220 3, 0, 0, (SCM stil
, SCM axis
, SCM dir
),
221 "Align @var{stil} using its own extents. "
222 "@var{dir} is a number -1, 1 are left and right respectively. "
223 "Other values are interpolated (so 0 means the center. ")
225 SCM_ASSERT_TYPE (unsmob_stencil (stil
), stil
, SCM_ARG1
, __FUNCTION__
, "stencil");
226 SCM_ASSERT_TYPE (is_axis (axis
), axis
, SCM_ARG2
, __FUNCTION__
, "axis");
227 SCM_ASSERT_TYPE (ly_c_number_p (dir
), dir
, SCM_ARG3
, __FUNCTION__
, "number");
229 unsmob_stencil (stil
)->align_to ((Axis
)ly_scm2int (axis
),
230 ly_scm2double (dir
));