2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 Jan Nieuwenhuizen <janneke@gnu.org>
5 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 LilyPond is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 LilyPond is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
23 #include "axis-group-interface.hh"
24 #include "directional-element-interface.hh"
27 #include "output-def.hh"
28 #include "staff-symbol-referencer.hh"
31 #include "line-interface.hh"
34 should move to lookup?
36 TODO: this will fail for very short (shorter than the flare)
40 Bracket::make_bracket (Grob *me, // for line properties.
41 Axis protrusion_axis, Offset dz,
42 Drul_array<Real> height, Interval gap,
43 Drul_array<Real> flare, Drul_array<Real> shorten)
45 Drul_array<Offset> corners (Offset (0, 0), dz);
47 Real length = dz.length ();
48 Drul_array<Offset> gap_corners;
50 Axis bracket_axis = other_axis (protrusion_axis);
52 Drul_array<Offset> straight_corners = corners;
54 for (LEFT_and_RIGHT (d))
55 straight_corners[d] += -d * shorten[d] / length * dz;
59 for (LEFT_and_RIGHT (d))
60 gap_corners[d] = (dz * 0.5) + gap[d] / length * dz;
63 Drul_array<Offset> flare_corners = straight_corners;
64 for (LEFT_and_RIGHT (d))
66 flare_corners[d][bracket_axis] = straight_corners[d][bracket_axis];
67 flare_corners[d][protrusion_axis] += height[d];
68 straight_corners[d][bracket_axis] += -d * flare[d];
73 for (LEFT_and_RIGHT (d))
74 m.add_stencil (Line_interface::line (me, straight_corners[d],
77 m.add_stencil (Line_interface::line (me, straight_corners[LEFT],
78 straight_corners[RIGHT]));
80 if (scm_is_number (me->get_property ("dash-fraction")))
81 me->set_property ("dash-fraction", scm_from_double (1.0));
82 for (LEFT_and_RIGHT (d))
83 m.add_stencil (Line_interface::line (me, straight_corners[d],
89 Return an ungapped bracket along either the X- or Y-axis.
92 Bracket::make_axis_constrained_bracket (Grob *me, Real length, Axis a,
95 Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
97 Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
99 Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
102 // Make sure that it points in the correct direction:
103 scale_drul (&edge_height, Real (-dir));
108 Drul_array<bool> connect_to_other
109 = robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
110 Drul_array<bool> (false, false));
112 for (LEFT_and_RIGHT (d))
114 if (connect_to_other[d])
116 edge_height[d] = 0.0;
122 return make_bracket (me, other_axis (a), start, edge_height,
123 Interval (), flare, shorten);
127 Return an axis-constrained, ungapped bracket which encloses a group of
128 grobs. Used for analysis brackets (HorizontalBracket) and
129 figured bass (BassFigureBracket).
132 Bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
133 vector<Grob *> grobs, Axis a,
136 Grob *common = common_refpoint_of_array (grobs, refpoint, a);
137 Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
141 me->programming_error ("Can't enclose empty extents with bracket");
146 Stencil b = make_axis_constrained_bracket (me, ext.length (), a, dir);
147 b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);