Left: | ||
Right: |
OLD | NEW |
---|---|
1 /* | 1 /* |
2 This file is part of LilyPond, the GNU music typesetter. | 2 This file is part of LilyPond, the GNU music typesetter. |
3 | 3 |
4 Copyright (C) 2003--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> | 4 Copyright (C) 2003--2015 Han-Wen Nienhuys <hanwen@xs4all.nl> |
5 | 5 |
6 LilyPond is free software: you can redistribute it and/or modify | 6 LilyPond is free software: you can redistribute it and/or modify |
7 it under the terms of the GNU General Public License as published by | 7 it under the terms of the GNU General Public License as published by |
8 the Free Software Foundation, either version 3 of the License, or | 8 the Free Software Foundation, either version 3 of the License, or |
9 (at your option) any later version. | 9 (at your option) any later version. |
10 | 10 |
11 LilyPond is distributed in the hope that it will be useful, | 11 LilyPond is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 GNU General Public License for more details. | 14 GNU General Public License for more details. |
15 | 15 |
16 You should have received a copy of the GNU General Public License | 16 You should have received a copy of the GNU General Public License |
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. | 17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>. |
18 */ | 18 */ |
19 | 19 |
20 #include "lyric-hyphen.hh" | 20 #include "lyric-hyphen.hh" |
21 | 21 |
22 #include "axis-group-interface.hh" | 22 #include "axis-group-interface.hh" |
23 #include "lookup.hh" | 23 #include "lookup.hh" |
24 #include "output-def.hh" | 24 #include "output-def.hh" |
25 #include "paper-column.hh" | 25 #include "paper-column.hh" |
26 #include "moment.hh" | 26 #include "moment.hh" |
27 #include "spanner.hh" | 27 #include "spanner.hh" |
28 | 28 #include "text-interface.hh" |
29 /* | |
30 TODO: should extract hyphen dimensions or hyphen glyph from the | |
31 font. | |
32 */ | |
33 | 29 |
34 MAKE_SCHEME_CALLBACK (Lyric_hyphen, print, 1); | 30 MAKE_SCHEME_CALLBACK (Lyric_hyphen, print, 1); |
35 SCM | 31 SCM |
36 Lyric_hyphen::print (SCM smob) | 32 Lyric_hyphen::print (SCM smob) |
37 { | 33 { |
38 Spanner *me = unsmob<Spanner> (smob); | 34 Spanner *me = unsmob<Spanner> (smob); |
39 Drul_array<Item *> bounds (me->get_bound (LEFT), | 35 Drul_array<Item *> bounds (me->get_bound (LEFT), |
40 me->get_bound (RIGHT)); | 36 me->get_bound (RIGHT)); |
41 | 37 |
42 if (bounds[LEFT]->break_status_dir () | 38 if (bounds[LEFT]->break_status_dir () |
43 && (Paper_column::when_mom (bounds[LEFT]) | 39 && (Paper_column::when_mom (bounds[LEFT]) |
44 == Paper_column::when_mom (bounds[RIGHT]->get_column ()))) | 40 == Paper_column::when_mom (bounds[RIGHT]->get_column ()))) |
45 return SCM_EOL; | 41 return SCM_EOL; |
46 | 42 |
47 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS); | 43 Grob *common = bounds[LEFT]->common_refpoint (bounds[RIGHT], X_AXIS); |
48 | 44 |
49 Interval span_points; | 45 Interval span_points; |
50 for (LEFT_and_RIGHT (d)) | 46 for (LEFT_and_RIGHT (d)) |
51 { | 47 { |
52 Interval iv = Axis_group_interface::generic_bound_extent (bounds[d], commo n, X_AXIS); | 48 Interval iv = Axis_group_interface::generic_bound_extent (bounds[d], commo n, X_AXIS); |
53 | 49 |
54 span_points[d] = iv.is_empty () | 50 span_points[d] = iv.is_empty () |
55 ? bounds[d]->relative_coordinate (common, X_AXIS) | 51 ? bounds[d]->relative_coordinate (common, X_AXIS) |
56 : iv[-d]; | 52 : iv[-d]; |
57 } | 53 } |
58 | 54 |
55 bool use_markup = to_boolean (me->get_property ("use-markup")); | |
dak
2017/09/14 09:34:03
That property seems spurious. Why not just use th
knupero
2017/09/14 10:57:30
Ok. I uploaded a revised version.
| |
59 Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness")); | 56 Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness")); |
60 Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt; | 57 Real th = robust_scm2double (me->get_property ("thickness"), 1) * lt; |
61 Real font_size_step = robust_scm2double (me->get_property ("font-size"), 0.0); | 58 Real font_size_step = robust_scm2double (me->get_property ("font-size"), 0.0); |
62 Real h = robust_scm2double (me->get_property ("height"), 0.5) | 59 Real h = robust_scm2double (me->get_property ("height"), 0.5) |
63 * pow (2.0, font_size_step / 6.0); | 60 * pow (2.0, font_size_step / 6.0); |
64 | 61 |
65 // interval? | 62 // interval? |
66 | 63 |
67 Real dash_period = robust_scm2double (me->get_property ("dash-period"), 1.0); | 64 Real dash_period = robust_scm2double (me->get_property ("dash-period"), 1.0); |
68 Real dash_length = robust_scm2double (me->get_property ("length"), .5); | 65 Real dash_length = robust_scm2double (me->get_property ("length"), .5); |
(...skipping 21 matching lines...) Expand all Loading... | |
90 /* | 87 /* |
91 If there is not enough space, the hyphen should disappear, but not | 88 If there is not enough space, the hyphen should disappear, but not |
92 at the end of the line. | 89 at the end of the line. |
93 */ | 90 */ |
94 if (space_left < 0.0 | 91 if (space_left < 0.0 |
95 && !bounds[RIGHT]->break_status_dir ()) | 92 && !bounds[RIGHT]->break_status_dir ()) |
96 return SCM_EOL; | 93 return SCM_EOL; |
97 | 94 |
98 space_left = max (space_left, 0.0); | 95 space_left = max (space_left, 0.0); |
99 | 96 |
100 Box b (Interval (0, dash_length), Interval (h, h + th)); | |
101 Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt)); | |
102 | |
103 Stencil total; | 97 Stencil total; |
104 for (int i = 0; i < n; i++) | 98 for (int i = 0; i < n; i++) |
105 { | 99 { |
106 Stencil m (dash_mol); | 100 if (use_markup) { |
107 m.translate_axis (span_points[LEFT] + i * dash_period + | 101 SCM stc_scm = Text_interface::print (smob); |
108 space_left / 2, X_AXIS); | 102 Stencil *stc = unsmob<Stencil> (stc_scm); |
109 total.add_stencil (m); | 103 Stencil gl (*stc); |
110 if (whiteout > 0.0 ) | 104 Real glxl = gl.extent (X_AXIS)[LEFT]; |
111 { | 105 Real glxr = gl.extent (X_AXIS)[RIGHT]; |
112 Box c (Interval (0, dash_length + 2 * whiteout * lt), | 106 Real glyu = gl.extent (Y_AXIS)[UP]; |
113 Interval (h - whiteout * lt, h + th + whiteout * lt)); | 107 Real glyd = gl.extent (Y_AXIS)[DOWN]; |
114 Stencil w (Lookup::round_filled_box (c, 0.8 * lt)); | 108 Real disp = ( glxr + glxl - dash_length ) / 2; |
115 w = w.in_color (1.0, 1.0, 1.0); | 109 gl.translate_axis (span_points[LEFT] + i * dash_period + |
116 w.translate_axis (span_points[LEFT] + i * dash_period + | 110 space_left / 2 - disp, X_AXIS); |
117 space_left / 2 - whiteout * lt, X_AXIS); | 111 gl.translate_axis (h, Y_AXIS); |
118 total.add_stencil (w); | 112 total.add_stencil (gl); |
119 } | 113 if (whiteout > 0.0 ) |
114 { | |
115 Box c (Interval (glxl - whiteout * lt, glxr + whiteout * lt), | |
116 Interval (glyd - whiteout * lt, glyu + whiteout * lt )); | |
117 Stencil w (Lookup::round_filled_box (c, 0.8 * lt)); | |
118 w = w.in_color (1.0, 1.0, 1.0); | |
119 w.translate_axis (span_points[LEFT] + i * dash_period + | |
120 space_left / 2 - disp , X_AXIS); | |
121 w.translate_axis (h, Y_AXIS); | |
122 total.add_stencil (w); | |
123 } | |
124 } else { | |
125 Box b (Interval (0, dash_length), Interval (h, h + th)); | |
126 Stencil dash_mol (Lookup::round_filled_box (b, 0.8 * lt)); | |
127 Stencil m (dash_mol); | |
128 m.translate_axis (span_points[LEFT] + i * dash_period + | |
129 space_left / 2, X_AXIS); | |
130 total.add_stencil (m); | |
131 if (whiteout > 0.0 ) | |
132 { | |
133 Box c (Interval (0, dash_length + 2 * whiteout * lt), | |
134 Interval (h - whiteout * lt, h + th + whiteout * lt)); | |
135 Stencil w (Lookup::round_filled_box (c, 0.8 * lt)); | |
136 w = w.in_color (1.0, 1.0, 1.0); | |
137 w.translate_axis (span_points[LEFT] + i * dash_period + | |
138 space_left / 2 - whiteout * lt, X_AXIS); | |
139 total.add_stencil (w); | |
140 } | |
141 } | |
120 } | 142 } |
121 | 143 |
122 total.translate_axis (-me->relative_coordinate (common, X_AXIS), X_AXIS); | 144 total.translate_axis (-me->relative_coordinate (common, X_AXIS), X_AXIS); |
123 return total.smobbed_copy (); | 145 return total.smobbed_copy (); |
124 } | 146 } |
125 | 147 |
126 MAKE_SCHEME_CALLBACK (Lyric_hyphen, set_spacing_rods, 1); | 148 MAKE_SCHEME_CALLBACK (Lyric_hyphen, set_spacing_rods, 1); |
127 SCM | 149 SCM |
128 Lyric_hyphen::set_spacing_rods (SCM smob) | 150 Lyric_hyphen::set_spacing_rods (SCM smob) |
129 { | 151 { |
(...skipping 11 matching lines...) Expand all Loading... | |
141 } | 163 } |
142 | 164 |
143 if (r.item_drul_[LEFT] | 165 if (r.item_drul_[LEFT] |
144 && r.item_drul_[RIGHT]) | 166 && r.item_drul_[RIGHT]) |
145 r.add_to_cols (); | 167 r.add_to_cols (); |
146 | 168 |
147 return SCM_UNSPECIFIED; | 169 return SCM_UNSPECIFIED; |
148 } | 170 } |
149 | 171 |
150 ADD_INTERFACE (Lyric_hyphen, | 172 ADD_INTERFACE (Lyric_hyphen, |
151 "A centered hyphen is simply a line between lyrics used to" | 173 "A centered hyphen is by default a line between lyrics used to" |
152 " divide syllables.", | 174 " divide syllables. But lilypond also can use the hyphen glyph" |
175 " of the lyrics font or an arbitrary markup.", | |
153 | 176 |
154 /* properties */ | 177 /* properties */ |
155 "dash-period " | 178 "dash-period " |
156 "height " | 179 "height " |
157 "length " | 180 "length " |
158 "minimum-distance " | 181 "minimum-distance " |
159 "minimum-length " | 182 "minimum-length " |
160 "padding " | 183 "padding " |
184 "text " | |
161 "thickness " | 185 "thickness " |
186 "use-markup " | |
162 ); | 187 ); |
OLD | NEW |