]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-algorithm.cc
release: 1.3.70
[lilypond.git] / lily / break-algorithm.cc
1 /*
2   break.cc -- implement Break_algorithm
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1996--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "paper-column.hh"
10 #include "break-algorithm.hh"
11 #include "paper-def.hh"
12 #include "debug.hh"
13 #include "line-of-score.hh"
14 #include "paper-score.hh"
15 #include "paper-column.hh"
16 #include "cpu-timer.hh"
17 #include "command-request.hh"
18 #include "simple-spacer.hh"
19 #include "group-interface.hh"
20
21
22 Array<int>
23 Break_algorithm::find_break_indices () const
24 {
25   Link_array<Score_element> all = pscore_l_->line_l_->column_l_arr ();
26   Array<int> retval;
27
28   for (int i=0; i < all.size (); i++)
29     if (Item::breakable_b (all[i]))
30       retval.push (i);
31
32   if (linewidth_f_ <=0)
33     while (retval.size () >2)
34       retval.del (1);
35
36   return retval;
37 }
38
39
40 Link_array<Score_element>
41 Break_algorithm::find_breaks () const
42 {
43   Link_array<Score_element> all = pscore_l_->line_l_->column_l_arr ();
44   Link_array<Score_element> retval;
45
46   for (int i=0; i < all.size (); i++)
47     if (Item::breakable_b (all[i]))
48       retval.push (all[i]);
49
50   if (linewidth_f_ <=0)
51     while (retval.size () >2)
52       retval.del (1);
53
54   return retval;
55 }
56
57
58 Simple_spacer*
59 Break_algorithm::generate_spacing_problem (Link_array<Score_element> curline, Interval line) const
60 {
61   Simple_spacer * sp =  new Simple_spacer;
62   Paper_def * d = pscore_l_->paper_l_;
63   sp->default_space_f_ = d->get_var ("loose_column_distance");
64
65   sp->indent_f_ = line[LEFT];
66
67   /*
68     sort out how interfacing this should work;
69    */
70   if (line.empty_b())
71     {
72      sp->line_len_f_ = -1;
73     }
74   else
75     sp->line_len_f_ = line.length ();
76   
77   sp->add_columns (curline);
78
79
80   return sp;
81 }
82
83 Break_algorithm::Break_algorithm ()
84 {
85   pscore_l_ = 0;
86   linewidth_f_ = 0;
87 }
88
89 void
90 Break_algorithm::set_pscore (Paper_score*s)
91 {
92   pscore_l_ = s;
93   linewidth_f_ = s->paper_l_->get_var("linewidth");
94 }
95
96 Array<Column_x_positions>
97 Break_algorithm::solve () const
98 {
99   Array<Column_x_positions> h= do_solve ();
100   
101   return h;
102 }
103