release commit
[lilypond.git] / lily / system-start-delimiter.cc
blob4254c4b6729a960e2fe5e045ddcb93f11e5da0a0
1 /*
2 system-start-delimiter.cc -- implement System_start_delimiter
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include <math.h>
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"
21 Molecule
22 System_start_delimiter::staff_bracket (Grob*me,Real height)
24 Real arc_height = gh_scm2double (me->get_grob_property ("arch-height")) ;
26 SCM at = scm_list_n (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 ("thickness"),
33 SCM_UNDEFINED);
36 TODO: sort this out.
38 Another thing:
39 In system-start-delimiter.cc I see the line
41 Real h = height + 2 * arc_height;
43 But I really think that you mean
45 Real h = height + 2 * arc_width;
47 (arc_height changes the x-axis-size of arc ; arc_width changes the
48 y-axis-size)
49 Will not fix it since I'm not sure.
53 Real h = height + 2 * arc_height;
54 Box b (Interval (0, 1.5), Interval (-h/2, h/2));
55 Molecule mol (b, at);
56 mol.align_to (X_AXIS, CENTER);
57 return mol;
62 Molecule
63 System_start_delimiter::simple_bar (Grob*me,Real h)
65 Real w = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")) *
66 gh_scm2double (me->get_grob_property ("thickness"));
67 return Lookup::filledbox (Box (Interval (0,w), Interval (-h/2, h/2)));
70 MAKE_SCHEME_CALLBACK (System_start_delimiter,after_line_breaking,1);
72 SCM
73 System_start_delimiter::after_line_breaking (SCM smob)
75 Grob * me = unsmob_grob (smob);
76 SCM gl = me->get_grob_property ("glyph");
77 if (gh_equal_p (gl,scm_makfrom0str ("bar-line")))
79 int count = 0;
82 Get all coordinates, to trigger Hara kiri.
84 SCM elts = me->get_grob_property ("elements");
85 Grob *common = common_refpoint_of_list (elts, me, Y_AXIS);
86 for (SCM s = elts; gh_pair_p (s); s = gh_cdr (s))
88 Interval v = unsmob_grob (gh_car (s))->extent (common, Y_AXIS);
90 if (!v.empty_b ())
91 count ++;
95 if (count <= 1)
97 me->suicide ();
100 return SCM_UNSPECIFIED;
104 MAKE_SCHEME_CALLBACK (System_start_delimiter,brew_molecule,1);
106 System_start_delimiter::brew_molecule (SCM smob)
108 Grob * me = unsmob_grob (smob);
110 SCM s = me->get_grob_property ("glyph");
111 if (!gh_string_p (s))
112 return SCM_EOL;
113 SCM gsym = scm_string_to_symbol (s) ;
114 SCM c = me->get_grob_property ("collapse-height");
116 Real staff_space = Staff_symbol_referencer::staff_space (me);
117 Interval ext = ly_scm2interval (Axis_group_interface::group_extent_callback
118 (me->self_scm (), gh_int2scm (Y_AXIS)));
119 Real l = ext.length () / staff_space;
121 if (ext.empty_b ()
122 || (gh_number_p (c) && l <= gh_scm2double (c)))
124 me->suicide ();
125 return SCM_EOL;
128 Molecule m;
130 if (gsym== ly_symbol2scm ("bracket"))
131 m = staff_bracket (me,l);
132 else if (gsym == ly_symbol2scm ("brace"))
133 m = staff_brace (me,l);
134 else if (gsym == ly_symbol2scm ("bar-line"))
135 m = simple_bar (me,l);
137 m.translate_axis (ext.center (), Y_AXIS);
138 return m.smobbed_copy ();
141 Molecule
142 System_start_delimiter::staff_brace (Grob*me, Real y)
144 Font_metric *fm = 0;
146 /* We go through the style sheet to lookup the font file
147 name. This is better than using find_font directly,
148 esp. because that triggers mktextfm for non-existent
149 fonts. */
150 SCM br = ly_symbol2scm ("braces");
151 SCM fam = gh_cons (ly_symbol2scm ("font-family"), br);
152 SCM sz = gh_cons (ly_symbol2scm ("font-relative-size"), ly_symbol2scm ("*"));
154 SCM alist = scm_list_n (fam, sz, SCM_UNDEFINED);
155 fm = select_font (me->get_paper (), scm_list_n (alist, SCM_UNDEFINED));
158 int lo = 0;
160 int hi = (fm->count () - 1) >? 2;
161 Box b;
163 /* do a binary search for each Y, not very efficient, but passable? */
166 int cmp = (lo + hi) / 2;
167 b = fm->get_char (cmp);
168 if (b[Y_AXIS].empty_b () || b[Y_AXIS].length () > y)
169 hi = cmp;
170 else
171 lo = cmp;
173 while (hi - lo > 1);
175 Molecule m (fm->get_char_molecule (lo));
176 b=m.extent_box();
177 b[X_AXIS] = Interval (0,0);
179 return Molecule (b, m.get_expr());
185 ADD_INTERFACE (System_start_delimiter,"system-start-delimiter-interface",
186 "#'style can be bar-line, bracket or brace",
187 "collapse-height thickness arch-height arch-angle arch-thick arch-width bracket-thick glyph");