2 hyphen-spanner.cc -- implement Hyphen_spanner
4 source file of the GNU LilyPond music typesetter
6 (c) 2003--2004 Han-Wen Nienhuys <hanwen@xs4all.nl>
14 #include "paper-def.hh"
15 #include "paper-column.hh"
18 #include "lyric-hyphen.hh"
21 MAKE_SCHEME_CALLBACK (Hyphen_spanner
,print
,1)
23 Hyphen_spanner::print (SCM smob
)
25 Spanner
* me
= unsmob_spanner (smob
);
26 Drul_array
<Item
*> bounds (me
->get_bound (LEFT
),
27 me
->get_bound (RIGHT
));
29 if (bounds
[LEFT
]->break_status_dir ()
30 && Paper_column::when_mom (bounds
[LEFT
]) == Paper_column::when_mom (bounds
[RIGHT
]->get_column ()))
33 Grob
* common
= bounds
[LEFT
]->common_refpoint (bounds
[RIGHT
], X_AXIS
);
39 Interval iv
= bounds
[d
]->extent (common
, X_AXIS
);
41 span_points
[d
] = iv
.is_empty ()
42 ? bounds
[d
]->relative_coordinate (common
, X_AXIS
)
45 while (flip (&d
) != LEFT
);
47 Real lt
= me
->get_paper ()->get_realvar (ly_symbol2scm ("linethickness"));
48 Real th
= robust_scm2double (me
->get_property ("thickness"), 1) * lt
;
49 Real h
= robust_scm2double (me
->get_property ("height"), 0.5);
53 Real dp
= robust_scm2double (me
->get_property ("dash-period"), 1.0);
54 Real dl
= robust_scm2double (me
->get_property ("length"), .5 );
59 Real l
= span_points
.length ();
60 int n
= int (ceil (l
/dp
- 0.5));
64 Real space_left
= l
- dl
- (n
-1)* dp
;
67 If there is not enough space, the hyphen should disappear, but not
68 at the end of the line.
71 && !bounds
[RIGHT
]->break_status_dir ())
74 space_left
= space_left
>? 0.0;
76 Box
b (Interval (0, dl
), Interval (h
,h
+th
));
77 Stencil
dash_mol (Lookup::round_filled_box (b
, 0.8 * lt
));
80 for (int i
= 0; i
< n
; i
++)
83 m
.translate_axis (span_points
[LEFT
] + i
* dp
+ space_left
/ 2, X_AXIS
);
84 total
.add_stencil (m
);
87 total
.translate_axis ( -me
->relative_coordinate (common
, X_AXIS
), X_AXIS
);
88 return total
.smobbed_copy ();
92 MAKE_SCHEME_CALLBACK (Hyphen_spanner
,set_spacing_rods
,1);
94 Hyphen_spanner::set_spacing_rods (SCM smob
)
96 Grob
*me
= unsmob_grob (smob
);
99 Spanner
*sp
= dynamic_cast<Spanner
*> (me
);
101 robust_scm2double (me
->get_property ("minimum-length"), 0);
106 r
.item_l_drul_
[d
] = sp
->get_bound (d
);
107 if (r
.item_l_drul_
[d
])
108 r
.distance_
+= r
.item_l_drul_
[d
]->extent (r
.item_l_drul_
[d
], X_AXIS
)[-d
];
110 while (flip (&d
) != LEFT
);
112 if (r
.item_l_drul_
[LEFT
]
113 && r
.item_l_drul_
[RIGHT
])
116 return SCM_UNSPECIFIED
;
119 ADD_INTERFACE (Hyphen_spanner
, "lyric-hyphen-interface",
120 "A centred hyphen is a simple line between lyrics used to divide syllables",
121 "thickness height dash-period minimum-length length");