From: Nicolas Sceaux Date: Tue, 28 Oct 2008 10:55:16 +0000 (+0100) Subject: Nested book parts: proper \paper block inheritance X-Git-Tag: release/2.11.65-1~51^2~2^2~9 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0d9d01963bb242297f53b733957b2ca72fb9636d;p=lilypond.git Nested book parts: proper \paper block inheritance --- diff --git a/input/new/book-parts.ly b/input/new/book-parts.ly index ddfe0c0767..2e87120fd1 100644 --- a/input/new/book-parts.ly +++ b/input/new/book-parts.ly @@ -13,43 +13,42 @@ difference with the book last page. #(set-default-paper-size "a6") +\book { -%% top-level paper, which is inherited by all children bookparts -\paper { - id = "\nbook level paper\n" - ragged-last-bottom = ##t - %% Page footer: add a different part-tagline at part last page - oddFooterMarkup = \markup { - \column { - \fill-line { - %% Copyright header field only on book first page. - \on-the-fly #first-page \fromproperty #'header:copyright - } - \fill-line { - %% Part tagline header field only on each part last page. - \on-the-fly #part-last-page \fromproperty #'header:parttagline - } - \fill-line { - %% Tagline header field only on book last page. - \on-the-fly #last-page \fromproperty #'header:tagline + %% book paper, which is inherited by all children bookparts + \paper { + id = "\nbook level paper\n" + ragged-last-bottom = ##t + %% Page footer: add a different part-tagline at part last page + oddFooterMarkup = \markup { + \column { + \fill-line { + %% Copyright header field only on book first page. + \on-the-fly #first-page \fromproperty #'header:copyright + } + \fill-line { + %% Part tagline header field only on each part last page. + \on-the-fly #part-last-page \fromproperty #'header:parttagline + } + \fill-line { + %% Tagline header field only on book last page. + \on-the-fly #last-page \fromproperty #'header:tagline + } } } } -} - -%% top-level header, which is inherited by the first bookpart -\header { - title = "Book title" - copyright = "Copyright line on book first page" - parttagline = "Part tagline" - tagline = "Book tagline" -} - -\book { + %% book header, which is inherited by the first bookpart + \header { + title = "Book title" + copyright = "Copyright line on book first page" + parttagline = "Part tagline" + tagline = "Book tagline" + } + \bookpart { %% a different page breaking function may be used on each part - %\paper { #(define page-breaking optimal-page-breaks) } + \paper { #(define page-breaking optimal-page-breaks) } \header { subtitle = "First part" } \markup { The first book part } \markup { a page break } diff --git a/lily/include/lily-parser.hh b/lily/include/lily-parser.hh index ed4673de78..aa65621387 100644 --- a/lily/include/lily-parser.hh +++ b/lily/include/lily-parser.hh @@ -74,6 +74,10 @@ SCM ly_parser_scorify (SCM, SCM); Output_def *get_layout (Lily_parser *parser); Output_def *get_midi (Lily_parser *parser); Output_def *get_paper (Lily_parser *parser); +void init_papers (Lily_parser *parser, Output_def *default_paper); +void stack_paper (Lily_parser *parser, Output_def *paper); +void unstack_paper (Lily_parser *parser); +void set_paper (Lily_parser *parser, Output_def *paper); SCM get_header (Lily_parser *parser); #endif /* LILY_PARSER_HH */ diff --git a/lily/lily-parser.cc b/lily/lily-parser.cc index 13d62ebc5c..a7816a154c 100644 --- a/lily/lily-parser.cc +++ b/lily/lily-parser.cc @@ -221,17 +221,50 @@ get_midi (Lily_parser *parser) return layout; } +/* Return a copy of the top of $papers stack */ Output_def * get_paper (Lily_parser *parser) { - SCM id = parser->lexer_->lookup_identifier ("$defaultpaper"); - Output_def *layout = unsmob_output_def (id); - + SCM papers = parser->lexer_->lookup_identifier ("$papers"); + Output_def *layout = (papers == SCM_UNDEFINED || scm_is_null (papers)) ? + 0 : unsmob_output_def (scm_car (papers)); layout = layout ? dynamic_cast (layout->clone ()) : new Output_def; layout->set_variable (ly_symbol2scm ("is-paper"), SCM_BOOL_T); return layout; } +/* Initialize $papers stack with the default paper */ +void +init_papers (Lily_parser *parser, Output_def *default_paper) +{ + parser->lexer_->set_identifier (ly_symbol2scm ("$papers"), + scm_list_1 (default_paper->self_scm ())); +} + +/* Stack a paper on top of $papers */ +void +stack_paper (Lily_parser *parser, Output_def *paper) +{ + parser->lexer_->set_identifier (ly_symbol2scm ("$papers"), + scm_cons (paper->self_scm (), + parser->lexer_->lookup_identifier ("$papers"))); +} + +/* Unstack a paper from $papers */ +void +unstack_paper (Lily_parser *parser) +{ + parser->lexer_->set_identifier (ly_symbol2scm ("$papers"), + scm_cdr (parser->lexer_->lookup_identifier ("$papers"))); +} + +/* Change the paper on top of $papers */ +void +set_paper (Lily_parser *parser, Output_def *paper) +{ + scm_set_car_x (parser->lexer_->lookup_identifier ("$papers"), paper->self_scm ()); +} + SCM get_header (Lily_parser *parser) { diff --git a/lily/parser.yy b/lily/parser.yy index 213f3ec539..f821cd7efe 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -508,7 +508,10 @@ toplevel_expression: Output_def * od = $1; if ($1->c_variable ("is-paper") == SCM_BOOL_T) + { id = ly_symbol2scm ("$defaultpaper"); + init_papers (PARSER, od); + } else if ($1->c_variable ("is-midi") == SCM_BOOL_T) id = ly_symbol2scm ("$defaultmidi"); else if ($1->c_variable ("is-layout") == SCM_BOOL_T) @@ -654,6 +657,7 @@ context_def_spec_body: book_block: BOOK '{' book_body '}' { $$ = $3; + unstack_paper (PARSER); } ; @@ -666,6 +670,7 @@ book_body: $$->origin ()->set_spot (@$); $$->paper_ = dynamic_cast (unsmob_output_def (PARSER->lexer_->lookup_identifier ("$defaultpaper"))->clone ()); $$->paper_->unprotect (); + stack_paper (PARSER, $$->paper_); $$->header_ = PARSER->lexer_->lookup_identifier ("$defaultheader"); } | BOOK_IDENTIFIER { @@ -676,6 +681,7 @@ book_body: | book_body paper_block { $$->paper_ = $2; $2->unprotect (); + set_paper (PARSER, $2); } | book_body bookpart_block { Book *bookpart = $2;