Module typesetters.mixins.shaping

Shaping mixin for the typesetter.

Some code in this file comes from SILE's core typesetter.

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

This file is part of re·sil·ient, a set of extensions to SILE.

License: MIT. Copyright (c) 2025 Omikhkeia / Didier Willis

This mixin provides methods for shaping unshaped nodes in a node list, with support for automated italic correction (heuristic).

Pre-requisites:

  • The properties checked on shaped nodes assume the harfbuzz (default) shaper,

Local Functions

getLastShape (nodelist) Extract the last shaped item from a node list.
getFirstShape (nodelist) Extract the first shaped item from a node list.
fromItalicCorrection (precShape, curShape, punctSpaceWidth) Compute the italic correction when switching from italic to non-italic.
toItalicCorrection (precShape, curShape, punctSpaceWidth) Compute the italic correction when switching from non-italic to italic.
isItalicLike (nnode) Check if a shaped node is in italic-like style

Class typesetter

typesetter:shapeAll (nodelist) Shape all unshaped nodes in a list.


Local Functions

getLastShape (nodelist)
Extract the last shaped item from a node list.

Parameters:

  • nodelist table A list of nodes

Returns:

  1. table The last shaped item
  2. boolean Whether the list contains a glue after the last shaped item
  3. number or nil The width of a punctuation kern after the last shaped item, if any
getFirstShape (nodelist)
Extract the first shaped item from a node list.

Parameters:

  • nodelist table A list of nodes

Returns:

  1. table The first shaped item
  2. boolean Whether the list contains a glue before the first shaped item
  3. number or nil The width of a punctuation kern before the first shaped item, if any
fromItalicCorrection (precShape, curShape, punctSpaceWidth)
Compute the italic correction when switching from italic to non-italic.

Automated italic correction is at best heuristics.

The strong assumption is that italic is slanted to the right.

Thus, the part of the character that goes beyond its width is usually maximal at the top of the glyph. E.g. consider a "f", that would be the top hook extent.

Pathological cases exist, such as fonts with a Q with a long tail, but these will rarely occur in usual languages. For instance, Klingon's "QaQ" might be an issue, but there's not much we can do...

Another assumption is that we can distribute that extent in proportion with the next character's height. This might not work that well with non-Latin scripts.

Finally, there are cases where a punctuation character introduced an extra space (as in French typography for high punctuation marks and guillemets), and take it into account for compensating the italic correction. (That is, we only apply a correction if it exceeds that extra space.)

Parameters:

  • precShape table The last shaped item (italic)
  • curShape table The first shaped item (non-italic)
  • punctSpaceWidth number, nil or false The width of a punctuation kern between the two items, if applicable
toItalicCorrection (precShape, curShape, punctSpaceWidth)
Compute the italic correction when switching from non-italic to italic.

Same assumptions as fromItalicCorrection(), but on the starting side of the glyph.

Parameters:

  • precShape table The last shaped item (non-italic)
  • curShape table The first shaped item (italic)
  • punctSpaceWidth number, nil or false The width of a punctuation kern between the two items, if applicable
isItalicLike (nnode)
Check if a shaped node is in italic-like style

Parameters:

  • nnode SILE.node The node to check

Returns:

    boolean

Class typesetter

typesetter:shapeAll (nodelist)
Shape all unshaped nodes in a list.

This also inserts italic correction nodes if needed (and if enabled).

Parameters:

  • nodelist table A list of nodes, some of which may be unshaped

Returns:

    table A new list of nodes
generated by LDoc 1.5.0 Last updated 2025-09-14 22:28:52