Skip to main content

try_shy_break

Function try_shy_break 

Source
pub(crate) fn try_shy_break(
    word: &Word,
    max_prefix_width: f32,
    fallbacks: &[EmbeddedFontId],
) -> Option<ShyBreak>
Expand description

Try to break word at the latest SHY offset whose prefix-plus- visible-hyphen fits in max_prefix_width. Returns None if no valid offset fits. Offsets equal to 0 or word.text.len() (leading / trailing SHY) are ignored, matching the rule that a break must produce a non-empty visible prefix and a non-empty suffix. Consecutive duplicate offsets (e.g. a\u{AD}\u{AD}b[1, 1]) are deduped on the fly.

Re-shapes both halves through shape_with_fallback so the resulting Word::width_pt matches the post-shape subrun advances exactly; the cheap text_width estimate used during the fit search may differ from the shaped width when fallback splits the run, so the shaped sum is the authoritative value and is re-checked against max_prefix_width before the candidate is accepted.