From: Han-Wen Nienhuys Date: Fri, 26 Nov 2004 13:33:30 +0000 (+0000) Subject: * Documentation/user/changing-defaults.itely (Creating titles): X-Git-Tag: release/2.5.14~490 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=6b76fa0cfec5f88f03b8c512f1d5ef7da8f8f1ce;p=lilypond.git * Documentation/user/changing-defaults.itely (Creating titles): add breakbefore variable. * lily/paper-book.cc (set_system_penalty): new function. Set penalty_ based on breakBefore setting --- diff --git a/ChangeLog b/ChangeLog index 33e6d4ad22..ae8e10b505 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2004-11-26 Han-Wen Nienhuys + * Documentation/user/changing-defaults.itely (Creating titles): + add breakbefore variable. + + * lily/paper-book.cc (set_system_penalty): new function. Set + penalty_ based on breakBefore setting + * lily/context-specced-music-iterator.cc (construct_children): interpret special context id $uniqueContextId diff --git a/Documentation/user/changing-defaults.itely b/Documentation/user/changing-defaults.itely index f47925cf04..11102c2088 100644 --- a/Documentation/user/changing-defaults.itely +++ b/Documentation/user/changing-defaults.itely @@ -2109,6 +2109,11 @@ To whom the piece is dedicated. @item piece Name of the piece, flush-left below the instrument. + + +@cindex page breaks, forcing +@item breakbefore + This forces the title to start on a new page. @end table Here is a demonstration of the fields available, @@ -2183,7 +2188,7 @@ field). By default, headers are defined such that the page number is on the outside edge, and the instrument is centered. - @item oddFooterMarkup +@item oddFooterMarkup This is the page footer for odd-numbered pages. @item evenFooterMarkup @@ -2201,6 +2206,20 @@ field). @cindex page layout @cindex titles +The following definition will put the title flush left, and the +composer flush right on a single line. + +@verbatim +\paper { + bookTitleMarkup = \markup { + \fill-line < + \fromproperty #'header:title + \fromproperty #'header:composer + > + } +} +@end verbatim + diff --git a/input/regression/page-layout.ly b/input/regression/page-layout.ly index 98a47fce01..1fd4c9a4ff 100644 --- a/input/regression/page-layout.ly +++ b/input/regression/page-layout.ly @@ -56,7 +56,10 @@ This file is best viewed outside the collated files document. \repeat unfold 4 {c4} } } - \header {piece = "Piece II"} + \header { + breakbefore = ##f + piece = "Piece II" + } \layout {linewidth = 9\cm} } } diff --git a/lily/include/paper-system.hh b/lily/include/paper-system.hh index 92a394729f..50b4b4404b 100644 --- a/lily/include/paper-system.hh +++ b/lily/include/paper-system.hh @@ -25,7 +25,7 @@ class Paper_system bool is_title_; public: Interval staff_refpoints_; - Real penalty_; + Real break_before_penalty_; int number_; Paper_system (Stencil, bool); @@ -33,7 +33,7 @@ public: Stencil to_stencil () const; SCM stencils () const; bool is_title () const; - Real penalty () const; + Real break_before_penalty () const; }; DECLARE_UNSMOB (Paper_system, paper_system); diff --git a/lily/paper-book.cc b/lily/paper-book.cc index d2227ed86c..446725543b 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -343,7 +343,23 @@ Paper_book::score_title (int i) return title; } - + +void +set_system_penalty (Paper_system * ps, SCM header) +{ + if (ly_c_module_p (header)) + { + SCM force = ly_module_lookup (header, ly_symbol2scm ("breakbefore")); + if (SCM_VARIABLEP(force) + && scm_is_bool (SCM_VARIABLE_REF(force))) + { + ps->break_before_penalty_ = to_boolean (SCM_VARIABLE_REF(force)) + ? -10000 + : 10000; + } + } +} + SCM Paper_book::systems () { @@ -356,6 +372,8 @@ Paper_book::systems () if (!title.is_empty ()) { Paper_system *ps = new Paper_system (title, true); + set_system_penalty (ps, header_); + systems_ = scm_cons (ps->self_scm (), systems_); scm_gc_unprotect_object (ps->self_scm ()); } @@ -369,6 +387,9 @@ Paper_book::systems () Paper_system *ps = new Paper_system (title, true); systems_ = scm_cons (ps->self_scm (), systems_); scm_gc_unprotect_object (ps->self_scm ()); + + set_system_penalty (ps, score_systems_[i].header_); + } if (scm_vector_p (score_systems_[i].systems_) == SCM_BOOL_T) @@ -390,9 +411,10 @@ Paper_book::systems () Paper_system *ps = unsmob_paper_system (scm_car (s)); ps->number_ = ++i; - if (last && last->is_title ()) - // ugh, hardcoded. - ps->penalty_ = 10000; + if (last + && last->is_title () + && !ps->break_before_penalty_) + ps->break_before_penalty_ = 10000; last = ps; } diff --git a/lily/paper-system.cc b/lily/paper-system.cc index 3a5835079c..49fe5cb0b7 100644 --- a/lily/paper-system.cc +++ b/lily/paper-system.cc @@ -22,7 +22,7 @@ Paper_system::Paper_system (Stencil s, bool is_title) { is_title_ = is_title; number_ = 0; - penalty_ = 0; + break_before_penalty_ = 0; smobify_self (); stencil_ = s; staff_refpoints_ = Interval(0,0); @@ -48,7 +48,7 @@ Paper_system::print_smob (SCM smob, SCM port, scm_print_state*) scm_puts (" ", port); scm_puts (to_string (p->number_).to_str0 (), port); scm_puts ("p ", port); - scm_puts (to_string (p->penalty_).to_str0 (), port); + scm_puts (to_string (p->break_before_penalty_).to_str0 (), port); if (p->is_title ()) scm_puts (" t", port); scm_puts (" >", port); @@ -62,9 +62,9 @@ Paper_system::is_title () const } Real -Paper_system::penalty () const +Paper_system::break_before_penalty () const { - return penalty_; + return break_before_penalty_; } Stencil @@ -104,13 +104,13 @@ LY_DEFINE (ly_paper_system_number, "ly:paper-system-number", return scm_int2num (ps->number_); } -LY_DEFINE (ly_paper_system_break_score, "ly:paper-system-break-penalty", +LY_DEFINE (ly_paper_system_break_before_penalty, "ly:paper-system-break-before-penalty", 1, 0, 0, (SCM system), "Return the score for page break after @var{system}.") { Paper_system *ps = unsmob_paper_system (system); SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system"); - return scm_int2num (int (ps->penalty ())); + return scm_int2num (int (ps->break_before_penalty ())); } LY_DEFINE (ly_paper_system_stencil, "ly:paper-system-stencil", diff --git a/scm/page-layout.scm b/scm/page-layout.scm index 365bf6d49c..89ef9a7d8d 100644 --- a/scm/page-layout.scm +++ b/scm/page-layout.scm @@ -343,7 +343,15 @@ CURRENT-BEST is the best result sofar, or #f." satisfied-constraints) 10000)) (positions (cdr vertical-spacing)) - (user-penalty (ly:paper-system-break-penalty (car current-lines))) + (user-nobreak-penalties + (- + (apply + (filter negative? + (map ly:paper-system-break-before-penalty + (cdr current-lines)))))) + (user-penalty + (+ + (max (ly:paper-system-break-before-penalty (car current-lines)) 0.0) + user-nobreak-penalties)) (total-penalty (combine-penalties force user-penalty best-paths)) @@ -364,7 +372,7 @@ CURRENT-BEST is the best result sofar, or #f." #:penalty total-penalty) current-best))) - (if #f ;; debug + (if #t ;; debug (display (list "\nuser pen " user-penalty diff --git a/scm/safe-lily.scm b/scm/safe-lily.scm index 417a77b453..a90a6c3056 100644 --- a/scm/safe-lily.scm +++ b/scm/safe-lily.scm @@ -99,7 +99,7 @@ ly:layout-def? ly:paper-get-font ly:paper-get-number - ly:paper-system-break-penalty + ly:paper-system-break-before-penalty ly:paper-system-extent ly:paper-system-number ly:paper-system-stencil