]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/system.cc
* lily/pfb.cc (LY_DEFINE): ly:ttf->pfa, new function.
[lilypond.git] / lily / system.cc
index 0eecf4afebc1949dd1d1ac008993e2a2d21c976a..d667bdd2a0a22d32a5f58879e04c61b5075ad131 100644 (file)
@@ -3,35 +3,49 @@
 
   source file of the GNU LilyPond music typesetter
 
-  (c) 1996--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+  (c) 1996--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
 */
 
+#include "system.hh"
+
 #include <math.h>
 
 #include "align-interface.hh"
 #include "axis-group-interface.hh"
 #include "warn.hh"
-#include "system.hh"
 #include "main.hh"
 #include "paper-column.hh"
 #include "output-def.hh"
-#include "paper-outputter.hh"
 #include "paper-score.hh"
-#include "string.hh"
 #include "warn.hh"
-#include "stencil.hh"
 #include "all-font-metrics.hh"
 #include "spacing-interface.hh"
 #include "staff-symbol-referencer.hh"
 #include "paper-book.hh"
 #include "paper-system.hh"
+#include "tweak-registration.hh"
+
+
+System::System (System const &src, int count)
+  : Spanner (src, count)
+{
+  rank_ = 0;
+}
 
-System::System (SCM s)
-  : Spanner (s)
+System::System (SCM s, Object_key const*key)
+  : Spanner (s, key)
 {
   rank_ = 0;
 }
 
+
+Grob * 
+System::clone (int count) const
+{
+  return new System (*this, count);
+}
+
+
 int
 System::element_count () const
 {
@@ -98,7 +112,7 @@ System::get_lines ()
     fixups must be done in broken line_of_scores, because new elements
     are put over there.  */
   int count = 0;
-  for (int i=0; i < broken_intos_.size (); i++)
+  for (int i = 0; i < broken_intos_.size (); i++)
     {
       Grob *se = broken_intos_[i];
       SCM all = se->get_property ("all-elements");
@@ -130,7 +144,7 @@ System::get_lines ()
     }
 #endif
   
-  if (verbose_global_b)
+  if (be_verbose_global)
     progress_indication (_f ("Element count %d.",  count + element_count ()));
 
   int line_count = broken_intos_.size ();
@@ -138,14 +152,14 @@ System::get_lines ()
   
   for (int i = 0; i < line_count; i++)
     {
-      if (verbose_global_b)
+      if (be_verbose_global)
        progress_indication ("[");
 
       System *system = dynamic_cast<System*> (broken_intos_[i]);
       system->post_processing ();
       scm_vector_set_x (lines, scm_int2num (i), system->get_line ());
 
-      if (verbose_global_b)
+      if (be_verbose_global)
        progress_indication (to_string (i) + "]");
     }
   return lines;
@@ -201,7 +215,7 @@ set_loose_columns (System* which, Column_x_positions const *posns)
       Real rx =        right->extent (common, X_AXIS)[LEFT];
       Real lx = left->extent (common, X_AXIS)[RIGHT];
       Real total_dx = rx - lx;
-      Interval cval =col->extent (col, X_AXIS);
+      Interval cval = col->extent (col, X_AXIS);
 
       /* Put it in the middle.  This is not an ideal solution -- the
         break alignment code inserts a fixed space before the clef
@@ -230,14 +244,14 @@ System::break_into_pieces (Array<Column_x_positions> const &breaking)
 {
   for (int i = 0; i < breaking.size (); i++)
     {
-      System *system = dynamic_cast <System*> (clone ());
+      System *system = dynamic_cast <System*> (clone (i));
       system->rank_ = i;
 
       Link_array<Grob> c (breaking[i].cols_);
       pscore_->typeset_line (system);
       
-      system->set_bound (LEFT,c[0]);
-      system->set_bound (RIGHT,c.top ());
+      system->set_bound (LEFT, c[0]);
+      system->set_bound (RIGHT, c.top ());
       for (int j = 0; j < c.size (); j++)
        {
          c[j]->translate_axis (breaking[i].config_[j], X_AXIS);
@@ -262,20 +276,39 @@ System::add_column (Paper_column*p)
   Axis_group_interface::add_element (me, p);
 }
 
+void
+apply_tweaks (Grob *g, bool broken)
+{
+  if (bool (g->original_) == broken)
+    {
+      SCM tweaks = global_registry_->get_tweaks (g);
+      for (SCM s = tweaks; scm_is_pair (s); s = scm_cdr (s))
+       {
+         SCM proc = scm_caar (s);
+         SCM rest = scm_cdar (s);
+         scm_apply_1 (proc, g->self_scm(), rest);
+       }
+    }
+}
+
 void
 System::pre_processing ()
 {
   for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s))
     unsmob_grob (scm_car (s))->discretionary_processing ();
 
-  if (verbose_global_b)
+  if (be_verbose_global)
     progress_indication (_f ("Grob count %d", element_count ()));
   
   for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s))
     unsmob_grob (scm_car (s))->handle_prebroken_dependencies ();
   
   fixup_refpoints (get_property ("all-elements"));
+
   
+  for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s))
+    apply_tweaks (unsmob_grob (scm_car (s)), false);
+
   for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s))
     {
       Grob *sc = unsmob_grob (scm_car (s));
@@ -300,6 +333,9 @@ System::post_processing ()
   for (SCM s = get_property ("all-elements"); scm_is_pair (s); s = scm_cdr (s))
     {
       Grob *g = unsmob_grob (scm_car (s));
+      
+      apply_tweaks (g, true);
+
       g->calculate_dependencies (POSTCALCED, POSTCALCING,
           ly_symbol2scm ("after-line-breaking-callback"));
     }
@@ -332,12 +368,10 @@ System::get_line ()
   SCM exprs = SCM_EOL;
   SCM *tail = &exprs;
 
-  /* Output stencils in three layers: 0, 1, 2.  Default layer: 1.
-
-     Start with layer 3, since scm_cons prepends to list.  */
+  /* Output stencils in three layers: 0, 1, 2.  Default layer: 1. */
   SCM all = get_property ("all-elements");
   
-  for (int i = LAYER_COUNT; i--;)
+  for (int i = 0; i < LAYER_COUNT; i++)
     for (SCM s = all; scm_is_pair (s); s = scm_cdr (s))
       {
        Grob *g = unsmob_grob (scm_car (s));
@@ -360,6 +394,7 @@ System::get_line ()
 
        Stencil st = *stil;
        st.translate (o + extra);
+
        *tail = scm_cons (st.expr (), SCM_EOL);
        tail = SCM_CDRLOC(*tail);
       }
@@ -369,7 +404,7 @@ System::get_line ()
 
   Interval x (extent (this, X_AXIS));
   Interval y (extent (this, Y_AXIS));
-  Stencil sys_stencil (Box (x,y),
+  Stencil sys_stencil (Box (x, y),
                       scm_cons (ly_symbol2scm ("combine-stencil"),
                                 exprs));
 
@@ -385,8 +420,8 @@ System::get_line ()
  
   Paper_system *pl = new Paper_system (sys_stencil, false);
   pl->staff_refpoints_ = staff_refpoints;
-  Item * break_point =this->get_bound(LEFT);
-  pl->penalty_ =
+  Item * break_point = this->get_bound(LEFT);
+  pl->break_before_penalty_ =
     robust_scm2double (break_point->get_property ("page-penalty"), 0.0);
   
   return scm_gc_unprotect_object (pl->self_scm ());
@@ -444,7 +479,7 @@ System::columns () const
   return acs;
 }
 
-ADD_INTERFACE (System,"system-interface",
+ADD_INTERFACE (System, "system-interface",
               "This is the toplevel object: each object in a score "
               "ultimately has a System object as its X and Y parent. ",
               "all-elements spaceable-staves columns")