Refactor bidi and add reordering function

- Rename bidi-override enum to bidi-direction, including entries. This
  better reflects the general nature of it.
- Remove UTF-8-related bidi-functions, given it would be too complicated
  to reflect in an API and opens up some very difficult challenges.
- Rename *_preprocess to *_preprocess_paragraph and return the resolved
  paragraph embedding level as an optional out-parameter. This is the
  only way to meaningfully handle large chunks of text with paragraphs
  of different embedding levels.
- Separate the get_paragraph_level() function into two for
  isolated-paragraphs and whole paragraphs. This simplifies it a lot, as
  we don't have the crazy bool-flag-mess any more.
- Add a grapheme_bidirectional_reorder_line function that directly
  operates on preprocessed data and returns the reordered string without
  any additionally necessary buffering. For this the
  get_line_embedding_levels had to be made a bit more general to allow
  different ways of writing the levels into the output.
  This function makes use of the mirror-LUT and has a small section
  still commented out regarding the proper inversion of grapheme
  clusters that will need more investigation.

Signed-off-by: Laslo Hunhold <>
3 files changed