]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-line.cc
56c97c7ea1168f3368e7cf6df7e928599675acda
[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   is_title_ = is_title;
19   penalty_ = penalty;
20   smobify_self ();
21
22
23   /*
24     TODO: we should extend the definition of stencil to allow
25
26     stencil-expr:  LISTOF stencil-expr*
27
28     so that we don't use as much memory for combining the stencils, and
29     can do this conversion in constant time. 
30   */
31   for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
32     stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
33
34   Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
35   stencil_ = Stencil (x, stencil_.expr ());
36 }
37
38 Paper_line::~Paper_line ()
39 {
40 }
41
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);
46
47 SCM
48 Paper_line::mark_smob (SCM smob)
49 {
50   Paper_line *line = (Paper_line*) ly_cdr (smob);
51   return line-> stencil_.expr ();
52 }
53
54 int
55 Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
56 {
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);
61   if (p->is_title ())
62     scm_puts (" t", port);
63   scm_puts (" >", port);
64   return 1;
65 }
66
67 bool
68 Paper_line::is_title () const
69 {
70   return is_title_;
71 }
72
73 int
74 Paper_line::penalty () const
75 {
76   return penalty_;
77 }
78
79 Offset
80 Paper_line::dim () const
81 {
82   return Offset (stencil_.extent (X_AXIS).length (),
83                  stencil_.extent (Y_AXIS).length ());
84 }
85
86 SCM
87 Paper_line::to_stencil () const
88 {
89   return stencil_.smobbed_copy ();
90 }
91
92 LY_DEFINE (ly_paper_line_height, "ly:paper-line-height",
93            1, 0, 0, (SCM line),
94            "Return the height of @var{line}.")
95 {
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]);
99 }
100
101 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
102            1, 0, 0, (SCM line),
103            "Return the number of @var{line}.")
104 {
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_);
108 }
109
110 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
111            1, 0, 0, (SCM line),
112            "Return the score for page break after @var{line}.")
113 {
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 ()));
117 }
118
119 LY_DEFINE (ly_paper_line_stencil, "ly:paper-line-stencil",
120            1, 0, 0, (SCM line),
121            "Return the height of @var{line}.")
122 {
123   Paper_line *pl = unsmob_paper_line (line);
124   SCM_ASSERT_TYPE (pl, line, SCM_ARG1, __FUNCTION__, "paper-line");
125   return pl->to_stencil ();
126 }
127