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