gfx/line_break.h
Where a line of text may end: the Unicode Line Breaking Algorithm (UAX #14).
#include <sonore/gfx/line_break.h>- 2other declarations
- Guides: The native editor
On this page
Design notes
Why spaces are not enough
Chinese and Japanese have no spaces: a line may end between almost any two ideographs, though not before a closing bracket or a small kana. A hyphen is a place to break after; "$12.50" and "(s)" are not places to break at all; a letter and its accents are one unit, and so is an emoji with its skin tone. Thai, Lao, Khmer and Myanmar have no spaces between words and may not be broken inside one. Wrapping at spaces alone runs a CJK line off its panel and cuts others where no reader would.
What is here
The rules LB1 to LB31 as Unicode 15.0 gives them, with LB1's default resolution and, for numbers, the tailoring UAX #14 gives as Example 7 -- "$(12.35)" and "12.54%" kept whole -- which is what Unicode's own test assumes. That resolution has no dictionary, so a Thai or Khmer word is not split -- they break at spaces, and Font::wrapText breaks a word longer than its line at its clusters. Checked against Unicode's LineBreakTest: all of its cases pass; a sample of it is in tests/data/linebreak.
Functions 1
- fn
inline std::vector<LineBreak> findLineBreaks(const uint32_t* text, size_t n)The line breaks ofgfx::findLineBreaks · line_break.h:712text, one for each of its n + 1 boundaries: [i] is the one before character i. Never at the start (LB2), always at the end (LB3), after a hard line break mandatory.
Enums 1
- enum
enum class LineBreak : uint8_tWhether a line may end before a character.gfx::LineBreak · line_break.h:701