]> git.donarmstrong.com Git - lilypond.git/blob - lily/span-bar.cc
release: 1.3.61
[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   Pointer_group_interface gi (this);
22   gi.add_element (b);
23
24   add_dependency (b);
25 }
26
27
28 Interval
29 Span_bar::width_callback (Score_element const *se, Axis )
30 {
31   Span_bar*  s= dynamic_cast<Span_bar*> ((Score_element*)se);
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   Interval i (get_spanned_interval ());
54
55   /*
56     Bar::brew_molecule delivers a barline of y-extent (-h/2,h/2), so
57     we have to translate ourselves to be in the center of the 
58     interval that we span.  */
59   translate_axis (i.center (), Y_AXIS);
60 }
61
62 void
63 Span_bar::evaluate_empty ()
64
65   if (!gh_pair_p (get_elt_pointer ("elements")))
66     {
67       suicide ();
68     }
69   
70   SCM gl = get_elt_property ("glyph");
71   if (!gh_string_p (gl))
72     {
73       suicide ();
74       return ; 
75     }
76   else {
77     String type_str = ly_scm2string (gl);
78     String orig = type_str;
79     if (type_str == "|:") 
80       {
81         type_str= ".|";
82       }
83     else if (type_str== ":|")
84       {
85         type_str= "|.";
86       }
87     else if (type_str== ":|:")
88       {
89         type_str= ".|.";
90       }
91     if (orig != type_str)
92       set_elt_property ("glyph", ly_str02scm (type_str.ch_C()));
93   }
94 }
95
96 Interval
97 Span_bar::get_spanned_interval () const
98 {
99   return Axis_group_interface::group_extent_callback (this, Y_AXIS);  
100 }
101
102
103 Real
104 Span_bar::get_bar_size () const
105 {
106   Interval iv (get_spanned_interval ());
107   if (iv.empty_b ())
108     {
109       programming_error("Huh? My children deflated (FIXME)");
110       iv = Interval (0,0);
111     }
112   return iv.length ();
113 }
114
115 Span_bar::Span_bar (SCM s)
116   : Bar (s)
117 {
118   Pointer_group_interface(this).set_interface ();
119   set_extent_callback (width_callback, X_AXIS);
120   
121   // dim_cache_[Y_AXIS]->set_extent_callback (Axis_group_interface::group_extent_callback);
122
123   set_extent_callback (0, Y_AXIS);
124 }
125