2 text-spanner.cc -- implement Text_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Jan Nieuwenhuizen <janneke@gnu.org>
8 Revised over good by Han-Wen.
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "text-spanner.hh"
14 #include "line-spanner.hh"
16 #include "font-interface.hh"
17 #include "dimensions.hh"
18 #include "paper-def.hh"
20 #include "paper-column.hh"
21 #include "staff-symbol-referencer.hh"
25 - vertical start / vertical end (fixme-name) |
26 - contination types (vert. star, vert. end) |-> eat volta-bracket
28 - more texts/positions
31 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
34 TODO: this function is too long
37 TODO: the string for ottava shoudl depend on the available space, ie.
40 Long: 15ma Short: 15ma Empty: 15
47 Text_spanner::brew_molecule (SCM smob)
49 Grob *me= unsmob_grob (smob);
50 Spanner *spanner = dynamic_cast<Spanner*> (me);
52 /* Ugh, must be same as Hairpin::brew_molecule. */
54 SCM itp= me->get_grob_property ("if-text-padding");
55 if (gh_number_p (itp))
56 padding = gh_scm2double (itp);
58 Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
59 Paper_def * paper = me->get_paper();
61 SCM flare = me->get_grob_property ("bracket-flare");
62 SCM shorten = me->get_grob_property ("shorten-pair");
65 Drul_array<bool> broken;
69 Item *b = spanner->get_bound (d);
70 broken[d] = b->break_status_dir () != CENTER;
75 span_points[d] = spanner->get_broken_left_end_align ();
77 span_points[d] = b->relative_coordinate (common, X_AXIS);
81 bool encl = to_boolean (me->get_grob_property ("enclose-bounds"));
82 span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d];
84 if (is_number_pair (shorten))
85 span_points -= d * gh_scm2double (index_get_cell (shorten, d));
88 if (is_number_pair (flare))
89 span_points -= d * gh_scm2double (index_get_cell (flare, d));
91 while (flip (&d) != LEFT);
94 SCM properties = Font_interface::font_alist_chain (me);
95 SCM edge_text = me->get_grob_property ("edge-text");
96 Drul_array<Molecule> edge;
97 if (gh_pair_p (edge_text))
102 if (!to_boolean (me->get_grob_property ("text-repeat-if-broken"))
106 SCM text = index_get_cell (edge_text, d);
108 if (Text_item::markup_p (text))
109 edge[d] = *unsmob_molecule (Text_item::interpret_markup (paper->self_scm (), properties, text));
111 if (!edge[d].is_empty ())
112 edge[d].align_to (Y_AXIS, CENTER);
114 while (flip (&d) != LEFT);
117 Real thick = paper->get_realvar (ly_symbol2scm ("linethickness"));
118 SCM st = me->get_grob_property ("thickness");
119 if (gh_number_p (st))
121 thick *= gh_scm2double (st);
124 Drul_array<Molecule> edge_line;
125 SCM edge_height = me->get_grob_property ("edge-height");
126 if (is_number_pair (edge_height))
129 int dir = to_dir (me->get_grob_property ("direction"));
136 if (gh_pair_p (flare))
137 dx = gh_scm2double (index_get_cell (flare, d)) * d;
139 Real dy = gh_scm2double (index_get_cell (edge_height, d)) * - dir;
141 edge_line[d] = Line_spanner::line_molecule (me, thick, Offset(0,0),
144 while (flip (&d) != LEFT);
150 Interval ext = edge[d].extent (X_AXIS);
151 if (!ext.is_empty ())
153 edge[d].translate_axis (span_points[d], X_AXIS);
154 m.add_molecule (edge[d]);
155 span_points[d] += -d * ext[-d];
158 while (flip (&d) != LEFT);
161 if (d* span_points[d] > d * edge[-d].extent(X_AXIS)[d])
163 edge_line[d].translate_axis (span_points[d], X_AXIS);
164 m.add_molecule (edge_line[d]);
167 while (flip (&d) != LEFT);
169 if (!span_points.is_empty ())
171 Molecule l =Line_spanner::line_molecule (me, thick,
172 Offset (span_points[LEFT], 0),
173 Offset (span_points[RIGHT], 0));
176 m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
177 return m.smobbed_copy ();
183 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
184 "generic text spanner",
185 "text-repeat-if-broken dash-period if-text-padding dash-fraction edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds width-correct");