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