]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-algorithm.cc
Imported sources
[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--2004 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 "system.hh"
13 #include "paper-score.hh"
14 #include "paper-column.hh"
15 #include "cpu-timer.hh"
16
17 #include "simple-spacer.hh"
18 #include "group-interface.hh"
19
20
21 Array<int>
22 Break_algorithm::find_break_indices () const
23 {
24   Link_array<Grob> all = pscore_->system_->columns ();
25   Array<int> retval;
26
27   for (int i=0; i < all.size (); i++)
28     if (Item::breakable_b (all[i]))
29       retval.push (i);
30
31   if (linewidth_ <=0)
32     while (retval.size () >2)
33       retval.del (1);
34
35   return retval;
36 }
37
38
39 Link_array<Grob>
40 Break_algorithm::find_breaks () const
41 {
42   Link_array<Grob> all = pscore_->system_->columns ();
43   Link_array<Grob> retval;
44
45   for (int i=0; i < all.size (); i++)
46     if (Item::breakable_b (all[i]))
47       retval.push (all[i]);
48
49   if (linewidth_ <=0)
50     while (retval.size () >2)
51       retval.del (1);
52
53   return retval;
54 }
55
56
57 Simple_spacer*
58 Break_algorithm::generate_spacing_problem (Link_array<Grob> const &curline,
59                                            Interval line) const
60 {
61   Simple_spacer * sp =  new Simple_spacer;
62
63   /*
64     this is hardcoded, but this shouldn't happen anyway.
65     used to be get_realvar (ly_symbol2scm ("loose_column_distance"));        
66    */
67   sp->default_space_ = 1.0;
68
69
70   sp->indent_ = line[LEFT];
71
72   /*
73     sort out how interfacing this should work;
74    */
75   if (line.is_empty ())
76     {
77      sp->line_len_ = -1;
78     }
79   else
80     sp->line_len_ = line.length ();
81   
82   sp->add_columns (curline);
83
84
85   return sp;
86 }
87
88 Break_algorithm::Break_algorithm ()
89 {
90   pscore_ = 0;
91   linewidth_ = 0;
92 }
93
94 void
95 Break_algorithm::set_pscore (Paper_score*s)
96 {
97   pscore_ = s;
98   linewidth_ = s->paper_->get_realvar (ly_symbol2scm ("linewidth"));
99 }
100
101 Array<Column_x_positions>
102 Break_algorithm::solve () const
103 {
104   Array<Column_x_positions> h= do_solve ();
105   
106   return h;
107 }
108