]> git.donarmstrong.com Git - lilypond.git/blobdiff - lily/paper-line.cc
(conv): \apply -> \applymusic
[lilypond.git] / lily / paper-line.cc
index e4da3cb548337bba2cf5120c3466e0f1c67b4d18..ee258154475cf8ee27b58463187a5f8ded1e309b 100644 (file)
@@ -7,13 +7,48 @@
 */
 
 #include "paper-line.hh"
-#include "ly-smobs.icc"
+#include "stencil.hh"
+#include "string.hh"
+#include "virtual-methods.hh"
+
+#define TITLE_PENALTY -1
 
-Paper_line::Paper_line (Offset o, SCM stencils, bool is_title)
+Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
 {
   dim_ = o;
   stencils_ = stencils;
   is_title_ = is_title;
+  penalty_ = penalty;
+  smobify_self ();
+}
+
+Paper_line::~Paper_line ()
+{
+}
+
+#include "ly-smobs.icc"
+IMPLEMENT_SMOBS (Paper_line);
+IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
+IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
+
+SCM
+Paper_line::mark_smob (SCM smob)
+{
+  Paper_line *line = (Paper_line*) ly_cdr (smob);
+  return line->stencils_;
+}
+
+int
+Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
+{
+  Paper_line *p = (Paper_line*) ly_cdr (smob);
+  scm_puts ("#<", port);
+  scm_puts (classname (p), port);
+  scm_puts (to_string (p->number_).to_str0 (), port);
+  if (p->is_title ())
+    scm_puts (" t", port);
+  scm_puts (" >", port);
+  return 1;
 }
 
 Offset
@@ -28,6 +63,12 @@ Paper_line::is_title () const
   return is_title_;
 }
 
+int
+Paper_line::penalty () const
+{
+  return penalty_;
+}
+
 SCM
 Paper_line::stencils () const
 {
@@ -35,27 +76,50 @@ Paper_line::stencils () const
 }
 
 SCM
-Paper_line::mark_smob (SCM s)
+Paper_line::to_stencil () const
 {
-  Paper_line *line = (Paper_line*) ly_cdr (s);
-  return line->stencils_;
+  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 ();
 }
 
-int
-Paper_line::print_smob (SCM, SCM port, scm_print_state*)
+LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
+          1, 0, 0, (SCM line),
+          "Return the height of @var{line}.")
 {
-  scm_puts ("#<Paper_line ", port);
-  scm_puts (" >", port);
-  return 1;
+  Paper_line *pl = unsmob_paper_line (line);
+  SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
+  return scm_make_real (pl->dim ()[Y_AXIS]);
 }
 
-SCM
-Paper_line::smobbed_copy () const
+LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
+          1, 0, 0, (SCM line),
+          "Return the number of @var{line}.")
 {
-  Paper_line *line = new Paper_line (*this);
-  return line->smobbed_self ();
+  Paper_line *pl = unsmob_paper_line (line);
+  SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
+  return scm_int2num (pl->number_);
+}
+
+LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
+          1, 0, 0, (SCM line),
+          "Return the score for page break after @var{line}.")
+{
+  Paper_line *pl = unsmob_paper_line (line);
+  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 ();
 }
 
-IMPLEMENT_SIMPLE_SMOBS (Paper_line);
-IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
-IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);