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 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. */
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
);
51 Drul_array
<bool> broken
;
55 Item
*b
= spanner
->get_bound (d
);
56 broken
[d
] = b
->break_status_dir () != CENTER
;
61 span_points
[d
] = spanner
->get_broken_left_end_align ();
63 span_points
[d
] = b
->relative_coordinate (common
, X_AXIS
);
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
))
83 /* Don't repeat edge text for broken end */
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
;
103 SCM ew
= me
->get_grob_property ("bracket-flare");
104 SCM s
= me
->get_grob_property ("shorten-pair");
107 span_points
[LEFT
] += gh_scm2double (ly_car (s
));
108 span_points
[RIGHT
] -= gh_scm2double (ly_cdr (s
));
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");
128 int dir
= to_dir (me
->get_grob_property ("direction"));
136 dx
= gh_scm2double (index_get_cell (ew
, d
)) * d
;
138 Real dy
= gh_scm2double (index_get_cell (s
, d
)) * - dir
;
140 edge_line
[d
] = Line_spanner::line_molecule (me
, thick
, Offset(0,0),
143 while (flip (&d
) != LEFT
);
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
]);
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));
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");