]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/book.cc (to_stencil): New method.
authorJan Nieuwenhuizen <janneke@gnu.org>
Tue, 27 Apr 2004 22:23:00 +0000 (22:23 +0000)
committerJan Nieuwenhuizen <janneke@gnu.org>
Tue, 27 Apr 2004 22:23:00 +0000 (22:23 +0000)
* lily/parser.yy (markup): Use it to grok \score.

28 files changed:
ChangeLog
flower/include/offset.hh
flower/include/string.hh
flower/offset.cc
lily/ambitus.cc
lily/balloon.cc
lily/book.cc
lily/cluster.cc
lily/grob.cc
lily/include/book.hh
lily/include/page.hh
lily/include/paper-outputter.hh
lily/include/smobs.hh
lily/include/stencil.hh
lily/mensural-ligature.cc
lily/my-lily-parser.cc
lily/note-head.cc
lily/ottava-bracket.cc
lily/page.cc
lily/paper-book.cc
lily/paper-line.cc
lily/paper-outputter.cc
lily/parser.yy
lily/stencil-scheme.cc
lily/stencil.cc
lily/system-start-delimiter.cc
lily/vaticana-ligature.cc
scm/lily.scm

index 9c1cdbb64cf4fdc626d0520215152a7cfe728002..cd5b51712ab56b6dfff6ea22f5d7cdc40e8a5567 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
+2004-04-28  Jan Nieuwenhuizen  <janneke@gnu.org>
+
+       * lily/book.cc (to_stencil): New method.
+
+       * lily/parser.yy (markup): Use it to grok \score.
+
 2004-04-27  Jan Nieuwenhuizen  <janneke@gnu.org>
 
+       * lily/stencil.cc (expr): Rename (was: get_expr).  Update callers.
+
        * lily/paper-book.cc (pages): Change signature.  Update callers.
 
        * lily/include/page.hh:
index a59b354526a50628ec5360bf3172f06d461bdaae..b7fea1313abe0909026ccc12693e41c7bb592afb 100644 (file)
 #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 */
 
 
index bee1cf986ac95558336b8af935a93753b532bb47..4e06820c042f9a4835646764d2aa3010a8dd7906 100644 (file)
@@ -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, ... );
index dd205661fc87aae4295286ced62bf8741322695e..41eb841c244b925e5679cad9cb43390afb6643cb 100644 (file)
@@ -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];
-}
index eb586b3a8fbc8c3708c74620c83362250fc0b224..669cd61a0783493cc99c393d85c81178a5fc0f2f 100644 (file)
@@ -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;
index 5421c05a900c9360032724963a1bf57464322565..43ee85e7e8eab6c40df572c6ef5d0e175cf85514 100644 (file)
@@ -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 ();
 }
 
index 32985c9cca122e57195ac96f1cb93ea1f3fcd485..7400270e7b6ef154a6052f3c0d0005d69b7cd67d 100644 (file)
@@ -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;
+}
index 86b062b8098f37bb36502bb5fa4d2163260b4b2f..687eaabae3309014ebfd2a98a8b5719ba3d3223b 100644 (file)
@@ -53,7 +53,7 @@ brew_cluster_piece (Grob *me, Array<Offset> bottom_points, Array<Offset> top_poi
     }
 
 
-  Stencil out = Stencil ();
+  Stencil out;
   Array<Offset> points;
   points.clear ();
   int size = bottom_points.size ();
index 6e3833f5fd9362388b1c9b3cc8ff870512307060..b1e6324a943a7f7904f12ff08dd488e8e0eccc99 100644 (file)
@@ -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);
index 7ffeec5888f60576b40da561152ca519ad685927..86825995492ee083b3765022d9463e2a0ea60c16 100644 (file)
@@ -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); 
 
index 152f612a55e6bcb75148510714bf65e6e7b39a38..880cbc0bd562e2324dfa60f6cbe614b00c3f3dbe 100644 (file)
 #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);
index e232f26a274cecd297464e54801bad01d3573637..c6531ef8c1503d8522b5f149cdc72bfe3c4e0aec 100644 (file)
@@ -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 */
index e54fbd480ae9ce431a792a07902cee0e7f689be6..0feae768fd29262f33315644af50185fdd95adf1 100644 (file)
    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
    - 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);                        \
index 0af30a3d634b2566e69918a2d8bd970da4bd20c0..5168dca5efa548a438c40bf564a4134fb01a7250 100644 (file)
@@ -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) */
index 545018dc59a13c80a66196da6a6431475a296278..2035745173a32db57f5b4e85529fdc9a14716f08 100644 (file)
@@ -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)
     {
index 4f56f1d0fd52bad179d6568281dad21ffd45fc8a..9a0c36726ca098d88f926746fb11b3fbc6c894db 100644 (file)
@@ -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");
index 15841c801c0f86c4161ce807f437ae65ac135413..39f57e848c82c48d7b65154359d5c42ba90067f9 100644 (file)
@@ -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 =
index afea781d863ae991091fa12bc288b1e340d72731..3a13fdcf0cc93826158dcbfa49016ba95a032f57 100644 (file)
@@ -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);
index 3e0db3c82a8e5b4b8f96d99c3c662bf33f298f01..a25d2a78f9510c52387989b98e620e71a43c7129 100644 (file)
@@ -6,6 +6,7 @@
   (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
 */
 
+#include "dimensions.hh"
 #include "ly-module.hh"
 #include "page.hh"
 #include "paper-def.hh"
 #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;
 }
+
index ab59d41a4096c4464a053cf54c8c137e338e94d7..88eb8bb75c246a8e0264616a18b187c430b93ecd 100644 (file)
 #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");
 }
 
index a34a17b0d004c113b362e200da0d5dbcab563c37..746b4aca46052047179ab6f9a114faaa1cbcb479 100644 (file)
@@ -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 ();
index 1794db725a85cc544f1cf7d05e5e3ce786516a7c..7999da4e749beb459aacbbf1a2616f5d791b2330 100644 (file)
@@ -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  */
index 27bdcdf994caae3af6d9140614669fadfe131c13..033e57158a15bd86aa398f6381b7ef7fbf690aa8 100644 (file)
@@ -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:
index 8c986b2a7105a4a82467e00ca2cd4126c159e554..af6904f5c25656752e0130bbb19c1549077b4b04 100644 (file)
@@ -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",
index f1cab5ba1cc015f9aeb506678946dd9b6d81bd5c..5f0e04f3a8b7b20842b4c78d26ceb00562305599 100644 (file)
@@ -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_;
-}
index 3ab6cc37ed777ea6eafe2b78c0e070640a668465..4dff002c815835fc1625a9f0e660aa73311de861 100644 (file)
@@ -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 ());
 }
   
 
index d440da8611e7f4e5e6f5e3b721b8b739ca0fac71..ea1d4d447e6c5b253a76d0633876f12aa277b8d7 100644 (file)
@@ -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;
index e22e5a5acd686a1f28c9980e5de4a95151f9f775..d192d70af0794f7c0ef57f0927c952df80566caf 100644 (file)
@@ -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))