]> git.donarmstrong.com Git - lilypond.git/blob - lily/one-line-page-breaking.cc
Add One_line_page_breaking.
[lilypond.git] / lily / one-line-page-breaking.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2012 Joe Neeman <joeneeman@gmail.com>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "one-line-page-breaking.hh"
21
22 #include <limits>
23
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"
31 #include "system.hh"
32
33 One_line_page_breaking::One_line_page_breaking (Paper_book *pb)
34   : Page_breaking (pb, 0, 0)
35 {
36 }
37
38 One_line_page_breaking::~One_line_page_breaking ()
39 {
40 }
41
42 /*
43   This is a somewhat unconventional page-breaking algorithm. Every
44   score will be put on a single page, whose width is enough
45   to fit the entire score one one line. Line breaks and page breaks
46   are ignored, as are the page dimensions in the paper block.
47 */
48 SCM
49 One_line_page_breaking::solve ()
50 {
51   SCM all_pages = SCM_EOL;
52   for (vsize i = 0; i < system_specs_.size (); ++i)
53     if (Paper_score *ps = system_specs_[i].pscore_)
54       {
55         vector<Grob*> cols = ps->root_system ()->used_columns ();
56
57         // No indent, "infinite" line width, ragged.
58         Column_x_positions pos = get_line_configuration (cols, numeric_limits<Real>::max (), 0, true);
59         vector<Column_x_positions> positions;
60         positions.push_back (pos);
61
62         ps->root_system ()->break_into_pieces (positions);
63         ps->root_system ()->do_break_substitution_and_fixup_refpoints ();
64         Grob *system = ps->root_system ()->broken_intos_[0];
65         Real width = system->extent (system, X_AXIS).length ();
66         Real height = system->extent (system, Y_AXIS).length ();
67         
68         // HACK: probably shouldn't be modifying the paper_; better to modify the page
69         // afterwards.
70         book_->paper_->set_variable (ly_symbol2scm ("paper-width"), scm_from_double (width + 100));
71         // TODO: figure out what the height should be.
72         //book_->paper_->set_variable (ly_symbol2scm ("paper-height"), scm_from_double (height));
73         vector<vsize> lines_per_page;
74         lines_per_page.push_back (1);
75         SCM systems = scm_list_1 (system->self_scm ());
76         SCM pages = make_pages (lines_per_page, systems);
77         all_pages = scm_cons (scm_car (pages), all_pages);
78       }
79
80   return scm_reverse_x (all_pages, SCM_EOL);
81 }