]> git.donarmstrong.com Git - lilypond.git/blob - lily/bar.cc
release: 1.3.56
[lilypond.git] / lily / bar.cc
1 /*
2   bar.cc -- implement 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 <math.h>
9
10 #include "main.hh"
11 #include "dimensions.hh"
12 #include "dimension-cache.hh"
13 #include "bar.hh"
14 #include "string.hh"
15 #include "molecule.hh"
16 #include "paper-def.hh"
17 #include "lookup.hh"
18 #include "debug.hh"
19 #include "all-font-metrics.hh"
20
21 Bar::Bar (SCM s)
22   : Item (s)
23 {
24 }
25
26
27 Real
28 Bar::get_bar_size () const
29 {
30   // Never called!
31   return 0;
32 }
33
34
35 Molecule 
36 Bar::do_brew_molecule () const
37 {
38   SCM s = get_elt_property ("glyph");
39   if (gh_string_p (s))
40     {
41       String str  =ly_scm2string (s);
42       return compound_barline (str, get_bar_size ());
43     }
44   return Molecule ();
45 }
46
47 MAKE_SCHEME_SCORE_ELEMENT_CALLBACKS(Bar);
48
49 Molecule
50 Bar::compound_barline (String str, Real h) const
51 {
52   Real kern = paper_l()->get_var ("bar_kern");
53   Real thinkern = paper_l()->get_var ("bar_thinkern");
54
55   Molecule thin = simple_barline (paper_l()->get_var ("barthick_thin"), h);
56   Molecule thick = simple_barline (paper_l()->get_var ("barthick_thick"), h);
57   Molecule colon = lookup_l ()->afm_find ("dots-repeatcolon");  
58
59   Molecule m;
60   
61   if (str == "")
62     {
63       return lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
64     }
65   if (str == "scorepostbreak")
66     {
67       return simple_barline (paper_l ()->get_var ("barthick_score"), h);
68     }
69   else if (str == "|")
70     {
71       return thin;
72     }
73   else if (str == "|.")
74     {
75       m.add_at_edge (X_AXIS, LEFT, thick, 0);      
76       m.add_at_edge (X_AXIS, LEFT, thin, kern);
77     }
78   else if (str == ".|")
79     {
80       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
81       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
82     }
83   else if (str == ":|")
84     {
85       m.add_at_edge (X_AXIS, LEFT, thick, 0);
86       m.add_at_edge (X_AXIS, LEFT, thin, kern);
87       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
88     }
89   else if (str == "|:")
90     {
91       m.add_at_edge (X_AXIS, RIGHT, thick, 0);
92       m.add_at_edge (X_AXIS, RIGHT, thin, kern);
93       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
94     }
95   else if (str == ":|:")
96     {
97       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
98       m.add_at_edge (X_AXIS, LEFT, colon, kern);      
99       m.add_at_edge (X_AXIS, RIGHT, thick, kern);
100       m.add_at_edge (X_AXIS, RIGHT, colon, kern);      
101     }
102   else if (str == ".|.")
103     {
104       m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
105       m.add_at_edge (X_AXIS, RIGHT, thick, kern);      
106     }
107   else if (str == "||")
108     {
109       m.add_at_edge (X_AXIS, RIGHT, thin, 0);
110       m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);      
111     }
112
113   return m;
114 }
115
116
117 Molecule
118 Bar::simple_barline (Real w, Real h) const
119 {
120   return lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
121 }
122
123
124 void
125 Bar::before_line_breaking ()
126 {
127   SCM g = get_elt_property ("glyph");
128   SCM orig = g;
129   Direction bsd = break_status_dir ();
130   if (gh_string_p (g))
131     {
132       if (bsd)
133         {
134           SCM breakdir = gh_int2scm (bsd);
135           g = scm_eval (gh_list (ly_symbol2scm ("break-barline"),
136                                  g,
137                                  breakdir,
138                                  SCM_UNDEFINED));
139         }
140     }
141   else
142     {
143       g = SCM_UNDEFINED;
144     }
145   
146   if (!gh_string_p (g))
147     {
148       set_elt_property ("molecule-callback", SCM_BOOL_T);
149       set_extent_callback (0, X_AXIS);
150       // leave y_extent for spanbar? 
151     }
152   else if (! gh_equal_p  (g, orig))
153     set_elt_property ("glyph", g);
154 }
155   
156