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