Skip to main content

LineBreakOverrideFn

Type Alias LineBreakOverrideFn 

Source
pub type LineBreakOverrideFn = dyn Fn(LineBreakContext) -> Option<bool> + Send + Sync;
Expand description

Line break opportunity override.

Called for each adjacent pair of Unicode code points in the text, in order, with a LineBreakContext describing the potential break.

Returning:

  • Some(true) : forces a line break opportunity between the pair
  • Some(false) : suppresses any opportunity
  • None : defers to the default (ICU) behavior

Mandatory breaks are unaffected (e.g. \n).

This is typically used to force preferential line breaking decisions when it comes to ASCII punctuation like /, -, etc. For example, to prevent break opportunities within “1/2”.

A separate use case is to match the line breaking behavior of existing systems such as web browsers. See CHROMIUM_LINE_BREAK_OVERRIDE for a ready-made override function that mirrors Chromium’s behavior.