X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fmolecule.cc;h=5620a92d180e07aeccd5580b4a54439c76d56ccd;hb=f798a4c8737f0d279fcf54ba4f0951074565fa76;hp=613fc0ea1dd5586f8414b9f02222664899dfeba0;hpb=69b9cead5afe7164b9053d26eba582fec3825ef8;p=lilypond.git diff --git a/lily/molecule.cc b/lily/molecule.cc index 613fc0ea1d..5620a92d18 100644 --- a/lily/molecule.cc +++ b/lily/molecule.cc @@ -3,99 +3,149 @@ source file of the GNU LilyPond music typesetter - (c) 1997--1998 Han-Wen Nienhuys + (c) 1997--2000 Han-Wen Nienhuys */ +/* + ugh. Rewrite not finished yet. Still must copy atom lists. + */ + + +#include + +#include "font-metric.hh" +#include "dimensions.hh" #include "interval.hh" -#include "dimen.hh" #include "string.hh" #include "molecule.hh" -#include "atom.hh" + #include "debug.hh" -#include "tex.hh" +#include "killing-cons.tcc" -String -Molecule::TeX_string() const -{ - String s; - for (iter_top (ats,c); c.ok(); c++) - s+=c->TeX_string(); - return s; -} Box Molecule::extent() const { - Box b; - for (iter_top (ats,c); c.ok(); c++) - b.unite (c->extent()); - return b; + return dim_; } -void -Molecule::translate (Offset o) +Interval +Molecule::extent(Axis a) const { - for (iter_top (ats,c); c.ok(); c++) - c->translate (o); + return dim_[a]; } -void -Molecule::translate_axis (Real x,Axis a) +Molecule::Molecule (Box b, SCM func) { - for (iter_top (ats,c); c.ok(); c++) - c->translate_axis (x,a); + expr_ = func; + dim_ = b ; +} + +Molecule::Molecule() +{ + expr_ = SCM_EOL; + set_empty (true); } void -Molecule::add (Molecule const &m) +Molecule::translate (Offset o) { - for (iter_top (m.ats,c); c.ok(); c++) + Axis a = X_AXIS; + while (a < NO_AXES) { - add (**c); + if (abs(o[a]) > 30 CM + || isinf (o[a]) || isnan (o[a])) + { + programming_error ("Improbable offset for translation: setting to zero"); + o[a] = 0.0; + } + incr (a); } + + expr_ = gh_list (ly_symbol2scm ("translate-molecule"), + to_scm (o), + expr_, SCM_UNDEFINED); + if (!empty_b ()) + dim_.translate (o); } + + +void +Molecule::translate_axis (Real x,Axis a) +{ + Offset o(0,0); + o[a] = x; + translate (o); +} + void -Molecule::add_at_edge (Axis a, Direction d, Molecule const &m) +Molecule::add_molecule (Molecule const &m) { - if (!ats.size()) + expr_ = gh_list (ly_symbol2scm ("combine-molecule"), + m.expr_, + expr_, SCM_UNDEFINED); + dim_.unite (m.dim_); +} + +void +Molecule::set_empty (bool e) +{ + if (e) { - add (m); - return; + dim_[X_AXIS].set_empty (); + dim_[Y_AXIS].set_empty (); + } + else + { + dim_[X_AXIS] = Interval(0,0); + dim_[Y_AXIS] = Interval (0,0); } - Real offset = extent ()[a][d] - m.extent ()[a][-d]; - Molecule toadd (m); - toadd.translate_axis (offset, a); - add (toadd); } - - void -Molecule::operator = (Molecule const &) +Molecule::print () const { - assert (false); +#ifndef NPRINT + gh_display (expr_); +#endif } -Molecule::Molecule (Molecule const &s) +void +Molecule::align_to (Axis a, Direction d) { - add (s); + Interval i (extent (a)); + Real r = (d == CENTER) ? i.center () : i[d]; + translate_axis (-r, a); } + void -Molecule::print() const +Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding) { -#ifndef NPRINT - if (! check_debug) - return; - for (iter_top (ats,c); c.ok(); c++) - c->print(); -#endif + Real my_extent= empty_b () ? 0.0 : dim_[a][d]; + Interval i (m.extent ()[a]); + if (i.empty_b ()) + programming_error ("Molecule::add_at_edge: adding empty molecule."); + + Real his_extent = i[-d]; + Real offset = my_extent - his_extent; + Molecule toadd (m); + toadd.translate_axis (offset + d * padding, a); + add_molecule (toadd); } -void -Molecule::add (Atom const &a) +bool +Molecule::empty_b () const +{ + return expr_ == SCM_EOL; +} + + +SCM +fontify_atom(Font_metric * met, SCM f) { - ats.bottom().add (new Atom (a)); + return gh_list (ly_symbol2scm ("fontify"), + ly_quote_scm (met->description ()), f, SCM_UNDEFINED); }