* lily/include/lily-guile.hh: many new ly_ functions. Thanks to
[lilypond.git] / lily / text-spanner.cc
blob41bef9c54c4c29738c9dbc1cb1056e7dc561d91e
1 /*
2 text-spanner.cc -- implement Text_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Jan Nieuwenhuizen <janneke@gnu.org>
8 Revised over good by Han-Wen.
9 */
11 #include "stencil.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, print, 1);
34 TODO: this function is too long
36 SCM
37 Text_spanner::print (SCM smob)
39 Grob *me= unsmob_grob (smob);
40 Spanner *spanner = dynamic_cast<Spanner*> (me);
42 /* Ugh, must be same as Hairpin::print. */
44 Grob *common = spanner->get_bound (LEFT)->common_refpoint (spanner->get_bound (RIGHT), X_AXIS);
45 Paper_def * paper = me->get_paper ();
47 SCM flare = me->get_property ("bracket-flare");
48 SCM shorten = me->get_property ("shorten-pair");
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 Real encl = robust_scm2double (me->get_property ("enclose-bounds"), 0.0);
68 span_points[d] = b->extent (common, X_AXIS).linear_combination (d * encl);
70 if (is_number_pair (shorten))
71 span_points -= d * ly_scm2double (index_get_cell (shorten, d));
74 if (is_number_pair (flare))
75 span_points -= d * ly_scm2double (index_get_cell (flare, d));
77 while (flip (&d) != LEFT);
80 SCM properties = Font_interface::text_font_alist_chain (me);
81 SCM edge_text = me->get_property ("edge-text");
82 Drul_array<Stencil> edge;
83 if (ly_pair_p (edge_text))
85 Direction d = LEFT;
88 if (broken[d])
89 continue;
91 SCM text = index_get_cell (edge_text, d);
93 if (Text_item::markup_p (text))
94 edge[d] = *unsmob_stencil (Text_item::interpret_markup (paper->self_scm (), properties, text));
96 if (!edge[d].is_empty ())
97 edge[d].align_to (Y_AXIS, CENTER);
99 while (flip (&d) != LEFT);
102 Drul_array<Real> edge_height = robust_scm2interval (me->get_property ("edge-height"),
103 Interval (0.0, 0.0));
104 Drul_array<Stencil> edge_line;
106 Direction d = LEFT;
107 int dir = to_dir (me->get_property ("direction"));
110 if (broken[d])
111 continue;
113 Real dx = 0.0;
114 if (is_number_pair (flare))
115 dx = ly_scm2double (index_get_cell (flare, d)) * d;
117 Real dy = - dir * edge_height[d] ;
118 if (dy)
119 edge_line[d] = Line_spanner::line_stencil (me, Offset (0,0), Offset (dx, dy));
121 while (flip (&d) != LEFT);
124 Stencil m;
127 Interval ext = edge[d].extent (X_AXIS);
128 if (!ext.is_empty ())
130 edge[d].translate_axis (span_points[d], X_AXIS);
131 m.add_stencil (edge[d]);
132 span_points[d] += -d * ext[-d];
135 while (flip (&d) != LEFT);
138 if (d* span_points[d] > d * edge[-d].extent (X_AXIS)[d])
140 edge_line[d].translate_axis (span_points[d], X_AXIS);
141 m.add_stencil (edge_line[d]);
144 while (flip (&d) != LEFT);
146 if (!span_points.is_empty ())
148 Stencil l =Line_spanner::line_stencil (me, Offset (span_points[LEFT], 0),
149 Offset (span_points[RIGHT], 0));
150 m.add_stencil (l);
152 m.translate_axis (- me->relative_coordinate (common, X_AXIS), X_AXIS);
153 return m.smobbed_copy ();
156 ADD_INTERFACE (Text_spanner,"text-spanner-interface",
157 "generic text spanner",
158 "dash-period if-text-padding dash-fraction edge-height bracket-flare edge-text shorten-pair style thickness enclose-bounds");