2 stencil.cc -- implement Stencil
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include <libc-extension.hh> // isinf
12 #include "font-metric.hh"
13 #include "dimensions.hh"
14 #include "interval.hh"
20 #include "ly-smobs.icc"
24 Stencil::smobbed_copy () const
26 Stencil *s = new Stencil (*this);
27 return s->smobbed_self ();
31 Stencil::origin () const
37 Stencil::extent (Axis a) const
42 Stencil::Stencil (Box b, SCM func)
55 Stencil::translate (Offset o)
60 if (abs (o[a]) > 100 CM
61 || isinf (o[a]) || isnan (o[a]))
63 programming_error ("Improbable offset for translation: setting to zero");
69 expr_ = scm_list_n (ly_symbol2scm ("translate-stencil"),
71 expr_, SCM_UNDEFINED);
78 Stencil::translate_axis (Real x, Axis a)
86 Stencil::add_stencil (Stencil const &s)
88 expr_ = scm_list_n (ly_symbol2scm ("combine-stencil"),
89 s.expr_, expr_, SCM_UNDEFINED);
94 Stencil::set_empty (bool e)
98 dim_[X_AXIS].set_empty ();
99 dim_[Y_AXIS].set_empty ();
103 dim_[X_AXIS] = Interval (0,0);
104 dim_[Y_AXIS] = Interval (0,0);
109 Stencil::align_to (Axis a, Real x)
114 Interval i (extent (a));
115 translate_axis (-i.linear_combination (x), a);
119 TODO: unintuitive naming, you would expect *this to be moved. Kept
120 API for compat with add_at_edge ().
123 Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, Real padding,
126 Real my_extent= is_empty () ? 0.0 : dim_[a][d];
127 Interval i (s.extent (a));
131 programming_error ("Stencil::move_to_edge: adding empty stencil.");
137 Real offset = (my_extent - his_extent) + d * padding;
140 toadd.translate_axis (offset,a);
143 && d *(- origin ()[a] + toadd.origin ()[a]) < minimum)
144 toadd.translate_axis ( -toadd.origin ()[a]
145 + origin ()[a] + d* minimum, a);
150 /* See scheme Function. */
152 Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding,
155 add_stencil (moved_to_edge (a,d,s,padding, minimum));
158 /* Hmm... maybe this is not such a good idea ; stuff can be empty,
159 while expr_ == '() */
161 Stencil::is_empty () const
163 return expr_ == SCM_EOL;
167 Stencil::get_expr () const
173 Stencil::extent_box () const
179 Stencil::print_smob (SCM , SCM port, scm_print_state *)
181 scm_puts ("#<Stencil ", port);
182 scm_puts (" >", port);
187 Stencil::mark_smob (SCM s)
189 Stencil *r = (Stencil *) ly_cdr (s);
193 IMPLEMENT_SIMPLE_SMOBS (Stencil);
194 IMPLEMENT_TYPE_P (Stencil, "ly:stencil?");
195 IMPLEMENT_DEFAULT_EQUAL_P (Stencil);