use super::{
effective_text_for_metrics, estimate_text_width_exact, ComposedLine, ResolvedStyleSet,
};
pub(super) fn plain_trailing_width(
line: &ComposedLine,
styles: &ResolvedStyleSet,
limit: usize,
) -> f64 {
let mut remaining = limit;
let mut width = 0.0;
for run in line.runs.iter().rev() {
if remaining == 0
|| run.inserted_control_text
|| run.char_overlap.is_some()
|| run.display_text.is_some()
{
break;
}
let text = effective_text_for_metrics(run);
let count = text
.chars()
.rev()
.take_while(|&c| c == ' ')
.count()
.min(remaining);
if count == 0 {
break;
}
let style = run.text_style(styles);
if style.underline != crate::renderer::UnderlineType::None || style.strikethrough {
break;
}
width += estimate_text_width_exact(&" ".repeat(count), &style);
remaining -= count;
if count != text.chars().count() {
break;
}
}
width
}