2 stencil.cc -- implement Stencil
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2005 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "dimensions.hh"
13 #include "font-metric.hh"
14 #include "input-smob.hh"
15 #include "string-convert.hh"
18 #include "ly-smobs.icc"
26 Stencil::Stencil (Box b, SCM func)
33 Stencil::print_smob (SCM, SCM port, scm_print_state *)
35 scm_puts ("#<Stencil ", port);
36 scm_puts (" >", port);
41 Stencil::mark_smob (SCM smob)
43 Stencil *s = (Stencil *) SCM_CELL_WORD_1 (smob);
47 IMPLEMENT_SIMPLE_SMOBS (Stencil);
48 IMPLEMENT_TYPE_P (Stencil, "ly:stencil?");
49 IMPLEMENT_DEFAULT_EQUAL_P (Stencil);
52 Stencil::extent (Axis a) const
58 Stencil::is_empty () const
60 return (expr_ == SCM_EOL
61 || dim_[X_AXIS].is_empty ()
62 || dim_[Y_AXIS].is_empty ());
66 Stencil::expr () const
72 Stencil::extent_box () const
77 Stencil::origin () const
83 Stencil::translate (Offset o)
94 programming_error (String_convert::form_string ("Improbable offset for stencil: %f staff space", o[a])
96 + "Setting to zero.");
102 expr_ = scm_list_n (ly_symbol2scm ("translate-stencil"),
104 expr_, SCM_UNDEFINED);
111 Stencil::translate_axis (Real x, Axis a)
119 Stencil::add_stencil (Stencil const &s)
121 expr_ = scm_list_3 (ly_symbol2scm ("combine-stencil"), s.expr_, expr_);
126 Stencil::set_empty (bool e)
130 dim_[X_AXIS].set_empty ();
131 dim_[Y_AXIS].set_empty ();
135 dim_[X_AXIS] = Interval (0, 0);
136 dim_[Y_AXIS] = Interval (0, 0);
141 Stencil::align_to (Axis a, Real x)
146 Interval i (extent (a));
147 translate_axis (-i.linear_combination (x), a);
150 /* FIXME: unintuitive naming, you would expect *this to be moved.
151 Kept (keeping?) API for compat with add_at_edge ().
153 What is PADDING, what is MINIMUM, exactly? */
155 Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s,
156 Real padding, Real minimum) const
158 Interval my_extent = dim_[a];
159 Interval i (s.extent (a));
163 programming_error ("Stencil::moved_to_edge: adding empty stencil.");
165 // SCM_ASSERT_TYPE (0, s.expr (), SCM_ARG1, __FUNCTION__, "non-empty stencil");
170 Real offset = (my_extent.is_empty () ? 0.0 : my_extent[d] - his_extent)
174 toadd.translate_axis (offset, a);
176 if (minimum > 0 && d * (-origin ()[a] + toadd.origin ()[a]) < minimum)
177 toadd.translate_axis (-toadd.origin ()[a]
178 + origin ()[a] + d * minimum, a);
183 /* See scheme Function. */
185 Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding,
188 add_stencil (moved_to_edge (a, d, s, padding, minimum));
192 Stencil::in_color (Real r, Real g, Real b) const
194 Stencil new_stencil (extent_box (),
195 scm_list_3 (ly_symbol2scm ("color"),
196 scm_list_3 (scm_from_double (r),
198 scm_from_double (b)),