]> git.donarmstrong.com Git - lilypond.git/blob - lily/text-spanner.cc
patch::: 1.3.96.jcn9
[lilypond.git] / lily / text-spanner.cc
1 /*
2   text-spanner.cc -- implement Text_spanner
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
7 */
8
9 #include "molecule.hh"
10 #include "text-item.hh"
11 #include "text-spanner.hh"
12 #include "spanner.hh"
13 #include "lookup.hh"
14 #include "dimensions.hh"
15 #include "paper-def.hh"
16 #include "debug.hh"
17 #include "paper-column.hh"
18 #include "staff-symbol-referencer.hh"
19
20 /*
21   TODO:
22     - vertical start / vertical end (fixme-name) |
23     - contination types (vert. star, vert. end)  |-> eat volta-spanner
24     - more styles
25     - more texts/positions
26     - style: hairpin ?
27  */
28
29 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
30
31 SCM
32 Text_spanner::brew_molecule (SCM smob) 
33 {
34   Score_element *me= unsmob_element (smob);
35   Spanner *spanner = dynamic_cast<Spanner*> (me);
36
37   Real staff_space = Staff_symbol_referencer::staff_space (me);
38   Real thickness = me->paper_l ()->get_var ("stafflinethickness");  
39   
40
41   Drul_array<bool> broken;
42   Direction d = LEFT;
43   do
44     {
45       Paper_column* s = dynamic_cast<Paper_column*>(spanner->get_bound (d)); // UGH
46       broken[d] = (!s->musical_b ());
47     }
48   while (flip (&d) != LEFT);
49   
50 #if 0
51   SCM s = me->get_elt_property ("text-style");
52
53   String text_style = "italic";
54   if (gh_string_p (s))
55     text_style = ly_scm2string (s);
56 #endif
57
58   SCM properties = gh_append2 (me->immutable_property_alist_,
59                                me->mutable_property_alist_);
60   SCM edge_text = me->get_elt_property ("edge-text");
61   Drul_array<Molecule> edge;
62   if (gh_pair_p (edge_text))
63     {
64       Direction d = LEFT;
65       do
66         {
67           SCM text = index_cell (edge_text, d);
68           edge[d] = Text_item::text2molecule (me, text, properties);
69           if (!edge[d].empty_b ())
70             edge[d].align_to (Y_AXIS, CENTER);
71         }
72       while (flip (&d) != LEFT);
73     }
74
75   Drul_array<Real> shorten;
76   shorten[LEFT] = 0;
77   shorten[RIGHT] = 0;
78
79   SCM s = me->get_elt_property ("shorten");
80   if (gh_pair_p (s))
81     {
82       shorten[LEFT] = gh_scm2double (gh_car (s)) * staff_space;
83       shorten[RIGHT] = gh_scm2double (gh_cdr (s)) * staff_space;
84     }
85
86   Real broken_left =  spanner->get_broken_left_end_align ();
87   Real width = spanner->spanner_length ();
88   Score_element *bnd = spanner->get_bound (RIGHT);
89   width += bnd->extent (bnd, X_AXIS).length ();
90   width -= broken_left;
91   width -= shorten[LEFT] + shorten[RIGHT];
92   width -= edge[LEFT].extent (X_AXIS).length ()
93     + edge[RIGHT].extent (X_AXIS).length ();
94
95   if (width < 0)
96     {
97       warning (_ ("Text_spanner too small"));
98       width = 0;
99     }
100
101
102   String type = "dashed-line";
103   s = me->get_elt_property ("type");
104   if (gh_string_p (s))
105     type = ly_scm2string (s);
106
107   Molecule line;
108   Drul_array<Molecule> edge_line;
109   if (type == "line"
110       || type == "dashed-line"
111       || type == "dotted-line")
112     {
113       Real thick = thickness;
114       s = me->get_elt_property ("line-thickness");
115       if (gh_number_p (s))
116         thick *= gh_scm2double (s);
117   
118       // maybe these should be in line-thickness?
119       Real length = staff_space;
120       s = me->get_elt_property ("dash-length");
121       if (gh_number_p (s))
122         length = gh_scm2double (s) * staff_space;
123
124       Real period = 2 * length + thick;
125       s = me->get_elt_property ("dash-period");
126       if (gh_number_p (s))
127         period = gh_scm2double (s) * staff_space;
128       
129       if (type == "dotted-line")
130         length = thick;
131         
132       if (type == "line")
133         length = period + thick;
134
135       Real on = length - thick;
136       Real off = period - on;
137
138       SCM list = gh_list (ly_symbol2scm ("dashed-line"),
139                           gh_double2scm (thick),
140                           gh_double2scm (on),
141                           gh_double2scm (off),
142                           gh_double2scm (width),
143                           gh_double2scm (0),
144                           SCM_UNDEFINED);
145
146       Box b (Interval (0, width), Interval (-thick / 2, thick / 2));
147       line = Molecule (b, list);
148
149       s = me->get_elt_property ("edge-height");
150       if (gh_pair_p (s))
151         {
152           Direction d = LEFT;
153           int dir = to_dir (me->get_elt_property ("direction"));
154           do
155             {
156               Real dy = gh_scm2double (index_cell (s, d)) * - dir;
157               if (dy)
158                 {
159                   SCM list = gh_list (ly_symbol2scm ("dashed-line"),
160                                       gh_double2scm (thick),
161                                       gh_double2scm (on),
162                                       gh_double2scm (off),
163                                       gh_double2scm (0),
164                                       gh_double2scm (dy),
165                                       SCM_UNDEFINED);
166                   
167                   Box b (Interval (0, thick),
168                          dy > 0
169                          ? Interval (0, dy)
170                          : Interval (dy, 0));
171                   edge_line[d] = Molecule (b, list);
172                 }
173             }
174           while (flip (&d) != LEFT);
175         }
176     }
177
178   Molecule m;
179   if (!edge[LEFT].empty_b ())
180     m = edge[LEFT];
181
182   if (!edge_line[LEFT].empty_b ())
183     m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
184   if (!line.empty_b ())
185     m.add_at_edge (X_AXIS, RIGHT, line, 0);
186   if (!edge_line[RIGHT].empty_b ())
187     m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], 0);
188   if (!edge[RIGHT].empty_b ())
189     m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
190   m.translate_axis (broken_left, X_AXIS);
191
192   return m.create_scheme ();
193 }
194
195