]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-system.cc
* lily/book.cc (process): bugfix: flip ?: cases.
[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--2005 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "paper-system.hh"
10 #include "item.hh"
11
12 #include "ly-smobs.icc"
13
14 IMPLEMENT_SMOBS (Paper_system);
15 IMPLEMENT_TYPE_P (Paper_system, "ly:paper-system?");
16 IMPLEMENT_DEFAULT_EQUAL_P (Paper_system);
17
18 Paper_system::Paper_system (Stencil s, bool is_title)
19 {
20   is_title_ = is_title;
21   number_ = 0;
22   break_before_penalty_ = 0;
23   smobify_self ();
24   stencil_ = s;
25   staff_refpoints_ = Interval (0, 0);
26 }
27
28 Paper_system::~Paper_system ()
29 {
30 }
31
32 SCM
33 Paper_system::mark_smob (SCM smob)
34 {
35   Paper_system *system = (Paper_system *) SCM_CELL_WORD_1 (smob);
36   scm_gc_mark (system->details_);
37   return system->stencil_.expr ();
38 }
39
40 int
41 Paper_system::print_smob (SCM smob, SCM port, scm_print_state*)
42 {
43   Paper_system *p = (Paper_system *) SCM_CELL_WORD_1 (smob);
44   scm_puts ("#<", port);
45   scm_puts (classname (p), port);
46   scm_puts ("n ", port);
47   scm_puts (to_string (p->number_).to_str0 (), port);
48   scm_puts (", p ", port);
49   scm_puts (to_string (p->break_before_penalty_).to_str0 (), port);
50   if (p->is_title ())
51     scm_puts (" t", port);
52   scm_puts (" >", port);
53   return 1;
54 }
55
56 bool
57 Paper_system::is_title () const
58 {
59   return is_title_;
60 }
61
62 Real
63 Paper_system::break_before_penalty () const
64 {
65   return break_before_penalty_;
66 }
67
68 Stencil
69 Paper_system::to_stencil () const
70 {
71   return stencil_;
72 }
73
74 void
75 Paper_system::read_left_bound (Item *left)
76 {
77   break_before_penalty_
78     = robust_scm2double (left->get_property ("page-penalty"), 0.0);
79
80   details_
81     = left->get_property ("line-break-system-details");
82
83   SCM yext
84     = scm_assq (ly_symbol2scm ("Y-extent"), details_);
85   
86   SCM staff_ext
87     = scm_assq (ly_symbol2scm ("refpoint-Y-extent"), details_);
88
89   if (scm_is_pair (yext)
90       && is_number_pair (scm_cdr (yext)))
91     {
92       Box b = stencil_.extent_box();
93       b[Y_AXIS] = ly_scm2interval (scm_cdr (yext));
94       
95       stencil_ = Stencil (b, stencil_.expr ());
96     }
97
98   if (scm_is_pair (staff_ext)
99       && is_number_pair (scm_cdr (staff_ext)))
100     {
101       staff_refpoints_ = ly_scm2interval (scm_cdr (staff_ext));
102     }
103 }
104
105 SCM
106 Paper_system::internal_get_property (SCM sym) const
107 {
108   SCM handle = scm_assq (sym, details_);
109   if (scm_is_pair (handle))
110     return scm_cdr (handle);
111   else
112     return SCM_EOL;
113 }
114
115 /*
116   todo: move to Paper_system property.
117  */
118 Interval
119 Paper_system::staff_refpoints () const
120 {
121   return staff_refpoints_;
122 }