*** empty log message ***
[lilypond.git] / lily / text-spanner.cc
blob6037882dd6a8d3303d4f017ce3d97ac8441a0444
1 /*
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.
9 */
11 #include "molecule.hh"
12 #include "text-item.hh"
13 #include "text-spanner.hh"
14 #include "line-spanner.hh"
15 #include "spanner.hh"
16 #include "font-interface.hh"
17 #include "dimensions.hh"
18 #include "paper-def.hh"
19 #include "warn.hh"
20 #include "paper-column.hh"
21 #include "staff-symbol-referencer.hh"
24 TODO:
25 - vertical start / vertical end (fixme-name) |
26 - contination types (vert. star, vert. end) |-> eat volta-bracket
27 - more styles
28 - more texts/positions
31 MAKE_SCHEME_CALLBACK (Text_spanner, brew_molecule, 1);
34 TODO: this function is too long
36 SCM
37 Text_spanner::brew_molecule (SCM smob)
39 Grob *me= unsmob_grob (smob);
40 Spanner *spanner = dynamic_cast<Spanner*> (me);
42 /* Ugh, must be same as Hairpin::brew_molecule. */
43 Real padding = 0.0;
44 SCM itp= me->get_grob_property ("if-text-padding");
45 if (gh_number_p (itp))
46 padding = gh_scm2double (itp);
48 Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
50 Interval span_points;
51 Drul_array<bool> broken;
52 Direction d = LEFT;
55 Item *b = spanner->get_bound (d);
56 broken[d] = b->break_status_dir () != CENTER;
58 if (broken[d])
60 if (d == LEFT)
61 span_points[d] = spanner->get_broken_left_end_align ();
62 else
63 span_points[d] = b->relative_coordinate (common, X_AXIS);
65 else
67 bool encl = to_boolean (me->get_grob_property ("enclose-bounds"));
68 span_points[d] = b->extent (common, X_AXIS)[encl ? d : -d];
71 while (flip (&d) != LEFT);
75 SCM properties = Font_interface::font_alist_chain (me);
76 SCM edge_text = me->get_grob_property ("edge-text");
77 Drul_array<Molecule> edge;
78 if (gh_pair_p (edge_text))
80 Direction d = LEFT;
83 /* Don't repeat edge text for broken end */
84 if (broken[d])
85 continue;
87 SCM text = index_get_cell (edge_text, d);
89 if (Text_item::markup_p (text))
90 edge[d] = *unsmob_molecule (Text_item::interpret_markup (smob, properties, text));
92 if (!edge[d].empty_b ())
93 edge[d].align_to (Y_AXIS, CENTER);
95 while (flip (&d) != LEFT);
99 Drul_array<Real> shorten;
100 shorten[LEFT] = 0;
101 shorten[RIGHT] = 0;
103 SCM ew = me->get_grob_property ("bracket-flare");
104 SCM s = me->get_grob_property ("shorten-pair");
105 if (gh_pair_p (s))
107 span_points[LEFT] += gh_scm2double (ly_car (s));
108 span_points[RIGHT] -= gh_scm2double (ly_cdr (s));
110 if (gh_pair_p (ew))
112 span_points[LEFT] += gh_scm2double (ly_car (ew));
113 span_points[RIGHT] -= gh_scm2double (ly_cdr (ew));
116 Real thick = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
117 SCM st = me->get_grob_property ("thickness");
118 if (gh_number_p (st))
120 thick *= gh_scm2double (st);
123 Drul_array<Molecule> edge_line;
124 s = me->get_grob_property ("edge-height");
125 if (gh_pair_p (s))
127 Direction d = LEFT;
128 int dir = to_dir (me->get_grob_property ("direction"));
131 if (broken[d])
132 continue;
134 Real dx = 0.0;
135 if (gh_pair_p (ew))
136 dx = gh_scm2double (index_get_cell (ew, d)) * d;
138 Real dy = gh_scm2double (index_get_cell (s, d)) * - dir;
139 if (dy)
140 edge_line[d] = Line_spanner::line_molecule (me, thick, Offset(0,0),
141 Offset (dx, dy));
143 while (flip (&d) != LEFT);
146 Molecule m;
149 Interval ext = edge[d].extent (X_AXIS);
151 edge[d].translate_axis (span_points[d], X_AXIS);
152 m.add_molecule (edge[d]);
153 edge_line[d].translate_axis (span_points[d], X_AXIS);
154 m.add_molecule (edge_line[d]);
155 if (!ext.empty_b ())
156 span_points[d] += -d * ext[-d];
158 while (flip (&d) != LEFT);
160 Molecule l =Line_spanner::line_molecule (me, thick,
161 Offset (span_points[LEFT], 0),
162 Offset (span_points[RIGHT], 0));
163 m.add_molecule (l);
165 m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
166 return m.smobbed_copy ();
172 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
173 "generic text spanner",
174 "dash-period if-text-padding dash-length edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds width-correct");