]> git.donarmstrong.com Git - lilypond.git/blob - lily/volta-bracket.cc
* lily/text-item.cc (interpret_string): new file, select font with
[lilypond.git] / lily / volta-bracket.cc
1 /*
2   volta-bracket.cc -- implement Volta_bracket_interface
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2004 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include <string.h>
10
11 #include "box.hh"
12 #include "warn.hh"
13 #include "font-interface.hh"
14 #include "line-interface.hh"
15 #include "stencil.hh"
16 #include "paper-column.hh"
17 #include "paper-def.hh"
18 #include "text-item.hh"
19 #include "volta-bracket.hh"
20 #include "group-interface.hh"
21 #include "side-position-interface.hh"
22 #include "directional-element-interface.hh"
23 #include "lookup.hh"
24
25 /*
26   this is too complicated. Yet another version of side-positioning,
27   badly implemented.
28
29   --
30
31   * Should look for system_start_delim to find left edge of staff.
32   
33 */
34
35 MAKE_SCHEME_CALLBACK (Volta_bracket_interface,print,1);
36 SCM
37 Volta_bracket_interface::print (SCM smob) 
38 {
39   Grob *me = unsmob_grob (smob);
40   Link_array<Item> bars
41     = Pointer_group_interface__extract_grobs (me, (Item*)0, "bars");
42
43   if (!bars.size ())
44     return SCM_EOL;
45
46   Spanner *orig_span =  dynamic_cast<Spanner*> (me->original_);
47
48   bool broken_first_bracket = orig_span && (orig_span->broken_intos_[0] == (Spanner*)me);
49
50   bool broken_last_bracket = orig_span && (orig_span->broken_intos_.top () == (Spanner*)me);
51
52   bool no_vertical_start = orig_span && !broken_first_bracket;
53   bool no_vertical_end = orig_span && !broken_last_bracket;
54   SCM s = me->get_property ("bars");
55   Grob * endbar =   unsmob_grob (ly_car (s));
56   SCM glyph = endbar->get_property ("glyph");
57   
58   String str;
59   if (is_string (glyph))
60     str = ly_scm2string (glyph);
61   else
62     return SCM_EOL;
63   
64   const char* cs = str.to_str0 ();
65   no_vertical_end |=
66     (strcmp (cs,":|")!=0 && strcmp (cs,"|:")!=0 && strcmp (cs,"|.")!=0
67      && strcmp (cs,":|:")!=0 && strcmp (cs,".|")!=0);
68
69   Paper_def * paper =me->get_paper ();
70   Real half_space = 0.5;
71
72   Item * bound = dynamic_cast<Spanner*> (me)->get_bound (LEFT);
73
74   /*
75     not a start, but really broken in two
76   */
77   Real left =0.;  
78   if (bound->break_status_dir () == RIGHT)
79     {
80       Paper_column *pc = bound->get_column ();
81       left = pc->extent (pc, X_AXIS)[RIGHT]   - bound->relative_coordinate (pc, X_AXIS);
82     }
83   else
84     {
85       /*
86         the volta spanner is attached to the bar-line, which is moved
87         to the right. We don't need to compensate for the left edge.
88       */
89     }
90
91   Real w = dynamic_cast<Spanner*> (me)->spanner_length () - left - half_space;
92   Real h =  robust_scm2double (me->get_property ("height"), 1);
93
94   Stencil start,end ;
95   if (!no_vertical_start)
96     start = Line_interface::line (me, Offset (0,0), Offset (0, h)); 
97   
98   if (!no_vertical_end)
99     end = Line_interface::line (me, Offset (w, 0), Offset (w,h));
100
101   Stencil mol = Line_interface::line (me, Offset (0, h), Offset (w,h));
102   mol.add_stencil (start);
103   mol.add_stencil (end);
104
105   if (!orig_span || broken_first_bracket)
106     {
107       SCM text = me->get_property ("text");
108       SCM properties = me->get_property_alist_chain (SCM_EOL);
109       SCM snum  = Text_item::interpret_markup (paper->self_scm (), properties, text);
110       Stencil num = *unsmob_stencil (snum);
111
112       mol.add_at_edge (X_AXIS, LEFT, num, - num.extent (X_AXIS).length ()
113                        - 1.0, 0);
114     }
115   mol.translate_axis (left, X_AXIS);
116   return mol.smobbed_copy ();
117 }
118
119
120 void
121 Volta_bracket_interface::add_bar (Grob *me, Item* b)
122 {
123   Pointer_group_interface::add_grob (me, ly_symbol2scm ("bars"), b);
124   Side_position_interface::add_support (me,b);
125   add_bound_item (dynamic_cast<Spanner*> (me), b); 
126 }
127
128 void
129 Volta_bracket_interface::add_column (Grob*me, Grob* c)
130 {
131   Side_position_interface::add_support (me,c);
132 }
133
134 ADD_INTERFACE (Volta_bracket_interface,"volta-bracket-interface",
135                "Volta bracket with number",
136                "bars thickness height");
137