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"
10 #include "paper-def.hh"
14 #include "spring-spacer.hh"
20 A Dynamic Programming type of algorithm
21 similar to TeX's is in Gourlay_breaking
25 Word_wrap::do_solve() const
29 PCursor
<Paper_column
*> curcol (pscore_l_
->col_p_list_
.top());
30 Array
<Col_hpositions
> breaking
;
31 Line_of_cols
breakpoints (find_breaks());
32 assert (breakpoints
.size()>=2);
36 while (break_idx_i
< breakpoints
.size() -1)
38 Col_hpositions minimum
;
39 Col_hpositions current
;
43 Paper_column
*post
= breakpoints
[break_idx_i
]->postbreak_l();
45 curcol
++; // skip the breakable.
48 while (break_idx_i
< breakpoints
.size())
51 // add another measure.
52 while (breakpoints
[break_idx_i
] != curcol
.ptr())
57 current
.add (breakpoints
[break_idx_i
]->prebreak_l());
59 current
.spacer_l_
= generate_spacing_problem (current
.cols
,
60 pscore_l_
->paper_l_
->line_dimensions_int (line_no_i
));
63 if (!feasible (current
.cols
))
65 if (!minimum
.cols
.size())
67 warning (_("Ugh, this measure is too long, breakpoint: ")
68 + String (break_idx_i
) +
69 _(" (generating stupido solution)"));
70 current
.stupid_solution();
71 current
.energy_f_
= - 1; // make sure we break out.
74 current
.energy_f_
= infinity_f
; // make sure we go back
83 delete current
.spacer_l_
;
86 // update minimum, or backup.
87 if (current
.energy_f_
< minimum
.energy_f_
|| current
.energy_f_
< 0)
91 else { // we're one col too far.
93 while (curcol
.ptr() != breakpoints
[break_idx_i
])
95 break; // do the next line.
99 // add nobreak version of breakable column
100 current
.cols
.top()=breakpoints
[break_idx_i
];
105 *mlog
<< "[" <<break_idx_i
<<"]"<<flush
;
106 breaking
.push (minimum
);
111 Word_wrap::Word_wrap()
113 get_line_spacer
= Spring_spacer::constructor
;