2 wordwrap.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"
16 /** el stupido. This should be done more accurately:
18 It would be nice to have a Dynamic Programming type of algorithm
23 Word_wrap::do_solve()const
26 iter_top(pscore_l_
->col_p_list_
,curcol
);
27 Array
<Col_hpositions
> breaking
;
28 Line_of_cols
breakpoints(find_breaks());
29 assert(breakpoints
.size()>=2);
32 while ( break_idx_i
< breakpoints
.size() -1) {
33 Col_hpositions minimum
;
34 Col_hpositions current
;
37 PCol
*post
= breakpoints
[break_idx_i
]->postbreak_p_
;
39 curcol
++; // skip the breakable.
42 while (break_idx_i
< breakpoints
.size()) {
44 // add another measure.
45 while (breakpoints
[break_idx_i
] != curcol
.ptr()){
49 current
.add(breakpoints
[break_idx_i
]->prebreak_p_
);
52 if (!feasible(current
.cols
)) {
53 if (!minimum
.cols
.size()) {
54 warning("Ugh, this measure is too long, breakpoint: "
55 + String(break_idx_i
) +
56 " (generating stupido solution)");
57 current
= stupid_solution(current
.cols
);
58 current
.energy
= - 1; // make sure we break out.
60 current
.energy
= INFTY_f
; // make sure we go back
62 current
= solve_line(current
.cols
);
66 // update minimum, or backup.
67 if (current
.energy
< minimum
.energy
|| current
.energy
< 0) {
69 } else { // we're one col too far.
71 while (curcol
.ptr() != breakpoints
[break_idx_i
])
73 break; // do the next line.
77 // add nobreak version of breakable column
78 current
.cols
.top()=breakpoints
[break_idx_i
];
83 *mlog
<< "[" <<break_idx_i
<<"]"<<flush
;
84 breaking
.push(minimum
);
90 Word_wrap::Word_wrap(PScore
&ps
)
93 get_line_spacer
= Spring_spacer::constructor
;