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::extent (Axis a) const
36 Stencil::Stencil (Box b, SCM func)
49 Stencil::translate (Offset o)
54 if (abs (o[a]) > 100 CM
55 || isinf (o[a]) || isnan (o[a]))
57 programming_error ("Improbable offset for translation: setting to zero");
63 expr_ = scm_list_n (ly_symbol2scm ("translate-stencil"),
65 expr_, SCM_UNDEFINED);
71 Stencil::translate_axis (Real x, Axis a)
79 Stencil::add_stencil (Stencil const &s)
81 expr_ = scm_list_n (ly_symbol2scm ("combine-stencil"),
82 s.expr_, expr_, SCM_UNDEFINED);
87 Stencil::set_empty (bool e)
91 dim_[X_AXIS].set_empty ();
92 dim_[Y_AXIS].set_empty ();
96 dim_[X_AXIS] = Interval (0,0);
97 dim_[Y_AXIS] = Interval (0,0);
102 Stencil::align_to (Axis a, Real x)
107 Interval i (extent (a));
108 translate_axis (-i.linear_combination (x), a);
111 /* See scheme Function. */
113 Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding,
116 Real my_extent= is_empty () ? 0.0 : dim_[a][d];
117 Interval i (s.extent (a));
121 programming_error ("Stencil::add_at_edge: adding empty stencil.");
127 Real offset = (my_extent - his_extent) + d * padding;
128 if (minimum > 0 && fabs (offset) < minimum)
129 offset = sign (offset) * minimum;
132 toadd.translate_axis (offset, a);
136 /* Hmm... maybe this is not such a good idea ; stuff can be empty,
137 while expr_ == '() */
139 Stencil::is_empty () const
141 return expr_ == SCM_EOL;
145 Stencil::get_expr () const
151 Stencil::extent_box () const
157 Stencil::print_smob (SCM , SCM port, scm_print_state *)
159 scm_puts ("#<Stencil ", port);
160 scm_puts (" >", port);
165 Stencil::mark_smob (SCM s)
167 Stencil *r = (Stencil *) ly_cdr (s);
171 IMPLEMENT_SIMPLE_SMOBS (Stencil);
172 IMPLEMENT_TYPE_P (Stencil, "ly:stencil?");
173 IMPLEMENT_DEFAULT_EQUAL_P (Stencil);