]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
be44c6c6e210d1bced0afa42507149f65365f59a
[lilypond.git] / lily / system-start-delimiter.cc
1 /*   
2   system-start-delimiter.cc --  implement System_start_delimiter
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include <math.h>
10
11 #include "system-start-delimiter.hh"
12 #include "paper-def.hh"
13 #include "molecule.hh"
14 #include "axis-group-interface.hh"
15 #include "lookup.hh"
16 #include "all-font-metrics.hh"
17
18 Molecule
19 System_start_delimiter::staff_bracket (Real height) const 
20 {
21   Paper_def* p= paper_l ();
22   Real arc_height = p->get_var("bracket_arch_height");
23   SCM at = gh_list (ly_symbol2scm ("bracket"),
24                     gh_double2scm (p->get_var("bracket_arch_angle")),
25                     gh_double2scm (p->get_var("bracket_arch_width")),
26                     gh_double2scm (arc_height),
27                     gh_double2scm (p->get_var("bracket_width")),
28                     gh_double2scm (height),
29                     gh_double2scm (p->get_var("bracket_arch_thick")),
30                     gh_double2scm (p->get_var("bracket_thick")),
31                     SCM_UNDEFINED);
32
33   Real staff_space = p->get_var ("interline");
34   Real h = height + 2 * arc_height;
35   Box b (Interval (0, 1.5 * staff_space), Interval (-h/2, h/2));
36   Molecule mol (b, at);
37   
38   mol.translate_axis (- mol.dim_[X_AXIS].length () / 2, X_AXIS);
39   return mol;
40 }
41
42 System_start_delimiter::System_start_delimiter ()
43 {
44   set_extent_callback (0, Y_AXIS);
45   Group_interface (this).set_interface();
46 }
47
48 Molecule
49 System_start_delimiter::simple_bar (Real h) const
50 {
51   Real w = paper_l ()->get_var ("barthick_score");
52   return lookup_l ()->filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
53 }
54
55 void
56 System_start_delimiter::after_line_breaking ()
57 {
58   SCM   gl = get_elt_property ("glyph");
59   
60   if (scm_ilength (get_elt_property ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
61     {
62       set_elt_property ("transparent", SCM_BOOL_T);
63       set_extent_callback (0, X_AXIS);
64       set_extent_callback (0, Y_AXIS);
65     }
66 }
67
68 Molecule
69 System_start_delimiter::do_brew_molecule ()const
70 {
71   Interval ext = Axis_group_interface::group_extent_callback (dim_cache_[Y_AXIS]);
72   Real l = ext.length (); 
73   Molecule m;
74
75   SCM s = get_elt_property ("collapse-height");
76   if (gh_number_p (s) && l < gh_scm2double (s))
77     {
78       System_start_delimiter * me = (System_start_delimiter*)this;
79       me->set_elt_property ("transparent", SCM_BOOL_T);
80       me->set_extent_callback (0, X_AXIS);
81       me->set_extent_callback (0, Y_AXIS);
82       return m;
83     }
84
85   
86   s = get_elt_property ("glyph");
87   if (!gh_symbol_p(s))
88     return m;
89   
90   if (s == ly_symbol2scm ("bracket"))
91     m = staff_bracket (l);
92   else if ( s == ly_symbol2scm ("brace"))
93     m =  staff_brace (l);
94   else if (s == ly_symbol2scm ("bar-line"))
95     m = simple_bar (l);
96   
97   
98   m.translate_axis (ext.center (), Y_AXIS);
99   return m;
100 }
101
102 /*
103   ugh. Suck me plenty.
104  */
105 Molecule
106 System_start_delimiter::staff_brace (Real y)  const
107 {
108   Real staffht  = paper_l ()->get_var ("staffheight");
109   int staff_size  = int (rint (staffht ));
110
111   // URG
112   Real step  = 1.0;
113   int minht  = 2 * staff_size;
114   int maxht = 7 *  minht;
115   int idx = int (((maxht - step) <? y - minht) / step);
116   idx = idx >? 0;
117
118   SCM l = scm_eval (gh_list (ly_symbol2scm ("style-to-cmr"),
119                             ly_str02scm ("brace"),
120                             SCM_UNDEFINED));
121   
122   String nm = "feta-braces";
123   if (l != SCM_BOOL_F)
124     nm = ly_scm2string (gh_cdr (l));
125   nm += to_str (staff_size);
126   SCM e =gh_list (ly_symbol2scm ("char"), gh_int2scm (idx), SCM_UNDEFINED);
127   SCM at = (e);
128
129   at = fontify_atom (find_font (nm), at);
130   
131   Box b (Interval (0,0), Interval (-y/2, y/2));
132
133   return Molecule(b, at);
134 }
135