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 #include "ly-smobs.icc"
16 IMPLEMENT_SMOBS (Paper_line);
17 IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
18 IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
21 #define TITLE_PENALTY -1
24 Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
33 TODO: we should extend the definition of stencil to allow
35 stencil-expr: LISTOF stencil-expr*
37 so that we don't use as much memory for combining the stencils, and
38 can do this conversion in constant time.
40 for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
41 stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
43 Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
44 stencil_ = Stencil (x, stencil_.expr ());
47 Paper_line::~Paper_line ()
52 Paper_line::mark_smob (SCM smob)
54 Paper_line *line = (Paper_line*) ly_cdr (smob);
55 return line-> stencil_.expr ();
59 Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
61 Paper_line *p = (Paper_line*) ly_cdr (smob);
62 scm_puts ("#<", port);
63 scm_puts (classname (p), port);
65 scm_puts (to_string (p->number_).to_str0 (), port);
67 scm_puts (" t", port);
68 scm_puts (" >", port);
73 Paper_line::is_title () const
79 Paper_line::penalty () const
85 Paper_line::dim () const
87 return Offset (stencil_.extent (X_AXIS).length (),
88 stencil_.extent (Y_AXIS).length ());
92 Paper_line::to_stencil () const
97 LY_DEFINE (ly_paper_line_height, "ly:paper-line-extent",
98 2, 0, 0, (SCM line, SCM axis),
99 "Return the extent of @var{line}.")
101 Paper_line *pl = unsmob_paper_line (line);
102 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
103 SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
104 Axis ax = (Axis)ly_scm2int (axis);
105 return scm_make_real (pl->dim ()[ax]);
109 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
111 "Return the number of @var{line}.")
113 Paper_line *pl = unsmob_paper_line (line);
114 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
115 return scm_int2num (pl->number_);
118 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
120 "Return the score for page break after @var{line}.")
122 Paper_line *pl = unsmob_paper_line (line);
123 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
124 return scm_int2num (int (pl->penalty ()));
127 LY_DEFINE (ly_paper_line_stencil, "ly:paper-line-stencil",
129 "Return the height of @var{line}.")
131 Paper_line *pl = unsmob_paper_line (line);
132 SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
133 return pl->to_stencil ().smobbed_copy ();