flower-1.0.27
[lilypond.git] / src / wordwrap.cc
blob90d4d542dc7504ab23a8efa956d61c42cd210353
1 #include "break.hh"
2 #include "pscore.hh"
3 #include "debug.hh"
5 /** el stupido. This should be done more accurately:
7 It would be nice to have a Dynamic Programming type of algorithm
8 similar to TeX's
11 Array<Col_hpositions>
12 Word_wrap::solve()
14 problem_OK();
15 iter_top(pscore_.cols,curcol);
16 Array<Col_hpositions> breaking;
17 Line_of_cols breakpoints(find_breaks());
18 assert(breakpoints.size()>=2);
20 int break_idx_i=0;
21 while ( break_idx_i < breakpoints.size() -1) {
22 Col_hpositions minimum;
23 Col_hpositions current;
25 // do another line
26 PCol *post = breakpoints[break_idx_i]->postbreak_p_;
27 current.add( post);
28 curcol++; // skip the breakable.
29 break_idx_i++;
31 while (break_idx_i < breakpoints.size()) {
33 // add another measure.
34 while (breakpoints[break_idx_i] != curcol.ptr()){
35 current.add(curcol);
36 curcol++;
38 current.add(breakpoints[break_idx_i]->prebreak_p_ );
40 // try to solve
41 if (!feasible(current.cols)) {
42 if (!minimum.cols.size())
43 error("sorry, this measure is too long");
44 current.energy = INFTY; // make sure we go back
45 } else {
46 current = solve_line(current.cols);
47 current.print();
50 // update minimum, or backup.
51 if (current.energy < minimum.energy) {
52 minimum = current;
53 } else { // we're one col too far.
54 break_idx_i--;
55 while (curcol.ptr() != breakpoints[break_idx_i])
56 curcol --;
57 break; // do the next line.
61 // add nobreak version of breakable column
62 current.cols.top()=breakpoints[break_idx_i];
63 curcol ++;
64 break_idx_i++;
67 *mlog << "[" <<break_idx_i<<"]"<<flush;
68 breaking.push(minimum);
71 return breaking;
74 Word_wrap::Word_wrap(PScore&ps)
75 : Break_algorithm(ps)