foundrytools.utils package

foundrytools.utils.bits_tools module

foundrytools.utils.bits_tools.is_nth_bit_set(x: int, n: int) bool[source]

Check if the nth bit of an integer x is set.

Parameters:
  • x (int) – The number to check

  • n (int) – The bit to check

Returns:

True if the nth bit is set, False otherwise

Return type:

bool

foundrytools.utils.bits_tools.set_nth_bit(x: int, n: int) int[source]

Set the nth bit of an integer x to 1 and return the result.

Parameters:
  • x (int) – The number to modify

  • n (int) – The bit to set

Returns:

The number x with the nth bit set to 1

foundrytools.utils.bits_tools.unset_nth_bit(x: int, n: int) int[source]

Unset the nth bit of an integer x and return the result.

Parameters:
  • x (int) – The number to modify

  • n (int) – The bit to unset

Returns:

The number x with the nth bit unset

Return type:

int

foundrytools.utils.bits_tools.update_bit(num: int, pos: int, value: bool) int[source]

Handle a bitwise operation on an integer to set or unset a bit.

Parameters:
  • num (int) – The number to modify

  • pos (int) – The bit to modify

  • value (bool) – The value to set the bit to

Returns:

The number with the bit modified

Return type:

int

foundrytools.utils.misc module

foundrytools.utils.misc.restore_flavor(font: TTFont) Iterator[None][source]

This context manager is used to temporarily set the font flavor to None and restore it after operations that require the flavor to be None (e.g.: subroutinization or desubroutinization).

Parameters:

font (TTFont) – The TTFont object.

Returns:

A generator that yields.

Return type:

Iterator[None]

foundrytools.utils.path_tools module

foundrytools.utils.path_tools.get_temp_file_path(directory: str | Path | None = None) Path[source]

Returns a temporary file path.

Parameters:

directory (str | Path | None) – The directory to create the temporary file in.

Returns:

The temporary file path.

Return type:

Path