]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/molecule.cc
release: 1.3.40
[lilypond.git] / lily / molecule.cc
index 663a554e93a3a7e9c771b290b3dd4ea731e75f26..db6472b9e547804ba21e6227505e00a2b6b16505 100644 (file)
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+  (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"
 
-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 (Real x,Axis a)
+Molecule::Molecule (Box b, SCM func)
 {
-    for (iter_top (ats,c); c.ok(); c++)
-       c->translate (x,a);
+  expr_ = func;
+  dim_ = b ;
 }
 
-void
-Molecule::add (Molecule const &m)
+Molecule::Molecule()
 {
-    for (iter_top (m.ats,c); c.ok(); c++) {
-       add (**c);
-    }
+  expr_ = SCM_EOL;
+  set_empty (true);
 }
 
 void
-Molecule::add_right (Molecule const &m)
+Molecule::translate (Offset o)
 {
-     if (!ats.size()) {
-       add (m);
-       return;
+  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);
     }
-     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 ("translate-molecule"),
+                  ly_offset2scm (o),
+                  expr_, SCM_UNDEFINED);
+  if (!empty_b ())
+    dim_.translate (o);
 }
+  
 
 void
-Molecule::add_left (Molecule const &m)
+Molecule::translate_axis (Real x,Axis a)
 {
-    if (!ats.size()) {
-       add (m);
-       return;
-    }
-  Real xof=extent().x ().left - m.extent ().x ().right;
-   
-    Molecule toadd (m);
-    toadd.translate (Offset (xof, 0.0));
-    add (toadd);
-}
+  Offset o(0,0);
+  o[a] = x;
+  translate (o);
+}  
+
 
 
 void
-Molecule::add_top (Molecule const &m)
+Molecule::add_molecule (Molecule const &m)
 {
-      if (!ats.size()) {
-       add (m);
-       return;
-    }
-   Real yof=extent().y ().right - m.extent ().y ().left;
-
-    Molecule toadd (m);
-    toadd.translate (yof, Y_AXIS);
-    add (toadd);
+  expr_ = gh_list (ly_symbol2scm ("combine-molecule"),
+                  m.expr_,
+                  expr_, SCM_UNDEFINED);
+  dim_.unite (m.dim_);
 }
 
 void
-Molecule::add_bottom (Molecule const &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 yof=extent().y ().left- m.extent ().y ().right;
-    Molecule toadd (m);
-    toadd.translate (yof, Y_AXIS);
-    add (toadd);
 }
 
+
 void
-Molecule::operator = (Molecule const &)
+Molecule::align_to (Axis a, Direction d)
 {
-    assert (false);
+  Interval i (extent (a));
+  Real r =  (d == CENTER) ? i.center () : i[d];
+  translate_axis (-r, a);
 }
 
-Molecule::Molecule (Molecule const &s)
+
+void
+Molecule::add_at_edge (Axis a, Direction d, Molecule const &m, Real padding)
 {
-    add (s);
+  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::print() const
+bool
+Molecule::empty_b () const
 {
-#ifndef NPRINT
-    if (! check_debug)
-       return;
-    for (iter_top (ats,c); c.ok(); c++)
-       c->print();
-#endif
+  return expr_ == SCM_EOL;
 }
 
-void
-Molecule::add (Atom const &a)
+
+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);
 }