]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-system.cc
release commit
[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   staff_refpoints_ = Interval(0,0);
30 }
31
32 Paper_system::~Paper_system ()
33 {
34 }
35
36 SCM
37 Paper_system::mark_smob (SCM smob)
38 {
39   Paper_system *system = (Paper_system*) ly_cdr (smob);
40   return system-> stencil_.expr ();
41 }
42
43 int
44 Paper_system::print_smob (SCM smob, SCM port, scm_print_state*)
45 {
46   Paper_system *p = (Paper_system*) ly_cdr (smob);
47   scm_puts ("#<", port);
48   scm_puts (classname (p), port);
49   scm_puts (" ", port);
50   scm_puts (to_string (p->number_).to_str0 (), port);
51   scm_puts ("p ", port);
52   scm_puts (to_string (p->penalty_).to_str0 (), port);
53   if (p->is_title ())
54     scm_puts (" t", port);
55   scm_puts (" >", port);
56   return 1;
57 }
58
59 bool
60 Paper_system::is_title () const
61 {
62   return is_title_;
63 }
64
65 Real
66 Paper_system::penalty () const
67 {
68   return penalty_;
69 }
70
71 Stencil
72 Paper_system::to_stencil () const
73 {
74   return stencil_;
75 }
76
77 LY_DEFINE (ly_paper_system_height, "ly:paper-system-extent",
78            2, 0, 0, (SCM system, SCM axis),
79            "Return the extent of @var{system}.")
80 {
81   Paper_system *ps = unsmob_paper_system (system);
82   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
83   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
84   Axis ax = (Axis)scm_to_int (axis);
85   return ly_interval2scm (ps->to_stencil().extent (ax));
86 }
87
88
89
90 LY_DEFINE (ly_paper_system_title_p, "ly:paper-system-title?",
91            1, 0, 0, (SCM system),
92            "Is  @var{system} a title system?")
93 {
94   Paper_system *ps = unsmob_paper_system (system);
95   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
96   return SCM_BOOL (ps->is_title ());
97 }
98
99 LY_DEFINE (ly_paper_system_number, "ly:paper-system-number",
100            1, 0, 0, (SCM system),
101            "Return the number of @var{system}.")
102 {
103   Paper_system *ps = unsmob_paper_system (system);
104   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
105   return scm_int2num (ps->number_);
106 }
107
108 LY_DEFINE (ly_paper_system_break_score, "ly:paper-system-break-penalty",
109            1, 0, 0, (SCM system),
110            "Return the score for page break after @var{system}.")
111 {
112   Paper_system *ps = unsmob_paper_system (system);
113   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
114   return scm_int2num (int (ps->penalty ()));
115 }
116
117 LY_DEFINE (ly_paper_system_stencil, "ly:paper-system-stencil",
118            1, 0, 0, (SCM system),
119            "Return the height of @var{system}.")
120 {
121   Paper_system *ps = unsmob_paper_system (system);
122   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
123   return ps->to_stencil ().smobbed_copy ();
124 }
125
126
127
128 LY_DEFINE (ly_paper_system_staff_extent, "ly:paper-system-staff-extents",
129            1, 0, 0, (SCM system),
130            "Return the top and bottom staff refpoint.")
131 {
132   Paper_system *ps = unsmob_paper_system (system);
133   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
134   return ly_interval2scm (ps->staff_refpoints_);
135 }
136