]> git.donarmstrong.com Git - lilypond.git/blob - src/wordwrap.cc
release: 0.0.26
[lilypond.git] / src / wordwrap.cc
1 #include "break.hh"
2 #include "pscore.hh"
3 #include "debug.hh"
4
5 /* el stupido. This should be done more accurately:
6
7    It would be nice to have a Dynamic Programming type of algorithm
8    similar to TeX's
9    
10     */
11
12 Array<Col_configuration>
13 Word_wrap::solve()
14 {
15     problem_OK();
16     iter_top(pscore_.cols,curcol);
17     Array<Col_configuration> breaking;
18     Array<PCol *> breakpoints(find_breaks());
19     assert(breakpoints.size()>=2);
20     for (int i=0 ; i < breakpoints.size() -1; ) {
21         Col_configuration minimum;
22         Col_configuration current;
23
24         // do  another line
25         PCol *post = breakpoints[i]->postbreak_p_;
26         current.add( post);
27         curcol++;               // skip the breakable.
28         i++;
29
30         while (i < breakpoints.size()) {
31
32             // add another measure.
33             while (breakpoints[i] != curcol.ptr()){
34                 
35                 current.add(curcol);
36                 curcol++;
37             }
38             current.add(breakpoints[i]->prebreak_p_ );
39             if (!feasible(current.cols)) {
40                 if (!minimum.cols.size())
41                     error("sorry, this measure is too long");
42                 break;
43             }
44             current.setsol(solve_line(current.cols));
45             current.print();
46             
47             if (current.energy < minimum.energy) {              
48                 minimum = current;         
49             } else {            // we're one col too far.
50                 i--;
51                 while (curcol.ptr() != breakpoints[i])
52                     curcol --;
53                 
54                 break;
55             }
56         
57             current.cols.last()=breakpoints[i];
58             curcol ++;
59             i++;
60         }
61         mtor << "Adding cols~, next breakpoint " << i << '\n';
62         breaking.push(minimum);
63     }
64     
65     return breaking;
66 }
67
68 Word_wrap::Word_wrap(PScore&ps)
69     : Break_algorithm(ps)
70 {
71 }