2 word-wrap.cc -- implement Word_wrap
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
9 #include "word-wrap.hh"
13 #include "spring-spacer.hh"
19 A Dynamic Programming type of algorithm
20 similar to TeX's is in Gourlay_breaking
24 Word_wrap::do_solve() const
28 PCursor<Paper_column*> curcol (pscore_l_->col_p_list_.top());
29 Array<Col_hpositions> breaking;
30 Line_of_cols breakpoints (find_breaks());
31 assert (breakpoints.size()>=2);
34 while (break_idx_i < breakpoints.size() -1)
36 Col_hpositions minimum;
37 Col_hpositions current;
40 Paper_column *post = breakpoints[break_idx_i]->postbreak_l();
42 curcol++; // skip the breakable.
45 while (break_idx_i < breakpoints.size())
48 // add another measure.
49 while (breakpoints[break_idx_i] != curcol.ptr())
54 current.add (breakpoints[break_idx_i]->prebreak_l());
56 current.spacer_l_ = generate_spacing_problem (current.cols);
59 if (!feasible (current.cols))
61 if (!minimum.cols.size())
63 warning (_("Ugh, this measure is too long, breakpoint: ")
64 + String (break_idx_i) +
65 _(" (generating stupido solution)"));
66 current.stupid_solution();
67 current.energy_f_ = - 1; // make sure we break out.
70 current.energy_f_ = infinity_f; // make sure we go back
79 delete current.spacer_l_;
82 // update minimum, or backup.
83 if (current.energy_f_ < minimum.energy_f_ || current.energy_f_ < 0)
87 else { // we're one col too far.
89 while (curcol.ptr() != breakpoints[break_idx_i])
91 break; // do the next line.
95 // add nobreak version of breakable column
96 current.cols.top()=breakpoints[break_idx_i];
101 *mlog << "[" <<break_idx_i<<"]"<<flush;
102 breaking.push (minimum);
107 Word_wrap::Word_wrap()
109 get_line_spacer = Spring_spacer::constructor;