]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-system.cc
(struct Simple_spacer): remove
[lilypond.git] / lily / paper-system.cc
1 /*
2   paper-system.cc -- implement Paper_system
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "paper-system.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_system);
17 IMPLEMENT_TYPE_P (Paper_system, "ly:paper-system?");
18 IMPLEMENT_DEFAULT_EQUAL_P (Paper_system);
19
20
21
22 Paper_system::Paper_system (Stencil s, bool is_title)
23 {
24   is_title_ = is_title;
25   number_ = 0;
26   penalty_ = 0;
27   smobify_self ();
28   stencil_ = s;
29 }
30
31 Paper_system::~Paper_system ()
32 {
33 }
34
35 SCM
36 Paper_system::mark_smob (SCM smob)
37 {
38   Paper_system *system = (Paper_system*) ly_cdr (smob);
39   return system-> stencil_.expr ();
40 }
41
42 int
43 Paper_system::print_smob (SCM smob, SCM port, scm_print_state*)
44 {
45   Paper_system *p = (Paper_system*) ly_cdr (smob);
46   scm_puts ("#<", port);
47   scm_puts (classname (p), port);
48   scm_puts (" ", port);
49   scm_puts (to_string (p->number_).to_str0 (), port);
50   scm_puts ("p ", port);
51   scm_puts (to_string (p->penalty_).to_str0 (), port);
52   if (p->is_title ())
53     scm_puts (" t", port);
54   scm_puts (" >", port);
55   return 1;
56 }
57
58 bool
59 Paper_system::is_title () const
60 {
61   return is_title_;
62 }
63
64 Real
65 Paper_system::penalty () const
66 {
67   return penalty_;
68 }
69
70 Offset
71 Paper_system::dim () const
72 {
73   return Offset (stencil_.extent (X_AXIS).length (),
74                  stencil_.extent (Y_AXIS).length ());
75 }
76
77 Stencil
78 Paper_system::to_stencil () const
79 {
80   return stencil_;
81 }
82
83 LY_DEFINE (ly_paper_system_height, "ly:paper-system-extent",
84            2, 0, 0, (SCM system, SCM axis),
85            "Return the extent of @var{system}.")
86 {
87   Paper_system *ps = unsmob_paper_system (system);
88   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
89   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
90   Axis ax = (Axis)ly_scm2int (axis);
91   return scm_make_real (ps->dim ()[ax]);
92 }
93
94 LY_DEFINE (ly_paper_system_title_p, "ly:paper-system-title?",
95            1, 0, 0, (SCM system),
96            "Is  @var{system} a title system?")
97 {
98   Paper_system *ps = unsmob_paper_system (system);
99   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
100   return SCM_BOOL (ps->is_title ());
101 }
102
103 LY_DEFINE (ly_paper_system_number, "ly:paper-system-number",
104            1, 0, 0, (SCM system),
105            "Return the number of @var{system}.")
106 {
107   Paper_system *ps = unsmob_paper_system (system);
108   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
109   return scm_int2num (ps->number_);
110 }
111
112 LY_DEFINE (ly_paper_system_break_score, "ly:paper-system-break-penalty",
113            1, 0, 0, (SCM system),
114            "Return the score for page break after @var{system}.")
115 {
116   Paper_system *ps = unsmob_paper_system (system);
117   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
118   return scm_int2num (int (ps->penalty ()));
119 }
120
121 LY_DEFINE (ly_paper_system_stencil, "ly:paper-system-stencil",
122            1, 0, 0, (SCM system),
123            "Return the height of @var{system}.")
124 {
125   Paper_system *ps = unsmob_paper_system (system);
126   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
127   return ps->to_stencil ().smobbed_copy ();
128 }
129
130
131
132 LY_DEFINE (ly_paper_system_staff_extent, "ly:paper-system-staff-extents",
133            1, 0, 0, (SCM system),
134            "Return the top and bottom staff refpoint.")
135 {
136   Paper_system *ps = unsmob_paper_system (system);
137   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
138   return ly_interval2scm (ps->staff_refpoints_);
139 }
140