]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.3.47
[lilypond.git] / lily / span-bar.cc
1 /*
2   span-bar.cc -- implement Span_bar
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include "dimension-cache.hh"
9 #include "span-bar.hh"
10 #include "lookup.hh"
11 #include "dimensions.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "warn.hh"
15 #include "axis-group-interface.hh"
16 #include "group-interface.hh"
17
18 void
19 Span_bar::add_bar (Score_element*b)
20 {
21   Group_interface gi (this);
22   gi.add_element (b);
23
24   add_dependency (b);
25 }
26
27
28 Interval
29 Span_bar::width_callback (Dimension_cache const * c)
30 {
31   Span_bar*  s= dynamic_cast<Span_bar*> (c->element_l ());  
32   String gl = ly_scm2string (s->get_elt_property ("glyph"));
33
34   /*
35     urg.
36    */
37   Molecule m = s->compound_barline (gl, 40 PT);
38   
39   return m.extent (X_AXIS);
40 }
41
42 void
43 Span_bar::before_line_breaking ()
44 {
45   Bar::before_line_breaking ();
46   
47   evaluate_empty ();
48 }
49
50 void
51 Span_bar::after_line_breaking ()
52 {
53   Bar::after_line_breaking ();
54   Interval i (get_spanned_interval ());
55   translate_axis (i.center (), Y_AXIS);
56 }
57
58 void
59 Span_bar::evaluate_empty ()
60
61   if (!gh_pair_p (get_elt_property ("elements")))
62     {
63       set_elt_property ("transparent", SCM_BOOL_T);
64       set_extent_callback (0, X_AXIS);
65       set_extent_callback (0, Y_AXIS);   
66     }
67   
68   SCM gl = get_elt_property ("glyph");
69   if (!gh_string_p (gl))
70     {
71       set_elt_property ("transparent", SCM_BOOL_T);
72       set_extent_callback (0, X_AXIS);
73       set_extent_callback (0, Y_AXIS);   
74     }
75   else {
76     String type_str = ly_scm2string (gl);
77     if (type_str == "|:") 
78       {
79         type_str= ".|";
80       }
81     else if (type_str== ":|")
82       {
83         type_str= "|.";
84       }
85     else if (type_str== ":|:")
86       {
87         type_str= ".|.";
88       }
89
90     set_elt_property ("glyph", ly_str02scm (type_str.ch_C()));
91   }
92 }
93
94 Interval
95 Span_bar::get_spanned_interval () const
96 {
97   return Axis_group_interface::group_extent_callback (dim_cache_[Y_AXIS]);  
98 }
99
100
101 Real
102 Span_bar::get_bar_size () const
103 {
104   Interval iv (get_spanned_interval ());
105   if (iv.empty_b ())
106     {
107       programming_error("Huh? My children deflated (FIXME)");
108       iv = Interval (0,0);
109     }
110   return iv.length ();
111 }
112
113 Span_bar::Span_bar ()
114 {
115   group (this).set_interface ();
116   dim_cache_[X_AXIS]->set_extent_callback (width_callback);
117   
118   // dim_cache_[Y_AXIS]->set_extent_callback (Axis_group_interface::group_extent_callback);
119
120   dim_cache_[Y_AXIS]->set_extent_callback (0);
121 }
122