]> git.donarmstrong.com Git - lilypond.git/blob - lily/break-algorithm.cc
* The grand 2005-2006 replace.
[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--2006 Han-Wen Nienhuys <hanwen@xs4all.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     sp->line_len_ = -1;
71   else
72     sp->line_len_ = line.length ();
73
74   spw->add_columns (curline);
75   return spw;
76 }
77
78 Break_algorithm::Break_algorithm ()
79 {
80   pscore_ = 0;
81   linewidth_ = 0;
82 }
83
84 void
85 Break_algorithm::set_pscore (Paper_score *s)
86 {
87   pscore_ = s;
88   linewidth_ = s->layout ()->get_dimension (ly_symbol2scm ("linewidth"));
89 }
90
91 Array<Column_x_positions>
92 Break_algorithm::solve () const
93 {
94   Array<Column_x_positions> h= do_solve ();
95
96   return h;
97 }
98
99 Break_algorithm::~Break_algorithm ()
100 {
101 }