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-item.hh"
11 #include "text-spanner.hh"
14 #include "dimensions.hh"
15 #include "paper-def.hh"
17 #include "paper-column.hh"
18 #include "staff-symbol-referencer.hh"
23 type: "line", "dashed-line", "dotted-line"
24 edge-text: ("le" . "re")
26 egde-height: (lh . rh)
28 "le"--------------"re"
39 - vertical start / vertical end (fixme-name) |
40 - contination types (vert. star, vert. end) |-> eat volta-spanner
42 - more texts/positions
46 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
49 Text_spanner::brew_molecule (SCM smob)
51 Score_element *me= unsmob_element (smob);
52 Spanner *spanner = dynamic_cast<Spanner*> (me);
54 Real staff_space = Staff_symbol_referencer::staff_space (me);
55 Real thickness = me->paper_l ()->get_var ("stafflinethickness");
58 Drul_array<bool> broken;
62 Paper_column* s = dynamic_cast<Paper_column*>(spanner->get_bound (d)); // UGH
63 broken[d] = (!s->musical_b ());
65 while (flip (&d) != LEFT);
68 SCM s = me->get_elt_property ("text-style");
70 String text_style = "italic";
72 text_style = ly_scm2string (s);
75 SCM properties = gh_append2 (me->immutable_property_alist_,
76 me->mutable_property_alist_);
77 SCM edge_text = me->get_elt_property ("edge-text");
78 Drul_array<Molecule> edge;
79 if (gh_pair_p (edge_text))
84 SCM text = index_cell (edge_text, d);
85 edge[d] = Text_item::text2molecule (me, text, properties);
86 if (!edge[d].empty_b ())
87 edge[d].align_to (Y_AXIS, CENTER);
89 while (flip (&d) != LEFT);
92 Drul_array<Real> shorten;
96 SCM s = me->get_elt_property ("shorten");
99 shorten[LEFT] = gh_scm2double (gh_car (s)) * staff_space;
100 shorten[RIGHT] = gh_scm2double (gh_cdr (s)) * staff_space;
103 Real broken_left = spanner->get_broken_left_end_align ();
104 Real width = spanner->spanner_length ();
105 Score_element *bnd = spanner->get_bound (RIGHT);
106 width += bnd->extent (bnd, X_AXIS).length ();
107 width -= broken_left;
108 width -= shorten[LEFT] + shorten[RIGHT];
109 width -= edge[LEFT].extent (X_AXIS).length ()
110 + edge[RIGHT].extent (X_AXIS).length ();
114 warning (_ ("Text_spanner too small"));
119 String type = "dashed-line";
120 s = me->get_elt_property ("type");
122 type = ly_scm2string (s);
125 Drul_array<Molecule> edge_line;
127 || type == "dashed-line"
128 || type == "dotted-line")
130 Real thick = thickness;
131 s = me->get_elt_property ("line-thickness");
133 thick *= gh_scm2double (s);
135 // maybe these should be in line-thickness?
136 Real length = staff_space;
137 s = me->get_elt_property ("dash-length");
139 length = gh_scm2double (s) * staff_space;
141 Real period = 2 * length + thick;
142 s = me->get_elt_property ("dash-period");
144 period = gh_scm2double (s) * staff_space;
146 if (type == "dotted-line")
150 length = period + thick;
152 Real on = length - thick;
153 Real off = period - on;
155 SCM list = gh_list (ly_symbol2scm ("dashed-line"),
156 gh_double2scm (thick),
159 gh_double2scm (width),
163 Box b (Interval (0, width), Interval (-thick / 2, thick / 2));
164 line = Molecule (b, list);
166 s = me->get_elt_property ("edge-height");
170 int dir = me->get_elt_property ("direction");
173 Real dy = gh_scm2double (index_cell (s, d)) * - dir;
176 SCM list = gh_list (ly_symbol2scm ("dashed-line"),
177 gh_double2scm (thick),
184 Box b (Interval (0, thick),
188 edge_line[d] = Molecule (b, list);
191 while (flip (&d) != LEFT);
196 if (!edge[LEFT].empty_b ())
199 if (!edge_line[LEFT].empty_b ())
200 m.add_at_edge (X_AXIS, RIGHT, edge_line[LEFT], 0);
201 if (!line.empty_b ())
202 m.add_at_edge (X_AXIS, RIGHT, line, 0);
203 if (!edge_line[RIGHT].empty_b ())
204 m.add_at_edge (X_AXIS, RIGHT, edge_line[RIGHT], 0);
205 if (!edge[RIGHT].empty_b ())
206 m.add_at_edge (X_AXIS, RIGHT, edge[RIGHT], 0);
207 m.translate_axis (broken_left, X_AXIS);
209 return m.create_scheme ();