lilypond-1.3.65
[lilypond.git] / lily / bar.cc
blob8b9ecadc6069c728991e3d419cc7005caf880a2b
1 /*
2 bar.cc -- implement Bar
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <math.h>
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"
21 Bar::Bar (SCM s)
22 : Item (s)
27 Real
28 Bar::get_bar_size () const
30 // Never called!
31 return 0;
35 SCM
36 Bar::brew_molecule (SCM smob)
38 Score_element * self = unsmob_element (smob);
39 Bar * fly = dynamic_cast<Bar*> (self);
40 SCM s = self->get_elt_property ("glyph");
41 if (gh_string_p (s))
43 String str =ly_scm2string (s);
44 return fly->compound_barline (str, fly->get_bar_size ()).create_scheme ();
46 return SCM_EOL;
49 MAKE_SCHEME_SCORE_ELEMENT_CALLBACK(Bar,brew_molecule);
51 Molecule
52 Bar::compound_barline (String str, Real h) const
54 Real kern = gh_scm2double (get_elt_property ("kern"));
55 Real thinkern = gh_scm2double (get_elt_property ("thin-kern"));
56 Real hair = gh_scm2double (get_elt_property ("hair-thickness"));
57 Real fatline = gh_scm2double (get_elt_property ("thick-thickness"));
59 Real staffline = paper_l ()->get_var ("stafflinethickness");
61 kern *= staffline;
62 thinkern *= staffline;
63 hair *= staffline;
64 fatline *= staffline;
66 Molecule thin = simple_barline (hair, h);
67 Molecule thick = simple_barline (fatline, h);
68 Molecule colon = lookup_l ()->afm_find ("dots-repeatcolon");
70 Molecule m;
72 if (str == "")
74 return lookup_l ()->blank (Box (Interval(0, 0), Interval (-h/2, h/2)));
76 if (str == "scorepostbreak")
78 return simple_barline (paper_l ()->get_var ("barthick_score"), h);
80 else if (str == "|")
82 return thin;
84 else if (str == "|.")
86 m.add_at_edge (X_AXIS, LEFT, thick, 0);
87 m.add_at_edge (X_AXIS, LEFT, thin, kern);
89 else if (str == ".|")
91 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
92 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
94 else if (str == ":|")
96 m.add_at_edge (X_AXIS, LEFT, thick, 0);
97 m.add_at_edge (X_AXIS, LEFT, thin, kern);
98 m.add_at_edge (X_AXIS, LEFT, colon, kern);
100 else if (str == "|:")
102 m.add_at_edge (X_AXIS, RIGHT, thick, 0);
103 m.add_at_edge (X_AXIS, RIGHT, thin, kern);
104 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
106 else if (str == ":|:")
108 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
109 m.add_at_edge (X_AXIS, LEFT, colon, kern);
110 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
111 m.add_at_edge (X_AXIS, RIGHT, colon, kern);
113 else if (str == ".|.")
115 m.add_at_edge (X_AXIS, LEFT, thick, thinkern);
116 m.add_at_edge (X_AXIS, RIGHT, thick, kern);
118 else if (str == "||")
120 m.add_at_edge (X_AXIS, RIGHT, thin, 0);
121 m.add_at_edge (X_AXIS, RIGHT, thin, thinkern);
124 return m;
128 Molecule
129 Bar::simple_barline (Real w, Real h) const
131 return lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
135 GLUE_SCORE_ELEMENT(Bar,before_line_breaking );
137 Bar::member_before_line_breaking ()
139 SCM g = get_elt_property ("glyph");
140 SCM orig = g;
141 Direction bsd = break_status_dir ();
142 if (gh_string_p (g))
144 if (bsd)
146 SCM breakdir = gh_int2scm (bsd);
147 g = scm_eval (gh_list (ly_symbol2scm ("break-barline"),
149 breakdir,
150 SCM_UNDEFINED));
153 else
155 g = SCM_UNDEFINED;
158 if (!gh_string_p (g))
160 set_elt_property ("molecule-callback", SCM_BOOL_T);
161 set_extent_callback (0, X_AXIS);
162 // leave y_extent for spanbar?
164 else if (! gh_equal_p (g, orig))
165 set_elt_property ("glyph", g);
168 return SCM_UNDEFINED;