]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/molecule.cc
release: 1.3.40
[lilypond.git] / lily / molecule.cc
index c52fdc7b329b324a974f625bc2fce765b85095bc..db6472b9e547804ba21e6227505e00a2b6b16505 100644 (file)
-#include "varray.hh"
+/*
+  molecule.cc -- implement Molecule
+
+  source file of the GNU LilyPond music typesetter
+
+  (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+*/
+
+/*
+  ugh. Rewrite not finished yet. Still must copy atom lists.
+ */
+
+
+#include <math.h>
+
+#include "font-metric.hh"
+#include "dimensions.hh"
 #include "interval.hh"
-#include "dimen.hh"
 #include "string.hh"
 #include "molecule.hh"
-#include "symbol.hh"
+
 #include "debug.hh"
-#include "tex.hh"
+#include "killing-cons.tcc"
 
-void
-Atom::print() const
-{
-    mtor << "texstring: " <<sym.tex<<"\n";    
-}
 
 Box
-Atom::extent() const
+Molecule::extent() const
 {
-    Box b( sym.dim);
-    b.translate(off);
-    return b;
+  return dim_;
 }
 
-Atom::Atom(Symbol s)
+Interval
+Molecule::extent(Axis a) const
 {
-    sym=s;
+  return dim_[a];
 }
 
-
-String
-Atom::TeXstring() const
+Molecule::Molecule (Box b, SCM func)
 {
-    // whugh.. Hard coded...
-    String s("\\placebox{%}{%}{%}");
-    Array<String> a;
-    a.push(print_dimen(off.y));
-    a.push(print_dimen(off.x));
-    a.push(sym.tex);
-    return substitute_args(s, a);
+  expr_ = func;
+  dim_ = b ;
 }
 
-/* *************** */
-
-String
-Molecule::TeXstring() const
+Molecule::Molecule()
 {
-    String s;
-    for(iter_top(ats,c); c.ok(); c++)
-       s+=c->TeXstring();
-    return s;
-}
-
-Box
-Molecule::extent() const
-{
-    Box b;
-    for(iter_top(ats,c); c.ok(); c++)
-       b.unite(c->extent());
-    return b;
+  expr_ = SCM_EOL;
+  set_empty (true);
 }
 
 void
-Molecule::translate(Offset o)
+Molecule::translate (Offset o)
 {
-    for (iter_top(ats,c); c.ok(); c++)
-       c->translate(o);
+  Axis a = X_AXIS;
+  while (a < NO_AXES)
+    {
+      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"),
+                  ly_offset2scm (o),
+                  expr_, SCM_UNDEFINED);
+  if (!empty_b ())
+    dim_.translate (o);
 }
+  
 
 void
-Molecule::add(const Molecule &m)
+Molecule::translate_axis (Real x,Axis a)
 {
-    for (iter_top(m.ats,c); c.ok(); c++) {
-       add(**c);
-    }
-}
+  Offset o(0,0);
+  o[a] = x;
+  translate (o);
+}  
+
+
 
 void
-Molecule::add_right(const Molecule &m)
+Molecule::add_molecule (Molecule const &m)
 {
-     if (!ats.size()) {
-       add(m);
-       return;
-    }
-   Real xof=extent().x.right - m.extent().x.left;
-    Molecule toadd(m);
-    toadd.translate(Offset(xof, 0.0));
-    add(toadd);
+  expr_ = gh_list (ly_symbol2scm ("combine-molecule"),
+                  m.expr_,
+                  expr_, SCM_UNDEFINED);
+  dim_.unite (m.dim_);
 }
 
 void
-Molecule::add_left(const Molecule &m)
+Molecule::set_empty (bool e)
 {
-    if (!ats.size()) {
-       add(m);
-       return;
+  if (e)
+    {
+      dim_[X_AXIS].set_empty ();
+      dim_[Y_AXIS].set_empty ();
+    }
+  else
+    {
+      dim_[X_AXIS] = Interval(0,0);
+      dim_[Y_AXIS] = Interval (0,0);
     }
-    Real xof=extent().x.left - m.extent().x.right;
-    Molecule toadd(m);
-    toadd.translate(Offset(xof, 0.0));
-    add(toadd);
 }
 
 
 void
-Molecule::add_top(const Molecule &m)
+Molecule::align_to (Axis a, Direction d)
 {
-      if (!ats.size()) {
-       add(m);
-       return;
-    }
-  Real yof=extent().y.right - m.extent().y.left;
-    Molecule toadd(m);
-    toadd.translate(Offset(0,yof));
-    add(toadd);
+  Interval i (extent (a));
+  Real r =  (d == CENTER) ? i.center () : i[d];
+  translate_axis (-r, a);
 }
 
-void
-Molecule::add_bottom(const Molecule &m)
-{
-    if (!ats.size()) {
-       add(m);
-       return;
-    }
-    Real yof=extent().y.left- m.extent().y.right;
-    Molecule toadd(m);
-    toadd.translate(Offset(0,yof));
-    add(toadd);
-}
 
 void
-Molecule::operator = (const Molecule&)
+Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
 {
-    assert(false);
+  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);
 }
 
-Molecule::Molecule(const Molecule&s)
+bool
+Molecule::empty_b () const
 {
-    add(s);
+  return expr_ == SCM_EOL;
 }
 
-void
-Molecule::print() const
+
+SCM
+fontify_atom(Font_metric * met, SCM f)
 {
-    for (iter_top(ats,c); c.ok(); c++)
-       c->print();
+  return  gh_list (ly_symbol2scm ("fontify"),
+                  ly_quote_scm (met->description ()), f, SCM_UNDEFINED);
 }