]> git.donarmstrong.com Git - lilypond.git/commitdiff
lilypond-0.1.1
authorfred <fred>
Sun, 24 Mar 2002 19:52:51 +0000 (19:52 +0000)
committerfred <fred>
Sun, 24 Mar 2002 19:52:51 +0000 (19:52 +0000)
lily/horizontal-align-item.cc
lily/include/horizontal-align-item.hh
lily/word-wrap.cc [new file with mode: 0644]

index 972b52f8e0812f0472f6b5a177d6e37bbcdf2501..46c9b70b853b2a40d761e7ad48d6ec727e337ced 100644 (file)
 
 
 IMPLEMENT_IS_TYPE_B1(Horizontal_align_item,Item);
-
-
+void
+Horizontal_align_item::OK() const
+{
+   for  (int i =0; i < item_l_arr_.size(); i++) 
+       assert ( pcol_l_ == item_l_arr_[i]->pcol_l_ );
+}
 bool
 Horizontal_align_item::contains_b(Item *i)const
 {
@@ -57,6 +61,7 @@ struct Horizontal_align_item_content {
 void
 Horizontal_align_item::do_pre_processing()
 {
+    OK();
     {  
        Array<Horizontal_align_item_content> content;
        for  (int i =0; i < item_l_arr_.size(); i++) 
index 639ce1b22eeef5a5d4450ffb93de0c59a9c8bbb5..d66a85a99f616000c821cb8c21036179b2efd8bd 100644 (file)
@@ -35,6 +35,7 @@ public:
     DECLARE_MY_RUNTIME_TYPEINFO;
     SCORE_ELEM_CLONE(Horizontal_align_item);
     void add(Item*, int p);
+    void OK()const;
     Horizontal_align_item();
 protected:
     
diff --git a/lily/word-wrap.cc b/lily/word-wrap.cc
new file mode 100644 (file)
index 0000000..a2ac4e9
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+  word-wrap.cc -- implement Word_wrap
+
+  source file of the LilyPond music typesetter
+
+  (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
+*/
+
+#include "word-wrap.hh"
+#include "p-score.hh"
+#include "debug.hh"
+#include "p-col.hh"
+#include "spring-spacer.hh"
+
+
+/** el stupido. 
+   
+  
+   A Dynamic Programming type of algorithm
+   similar to TeX's is in Gourlay_breaking
+
+   */
+Array<Col_hpositions>
+Word_wrap::do_solve()const
+{
+    problem_OK();
+    
+    PCursor<PCol*> curcol(pscore_l_->col_p_list_.top());
+    Array<Col_hpositions> breaking;
+    Line_of_cols breakpoints(find_breaks());
+    assert(breakpoints.size()>=2);
+
+    int break_idx_i=0;                 
+    while ( break_idx_i < breakpoints.size() -1) {
+       Col_hpositions minimum;
+       Col_hpositions current;
+
+        // do  another line
+       PCol *post = breakpoints[break_idx_i]->postbreak_p_;
+       current.add( post);
+       curcol++;               // skip the breakable.
+       break_idx_i++;
+
+       while (break_idx_i < breakpoints.size()) {
+       
+           // add another measure.
+           while (breakpoints[break_idx_i] != curcol.ptr()){
+               current.add(curcol);
+               curcol++;
+           }
+           current.add(breakpoints[break_idx_i]->prebreak_p_ );
+
+           current.spacer_l_ = generate_spacing_problem( current.cols );
+
+           // try to solve
+           if (!feasible(current.cols)) {
+               if (!minimum.cols.size()) {
+                   warning("Ugh, this measure is too long, breakpoint: "
+                         + String(break_idx_i) +
+                       " (generating stupido solution)");
+                   current.stupid_solution();
+                   current.energy_f_ = - 1; // make sure we break out.
+               } else
+                   current.energy_f_ = infinity_f;     // make sure we go back
+           } else {
+               
+               current.solve_line();
+               current.print();
+           }
+
+           delete current.spacer_l_;
+           current.spacer_l_ =0;
+
+           // update minimum, or backup.
+           if (current.energy_f_ < minimum.energy_f_ || current.energy_f_ < 0) {
+               minimum = current;
+           } else {            // we're one col too far.
+               break_idx_i--;
+               while (curcol.ptr() != breakpoints[break_idx_i])
+                   curcol --;
+               break;          // do the next line.
+           }
+
+
+           // add nobreak version of breakable column
+           current.cols.top()=breakpoints[break_idx_i];
+           curcol ++;
+           break_idx_i++;
+       }
+
+       *mlog << "[" <<break_idx_i<<"]"<<flush;
+       breaking.push(minimum);
+    }
+    print_stats();
+    return breaking;
+}
+
+Word_wrap::Word_wrap()
+{
+    get_line_spacer = Spring_spacer::constructor;
+}