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