2 wordwrap.cc -- implement Word_wrap
4 source file of the LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
13 /** el stupido. This should be done more accurately:
15 It would be nice to have a Dynamic Programming type of algorithm
20 Word_wrap::do_solve()const
23 iter_top(pscore_.cols,curcol);
24 Array<Col_hpositions> breaking;
25 Line_of_cols breakpoints(find_breaks());
26 assert(breakpoints.size()>=2);
29 while ( break_idx_i < breakpoints.size() -1) {
30 Col_hpositions minimum;
31 Col_hpositions current;
34 PCol *post = breakpoints[break_idx_i]->postbreak_p_;
36 curcol++; // skip the breakable.
39 while (break_idx_i < breakpoints.size()) {
41 // add another measure.
42 while (breakpoints[break_idx_i] != curcol.ptr()){
46 current.add(breakpoints[break_idx_i]->prebreak_p_ );
49 if (!feasible(current.cols)) {
50 if (!minimum.cols.size()) {
51 warning("Ugh, this measure is too long, breakpoint: "
52 + String(break_idx_i) +
53 " (generating stupido solution)");
54 current = stupid_solution(current.cols);
55 current.energy = - 1; // make sure we break out.
57 current.energy = INFTY; // make sure we go back
59 current = solve_line(current.cols);
63 // update minimum, or backup.
64 if (current.energy < minimum.energy || current.energy < 0) {
66 } else { // we're one col too far.
68 while (curcol.ptr() != breakpoints[break_idx_i])
70 break; // do the next line.
74 // add nobreak version of breakable column
75 current.cols.top()=breakpoints[break_idx_i];
80 *mlog << "[" <<break_idx_i<<"]"<<flush;
81 breaking.push(minimum);
87 Word_wrap::Word_wrap(PScore&ps)