]> git.donarmstrong.com Git - lilypond.git/blob - lily/horizontal-bracket.cc
Fix off-by-one error in constrained-breaking.
[lilypond.git] / lily / horizontal-bracket.cc
1 /*
2   horizontal-bracket.cc -- implement Horizontal_bracket
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2002--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "horizontal-bracket.hh"        
10
11 #include "lookup.hh"
12 #include "side-position-interface.hh"
13 #include "pointer-group-interface.hh"
14 #include "directional-element-interface.hh"
15 #include "output-def.hh"
16 #include "staff-symbol-referencer.hh"
17 #include "tuplet-bracket.hh"
18 #include "axis-group-interface.hh"
19 #include "spanner.hh"
20 #include "item.hh"
21
22
23 Stencil
24 Horizontal_bracket::make_bracket (Grob *me,
25                                   Real length,
26                                   Axis a, Direction dir)                                 
27 {
28   Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
29                                                       Interval (1.0, 1.0));
30   Drul_array<Real> flare = robust_scm2interval (me->get_property ("bracket-flare"),
31                                                 Interval (0, 0));
32   Drul_array<Real> shorten = robust_scm2interval (me->get_property ("shorten-pair"),
33                                                   Interval (0, 0));
34
35   
36   // Make sure that it points in the correct direction:
37   scale_drul (&edge_height, Real (-dir));
38  
39   Interval empty;
40   Offset start;
41   start[a] = length;
42
43   Drul_array<bool> connect_to_other =
44     robust_scm2booldrul (me->get_property ("connect-to-neighbor"),
45                          Drul_array<bool> (false, false));
46
47   Direction d = LEFT;
48   do
49     {
50       if (connect_to_other[d])
51         {
52           edge_height[d] = 0.0;
53           flare[d] = 0.0;
54           shorten[d] = 0.0;
55         }
56     }
57   while (flip (&d) != LEFT);
58               
59   /*
60     ugh, Tuplet_bracket should use Horizontal_bracket, not the other way around. 
61   */
62   return Tuplet_bracket::make_bracket (me, other_axis (a), start, 
63                                        edge_height, empty, flare, shorten);
64 }
65
66
67 Stencil
68 Horizontal_bracket::make_enclosing_bracket (Grob *me, Grob *refpoint,
69                                             vector<Grob*> grobs,
70                                             Axis a, Direction dir)
71 {
72   Grob *common = common_refpoint_of_array (grobs, refpoint, a);
73   Interval ext = Axis_group_interface::relative_group_extent (grobs, common, a);
74
75   Stencil b = make_bracket (me, ext.length(), a, dir);
76   b.translate_axis (ext[LEFT] - refpoint->relative_coordinate (common, a), a);
77
78   return b;
79 }
80
81
82 /*
83   TODO:
84
85   Support texts on the brackets?
86 */
87
88 MAKE_SCHEME_CALLBACK (Horizontal_bracket, print, 1);
89 SCM
90 Horizontal_bracket::print (SCM smob)
91 {
92   Spanner *me = unsmob_spanner (smob);
93   extract_grob_set (me, "columns", gs);
94
95   vector<Grob*> enclosed = gs;
96   if (!gs.size ())
97     {
98       me->suicide ();
99       return SCM_EOL;
100     }
101
102   Direction d = LEFT;
103   do
104     {
105       Item *b = me->get_bound (d);
106       if (b->break_status_dir ())
107         enclosed.push_back (b);
108     }
109   while (flip (&d) != LEFT);
110   
111   Stencil b = make_enclosing_bracket (me, me, enclosed, X_AXIS, get_grob_direction (me));
112   return b.smobbed_copy ();
113 }
114
115 ADD_INTERFACE (Horizontal_bracket,
116                "A horizontal bracket encompassing notes.",
117
118                /* props */                
119                "bracket-flare "
120                "columns "
121                "edge-height "
122                "shorten-pair "
123                "connect-to-neighbor "
124                );
125