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"
19 #include "ly-smobs.icc"
22 Stencil::smobbed_copy () const
24 Stencil *s = new Stencil (*this);
25 return s->smobbed_self ();
29 Stencil::origin () const
35 Stencil::extent (Axis a) const
40 Stencil::Stencil (Box b, SCM func)
53 Stencil::translate (Offset o)
58 if (abs (o[a]) > 100 CM
59 || isinf (o[a]) || isnan (o[a]))
61 programming_error ("Improbable offset for translation: setting to zero");
67 expr_ = scm_list_n (ly_symbol2scm ("translate-stencil"),
69 expr_, SCM_UNDEFINED);
76 Stencil::translate_axis (Real x, Axis a)
84 Stencil::add_stencil (Stencil const &s)
86 expr_ = scm_list_n (ly_symbol2scm ("combine-stencil"),
87 s.expr_, expr_, SCM_UNDEFINED);
92 Stencil::set_empty (bool e)
96 dim_[X_AXIS].set_empty ();
97 dim_[Y_AXIS].set_empty ();
101 dim_[X_AXIS] = Interval (0,0);
102 dim_[Y_AXIS] = Interval (0,0);
107 Stencil::align_to (Axis a, Real x)
112 Interval i (extent (a));
113 translate_axis (-i.linear_combination (x), a);
117 TODO: unintuitive naming, you would expect *this to be moved. Kept
118 API for compat with add_at_edge ().
121 Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, Real padding,
124 Real my_extent= is_empty () ? 0.0 : dim_[a][d];
125 Interval i (s.extent (a));
129 programming_error ("Stencil::move_to_edge: adding empty stencil.");
135 Real offset = (my_extent - his_extent) + d * padding;
138 toadd.translate_axis (offset,a);
141 && d *(- origin ()[a] + toadd.origin ()[a]) < minimum)
142 toadd.translate_axis ( -toadd.origin ()[a]
143 + origin ()[a] + d* minimum, a);
148 /* See scheme Function. */
150 Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding,
153 add_stencil (moved_to_edge (a,d,s,padding, minimum));
156 /* Hmm... maybe this is not such a good idea ; stuff can be empty,
157 while expr_ == '() */
159 Stencil::is_empty () const
161 return expr_ == SCM_EOL;
165 Stencil::get_expr () const
171 Stencil::extent_box () const
177 Stencil::print_smob (SCM , SCM port, scm_print_state *)
179 scm_puts ("#<Stencil ", port);
180 scm_puts (" >", port);
185 Stencil::mark_smob (SCM s)
187 Stencil *r = (Stencil *) ly_cdr (s);
191 IMPLEMENT_SIMPLE_SMOBS (Stencil);
192 IMPLEMENT_TYPE_P (Stencil, "ly:stencil?");
193 IMPLEMENT_DEFAULT_EQUAL_P (Stencil);