2 system-start-delimiter.cc -- implement System_start_delimiter
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
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"
21 System_start_delimiter::staff_bracket (Grob*me,Real height)
23 Real arc_height = gh_scm2double (me->get_grob_property("arch-height")) ;
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 me->get_grob_property ("bracket-width"),
30 gh_double2scm (height),
31 me->get_grob_property ("arch-thick"),
32 me->get_grob_property ("bracket-thick"),
35 Real h = height + 2 * arc_height;
36 Box b (Interval (0, 1.5), Interval (-h/2, h/2));
38 mol.align_to (X_AXIS, CENTER);
43 System_start_delimiter::set_interface (Grob*me)
45 me->set_interface (ly_symbol2scm ("system-start-delimiter-interface"));
49 System_start_delimiter::has_interface (Grob*me)
51 return me->has_interface (ly_symbol2scm ("system-start-delimiter-interface"));
55 System_start_delimiter::simple_bar (Grob*me,Real h)
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)));
62 MAKE_SCHEME_CALLBACK(System_start_delimiter,after_line_breaking,1);
65 System_start_delimiter::after_line_breaking (SCM smob)
67 try_collapse (unsmob_grob (smob));
68 return SCM_UNSPECIFIED;
72 System_start_delimiter::try_collapse (Grob*me)
74 SCM gl = me->get_grob_property ("glyph");
76 if (scm_ilength (me->get_grob_property ("elements")) <= 1 && gl == ly_symbol2scm ("bar-line"))
84 MAKE_SCHEME_CALLBACK(System_start_delimiter,brew_molecule,1);
87 System_start_delimiter::brew_molecule (SCM smob)
89 Grob * me = unsmob_grob (smob);
90 Interval ext = ly_scm2interval (Axis_group_interface::group_extent_callback (me->self_scm(), gh_int2scm (Y_AXIS)));
91 Real l = ext.length ();
94 SCM s = me->get_grob_property ("collapse-height");
95 if (gh_number_p (s) && l < gh_scm2double (s))
101 s = me->get_grob_property ("glyph");
105 if (s == ly_symbol2scm ("bracket"))
106 m = staff_bracket (me,l);
107 else if (s == ly_symbol2scm ("brace"))
108 m = staff_brace (me,l);
109 else if (s == ly_symbol2scm ("bar-line"))
110 m = simple_bar (me,l);
113 m.translate_axis (ext.center (), Y_AXIS);
114 return m.smobbed_copy ();
118 System_start_delimiter::staff_brace (Grob*me,Real y)
122 Font_metric *fm = Font_interface::get_default_font (me);
125 /* do a binary search for each Y, not very efficient, but passable? */
128 int cmp = (lo + hi) / 2;
130 b = fm->get_char (cmp);
131 if (b[Y_AXIS].empty_b () || b[Y_AXIS].length () > y )
138 SCM at = gh_list (ly_symbol2scm ("char"), gh_int2scm (lo), SCM_UNDEFINED);
139 at = fontify_atom (fm, at);
141 b = fm->get_char (lo);
142 b[X_AXIS] = Interval (0,0);
144 return Molecule(b, at);