2 paper-line.cc -- implement Paper_line
4 source file of the GNU LilyPond music typesetter
6 (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
9 #include "paper-line.hh"
12 #include "virtual-methods.hh"
14 #define TITLE_PENALTY -1
16 Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
24 TODO: we should extend the definition of stencil to allow
26 stencil-expr: LISTOF stencil-expr*
28 so that we don't use as much memory for combining the stencils, and
29 can do this conversion in constant time.
31 for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
32 stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
34 Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
35 stencil_ = Stencil (x, stencil_.expr ());
38 Paper_line::~Paper_line ()
42 #include "ly-smobs.icc"
43 IMPLEMENT_SMOBS (Paper_line);
44 IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
45 IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
48 Paper_line::mark_smob (SCM smob)
50 Paper_line *line = (Paper_line*) ly_cdr (smob);
51 return line-> stencil_.expr ();
55 Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
57 Paper_line *p = (Paper_line*) ly_cdr (smob);
58 scm_puts ("#<", port);
59 scm_puts (classname (p), port);
60 scm_puts (to_string (p->number_).to_str0 (), port);
62 scm_puts (" t", port);
63 scm_puts (" >", port);
68 Paper_line::is_title () const
74 Paper_line::penalty () const
80 Paper_line::dim () const
82 return Offset (stencil_.extent (X_AXIS).length (),
83 stencil_.extent (Y_AXIS).length ());
87 Paper_line::to_stencil () const
89 return stencil_.smobbed_copy ();
92 LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
94 "Return the height of @var{line}.")
96 Paper_line *pl = unsmob_paper_line (line);
97 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
98 return scm_make_real (pl->dim ()[Y_AXIS]);
101 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
103 "Return the number of @var{line}.")
105 Paper_line *pl = unsmob_paper_line (line);
106 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
107 return scm_int2num (pl->number_);
110 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
112 "Return the score for page break after @var{line}.")
114 Paper_line *pl = unsmob_paper_line (line);
115 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
116 return scm_int2num (int (pl->penalty ()));
119 LY_DEFINE (ly_paper_line_stencil, "ly:paper-line-stencil",
121 "Return the height of @var{line}.")
123 Paper_line *pl = unsmob_paper_line (line);
124 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
125 return pl->to_stencil ();