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