2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2012 Joe Neeman <joeneeman@gmail.com>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "one-line-page-breaking.hh"
24 #include "column-x-positions.hh"
25 #include "international.hh"
26 #include "output-def.hh"
27 #include "page-spacing.hh"
28 #include "paper-book.hh"
29 #include "paper-score.hh"
30 #include "simple-spacer.hh"
35 One_line_page_breaking::One_line_page_breaking (Paper_book *pb)
36 : Page_breaking (pb, 0, 0)
40 One_line_page_breaking::~One_line_page_breaking ()
45 This is a somewhat unconventional page-breaking algorithm. Every
46 score will be put on a single page, whose width is enough
47 to fit the entire score one one line. Line breaks and page breaks
48 are ignored, and the paper-width setting in the paper block
49 will be modified to fit the music.
52 One_line_page_breaking::solve ()
54 SCM all_pages = SCM_EOL;
56 for (vsize i = 0; i < system_specs_.size (); ++i)
58 if (Paper_score *ps = system_specs_[i].pscore_)
60 vector<Grob *> cols = ps->root_system ()->used_columns ();
62 // No indent, "infinite" line width, ragged.
63 Column_x_positions pos = get_line_configuration (cols, numeric_limits<Real>::max (), 0, true);
64 vector<Column_x_positions> positions;
65 positions.push_back (pos);
67 ps->root_system ()->break_into_pieces (positions);
68 ps->root_system ()->do_break_substitution_and_fixup_refpoints ();
69 Grob *system = ps->root_system ()->broken_intos_[0];
71 vector<vsize> lines_per_page;
72 lines_per_page.push_back (1);
73 SCM systems = scm_list_1 (system->self_scm ());
74 SCM pages = make_pages (lines_per_page, systems);
76 max_width = max (max_width, system->extent (system, X_AXIS).length ());
77 all_pages = scm_cons (scm_car (pages), all_pages);
79 else if (Prob *pb = system_specs_[i].prob_)
80 // Because we don't call Page_breaking::systems in this algorithm,
81 // we need to manually unprotect the titles.
85 // Alter paper-width so that it is large enough to fit every system.
86 // TODO: it might be nice to allow different pages to have different widths.
87 // This would need support in the backends (eg. framework-ps.scm).
88 Real right_margin = robust_scm2double (book_->paper_->c_variable ("right-margin"), 0.0);
89 Real left_margin = robust_scm2double (book_->paper_->c_variable ("left-margin"), 0.0);
90 Real width = max_width + right_margin + left_margin;
91 book_->paper_->set_variable (ly_symbol2scm ("paper-width"), scm_from_double (width));
93 return scm_reverse_x (all_pages, SCM_EOL);