]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-system.cc
* lily/modified-font-metric.cc (text_dimension): try
[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
11 #include "virtual-methods.hh"
12
13 #include "ly-smobs.icc"
14
15 IMPLEMENT_SMOBS (Paper_system);
16 IMPLEMENT_TYPE_P (Paper_system, "ly:paper-system?");
17 IMPLEMENT_DEFAULT_EQUAL_P (Paper_system);
18
19
20
21 Paper_system::Paper_system (Stencil s, bool is_title)
22 {
23   is_title_ = is_title;
24   number_ = 0;
25   break_before_penalty_ = 0;
26   smobify_self ();
27   stencil_ = s;
28   staff_refpoints_ = Interval(0,0);
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*) SCM_CELL_WORD_1 (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*) SCM_CELL_WORD_1 (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->break_before_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::break_before_penalty () const
66 {
67   return break_before_penalty_;
68 }
69
70 Stencil
71 Paper_system::to_stencil () const
72 {
73   return stencil_;
74 }
75
76 LY_DEFINE (ly_paper_system_height, "ly:paper-system-extent",
77            2, 0, 0, (SCM system, SCM axis),
78            "Return the extent of @var{system}.")
79 {
80   Paper_system *ps = unsmob_paper_system (system);
81   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
82   SCM_ASSERT_TYPE (is_axis (axis), axis, SCM_ARG2, __FUNCTION__, "axis");
83   Axis ax = (Axis)scm_to_int (axis);
84   return ly_interval2scm (ps->to_stencil().extent (ax));
85 }
86
87
88
89 LY_DEFINE (ly_paper_system_title_p, "ly:paper-system-title?",
90            1, 0, 0, (SCM system),
91            "Is  @var{system} a title system?")
92 {
93   Paper_system *ps = unsmob_paper_system (system);
94   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
95   return SCM_BOOL (ps->is_title ());
96 }
97
98 LY_DEFINE (ly_paper_system_number, "ly:paper-system-number",
99            1, 0, 0, (SCM system),
100            "Return the number of @var{system}.")
101 {
102   Paper_system *ps = unsmob_paper_system (system);
103   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
104   return scm_int2num (ps->number_);
105 }
106
107 LY_DEFINE (ly_paper_system_break_before_penalty, "ly:paper-system-break-before-penalty",
108            1, 0, 0, (SCM system),
109            "Return the score for page break after @var{system}.")
110 {
111   Paper_system *ps = unsmob_paper_system (system);
112   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
113   return scm_int2num (int (ps->break_before_penalty ()));
114 }
115
116 LY_DEFINE (ly_paper_system_stencil, "ly:paper-system-stencil",
117            1, 0, 0, (SCM system),
118            "Return the height of @var{system}.")
119 {
120   Paper_system *ps = unsmob_paper_system (system);
121   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
122   return ps->to_stencil ().smobbed_copy ();
123 }
124
125
126
127 LY_DEFINE (ly_paper_system_staff_extent, "ly:paper-system-staff-extents",
128            1, 0, 0, (SCM system),
129            "Return the top and bottom staff refpoint.")
130 {
131   Paper_system *ps = unsmob_paper_system (system);
132   SCM_ASSERT_TYPE (ps, system, SCM_ARG1, __FUNCTION__, "paper-system");
133   return ly_interval2scm (ps->staff_refpoints_);
134 }
135