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)
25 TODO: we should extend the definition of stencil to allow
27 stencil-expr: LISTOF stencil-expr*
29 so that we don't use as much memory for combining the stencils, and
30 can do this conversion in constant time.
32 for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
33 stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
35 Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
36 stencil_ = Stencil (x, stencil_.expr ());
39 Paper_line::~Paper_line ()
43 #include "ly-smobs.icc"
44 IMPLEMENT_SMOBS (Paper_line);
45 IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
46 IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
49 Paper_line::mark_smob (SCM smob)
51 Paper_line *line = (Paper_line*) ly_cdr (smob);
52 return line-> stencil_.expr ();
56 Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
58 Paper_line *p = (Paper_line*) ly_cdr (smob);
59 scm_puts ("#<", port);
60 scm_puts (classname (p), port);
62 scm_puts (to_string (p->number_).to_str0 (), port);
64 scm_puts (" t", port);
65 scm_puts (" >", port);
70 Paper_line::is_title () const
76 Paper_line::penalty () const
82 Paper_line::dim () const
84 return Offset (stencil_.extent (X_AXIS).length (),
85 stencil_.extent (Y_AXIS).length ());
89 Paper_line::to_stencil () const
94 LY_DEFINE (ly_paper_line_height, "ly:paper-line-extent",
95 2, 0, 0, (SCM line, SCM axis),
96 "Return the extent of @var{line}.")
98 Paper_line *pl = unsmob_paper_line (line);
99 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
100 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
101 Axis ax = (Axis)ly_scm2int (axis);
102 return scm_make_real (pl->dim ()[ax]);
106 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
108 "Return the number of @var{line}.")
110 Paper_line *pl = unsmob_paper_line (line);
111 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
112 return scm_int2num (pl->number_);
115 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
117 "Return the score for page break after @var{line}.")
119 Paper_line *pl = unsmob_paper_line (line);
120 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
121 return scm_int2num (int (pl->penalty ()));
124 LY_DEFINE (ly_paper_line_stencil, "ly:paper-line-stencil",
126 "Return the height of @var{line}.")
128 Paper_line *pl = unsmob_paper_line (line);
129 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
130 return pl->to_stencil ().smobbed_copy ();