From: Jan Nieuwenhuizen Date: Wed, 28 Apr 2004 12:55:37 +0000 (+0000) Subject: * lily/stencil-scheme.cc (ly:stencil-expr): Rename (was: X-Git-Tag: release/2.3.1~40 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e2a4be3b72b1c473658436e4f82234b401dd7b60;p=lilypond.git * lily/stencil-scheme.cc (ly:stencil-expr): Rename (was: ly:stencil-get-expr). Update callers. (ly:stencil-align-to!): Return stencil too. * lily/paper-outputter.cc (output_page): Bugfix. Use page stencil. Remove looped line-based page output. (output_line): Use line stencil. Remove looped stencil-based line output. * lily/page.cc (ly:page-paper-lines): New function. * input/test/markup-score.ly: New file. * lily/book.cc (to_stencil): New method. * lily/parser.yy (markup): Use it to grok \score. --- diff --git a/ChangeLog b/ChangeLog index 8f33232174..7ad5d7fb8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2004-04-28 Jan Nieuwenhuizen + * lily/stencil-scheme.cc (ly:stencil-expr): Rename (was: + ly:stencil-get-expr). Update callers. + (ly:stencil-align-to!): Return stencil too. + + * lily/paper-outputter.cc (output_page): Bugfix. Use page + stencil. Remove looped line-based page output. + (output_line): Use line stencil. Remove looped stencil-based line + output. + + * lily/page.cc (ly:page-paper-lines): New function. + * input/test/markup-score.ly: New file. * scm/define-markup-commands.scm (stencil): New markup. diff --git a/input/test/markup-score.ly b/input/test/markup-score.ly index 8e1966ff7e..81b32a54ef 100644 --- a/input/test/markup-score.ly +++ b/input/test/markup-score.ly @@ -1,41 +1,58 @@ - \header { %% WIP texidoc = "Use \\score block as markup command." - } \version "2.3.1" +%%;; Hmm - why is stencil so tall? +#(define (page-stack-lines page) + (stack-stencils Y 1 0 + (map ly:paper-line-stencil (ly:page-paper-lines page)))) + +#(define (page-stack-lines page) + (let* ((urg-stencil (ly:stencil-align-to! (stack-stencils Y DOWN 0 + (map ly:paper-line-stencil (ly:page-paper-lines page))) + Y DOWN)) + (expr (ly:stencil-expr urg-stencil)) + (xext (ly:stencil-extent urg-stencil X)) + (yext (ly:stencil-extent urg-stencil Y))) + (ly:stencil-align-to! + ;; urgr + (ly:make-stencil expr xext (cons (* -0.25 (cdr yext)) 0)) + Y CENTER))) -\paper { +inBed = \paper { raggedright = ##t - vsize = 30 \mm - linewidth = 30\mm + linewidth = 40\mm indent = 0 \mm - hsize = 40\mm + + %% #(define page-to-stencil page-stack-lines) + #(define (page-to-stencil page) + (box-stencil (page-stack-lines page) 0.1 0.5)) + + \context { + \StaffContext + minimumVerticalExtent = ##f + } } + \header { title = "title" subtitle = \markup { \fill-line < "subtitle with score: " - \score { \relative \notes { a'^"Hi" b c } } + \score { \relative \notes { a'^"Hi" b c } \paper { \inBed } } "woo!" > } subsubtitle = "subsubtitle" } -\paper { - raggedright = ##f - linewidth = 150\mm - indent = 15\mm - vsize = 298\mm - hsize = 210 \mm -} - \relative { a' b c d \break a b c d \break + %% interesting bug: + %%a b^\markup { \score{ \notes\relative{ } \paper{ \inBed }}} c d + a b c d \break a b c d \break } diff --git a/lily/book.cc b/lily/book.cc index 7400270e7b..477c250878 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -108,7 +108,8 @@ Book::to_stencil (Music_output_def *default_def, SCM header) for (int i = 0; i < score_count; i++) { Paper_def *paper = 0; - SCM systems = scores_[i]->book_rendering ("", default_def, &paper); + SCM systems = scores_[i]->book_rendering ("", default_def, + &paper); if (systems != SCM_UNDEFINED) { if (paper) @@ -121,6 +122,9 @@ Book::to_stencil (Music_output_def *default_def, SCM header) SCM pages = paper_book->pages (); scm_gc_unprotect_object (paper_book->self_scm ()); if (pages != SCM_EOL) - return unsmob_page (ly_car (pages))->to_stencil (); + { + progress_indication (_f ("paper output to `%s'...", "")); + return unsmob_page (ly_car (pages))->to_stencil (); + } return SCM_EOL; } diff --git a/lily/page.cc b/lily/page.cc index a25d2a78f9..801e9c9c50 100644 --- a/lily/page.cc +++ b/lily/page.cc @@ -112,7 +112,7 @@ stack_stencils (Stencil &a, Stencil *b, Offset *origin) SCM Page::to_stencil () const { - SCM proc = ly_scheme_function ("page-to-stencil"); + SCM proc = paper_->lookup_variable (ly_symbol2scm ("page-to-stencil")); return scm_call_1 (proc, self_scm ()); } @@ -141,20 +141,11 @@ LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-ste stack_stencils (stencil, s, &o); o[Y_AXIS] += p->head_sep_; } + for (SCM s = p->lines_; s != SCM_EOL; s = ly_cdr (s)) { Paper_line *p = unsmob_paper_line (ly_car (s)); -#if 0 // ugh, parse error? - Stencil line (Box (Interval (0, p->dim ()[X_AXIS]), - Interval (0, p->dim ()[Y_AXIS])), SCM_EOL); -#else - Box x (Interval (0, p->dim ()[X_AXIS]), - Interval (0, p->dim ()[Y_AXIS])); - Stencil line (x, SCM_EOL); -#endif - line.add_stencil (*unsmob_stencil (p->to_stencil ())); - stack_stencils (stencil, &line, &o); - + stack_stencils (stencil, unsmob_stencil (p->to_stencil ()), &o); /* Do not put vfill between title and its music, */ if (ly_cdr (s) != SCM_EOL && (!p->is_title () || vfill < 0)) @@ -200,3 +191,11 @@ Page::text_height () const return h; } +LY_DEFINE (ly_page_paper_lines, "ly:page-paper-lines", + 1, 0, 0, (SCM page), + "Return paper-lines from PAGE.") +{ + Page *p = unsmob_page (page); + SCM_ASSERT_TYPE (p, page, SCM_ARG1, __FUNCTION__, "page"); + return p->lines_; +} diff --git a/lily/paper-line.cc b/lily/paper-line.cc index 746b4aca46..ee25815447 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -81,6 +81,9 @@ Paper_line::to_stencil () const Stencil stencil; for (SCM s = stencils_; ly_c_pair_p (s); s = ly_cdr (s)) stencil.add_stencil (*unsmob_stencil (ly_car (s))); + Offset o = dim (); + Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS])); + stencil = Stencil (x, stencil.expr ()); return stencil.smobbed_copy (); } @@ -110,3 +113,13 @@ LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score", SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line"); return scm_int2num (int (pl->penalty ())); } + +LY_DEFINE (ly_paper_line_stencil, "ly:paper-line-stencil", + 1, 0, 0, (SCM line), + "Return the height of @var{line}.") +{ + Paper_line *pl = unsmob_paper_line (line); + SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line"); + return pl->to_stencil (); +} + diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 7999da4e74..8de4a29e16 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -183,12 +183,7 @@ Paper_outputter::output_line (SCM line, Offset *origin, bool is_last) ly_quote_scm (ly_offset2scm (*origin)), ly_quote_scm (ly_offset2scm (dim)))); -#if 1 /* FIXME: how stupid is this memorywise? */ output_stencil (unsmob_stencil (p->to_stencil ())); -#else - for (SCM s = p->stencils (); ly_c_pair_p (s); s = ly_cdr (s)) - output_expr (unsmob_stencil (ly_car (s))->expr (), Offset (0, 0)); -#endif (*origin)[Y_AXIS] += dim[Y_AXIS]; output_scheme (scm_list_2 (ly_symbol2scm ("stop-system"), @@ -200,8 +195,6 @@ Paper_outputter::output_page (Page *p, bool is_last) { output_scheme (scm_list_1 (ly_symbol2scm ("start-page"))); -#if 0 /* FIXME: how stupid is this, memorywise? */ - output_scheme (scm_list_3 (ly_symbol2scm ("start-system"), ly_quote_scm (ly_offset2scm (Offset (0, 0))), ly_quote_scm (ly_offset2scm (Offset (0, 0))))); @@ -209,63 +202,6 @@ Paper_outputter::output_page (Page *p, bool is_last) output_stencil (unsmob_stencil (p->to_stencil ())); output_scheme (scm_list_2 (ly_symbol2scm ("stop-system"), SCM_BOOL_T)); -#else - Offset o (p->left_margin_, p->top_margin_); - Real vfill = (p->line_count_ > 1 - ? (p->text_height () - p->height_) / (p->line_count_ - 1) - : 0); - - Real coverage = p->height_ / p->text_height (); - if (coverage < p->MIN_COVERAGE_) - /* Do not space out a badly filled page. This is too simplistic - (ie broken), because this should not vary too much between - (subsequent?) pages in a book. */ - vfill = 0; - - if (unsmob_stencil (p->header_)) - { - output_line (stencil2line (unsmob_stencil (p->header_)), &o, false); - o[Y_AXIS] += p->head_sep_; - } - for (SCM s = p->lines_; s != SCM_EOL; s = ly_cdr (s)) - { - SCM line = ly_car (s); - output_line (line, &o, - is_last && ly_cdr (s) != SCM_EOL - && !unsmob_stencil (p->copyright_) - && !unsmob_stencil (p->tagline_) - && !unsmob_stencil (p->footer_)); - - /* Do not put vfill between title and its music, */ - if (scm_pair_p (ly_cdr (s)) - && (!unsmob_paper_line (line)->is_title () || vfill < 0)) - o[Y_AXIS] += vfill; - /* rather put extra just before the title. */ - if (ly_cdr (s) != SCM_EOL - && (unsmob_paper_line (ly_cadr (s))->is_title () && vfill > 0)) - o[Y_AXIS] += vfill; - } - - o[Y_AXIS] = p->vsize_ - p->bottom_margin_; - if (unsmob_stencil (p->copyright_)) - o[Y_AXIS] -= unsmob_stencil (p->copyright_)->extent (Y_AXIS).length (); - if (unsmob_stencil (p->tagline_)) - o[Y_AXIS] -= unsmob_stencil (p->tagline_)->extent (Y_AXIS).length (); - if (unsmob_stencil (p->footer_)) - o[Y_AXIS] -= unsmob_stencil (p->footer_)->extent (Y_AXIS).length (); - - if (unsmob_stencil (p->copyright_)) - output_line (stencil2line (unsmob_stencil (p->copyright_)), &o, - is_last - && !unsmob_stencil (p->tagline_) - && !unsmob_stencil (p->footer_)); - if (unsmob_stencil (p->tagline_)) - output_line (stencil2line (unsmob_stencil (p->tagline_)), &o, - is_last && !unsmob_stencil (p->footer_)); - if (unsmob_stencil (p->footer_)) - output_line (stencil2line (unsmob_stencil (p->footer_)), &o, is_last); -#endif - output_scheme (scm_list_2 (ly_symbol2scm ("stop-page"), ly_bool2scm (is_last && !unsmob_stencil (p->footer_)))); diff --git a/lily/parser.yy b/lily/parser.yy index 5914531b85..842244079c 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -315,6 +315,11 @@ or %token WITH /* escaped */ +/* FIXME: this sucks. The user will get to see these names: + syntax error, unexpected E_CHAR: + \ + %% + */ %token E_CHAR E_EXCLAMATION E_SMALLER E_BIGGER E_OPEN E_CLOSE %token E_LEFTSQUARE E_RIGHTSQUARE E_TILDE %token E_BACKSLASH @@ -2455,6 +2460,7 @@ markup: SCM s = book->to_stencil (paper, THIS->header_); $$ = scm_list_2 (ly_scheme_function ("stencil-markup"), s); scm_gc_unprotect_object (score->self_scm ()); + scm_gc_unprotect_object (book->self_scm ()); } ; diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc index af6904f5c2..7971229f07 100644 --- a/lily/stencil-scheme.cc +++ b/lily/stencil-scheme.cc @@ -66,7 +66,7 @@ LY_DEFINE (ly_translate_stencil, "ly:stencil-translate", return new_s; } -LY_DEFINE (ly_stencil_expr, "ly:stencil-get-expr", +LY_DEFINE (ly_stencil_expr, "ly:stencil-expr", 1, 0, 0, (SCM stil), "Return the expression of @var{stil}.") { @@ -223,5 +223,5 @@ LY_DEFINE (ly_align_to_x, "ly:stencil-align-to!", unsmob_stencil (stil)->align_to ((Axis)ly_scm2int (axis), ly_scm2double (dir)); - return SCM_UNDEFINED; + return stil; } diff --git a/ly/declarations-init.ly b/ly/declarations-init.ly index 671b97470c..48e17441ce 100644 --- a/ly/declarations-init.ly +++ b/ly/declarations-init.ly @@ -74,6 +74,8 @@ melismaEnd = #(make-span-event 'ManualMelismaEvent STOP) #(define page-breaking ly:ragged-page-breaks) %%#(define page-breaking ly:optimal-page-breaks) + #(define page-to-stencil ly:page-header-lines-footer-stencil) + \include "engraver-init.ly" } @@ -149,3 +151,5 @@ unusedEntry = \notes { c4 } #(define toplevel-book-handler default-toplevel-book-handler) #(define toplevel-music-handler default-toplevel-music-handler) #(define toplevel-score-handler default-toplevel-score-handler) + +#(define toplevel-score-handler default-toplevel-score-handler) diff --git a/scm/lily.scm b/scm/lily.scm index d192d70af0..e22e5a5acd 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -98,9 +98,6 @@ (define-public safe-mode? #f) -;; Hmm -(define-public page-to-stencil ly:page-header-lines-footer-stencil) - ;; parser stuff. (define-public (print-music-as-book parser music) (let* ((score (ly:music-scorify music))