From 85c0e5ad855373f43a22fd3a204f963486bde354 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sat, 26 May 2012 23:07:03 -0700 Subject: [PATCH] Add One_line_page_breaking. One_line_page_breaking is a page breaking algorithm that puts each score on a one line, with one page per line. --- lily/include/one-line-page-breaking.hh | 35 +++++++++++ lily/include/page-breaking.hh | 3 +- lily/one-line-page-breaking.cc | 81 ++++++++++++++++++++++++++ lily/page-breaking-scheme.cc | 9 +++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 lily/include/one-line-page-breaking.hh create mode 100644 lily/one-line-page-breaking.cc diff --git a/lily/include/one-line-page-breaking.hh b/lily/include/one-line-page-breaking.hh new file mode 100644 index 0000000000..12ea58a610 --- /dev/null +++ b/lily/include/one-line-page-breaking.hh @@ -0,0 +1,35 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2012 Joe Neeman + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ + +#ifndef ONE_LINE_PAGE_BREAKING_HH +#define ONE_LINE_PAGE_BREAKING_HH + +#include "page-breaking.hh" +#include "page-spacing.hh" + +class One_line_page_breaking: public Page_breaking +{ +public: + virtual SCM solve (); + + One_line_page_breaking (Paper_book *pb); + virtual ~One_line_page_breaking (); +}; + +#endif /* ONE_LINE_PAGE_BREAKING_HH */ diff --git a/lily/include/page-breaking.hh b/lily/include/page-breaking.hh index a7babd4f70..c84a56e679 100644 --- a/lily/include/page-breaking.hh +++ b/lily/include/page-breaking.hh @@ -178,10 +178,11 @@ protected: SCM breakpoint_property (vsize breakpoint, char const *str); vsize last_break_position () const; + + vector system_specs_; private: vector breaks_; vector chunks_; - vector system_specs_; vector line_breaking_; bool ragged_; bool ragged_last_; diff --git a/lily/one-line-page-breaking.cc b/lily/one-line-page-breaking.cc new file mode 100644 index 0000000000..2175e1727a --- /dev/null +++ b/lily/one-line-page-breaking.cc @@ -0,0 +1,81 @@ +/* + This file is part of LilyPond, the GNU music typesetter. + + Copyright (C) 2012 Joe Neeman + + LilyPond is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + LilyPond is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LilyPond. If not, see . +*/ + +#include "one-line-page-breaking.hh" + +#include + +#include "column-x-positions.hh" +#include "international.hh" +#include "output-def.hh" +#include "page-spacing.hh" +#include "paper-book.hh" +#include "paper-score.hh" +#include "simple-spacer.hh" +#include "system.hh" + +One_line_page_breaking::One_line_page_breaking (Paper_book *pb) + : Page_breaking (pb, 0, 0) +{ +} + +One_line_page_breaking::~One_line_page_breaking () +{ +} + +/* + This is a somewhat unconventional page-breaking algorithm. Every + score will be put on a single page, whose width is enough + to fit the entire score one one line. Line breaks and page breaks + are ignored, as are the page dimensions in the paper block. +*/ +SCM +One_line_page_breaking::solve () +{ + SCM all_pages = SCM_EOL; + for (vsize i = 0; i < system_specs_.size (); ++i) + if (Paper_score *ps = system_specs_[i].pscore_) + { + vector cols = ps->root_system ()->used_columns (); + + // No indent, "infinite" line width, ragged. + Column_x_positions pos = get_line_configuration (cols, numeric_limits::max (), 0, true); + vector positions; + positions.push_back (pos); + + ps->root_system ()->break_into_pieces (positions); + ps->root_system ()->do_break_substitution_and_fixup_refpoints (); + Grob *system = ps->root_system ()->broken_intos_[0]; + Real width = system->extent (system, X_AXIS).length (); + Real height = system->extent (system, Y_AXIS).length (); + + // HACK: probably shouldn't be modifying the paper_; better to modify the page + // afterwards. + book_->paper_->set_variable (ly_symbol2scm ("paper-width"), scm_from_double (width + 100)); + // TODO: figure out what the height should be. + //book_->paper_->set_variable (ly_symbol2scm ("paper-height"), scm_from_double (height)); + vector lines_per_page; + lines_per_page.push_back (1); + SCM systems = scm_list_1 (system->self_scm ()); + SCM pages = make_pages (lines_per_page, systems); + all_pages = scm_cons (scm_car (pages), all_pages); + } + + return scm_reverse_x (all_pages, SCM_EOL); +} diff --git a/lily/page-breaking-scheme.cc b/lily/page-breaking-scheme.cc index 26b9ffa866..796324cbc2 100644 --- a/lily/page-breaking-scheme.cc +++ b/lily/page-breaking-scheme.cc @@ -19,6 +19,7 @@ #include "paper-book.hh" #include "page-turn-page-breaking.hh" +#include "one-line-page-breaking.hh" #include "optimal-page-breaking.hh" #include "minimal-page-breaking.hh" @@ -51,3 +52,11 @@ LY_DEFINE (ly_minimal_breaking, "ly:minimal-breaking", Minimal_page_breaking b (unsmob_paper_book (pb)); return b.solve (); } + +LY_DEFINE (ly_one_line_breaking, "ly:one-line-breaking", + 1, 0, 0, (SCM pb), + "Put each score on a single line, and put each line on its own page.") +{ + One_line_page_breaking b (unsmob_paper_book (pb)); + return b.solve (); +} -- 2.39.5