2 molecule.cc -- implement Molecule
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "font-metric.hh"
12 #include "dimensions.hh"
13 #include "interval.hh"
15 #include "molecule.hh"
17 #include "killing-cons.tcc"
20 Molecule::extent(Axis a) const
25 Molecule::Molecule (Box b, SCM func)
38 Molecule::translate (Offset o)
44 || isinf (o[a]) || isnan (o[a]))
46 programming_error ("Improbable offset for translation: setting to zero");
52 expr_ = gh_list (ly_symbol2scm ("translate-molecule"),
54 expr_, SCM_UNDEFINED);
61 Molecule::translate_axis (Real x,Axis a)
71 Molecule::add_molecule (Molecule const &m)
73 expr_ = gh_list (ly_symbol2scm ("combine-molecule"),
75 expr_, SCM_UNDEFINED);
80 Molecule::set_empty (bool e)
84 dim_[X_AXIS].set_empty ();
85 dim_[Y_AXIS].set_empty ();
89 dim_[X_AXIS] = Interval(0,0);
90 dim_[Y_AXIS] = Interval (0,0);
96 Molecule::align_to (Axis a, Direction d)
98 Interval i (extent (a));
99 Real r = (d == CENTER) ? i.center () : i[d];
100 translate_axis (-r, a);
104 Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
106 Real my_extent= empty_b () ? 0.0 : dim_[a][d];
107 Interval i (m.extent (a));
109 programming_error ("Molecule::add_at_edge: adding empty molecule.");
111 Real his_extent = i[-d];
112 Real offset = my_extent - his_extent;
114 toadd.translate_axis (offset + d * padding, a);
115 add_molecule (toadd);
119 Molecule::empty_b () const
121 return expr_ == SCM_EOL;
125 fontify_atom(Font_metric * met, SCM f)
127 return gh_list (ly_symbol2scm ("fontify"),
128 ly_quote_scm (met->description ()), f, SCM_UNDEFINED);
132 Molecule::get_expr () const
138 create_molecule (SCM scm_mol)
140 if (!gh_pair_p (scm_mol))
143 SCM exp = gh_car (scm_mol);
144 scm_mol = gh_cdr (scm_mol);
146 if (gh_pair_p (scm_mol))
148 Interval i1 = ly_scm2interval (gh_car (scm_mol));
149 Interval i2 = ly_scm2interval (gh_cdr (scm_mol));
152 return Molecule (b, exp);
156 Molecule::create_scheme () const
158 return gh_cons (expr_,
159 gh_cons (ly_interval2scm (dim_[X_AXIS]),
160 ly_interval2scm (dim_[Y_AXIS])));