From 2b674efda345226c994146316a80c8014a16d852 Mon Sep 17 00:00:00 2001 From: janneke Date: Tue, 27 Apr 2004 22:23:00 +0000 Subject: [PATCH] * lily/book.cc (to_stencil): New method. * lily/parser.yy (markup): Use it to grok \score. --- ChangeLog | 8 ++ flower/include/offset.hh | 83 +++++++++++++------- flower/include/string.hh | 2 +- flower/offset.cc | 5 -- lily/ambitus.cc | 4 +- lily/balloon.cc | 2 +- lily/book.cc | 27 +++++++ lily/cluster.cc | 2 +- lily/grob.cc | 2 +- lily/include/book.hh | 1 + lily/include/page.hh | 12 +-- lily/include/paper-outputter.hh | 1 + lily/include/smobs.hh | 26 +++---- lily/include/stencil.hh | 2 +- lily/mensural-ligature.cc | 2 +- lily/my-lily-parser.cc | 2 +- lily/note-head.cc | 10 +-- lily/ottava-bracket.cc | 2 +- lily/page.cc | 133 ++++++++++++++++++-------------- lily/paper-book.cc | 29 +++++-- lily/paper-line.cc | 2 +- lily/paper-outputter.cc | 93 ++++++++++++++++++++-- lily/parser.yy | 11 +++ lily/stencil-scheme.cc | 4 +- lily/stencil.cc | 60 +++++++------- lily/system-start-delimiter.cc | 11 +-- lily/vaticana-ligature.cc | 2 +- scm/lily.scm | 3 + 28 files changed, 365 insertions(+), 176 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9c1cdbb64c..cd5b51712a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ +2004-04-28 Jan Nieuwenhuizen + + * lily/book.cc (to_stencil): New method. + + * lily/parser.yy (markup): Use it to grok \score. + 2004-04-27 Jan Nieuwenhuizen + * lily/stencil.cc (expr): Rename (was: get_expr). Update callers. + * lily/paper-book.cc (pages): Change signature. Update callers. * lily/include/page.hh: diff --git a/flower/include/offset.hh b/flower/include/offset.hh index a59b354526..b7fea1313a 100644 --- a/flower/include/offset.hh +++ b/flower/include/offset.hh @@ -7,79 +7,101 @@ #ifndef OFFSET_HH #define OFFSET_HH +#include "flower-proto.hh" #include "real.hh" #include "axes.hh" #include "arithmetic-operator.hh" -struct Offset; - Offset complex_multiply (Offset, Offset); Offset complex_divide (Offset, Offset); Offset complex_exp (Offset); /** 2d vector - should change to Complex + should change to Complex -- how is vector == complex? + + ughr wat een beerput */ -struct Offset { +class Offset +{ public: Real coordinate_a_[NO_AXES]; - Real &operator[] (Axis i) { + Real &operator[] (Axis i) + { return coordinate_a_[i]; } - Real operator[] (Axis i) const{ + + Real operator[] (Axis i) const + { return coordinate_a_[i]; } - Offset& operator+= (Offset o) { - (*this)[X_AXIS] += o[X_AXIS]; - (*this)[Y_AXIS] += o[Y_AXIS]; + Offset& operator+= (Offset o) + { + (*this)[X_AXIS] += o[X_AXIS]; + (*this)[Y_AXIS] += o[Y_AXIS]; return *this; } - Offset operator - () const { + + Offset operator - () const + { Offset o = *this; o[X_AXIS] = - o[X_AXIS]; o[Y_AXIS] = - o[Y_AXIS]; return o; } - Offset& operator-= (Offset o) { - (*this)[X_AXIS] -= o[X_AXIS]; - (*this)[Y_AXIS] -= o[Y_AXIS]; + + Offset& operator-= (Offset o) + { + (*this)[X_AXIS] -= o[X_AXIS]; + (*this)[Y_AXIS] -= o[Y_AXIS]; return *this; } - Offset &scale (Offset o) { - (*this)[X_AXIS] *= o[X_AXIS]; - (*this)[Y_AXIS] *= o[Y_AXIS]; + Offset &scale (Offset o) + { + (*this)[X_AXIS] *= o[X_AXIS]; + (*this)[Y_AXIS] *= o[Y_AXIS]; return *this; } - Offset &operator *= (Real a) { - (*this)[X_AXIS] *= a; - (*this)[Y_AXIS] *= a; + + Offset &operator *= (Real a) + { + (*this)[X_AXIS] *= a; + (*this)[Y_AXIS] *= a; return *this; } - Offset (Real ix , Real iy) { + Offset (Real ix , Real iy) + { coordinate_a_[X_AXIS] =ix; coordinate_a_[Y_AXIS] =iy; } - Offset () { - coordinate_a_[X_AXIS]= - coordinate_a_[Y_AXIS]= - 0.0; + + Offset () + { + coordinate_a_[X_AXIS] = coordinate_a_[Y_AXIS]= 0.0; } String to_string () const; - void mirror (Axis); + Offset& mirror (Axis a) + { + coordinate_a_[a] = - coordinate_a_[a]; + return *this; + } + Real arg () const; Real length () const; - Offset operator *= (Offset z2) { + + //wtf, How is Offset a Complex? is this used? + Offset operator *= (Offset z2) + { *this = complex_multiply (*this,z2); return *this; } @@ -104,7 +126,14 @@ operator* (Offset o1, Real o2) return o1; } +inline Offset +mirror (Offset o, Axis a) +{ + o.mirror (a); + return o; +} + -#endif // OFFSET_HH +#endif /* OFFSET_HH */ diff --git a/flower/include/string.hh b/flower/include/string.hh index bee1cf986a..4e06820c04 100644 --- a/flower/include/string.hh +++ b/flower/include/string.hh @@ -172,7 +172,7 @@ inline String to_string (String s) { return s; } /// "cccc" String to_string (char c, int n = 1); String to_string (int i, char const* format = 0); -String to_string (double f , char const* format = 0); +String to_string (double f, char const* format = 0); String to_string (long b); String to_string (bool b); String to_string (char const* format, ... ); diff --git a/flower/offset.cc b/flower/offset.cc index dd205661fc..41eb841c24 100644 --- a/flower/offset.cc +++ b/flower/offset.cc @@ -91,8 +91,3 @@ Offset::length () const { return sqrt (sqr (coordinate_a_[X_AXIS]) + sqr (coordinate_a_[Y_AXIS])); } -void -Offset::mirror (Axis a) -{ - coordinate_a_[a] = - coordinate_a_[a]; -} diff --git a/lily/ambitus.cc b/lily/ambitus.cc index eb586b3a8f..669cd61a07 100644 --- a/lily/ambitus.cc +++ b/lily/ambitus.cc @@ -144,8 +144,8 @@ MAKE_SCHEME_CALLBACK (Ambitus,print,1); SCM Ambitus::print (SCM smob) { - Item *me = (Item *)unsmob_grob (smob); - Stencil stencil = Stencil (); + Item *me = (Item*) unsmob_grob (smob); + Stencil stencil; SCM scm_note_head_style = me->get_property ("note-head-style"); String note_head_style; diff --git a/lily/balloon.cc b/lily/balloon.cc index 5421c05a90..43ee85e7e8 100644 --- a/lily/balloon.cc +++ b/lily/balloon.cc @@ -80,7 +80,7 @@ Balloon_interface::print (SCM smob) text_stil->translate (z2); fr.add_stencil (*text_stil); - fr = Stencil (orig_extent, fr.get_expr ()); + fr = Stencil (orig_extent, fr.expr ()); return fr.smobbed_copy (); } diff --git a/lily/book.cc b/lily/book.cc index 32985c9cca..7400270e7b 100644 --- a/lily/book.cc +++ b/lily/book.cc @@ -18,6 +18,7 @@ #include "music-output-def.hh" #include "music-output.hh" #include "music.hh" +#include "page.hh" #include "paper-book.hh" #include "paper-def.hh" #include "score.hh" @@ -97,3 +98,29 @@ Book::process (String outname, Music_output_def *default_def, SCM header) paper_book->output (outname); scm_gc_unprotect_object (paper_book->self_scm ()); } + +/* FIXME: WIP, this is a hack. Return first page as stencil. */ +SCM +Book::to_stencil (Music_output_def *default_def, SCM header) +{ + Paper_book *paper_book = new Paper_book (); + int score_count = scores_.size (); + for (int i = 0; i < score_count; i++) + { + Paper_def *paper = 0; + SCM systems = scores_[i]->book_rendering ("", default_def, &paper); + if (systems != SCM_UNDEFINED) + { + if (paper) + paper_book->papers_.push (paper); + paper_book->scores_.push (systems); + paper_book->headers_.push (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 (); + return SCM_EOL; +} diff --git a/lily/cluster.cc b/lily/cluster.cc index 86b062b809..687eaabae3 100644 --- a/lily/cluster.cc +++ b/lily/cluster.cc @@ -53,7 +53,7 @@ brew_cluster_piece (Grob *me, Array bottom_points, Array top_poi } - Stencil out = Stencil (); + Stencil out; Array points; points.clear (); int size = bottom_points.size (); diff --git a/lily/grob.cc b/lily/grob.cc index 6e3833f5fd..b1e6324a94 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -253,7 +253,7 @@ Grob::get_uncached_stencil ()const // ugr. mol = Stencil (m->extent_box (), - scm_list_n (origin, m->get_expr (), SCM_UNDEFINED) + scm_list_n (origin, m->expr (), SCM_UNDEFINED) ). smobbed_copy (); m = unsmob_stencil (mol); diff --git a/lily/include/book.hh b/lily/include/book.hh index 7ffeec5888..8682599549 100644 --- a/lily/include/book.hh +++ b/lily/include/book.hh @@ -26,6 +26,7 @@ public: Book (); Book (Book const&); void process (String outname, Music_output_def*, SCM header); + SCM to_stencil (Music_output_def*, SCM header); }; DECLARE_UNSMOB (Book,book); diff --git a/lily/include/page.hh b/lily/include/page.hh index 152f612a55..880cbc0bd5 100644 --- a/lily/include/page.hh +++ b/lily/include/page.hh @@ -11,13 +11,15 @@ #include "lily-proto.hh" #include "smobs.hh" -/* WIP -- moving toward flexible stencil based output. */ +/* WIP -- moving toward flexible stencil based output. + Rename to Paper_page? */ class Page { DECLARE_SMOBS (Page, ); public: static int page_count_; + static Real MIN_COVERAGE_; Paper_def *paper_; int number_; int line_count_; @@ -40,11 +42,11 @@ public: Real head_sep_; Real text_width_; - /* available area for text. */ - Real text_height (); - Page (Paper_def*, int); - void output (Paper_outputter*, bool); + + /* available area for text. */ + Real text_height () const; + SCM to_stencil () const; }; DECLARE_UNSMOB (Page, page); diff --git a/lily/include/paper-outputter.hh b/lily/include/paper-outputter.hh index e232f26a27..c6531ef8c1 100644 --- a/lily/include/paper-outputter.hh +++ b/lily/include/paper-outputter.hh @@ -44,6 +44,7 @@ public: void output_stencil (Stencil*); void output_header (Paper_def*, SCM, int, bool); void output_line (SCM, Offset*, bool); + void output_page (Page*, bool); }; #endif /* PAPER_OUTPUTTER_HH */ diff --git a/lily/include/smobs.hh b/lily/include/smobs.hh index e54fbd480a..0feae768fd 100644 --- a/lily/include/smobs.hh +++ b/lily/include/smobs.hh @@ -45,20 +45,21 @@ For example, Complex_smob::Complex_smob () { - scm_member_ =SCM_EOL; + scm_member_ = SCM_EOL; smobify_self (); scm_member_ = <..what you want to store..> } - after creation, the self_scm() field of a complex smob is protected - from Garbage Collection. This protection should be removed once the - object is put into another (reachable) Scheme data structure, ie. + after construction, the self_scm () field of a complex smob is + protected from Garbage Collection. This protection should be + removed once the object is put into another (reachable) Scheme data + structure, i.e. - Complex_smob * p = new Complex_smob; + Complex_smob *p = new Complex_smob; list = scm_cons (p->self_scm (), list); scm_gc_unprotect_object (p->self_scm ()); - Complex smobs are made with DECLARE_SMOBS(Classname,) in the class + Complex smobs are made with DECLARE_SMOBS (Classname,) in the class declaration. CALLING INTERFACE @@ -75,7 +76,7 @@ For implementating a class, the following should be provided - - an equal_p() function (a default is in the + - an equal_p () function (a default is in the IMPLEMENT_DEFAULT_EQUAL_P macro in ly-smobs.icc) - mark_smob () function, that calls scm_gc_mark () on all Scheme @@ -84,20 +85,19 @@ - a print_smob () function, that displays a representation for debugging purposes - - A call to one of the IMPLEMENT_SMOBS or IMPLEMENT_SIMPLE_SMOBS macros - from file "ly-smobs.icc" - + - A call to one of the IMPLEMENT_SMOBS or IMPLEMENT_SIMPLE_SMOBS macros + from file "ly-smobs.icc" */ -#define DECLARE_SIMPLE_SMOBS(CL,dummy) \ +#define DECLARE_SIMPLE_SMOBS(CL, dummy) \ public: \ SCM smobbed_copy () const; \ DECLARE_BASE_SMOBS(CL) #define DECLARE_BASE_SMOBS(CL) \ - friend class Non_existant_class ; \ -private:\ + friend class Non_existent_class; \ +private: \ static scm_t_bits smob_tag_; \ static SCM mark_smob (SCM); \ static size_t free_smob (SCM s); \ diff --git a/lily/include/stencil.hh b/lily/include/stencil.hh index 0af30a3d63..5168dca5ef 100644 --- a/lily/include/stencil.hh +++ b/lily/include/stencil.hh @@ -58,7 +58,7 @@ public: Stencil (); Offset origin () const; - SCM get_expr () const; + SCM expr () const; /** Set dimensions to empty, or to (Interval (0,0),Interval (0,0) */ diff --git a/lily/mensural-ligature.cc b/lily/mensural-ligature.cc index 545018dc59..2035745173 100644 --- a/lily/mensural-ligature.cc +++ b/lily/mensural-ligature.cc @@ -33,7 +33,7 @@ brew_flexa (Grob *me, { Real staff_space = Staff_symbol_referencer::staff_space (me); Real height = 0.6 * staff_space; - Stencil stencil = Stencil (); + Stencil stencil; if (add_cauda) { diff --git a/lily/my-lily-parser.cc b/lily/my-lily-parser.cc index 4f56f1d0fd..9a0c36726c 100644 --- a/lily/my-lily-parser.cc +++ b/lily/my-lily-parser.cc @@ -333,7 +333,7 @@ LY_DEFINE (ly_parser_parse_string, "ly:parser-parse-string", return SCM_UNSPECIFIED; } -static Music_output_def* +Music_output_def* get_paper (My_lily_parser *parser) { SCM id = parser->lexer_->lookup_identifier ("$defaultpaper"); diff --git a/lily/note-head.cc b/lily/note-head.cc index 15841c801c..39f57e848c 100644 --- a/lily/note-head.cc +++ b/lily/note-head.cc @@ -72,12 +72,10 @@ Note_head::brew_ledger_lines (Grob *me, { Grob *staff = Staff_symbol_referencer::get_staff_symbol (me); Real inter_f = Staff_symbol_referencer::staff_space (me)/2; - int line_count = (abs (pos) < interspaces) - ? 0 - : (abs (pos) - interspaces) / 2; - Stencil stencil = Stencil (); - - + int line_count = ((abs (pos) < interspaces) + ? 0 + : (abs (pos) - interspaces) / 2); + Stencil stencil; if (line_count) { Real ledgerlinethickness = diff --git a/lily/ottava-bracket.cc b/lily/ottava-bracket.cc index afea781d86..3a13fdcf0c 100644 --- a/lily/ottava-bracket.cc +++ b/lily/ottava-bracket.cc @@ -156,7 +156,7 @@ Ottava_bracket::print (SCM smob) b = Stencil (Box (b.extent (X_AXIS), Interval (0.1,0.1)), - b.get_expr ()); + b.expr ()); b.translate_axis (bracket_span_points[LEFT], X_AXIS); text.translate_axis (span_points[LEFT], X_AXIS); diff --git a/lily/page.cc b/lily/page.cc index 3e0db3c82a..a25d2a78f9 100644 --- a/lily/page.cc +++ b/lily/page.cc @@ -6,6 +6,7 @@ (c) 2004 Jan Nieuwenhuizen */ +#include "dimensions.hh" #include "ly-module.hh" #include "page.hh" #include "paper-def.hh" @@ -14,25 +15,8 @@ #include "stencil.hh" #include "warn.hh" -// JUNKME -SCM -stencil2line (Stencil* stil, bool is_title = false) -{ - static SCM z; - if (!z) - z = scm_permanent_object (ly_offset2scm (Offset (0, 0))); - Offset dim = Offset (stil->extent (X_AXIS).length (), - stil->extent (Y_AXIS).length ()); - Paper_line *pl = new Paper_line (dim, scm_cons (stil->smobbed_copy (), - SCM_EOL), - -10001 * is_title, is_title); - - return scm_gc_unprotect_object (pl->self_scm ()); -} - -static Real const MIN_COVERAGE = 0.66; - int Page::page_count_ = 0; +Real Page::MIN_COVERAGE_ = 0.66; Page::Page (Paper_def *paper, int number) { @@ -101,7 +85,6 @@ int Page::print_smob (SCM smob, SCM port, scm_print_state*) { Page *p = (Page*) ly_cdr (smob); - scm_puts ("#<", port); scm_puts (classname (p), port); scm_puts (to_string (p->number_).to_str0 (), port); @@ -110,37 +93,71 @@ Page::print_smob (SCM smob, SCM port, scm_print_state*) return 1; } -void -Page::output (Paper_outputter *out, bool is_last) +static void +stack_stencils (Stencil &a, Stencil *b, Offset *origin) { - progress_indication ("[" + to_string (number_)); - out->output_scheme (scm_list_1 (ly_symbol2scm ("start-page"))); - Offset o (left_margin_, top_margin_); - Real vfill = line_count_ > 1 ? (text_height () - height_) / (line_count_ - 1) - : 0; - - Real coverage = height_ / text_height (); - if (coverage < MIN_COVERAGE) + Real height = b->extent (Y_AXIS).length (); + if (height > 50 CM) + { + programming_error (to_string ("Improbable stencil height: %f", height)); + height = 50 CM; + } + Offset o = *origin; + o.mirror (Y_AXIS); + b->translate (o); + a.add_stencil (*b); + (*origin)[Y_AXIS] += height; +} + +SCM +Page::to_stencil () const +{ + SCM proc = ly_scheme_function ("page-to-stencil"); + return scm_call_1 (proc, self_scm ()); +} + +LY_DEFINE (ly_page_header_lines_footer_stencil, "ly:page-header-lines-footer-stencil", + 1, 0, 0, (SCM page), + "Simple header, lines, footer stencil from PAGE.") +{ + Page *p = unsmob_page (page); + SCM_ASSERT_TYPE (p, page, SCM_ARG1, __FUNCTION__, "page"); + + Stencil stencil; + 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 (header_)) + if (Stencil *s = unsmob_stencil (p->header_)) { - out->output_line (stencil2line (unsmob_stencil (header_)), &o, false); - o[Y_AXIS] += head_sep_; + stack_stencils (stencil, s, &o); + o[Y_AXIS] += p->head_sep_; } - for (SCM s = lines_; s != SCM_EOL; s = ly_cdr (s)) + for (SCM s = p->lines_; s != SCM_EOL; s = ly_cdr (s)) { - SCM line = ly_car (s); - out->output_line (line, &o, - is_last && ly_cdr (s) != SCM_EOL && !unsmob_stencil (copyright_) - && !unsmob_stencil (tagline_) && !unsmob_stencil (footer_)); + 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); /* Do not put vfill between title and its music, */ - if (scm_pair_p (ly_cdr (s)) - && (!unsmob_paper_line (line)->is_title () || vfill < 0)) + if (ly_cdr (s) != SCM_EOL + && (!p->is_title () || vfill < 0)) o[Y_AXIS] += vfill; /* rather put extra just before the title. */ if (ly_cdr (s) != SCM_EOL @@ -148,29 +165,26 @@ Page::output (Paper_outputter *out, bool is_last) o[Y_AXIS] += vfill; } - o[Y_AXIS] = vsize_ - bottom_margin_; - if (unsmob_stencil (copyright_)) - o[Y_AXIS] -= unsmob_stencil (copyright_)->extent (Y_AXIS).length (); - if (unsmob_stencil (tagline_)) - o[Y_AXIS] -= unsmob_stencil (tagline_)->extent (Y_AXIS).length (); - if (unsmob_stencil (footer_)) - o[Y_AXIS] -= unsmob_stencil (footer_)->extent (Y_AXIS).length (); - - if (unsmob_stencil (copyright_)) - out->output_line (stencil2line (unsmob_stencil (copyright_)), &o, - is_last && !unsmob_stencil (tagline_) && !unsmob_stencil (footer_)); - if (unsmob_stencil (tagline_)) - out->output_line (stencil2line (unsmob_stencil (tagline_)), &o, - is_last && !unsmob_stencil (footer_)); - if (unsmob_stencil (footer_)) - out->output_line (stencil2line (unsmob_stencil (footer_)), &o, is_last); - out->output_scheme (scm_list_2 (ly_symbol2scm ("stop-page"), - ly_bool2scm (is_last && !unsmob_stencil (footer_)))); - progress_indication ("]"); + 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 (Stencil *s = unsmob_stencil (p->copyright_)) + stack_stencils (stencil, s, &o); + if (Stencil *s = unsmob_stencil (p->tagline_)) + stack_stencils (stencil, s, &o); + if (Stencil *s = unsmob_stencil (p->footer_)) + stack_stencils (stencil, s, &o); + + return stencil.smobbed_copy (); } Real -Page::text_height () +Page::text_height () const { Real h = vsize_ - top_margin_ - bottom_margin_; if (unsmob_stencil (header_)) @@ -185,3 +199,4 @@ Page::text_height () h -= unsmob_stencil (footer_)->extent (Y_AXIS).length (); return h; } + diff --git a/lily/paper-book.cc b/lily/paper-book.cc index ab59d41a40..88eb8bb75c 100644 --- a/lily/paper-book.cc +++ b/lily/paper-book.cc @@ -17,8 +17,22 @@ #include "stencil.hh" #include "warn.hh" -// JUNKME. -extern SCM stencil2line (Stencil* stil, bool is_title = false); +// JUNKME +SCM +stencil2line (Stencil* stil, bool is_title = false) +{ + static SCM z; + if (!z) + z = scm_permanent_object (ly_offset2scm (Offset (0, 0))); + Offset dim = Offset (stil->extent (X_AXIS).length (), + stil->extent (Y_AXIS).length ()); + Paper_line *pl = new Paper_line (dim, scm_cons (stil->smobbed_copy (), + SCM_EOL), + -10001 * is_title, is_title); + + return scm_gc_unprotect_object (pl->self_scm ()); +} + Paper_book::Paper_book () { @@ -73,6 +87,7 @@ void Paper_book::output (String outname) { if (!papers_.size ()) + // FIXME: no end-output? return; /* Generate all stencils to trigger font loads. */ @@ -83,11 +98,15 @@ Paper_book::output (String outname) int page_count = scm_ilength (pages); out->output_header (paper, scopes (0), page_count, false); - for (SCM s = pages; ly_c_pair_p (s); s = ly_cdr (s)) - unsmob_page (ly_car (s))->output (out, ly_c_pair_p (ly_cdr (s))); + for (SCM s = pages; s != SCM_EOL; s = ly_cdr (s)) + { + Page *p = unsmob_page (ly_car (s)); + progress_indication ("[" + to_string (p->number_)); + out->output_page (p, ly_cdr (s) == SCM_EOL); + progress_indication ("]"); + } out->output_scheme (scm_list_1 (ly_symbol2scm ("end-output"))); - progress_indication ("\n"); } diff --git a/lily/paper-line.cc b/lily/paper-line.cc index a34a17b0d0..746b4aca46 100644 --- a/lily/paper-line.cc +++ b/lily/paper-line.cc @@ -78,7 +78,7 @@ Paper_line::stencils () const SCM Paper_line::to_stencil () const { - Stencil stencil = Stencil (); + Stencil stencil; for (SCM s = stencils_; ly_c_pair_p (s); s = ly_cdr (s)) stencil.add_stencil (*unsmob_stencil (ly_car (s))); return stencil.smobbed_copy (); diff --git a/lily/paper-outputter.cc b/lily/paper-outputter.cc index 1794db725a..7999da4e74 100644 --- a/lily/paper-outputter.cc +++ b/lily/paper-outputter.cc @@ -18,6 +18,7 @@ #include "lily-version.hh" #include "ly-module.hh" #include "main.hh" +#include "page.hh" #include "paper-book.hh" #include "paper-def.hh" #include "paper-line.hh" @@ -28,6 +29,8 @@ #include "string-convert.hh" #include "warn.hh" +// JUNKME +extern SCM stencil2line (Stencil* stil, bool is_title = false); Paper_outputter::Paper_outputter (String filename) { @@ -171,7 +174,8 @@ Paper_outputter::output_line (SCM line, Offset *origin, bool is_last) Offset dim = p->dim (); if (dim[Y_AXIS] > 50 CM) { - programming_error ("Improbable system height."); + programming_error (to_string ("Improbable line height: %f", + dim[Y_AXIS])); dim[Y_AXIS] = 50 CM; } @@ -179,17 +183,94 @@ Paper_outputter::output_line (SCM line, Offset *origin, bool is_last) ly_quote_scm (ly_offset2scm (*origin)), ly_quote_scm (ly_offset2scm (dim)))); -#if 0 /* FIXME: how stupid is this wrt memory management? */ - for (SCM s = p->stencils (); ly_c_pair_p (s); s = ly_cdr (s)) - output_expr (unsmob_stencil (ly_car (s))->get_expr (), Offset (0, 0)); -#else +#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"), ly_bool2scm (is_last))); } +void +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))))); + + 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_)))); +} + void Paper_outputter::output_music_output_def (Music_output_def *odef) { @@ -200,7 +281,7 @@ Paper_outputter::output_music_output_def (Music_output_def *odef) void Paper_outputter::output_stencil (Stencil *stil) { - output_expr (stil->get_expr (), stil->origin ()); + output_expr (stil->expr (), stil->origin ()); } /* TODO: replaceme/rewriteme, see output-ps.scm: output-stencil */ diff --git a/lily/parser.yy b/lily/parser.yy index 27bdcdf994..033e57158a 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -2445,6 +2445,17 @@ markup: | STRING_IDENTIFIER { $$ = $1; } + | score_block { + Score *score = $1; + //Book *book = unsmob_book (ly_score_bookify (score->self_scm ())); + Book *book = new Book; + book->scores_.push (score); + extern Music_output_def* get_paper (My_lily_parser *parser); + Music_output_def *paper = get_paper (THIS); + SCM s = book->to_stencil (paper, THIS->header_); +// $$ = s; + $$ = Text_item::interpret_markup (paper->self_scm (), SCM_EOL, s); + } ; markup_list: diff --git a/lily/stencil-scheme.cc b/lily/stencil-scheme.cc index 8c986b2a71..af6904f5c2 100644 --- a/lily/stencil-scheme.cc +++ b/lily/stencil-scheme.cc @@ -66,13 +66,13 @@ LY_DEFINE (ly_translate_stencil, "ly:stencil-translate", return new_s; } -LY_DEFINE (ly_stencil_get_expr, "ly:stencil-get-expr", +LY_DEFINE (ly_stencil_expr, "ly:stencil-get-expr", 1, 0, 0, (SCM stil), "Return the expression of @var{stil}.") { Stencil *s = unsmob_stencil (stil); SCM_ASSERT_TYPE (s, stil, SCM_ARG1, __FUNCTION__, "stencil"); - return s->get_expr (); + return s->expr (); } LY_DEFINE (ly_stencil_get_extent, "ly:stencil-extent", diff --git a/lily/stencil.cc b/lily/stencil.cc index f1cab5ba1c..5f0e04f3a8 100644 --- a/lily/stencil.cc +++ b/lily/stencil.cc @@ -55,6 +55,25 @@ Stencil::extent (Axis a) const return dim_[a]; } +/* Hmm... maybe this is not such a good idea ; stuff can be empty, + while expr_ == '() */ +bool +Stencil::is_empty () const +{ + return expr_ == SCM_EOL; +} + +SCM +Stencil::expr () const +{ + return expr_; +} + +Box +Stencil::extent_box () const +{ + return dim_; +} Offset Stencil::origin () const { @@ -125,14 +144,14 @@ Stencil::align_to (Axis a, Real x) } /* FIXME: unintuitive naming, you would expect *this to be moved. - Kept (keeping?) API for compat with add_at_edge (). */ + Kept (keeping?) API for compat with add_at_edge (). + + What is PADDING, what is MINIMUM, exactly? */ Stencil -Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, Real padding, - Real minimum) const +Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, + Real padding, Real minimum) const { - Interval my_extent= dim_[a]; - - + Interval my_extent = dim_[a]; Interval i (s.extent (a)); Real his_extent; if (i.is_empty ()) @@ -143,17 +162,16 @@ Stencil::moved_to_edge (Axis a, Direction d, Stencil const &s, Real padding, else his_extent = i[-d]; - Real offset = (my_extent. is_empty () ? 0.0 : my_extent[d] - his_extent) + Real offset = (my_extent.is_empty () ? 0.0 : my_extent[d] - his_extent) + d * padding; Stencil toadd (s); toadd.translate_axis (offset,a); - if (minimum > 0 - && d *(- origin ()[a] + toadd.origin ()[a]) < minimum) + if (minimum > 0 && d * (-origin ()[a] + toadd.origin ()[a]) < minimum) toadd.translate_axis ( -toadd.origin ()[a] - + origin ()[a] + d* minimum, a); - + + origin ()[a] + d * minimum, a); + return toadd; } @@ -164,23 +182,3 @@ Stencil::add_at_edge (Axis a, Direction d, Stencil const &s, Real padding, { add_stencil (moved_to_edge (a, d, s, padding, minimum)); } - -/* Hmm... maybe this is not such a good idea ; stuff can be empty, - while expr_ == '() */ -bool -Stencil::is_empty () const -{ - return expr_ == SCM_EOL; -} - -SCM -Stencil::get_expr () const -{ - return expr_; -} - -Box -Stencil::extent_box () const -{ - return dim_; -} diff --git a/lily/system-start-delimiter.cc b/lily/system-start-delimiter.cc index 3ab6cc37ed..4dff002c81 100644 --- a/lily/system-start-delimiter.cc +++ b/lily/system-start-delimiter.cc @@ -169,12 +169,13 @@ System_start_delimiter::staff_brace (Grob*me, Real y) lo = cmp; } while (hi - lo > 1); - - Stencil m (fm->get_indexed_char_stencil (lo)); // ugh. ascii? - b=m.extent_box (); - b[X_AXIS] = Interval (0,0); - return Stencil (b, m.get_expr ()); + /* FIXME: ascii? */ + Stencil stil (fm->get_indexed_char_stencil (lo)); + b = stil.extent_box (); + b[X_AXIS] = Interval (0, 0); + + return Stencil (b, stil.expr ()); } diff --git a/lily/vaticana-ligature.cc b/lily/vaticana-ligature.cc index d440da8611..ea1d4d447e 100644 --- a/lily/vaticana-ligature.cc +++ b/lily/vaticana-ligature.cc @@ -71,7 +71,7 @@ vaticana_brew_flexa (Grob *me, Real line_thickness) { Real staff_space = Staff_symbol_referencer::staff_space (me); - Stencil stencil = Stencil (); + Stencil stencil; Real right_height = 0.6 * staff_space; Real interval; diff --git a/scm/lily.scm b/scm/lily.scm index e22e5a5acd..d192d70af0 100644 --- a/scm/lily.scm +++ b/scm/lily.scm @@ -98,6 +98,9 @@ (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)) -- 2.39.2