]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-line.cc
release commit
[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 #include "ly-smobs.icc"
15
16 IMPLEMENT_SMOBS (Paper_line);
17 IMPLEMENT_TYPE_P (Paper_line, "ly:paper-line?");
18 IMPLEMENT_DEFAULT_EQUAL_P (Paper_line);
19
20
21 #define TITLE_PENALTY -1
22
23
24 Paper_line::Paper_line (Offset o, SCM stencils, int penalty, bool is_title)
25 {
26   is_title_ = is_title;
27   number_ = 0;
28   penalty_ = penalty;
29   smobify_self ();
30
31
32   /*
33     TODO: we should extend the definition of stencil to allow
34
35     stencil-expr:  LISTOF stencil-expr*
36
37     so that we don't use as much memory for combining the stencils, and
38     can do this conversion in constant time. 
39   */
40   for (SCM s = stencils; ly_c_pair_p (s); s = ly_cdr (s))
41     stencil_.add_stencil (*unsmob_stencil (ly_car (s)));
42
43   Box x (Interval (0, o[X_AXIS]), Interval (0, o[Y_AXIS]));
44   stencil_ = Stencil (x, stencil_.expr ());
45 }
46
47 Paper_line::~Paper_line ()
48 {
49 }
50
51 SCM
52 Paper_line::mark_smob (SCM smob)
53 {
54   Paper_line *line = (Paper_line*) ly_cdr (smob);
55   return line-> stencil_.expr ();
56 }
57
58 int
59 Paper_line::print_smob (SCM smob, SCM port, scm_print_state*)
60 {
61   Paper_line *p = (Paper_line*) ly_cdr (smob);
62   scm_puts ("#<", port);
63   scm_puts (classname (p), port);
64   scm_puts (" ", port);
65   scm_puts (to_string (p->number_).to_str0 (), port);
66   if (p->is_title ())
67     scm_puts (" t", port);
68   scm_puts (" >", port);
69   return 1;
70 }
71
72 bool
73 Paper_line::is_title () const
74 {
75   return is_title_;
76 }
77
78 int
79 Paper_line::penalty () const
80 {
81   return penalty_;
82 }
83
84 Offset
85 Paper_line::dim () const
86 {
87   return Offset (stencil_.extent (X_AXIS).length (),
88                  stencil_.extent (Y_AXIS).length ());
89 }
90
91 Stencil
92 Paper_line::to_stencil () const
93 {
94   return stencil_;
95 }
96
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}.")
100 {
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]);
106 }
107
108
109 LY_DEFINE (ly_paper_line_number, "ly:paper-line-number",
110            1, 0, 0, (SCM line),
111            "Return the number of @var{line}.")
112 {
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_);
116 }
117
118 LY_DEFINE (ly_paper_line_break_score, "ly:paper-line-break-score",
119            1, 0, 0, (SCM line),
120            "Return the score for page break after @var{line}.")
121 {
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 ()));
125 }
126
127 LY_DEFINE (ly_paper_line_stencil, "ly:paper-line-stencil",
128            1, 0, 0, (SCM line),
129            "Return the height of @var{line}.")
130 {
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 ();
134 }
135