2 word-wrap.cc -- implement Word_wrap
4 source file of the LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.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
24 Array
<Column_x_positions
>
25 Word_wrap::do_solve() const
29 PCursor
<Paper_column
*> curcol (pscore_l_
->col_p_list_
.top());
30 Array
<Column_x_positions
> breaking
;
31 Line_of_cols
breakpoints (find_breaks());
32 assert (breakpoints
.size()>=2);
36 while (break_idx_i
< breakpoints
.size() -1)
38 Column_x_positions minimum
;
39 Column_x_positions current
;
43 Paper_column
*post
= breakpoints
[break_idx_i
]->postbreak_l();
44 int start_break_idx
= break_idx_i
;
45 current
.add_paper_column (post
);
46 curcol
++; // skip the breakable.
49 while (break_idx_i
< breakpoints
.size())
52 // add another measure.
53 while (breakpoints
[break_idx_i
] != curcol
.ptr())
55 current
.add_paper_column (curcol
);
58 current
.add_paper_column (breakpoints
[break_idx_i
]->prebreak_l());
60 current
.spacer_l_
= generate_spacing_problem (current
.cols
,
61 pscore_l_
->paper_l_
->line_dimensions_int (line_no_i
));
64 if (!feasible (current
.cols
))
66 if (!minimum
.cols
.size())
68 warning (_ ("ugh, this measure is too long")
69 + ", " + _f ("breakpoint: %d", break_idx_i
)
70 + "(" + _ ("generating stupido solution") + ")");
71 current
.stupid_solution();
72 current
.energy_f_
= - 1; // make sure we break out.
75 current
.energy_f_
= infinity_f
; // make sure we go back
83 delete current
.spacer_l_
;
86 if (!current
.satisfies_constraints_b_
&& start_break_idx
== break_idx_i
- 1)
88 warning ( _ ("I don't fit; put me on Montignac"));
93 if (current
.energy_f_
< minimum
.energy_f_
|| current
.energy_f_
< 0)
97 else { // we're one col too far.
99 while (curcol
.ptr() != breakpoints
[break_idx_i
])
101 break; // do the next line.
105 // add nobreak version of breakable column
106 current
.cols
.top()=breakpoints
[break_idx_i
];
111 *mlog
<< "[" << break_idx_i
<< "]" << flush
;
112 breaking
.push (minimum
);
117 Word_wrap::Word_wrap()
119 get_line_spacer
= Spring_spacer::constructor
;