2 system-start-delimiter.cc -- implement System_start_delimiter
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "system-start-delimiter.hh"
14 #include "axis-group-interface.hh"
15 #include "output-def.hh"
16 #include "font-interface.hh"
17 #include "all-font-metrics.hh"
18 #include "staff-symbol-referencer.hh"
22 #include "pointer-group-interface.hh"
25 System_start_delimiter::staff_bracket (Grob *me, Real height)
27 Font_metric *fm = Font_interface::get_default_font (me);
28 Drul_array<Stencil> tips (fm->find_by_name ("brackettips.down"),
29 fm->find_by_name ("brackettips.up"));
31 Real thickness = robust_scm2double (me->get_property ("thickness"), 0.25);
33 Real overlap = 0.1 * thickness;
35 Stencil bracket = Lookup::filled_box (Box (Interval (0, thickness),
37 * (height / 2 + overlap)));
41 bracket.add_at_edge (Y_AXIS, d, tips[d], -overlap, 0.0);
42 while (flip (&d) != DOWN)
49 System_start_delimiter::simple_bar (Grob *me, Real h)
51 Real lt = me->get_layout ()->get_dimension (ly_symbol2scm ("linethickness"));
52 Real w = lt * robust_scm2double (me->get_property ("thickness"), 1);
53 return Lookup::round_filled_box (Box (Interval (0, w), Interval (-h / 2, h / 2)),
57 MAKE_SCHEME_CALLBACK (System_start_delimiter, after_line_breaking, 1);
60 System_start_delimiter::after_line_breaking (SCM smob)
62 Spanner *me = dynamic_cast<Spanner *> (unsmob_grob (smob));
64 SCM gl = me->get_property ("glyph");
65 if (ly_is_equal (gl, scm_makfrom0str ("bar-line")))
68 Paper_column *left_column = me->get_bound (LEFT)->get_column ();
71 Get all coordinates, to trigger Hara kiri.
73 extract_grob_set (me, "elements", elts);
74 Grob *common = common_refpoint_of_array (elts, me, Y_AXIS);
76 for (int i = elts.size (); i--;)
78 Spanner *staff = dynamic_cast<Spanner *> (elts[i]);
80 || staff->get_bound (LEFT)->get_column () != left_column)
83 Interval v = staff->extent (common, Y_AXIS);
92 return SCM_UNSPECIFIED;
95 MAKE_SCHEME_CALLBACK (System_start_delimiter, print, 1);
97 System_start_delimiter::print (SCM smob)
99 Spanner *me = unsmob_spanner (smob);
103 SCM s = me->get_property ("glyph");
104 if (!scm_is_string (s))
106 SCM gsym = scm_string_to_symbol (s);
108 Real staff_space = Staff_symbol_referencer::staff_space (me);
110 extract_grob_set (me, "elements", elts);
111 Grob *common = common_refpoint_of_array (elts, me, Y_AXIS);
115 for (int i = elts.size (); i--;)
117 Spanner *sp = dynamic_cast<Spanner *> (elts[i]);
119 && sp->get_bound (LEFT) == me->get_bound (LEFT))
121 Interval dims = sp->extent (common, Y_AXIS);
122 if (!dims.is_empty ())
127 ext -= me->relative_coordinate (common, Y_AXIS);
129 Real len = ext.length () / staff_space;
132 || (robust_scm2double (me->get_property ("collapse-height"), 0.0) >= len))
140 if (gsym == ly_symbol2scm ("bracket"))
141 m = staff_bracket (me, len);
142 else if (gsym == ly_symbol2scm ("brace"))
143 m = staff_brace (me, len);
144 else if (gsym == ly_symbol2scm ("bar-line"))
145 m = simple_bar (me, len);
147 m.translate_axis (ext.center (), Y_AXIS);
148 return m.smobbed_copy ();
152 System_start_delimiter::staff_brace (Grob *me, Real y)
155 /* We go through the style sheet to lookup the font file
156 name. This is better than using find_font directly,
157 esp. because that triggers mktextfm for non-existent
159 SCM fam = scm_cons (ly_symbol2scm ("font-encoding"),
160 ly_symbol2scm ("fetaBraces"));
162 SCM alist = scm_list_n (fam, SCM_UNDEFINED);
163 fm = select_font (me->get_layout (), scm_list_n (alist, SCM_UNDEFINED));
166 int hi = max (fm->count () - 1, 2);
169 /* do a binary search for each Y, not very efficient, but passable? */
172 int cmp = (lo + hi) / 2;
173 b = fm->get_indexed_char (cmp);
174 if (b[Y_AXIS].is_empty () || b[Y_AXIS].length () > y)
181 Stencil stil (fm->find_by_name ("brace" + to_string (lo)));
182 b = stil.extent_box ();
183 b[X_AXIS] = Interval (0, 0);
185 return Stencil (b, stil.expr ());
188 ADD_INTERFACE (System_start_delimiter, "system-start-delimiter-interface",
189 "The brace, bracket or bar in front of the system. "
190 "It is implemented as a spanner.",
191 "collapse-height thickness "