Module typesetters.algorithms.bidi

Bidirectional text handling algorithm.

According to the Unicode Bidirectional Algorithm, most likely...

Original code from SILE

License: MIT Copyright (c) The SILE Organization / Simon Cozens

Adapted for re·sil·ient and the sile·nt typesetter

  • Minimal tweaks to some bidi functions (to take, for example, a direction instead of a typesetter, to reduce direct dependency)
  • Also modified to fit re·sil·ient's file structure, and to add some basic LDoc annotations.
  • Added an early return for empty nodelists.

Functions

splitNodelistIntoBidiRuns (nl, direction) Split a nodelist into bidirectional runs.
reorder (nl, direction) Reorder a nodelist according to the bidirectional algorithm.

Local Functions

reverse_portion (tbl, s, e) Reverse a portion of a table.
create_matrix (line, base_level) Create some transformation matrix.
reverse_each_node (nodelist) Reverse each hbox's items and glyphs in a nodelist.
nodeListToText (nl) Convert a nodelist to a text string.
splitNodeAtPos (n, splitstart, p) Split an unshaped node at a given position.


Functions

splitNodelistIntoBidiRuns (nl, direction)
Split a nodelist into bidirectional runs.

Parameters:

  • nl table List of nodes
  • direction string Base direction ("LTR" or "RTL")

Returns:

    table Nodelist split into runs
reorder (nl, direction)
Reorder a nodelist according to the bidirectional algorithm.

Parameters:

  • nl table List of shaped nodes
  • direction string Base direction ("LTR" or "RTL")

Returns:

    table Reordered list of nodes

Local Functions

reverse_portion (tbl, s, e)
Reverse a portion of a table.

Parameters:

  • tbl table The table to modify
  • s integer Start index
  • e integer End index (inclusive)

Returns:

    table A new table with the portion reversed
create_matrix (line, base_level)
Create some transformation matrix.

CODE SMELL: Do we ever call it with a base_level other than 0?

Parameters:

  • line table Something
  • base_level integer Some level

Returns:

    table A matrix
reverse_each_node (nodelist)
Reverse each hbox's items and glyphs in a nodelist.

Parameters:

  • nodelist table List of nodes
nodeListToText (nl)
Convert a nodelist to a text string.

It keeps track of the owner of each character, i.e., from which node each character came from, and its position in that node.

Parameters:

Returns:

  1. table Owners table
  2. table Text table
splitNodeAtPos (n, splitstart, p)
Split an unshaped node at a given position.

Parameters:

  • n SILE.types.node.unshaped Node to split
  • splitstart integer Start position
  • p integer Position

Returns:

  1. SILE.types.node.unshaped First part
  2. SILE.types.node.unshaped Second part
generated by LDoc 1.5.0 Last updated 2025-09-14 22:28:52