2 text-spanner.cc -- implement Text_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "text-spanner.hh"
13 #include "dimensions.hh"
14 #include "paper-def.hh"
16 #include "paper-column.hh"
17 #include "staff-symbol-referencer.hh"
22 type: "line", "dashed-line", "dotted-line"
23 edge-text: ("le" . "re")
25 egde-height: (lh . rh)
27 "le"--------------"re"
38 - vertical start / vertical end (fixme-name) |
39 - contination types (vert. star, vert. end) |-> eat volta-spanner
41 - more texts/positions
45 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
48 Text_spanner::brew_molecule (SCM smob)
50 Score_element *me= unsmob_element (smob);
51 Spanner *spanner = dynamic_cast<Spanner*> (me);
53 Real staff_space = Staff_symbol_referencer::staff_space (me);
54 Real thickness = me->paper_l ()->get_var ("stafflinethickness");
57 Drul_array<bool> broken;
61 Paper_column* s = dynamic_cast<Paper_column*>(spanner->get_bound (d)); // UGH
62 broken[d] = (!s->musical_b ());
64 while (flip (&d) != LEFT);
66 SCM s = me->get_elt_property ("text-style");
67 String text_style = "italic";
69 text_style = ly_scm2string (s);
71 SCM edge_text = me->get_elt_property ("edge-text");
72 Drul_array<Molecule> edge;
73 if (gh_pair_p (edge_text))
78 String text = ly_scm2string (index_cell (edge_text, d));
79 edge[d] = me->lookup_l ()->text (text_style, text, me->paper_l ());
80 if (!edge[d].empty_b ())
81 edge[d].align_to (Y_AXIS, CENTER);
83 while (flip (&d) != LEFT);
86 Drul_array<Real> shorten;
90 s = me->get_elt_property ("shorten");
93 shorten[LEFT] = gh_scm2double (gh_car (s)) * staff_space;
94 shorten[RIGHT] = gh_scm2double (gh_cdr (s)) * staff_space;
97 Real broken_left = spanner->get_broken_left_end_align ();
98 Real width = spanner->spanner_length ();
99 Score_element *bnd = spanner->get_bound (RIGHT);
100 width += bnd->extent (bnd, X_AXIS).length ();
101 width -= broken_left;
102 width -= shorten[LEFT] + shorten[RIGHT];
103 width -= edge[LEFT].extent (X_AXIS).length ()
104 + edge[RIGHT].extent (X_AXIS).length ();
108 warning (_ ("Text_spanner too small"));
113 String type = "dashed-line";
114 s = me->get_elt_property ("type");
116 type = ly_scm2string (s);
119 Drul_array<Molecule> edge_line;
121 || type == "dashed-line"
122 || type == "dotted-line")
124 Real thick = thickness;
125 s = me->get_elt_property ("line-thickness");
127 thick *= gh_scm2double (s);
129 // maybe these should be in line-thickness?
130 Real length = staff_space;
131 s = me->get_elt_property ("dash-length");
133 length = gh_scm2double (s) * staff_space;
135 Real period = 2 * length + thick;
136 s = me->get_elt_property ("dash-period");
138 period = gh_scm2double (s) * staff_space;
140 if (type == "dotted-line")
144 length = period + thick;
146 Real on = length - thick;
147 Real off = period - on;
149 SCM list = gh_list (ly_symbol2scm ("dashed-line"),
150 gh_double2scm (thick),
153 gh_double2scm (width),
157 Box b (Interval (0, width), Interval (-thick / 2, thick / 2));
158 line = Molecule (b, list);
160 s = me->get_elt_property ("edge-height");
164 int dir = me->get_elt_property ("direction");
167 Real dy = gh_scm2double (index_cell (s, d)) * - dir;
170 SCM list = gh_list (ly_symbol2scm ("dashed-line"),
171 gh_double2scm (thick),
178 Box b (Interval (0, thick),
182 edge_line[d] = Molecule (b, list);
185 while (flip (&d) != LEFT);
190 if (!edge[LEFT].empty_b ())
193 if (!edge_line[LEFT].empty_b ())
194 m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
195 if (!line.empty_b ())
196 m.add_at_edge (X_AXIS, RIGHT, line, 0);
197 if (!edge_line[RIGHT].empty_b ())
198 m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], 0);
199 if (!edge[RIGHT].empty_b ())
200 m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
201 m.translate_axis (broken_left, X_AXIS);
203 return m.create_scheme ();