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