]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-algorithm.cc
release: 1.3.19
[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,  1997--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
20
21
22
23
24 Array<int>
25 Break_algorithm::find_break_indices () const
26 {
27   Link_array<Paper_column> all (pscore_l_->col_l_arr_);
28   Array<int> retval;
29
30   for (int i=0; i < all.size (); i++)
31     if (all[i]->breakable_b ())
32       retval.push (i);
33
34   if (linewidth_f_ <=0)
35     while (retval.size () >2)
36       retval.del (1);
37
38   return retval;
39 }
40
41
42 Link_array<Paper_column>
43 Break_algorithm::find_breaks () const
44 {
45   Link_array<Paper_column> all (pscore_l_->col_l_arr_);
46   Link_array<Paper_column> retval;
47
48   for (int i=0; i < all.size (); i++)
49     if (all[i]->breakable_b ())
50       retval.push (all[i]);
51
52   if (linewidth_f_ <=0)
53     while (retval.size () >2)
54       retval.del (1);
55
56   return retval;
57 }
58
59
60 Simple_spacer*
61 Break_algorithm::generate_spacing_problem (Link_array<Paper_column> curline, Interval line) const
62 {
63   Simple_spacer * sp =  new Simple_spacer;
64   Paper_def * d = pscore_l_->paper_l_;
65   sp->compression_energy_factor_f_ = d->get_var ("compression_energy_factor");
66   sp->default_space_f_ = d->get_var ("loose_column_distance");
67
68   sp->indent_f_ = line[LEFT];
69
70   /*
71     sort out how interfacing this should work;
72    */
73   if (line.empty_b())
74     {
75      sp->line_len_f_ = -1;
76     }
77   else
78     sp->line_len_f_ = line.length ();
79   
80   sp->add_columns (curline);
81
82
83   return sp;
84 }
85
86 Break_algorithm::Break_algorithm ()
87 {
88   pscore_l_ = 0;
89   linewidth_f_ = 0;
90 }
91
92 void
93 Break_algorithm::set_pscore (Paper_score*s)
94 {
95   pscore_l_ = s;
96   linewidth_f_ = s->paper_l_->get_var("linewidth");
97   do_set_pscore ();
98 }
99
100
101
102 void
103 Break_algorithm::problem_OK () const
104 {
105   if (pscore_l_->col_l_arr_.empty ())
106     error (_("Score does not have any columns"));
107   OK ();
108 }
109
110 void
111 Break_algorithm::OK () const
112 {
113 }
114
115 Array<Column_x_positions>
116 Break_algorithm::solve () const
117 {
118   Array<Column_x_positions> h= do_solve ();
119   
120   return h;
121 }
122
123 void
124 Break_algorithm::do_set_pscore ()
125 {
126
127 }