use super::TextStyle;
pub(crate) fn family(style: &TextStyle, text: &str) -> Option<&'static str> {
let mut chars = text.chars();
let ch = chars.next()?;
if chars.next().is_some() || !matches!(ch, '\u{2024}' | '\u{2027}') {
return None;
}
let decision = super::layout::char_width_decision(&[ch], &[1], 0, style, true);
if !matches!(
decision.width_source,
"metricGlyphFallback" | "declaredGlyphFallbackMetric"
) {
return None;
}
let metric = decision.metric?.metric.name;
if decision.width_source == "declaredGlyphFallbackMetric"
&& style.glyph_fallback_advance_explicit
{
let declared = style
.font_family
.split(',')
.nth(1)
.map(|name| name.trim().trim_matches(['\'', '"']));
if !declared.is_some_and(|name| name.eq_ignore_ascii_case(metric)) {
return None;
}
}
Some(metric)
}
pub(crate) fn canvas_descriptor(style: &TextStyle, text: &str) -> Option<String> {
let family = family(style, text)?;
let mut paint_style = style.clone();
paint_style.font_family = family.to_owned();
Some(
super::canvas_text_font::CanvasTextFont::for_positioned_text(&paint_style, 0.0)
.descriptor()
.to_owned(),
)
}