]> git.donarmstrong.com Git - lilypond.git/blob - lily/system-start-delimiter.cc
release: 1.3.131
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9 #include <math.h>
10
11 #include "axis-group-interface.hh"
12 #include "system-start-delimiter.hh"
13 #include "paper-def.hh"
14 #include "molecule.hh"
15 #include "font-interface.hh"
16 #include "all-font-metrics.hh"
17 #include "grob.hh"
18 #include "staff-symbol-referencer.hh"
19 #include "lookup.hh"
20
21 Molecule
22 System_start_delimiter::staff_bracket (Grob*me,Real height)  
23 {
24   Real arc_height = gh_scm2double (me->get_grob_property("arch-height")) ;
25   
26   SCM at = gh_list (ly_symbol2scm ("bracket"),
27                     me->get_grob_property ("arch-angle"),
28                     me->get_grob_property ("arch-width"),
29                     gh_double2scm (arc_height),
30                     gh_double2scm (height),
31                     me->get_grob_property ("arch-thick"),
32                     me->get_grob_property ("bracket-thick"),
33                     SCM_UNDEFINED);
34
35   Real h = height + 2 * arc_height;
36   Box b (Interval (0, 1.5), Interval (-h/2, h/2));
37   Molecule mol (b, at);
38   mol.align_to (X_AXIS, CENTER);
39   return mol;
40 }
41
42 void
43 System_start_delimiter::set_interface (Grob*me)
44 {
45   me->set_interface (ly_symbol2scm ("system-start-delimiter-interface"));
46 }
47
48 bool
49 System_start_delimiter::has_interface (Grob*me)
50 {
51   return  me->has_interface (ly_symbol2scm ("system-start-delimiter-interface"));
52 }
53
54 Molecule
55 System_start_delimiter::simple_bar (Grob*me,Real h) 
56 {
57   Real w = me->paper_l ()->get_var ("stafflinethickness") *
58     gh_scm2double (me->get_grob_property ("thickness"));
59   return Lookup::filledbox (Box (Interval(0,w), Interval(-h/2, h/2)));
60 }
61
62 MAKE_SCHEME_CALLBACK(System_start_delimiter,after_line_breaking,1);
63
64 SCM
65 System_start_delimiter::after_line_breaking (SCM smob)
66 {
67   try_collapse (unsmob_grob (smob));
68   return SCM_UNSPECIFIED;
69 }
70
71 void
72 System_start_delimiter::try_collapse (Grob*me)
73 {
74   SCM   gl = me->get_grob_property ("glyph");
75   
76   if (scm_ilength (me->get_grob_property ("elements")) <=  1 && gl == ly_symbol2scm ("bar-line"))
77     {
78       me->suicide ();
79     }
80   
81 }
82
83
84 MAKE_SCHEME_CALLBACK(System_start_delimiter,brew_molecule,1);
85
86 SCM
87 System_start_delimiter::brew_molecule (SCM smob)
88 {
89   Grob * me = unsmob_grob (smob);
90
91   SCM s = me->get_grob_property ("glyph");
92   if (!gh_symbol_p (s))
93     return SCM_EOL;
94   
95   SCM c = me->get_grob_property ((ly_symbol2string (s) + "-collapse-height")
96                                  .ch_C ());
97   
98   Real staff_space = Staff_symbol_referencer::staff_space (me);
99   Interval ext = ly_scm2interval (Axis_group_interface::group_extent_callback
100                                   (me->self_scm(), gh_int2scm (Y_AXIS)));
101   Real l = ext.length () / staff_space;
102   
103   if (gh_number_p (c) && l <= gh_scm2double (c))
104     {
105       me->suicide();
106       return SCM_EOL;
107     }
108
109   Molecule m;
110   if (s == ly_symbol2scm ("bracket"))
111     m = staff_bracket (me,l);
112   else if (s == ly_symbol2scm ("brace"))
113     m =  staff_brace (me,l);
114   else if (s == ly_symbol2scm ("bar-line"))
115     m = simple_bar (me,l);
116   
117   m.translate_axis (ext.center (), Y_AXIS);
118   return m.smobbed_copy ();
119 }
120
121 Molecule
122 System_start_delimiter::staff_brace (Grob*me,Real y)  
123 {
124   int lo = 0;
125   int hi = 255;
126   Font_metric *fm = Font_interface::get_default_font (me);
127   Box b;
128
129   /* do a binary search for each Y, not very efficient, but passable?  */
130   do
131   {
132     int cmp = (lo + hi) / 2;
133
134     b = fm->get_char (cmp);
135     if (b[Y_AXIS].empty_b () || b[Y_AXIS].length () > y )
136       hi = cmp;
137     else
138       lo = cmp;
139     }
140   while (hi - lo > 1);
141
142   SCM at = gh_list (ly_symbol2scm ("char"), gh_int2scm (lo), SCM_UNDEFINED);
143   at = fontify_atom (fm, at);
144   
145   b = fm->get_char (lo);
146   b[X_AXIS] = Interval (0,0);
147
148   return Molecule(b, at);
149 }
150