]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-line.cc
* lily/book.cc (to_stencil): New method.
[lilypond.git] / lily / paper-line.cc
1 /*
2   paper-line.cc -- implement Paper_line
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "paper-line.hh"
10 #include "stencil.hh"
11 #include "string.hh"
12 #include "virtual-methods.hh"
13
14 #define TITLE_PENALTY -1
15
16 Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
17 {
18   dim_ = o;
19   stencils_ = stencils;
20   is_title_ = is_title;
21   penalty_ = penalty;
22   smobify_self ();
23 }
24
25 Paper_line::~Paper_line ()
26 {
27 }
28
29 #include "ly-smobs.icc"
30 IMPLEMENT_SMOBS (Paper_line);
31 IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
32 IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
33
34 SCM
35 Paper_line::mark_smob (SCM smob)
36 {
37   Paper_line *line = (Paper_line*) ly_cdr (smob);
38   return line->stencils_;
39 }
40
41 int
42 Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
43 {
44   Paper_line *p = (Paper_line*) ly_cdr (smob);
45   scm_puts ("#<", port);
46   scm_puts (classname (p), port);
47   scm_puts (to_string (p->number_).to_str0 (), port);
48   if (p->is_title ())
49     scm_puts (" t", port);
50   scm_puts (" >", port);
51   return 1;
52 }
53
54 Offset
55 Paper_line::dim () const
56 {
57   return dim_;
58 }
59
60 bool
61 Paper_line::is_title () const
62 {
63   return is_title_;
64 }
65
66 int
67 Paper_line::penalty () const
68 {
69   return penalty_;
70 }
71
72 SCM
73 Paper_line::stencils () const
74 {
75   return stencils_;
76 }
77
78 SCM
79 Paper_line::to_stencil () const
80 {
81   Stencil stencil;
82   for (SCM s = stencils_; ly_c_pair_p (s); s = ly_cdr (s))
83     stencil.add_stencil (*unsmob_stencil (ly_car (s)));
84   return stencil.smobbed_copy ();
85 }
86
87 LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
88            1, 0, 0, (SCM line),
89            "Return the height of @var{line}.")
90 {
91   Paper_line *pl = unsmob_paper_line (line);
92   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
93   return scm_make_real (pl->dim ()[Y_AXIS]);
94 }
95
96 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
97            1, 0, 0, (SCM line),
98            "Return the number of @var{line}.")
99 {
100   Paper_line *pl = unsmob_paper_line (line);
101   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
102   return scm_int2num (pl->number_);
103 }
104
105 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
106            1, 0, 0, (SCM line),
107            "Return the score for page break after @var{line}.")
108 {
109   Paper_line *pl = unsmob_paper_line (line);
110   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
111   return scm_int2num (int (pl->penalty ()));
112 }