The foundrytools.core.tables module contains classes for handling fontTools.ttLib.tables objects.

Each table wrapper provides a set of methods for accessing and modifying the table data.

from foundrytools import Font

font = Font("path/to/font.otf")
font.t_cff_.round_coordinates()
font.os_2.recalc_unicode_ranges()

Wrapped tables are accessible via the table property of the table wrapper.

from foundrytools import Font

font = Font("path/to/font.otf")

# Access the wrapped ``fontTools.ttLib.tables._c_m_a_p.table__c_m_a_p`` object
font.t_cmap.table.buildReversed()

foundrytools.core.tables.cff_ module

class foundrytools.core.tables.cff_.CFFTable(ttfont: TTFont)[source]

Bases: DefaultTbl

A class that wraps and manages the CFF table of a font, providing methods to manipulate hinting data, font names, and glyph contours.

_find_replace_in_font_names(old_string: str, new_string: str) None[source]
_find_replace_in_top_dict(old_string: str, new_string: str) None[source]
_restore_hinting_data() None[source]

Restore the original hinting data to the CFF table.

_set_cff_font_names(font_name: str) None[source]

Sets the cff.fontNames value.

Parameters:

font_name (str) – The font name to set.

_set_top_dict_names(names: dict[str, str]) None[source]

Sets the names of the CFF table.

Parameters:

names (dict[str, str]) – The names to set.

correct_contours(remove_hinting: bool = True, ignore_errors: bool = True, remove_unused_subroutines: bool = True, min_area: int = 25, drop_hinting_data: bool = False) set[str][source]

Corrects contours of the CFF table by removing overlaps, correcting the direction of the contours, and removing tiny paths.

Parameters:
  • remove_hinting (bool) – Whether to remove hinting from the font if one or more glyphs are modified.

  • ignore_errors (bool) – Whether to ignore skia pathops errors while correcting contours.

  • remove_unused_subroutines (bool) – Whether to remove unused subroutines from the font.

  • min_area (int) – The minimum area of a contour to be considered. Default is 25.

  • drop_hinting_data (bool) – If True, the hinting data will be removed from the font.

Returns:

A set of glyph names that were modified.

Return type:

set[str]

del_names(**kwargs: dict[str, str]) None[source]

Deletes names from topDictIndex[0] using the provided keyword arguments.

Parameters:

kwargs (dict[str, str]) – The names to delete from the CFF table TopDict.

find_replace(old_string: str, new_string: str) None[source]

Find and replace a string in the CFF table.

Parameters:
  • old_string (str) – The string to find.

  • new_string (str) – The string to replace the old string with.

get_hinting_data() dict[str, Any][source]

Returns the hinting data from the CFF table.

Returns:

The hinting data.

Return type:

dict[str, Any]

property private_dict: PrivateDict

Returns the private field of the CFF table.

Returns:

The private field of the CFF table.

Return type:

PrivateDict

remove_hinting(drop_hinting_data: bool = False) None[source]

Removes hinting data from a PostScript font.

Parameters:

drop_hinting_data (bool) – If True, the hinting data will be removed from the font.

round_coordinates(drop_hinting_data: bool = False) set[str][source]

Round the coordinates of the font’s glyphs using the RoundingPen.

Returns:

A set of glyph names whose coordinates were rounded.

Return type:

set[str]

set_hinting_data(**kwargs: dict[str, Any]) None[source]

Sets the hinting data in the CFF table.

Parameters:

kwargs (dict[str, Any]) – The hinting data to set.

set_names(**kwargs: dict[str, str]) None[source]

Sets the cff.fontNames[0] and topDictIndex[0] values.

Parameters:

kwargs (dict[str, str]) – The values to set in the CFF table.

property table: table_C_F_F_

The wrapped table_C_F_F_ object.

property top_dict: TopDict

Returns the topDictIndex field of the CFF table.

Returns:

The topDictIndex field of the CFF table.

Return type:

TopDict

foundrytools.core.tables.cmap module

class foundrytools.core.tables.cmap.CmapTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools cmap table.

add_missing_nbsp() None[source]

Fixes the missing non-breaking space glyph by double mapping the space glyph.

get_all_codepoints() set[int][source]

Returns all the codepoints in the cmap table.

Returns:

A set of codepoints

Return type:

set[int]

get_unmapped_glyphs() list[str][source]

Returns all the unmapped glyphs in the cmap table.

Returns:

A set of glyph names

Return type:

set[str]

property is_modified: bool

Returns whether the cmap table has been modified.

Returns:

Whether the cmap table has been modified.

Return type:

bool

rebuild_character_map(remap_all: bool = False) tuple[list[tuple[int, str]], list[tuple[int, str, str]]][source]

Rebuild the character map of the font.

Parameters:

remap_all (bool) – Whether to remap all glyphs. If False, only the unmapped glyphs will be remapped.

Returns:

A tuple containing the remapped and duplicate glyphs.

Return type:

tuple[list[tuple[int, str]], list[tuple[int, str, str]]]

property table: table__c_m_a_p

The wrapped table__c_m_a_p table object.

foundrytools.core.tables.default module

class foundrytools.core.tables.default.DefaultTbl(ttfont: TTFont, table_tag: str)[source]

Bases: Generic[T]

Manages font table data with functionality for detecting modifications and setting bits.

This class allows you to interact with a specific table in a font’s data to determine if the table has been modified and to set specific bits within the table’s fields.

property is_modified: bool

Checks if the table has been modified.

By default, we assume that when the table has been accessed, it has been modified. Subclasses should override this method to provide a more accurate check.

Returns:

True

Return type:

bool

set_bit(field_name: str, pos: int, value: bool) None[source]

Sets a specific bit in a field of the table.

Parameters:
  • field_name (str) – The field name.

  • pos (int) – The position of the bit to set.

  • value (bool) – The value to set.

property table: T

Thw wrapped table object.

property ttfont: TTFont

Returns the TTFont object to which the table belongs.

Returns:

The TTFont object.

Return type:

TTFont

foundrytools.core.tables.fvar module

class foundrytools.core.tables.fvar.FvarTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools fvar table.

property table: table__f_v_a_r

Thw wrapped table__f_v_a_r table object.

foundrytools.core.tables.gdef module

class foundrytools.core.tables.gdef.GdefTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class is a wrapper for the GDEF table.

property table: table_G_D_E_F_

The wrapped table_G_D_E_F_ table object.

foundrytools.core.tables.glyf module

class foundrytools.core.tables.glyf.GlyfTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools glyf table.

correct_contours(remove_hinting: bool = True, ignore_errors: bool = True, min_area: int = 25) set[str][source]

Corrects contours of the glyf table by removing overlaps, correcting the direction of the contours, and removing tiny paths.

Parameters:
  • remove_hinting (bool) – Whether to remove hinting from the font if one or more glyphs are modified.

  • ignore_errors (bool) – Whether to ignore skia pathops errors while correcting contours.

  • min_area (int) – The minimum area of a contour to be considered. Default is 25.

Returns:

A set of glyph names that were modified.

Return type:

set[str]

decompose_all() set[str][source]

Decompose all composite glyphs.

Returns:

A set of glyph names that were decomposed

Return type:

set[str]

decompose_glyph(glyph_name: str) None[source]

Decompose the components of a given glyph name.

Parameters:

glyph_name (str) – The name of the glyph to decompose.

decompose_transformed() set[str][source]

Decompose composite glyphs that have transformed components.

remove_duplicate_components() set[str][source]

Remove duplicate components from composite glyphs.

Returns:

A set of glyph names that were fixed.

Return type:

set[str]

property table: table__g_l_y_f

Thw wrapped table__g_l_y_f table object.

foundrytools.core.tables.gsub module

class foundrytools.core.tables.gsub.GsubTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools GSUB table.

get_feature_tags() set[str][source]

Returns a list of all the feature tags in the font’s GSUB table.

Returns:

The feature tags.

Return type:

list[str]

get_ui_name_ids() set[int][source]

Returns a set of all the UI name IDs in the font’s GSUB table.

Returns:

The UI name IDs.

Return type:

set[int]

remap_ui_name_ids(name_ids_map: dict[int, int]) None[source]

Remap the UI name IDs in the GSUB table.

Parameters:

name_ids_map (dict[int, int]) – A dictionary with the old and new UI name IDs.

rename_feature(feature_tag: str, new_feature_tag: str) bool[source]

Rename a GSUB feature.

Example:

>>> from foundrytools import Font
>>> font = Font("path/to/font.ttf")
>>> font.t_gsub.rename_feature("smcp", "ss20")
>>> font.save("path/to/font.ttf")
Parameters:
  • feature_tag (str) – The feature tag to rename.

  • new_feature_tag (str) – The new feature tag.

Returns:

True if the feature was renamed, False otherwise.

Return type:

bool

sort_feature_records() None[source]

Sorts the feature records in the GSUB table by tag.

property table: table_G_S_U_B_

The wrapped table_G_S_U_B_ table object.

foundrytools.core.tables.head module

class foundrytools.core.tables.head.HeadTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools head table.

property created_timestamp: int

A property with getter and setter for the created field of the head table.

Returns:

The created timestamp.

Return type:

int

property font_revision: float

A property with getter and setter for the fontRevision field of the head table.

Returns:

The font revision value.

Return type:

float

property is_modified: bool

A property that returns True if the head table has been modified, False otherwise.

Returns:

True if the head table has been modified, False otherwise.

Return type:

bool

property modified_timestamp: int

A property with getter and setter for the modified field of the head table.

Returns:

The modified timestamp.

Return type:

int

property table: table__h_e_a_d

The wrapped table__h_e_a_d table object.

property units_per_em: int

A read-only property for the unitsPerEm field of the head table.

Returns:

The units per em value.

Return type:

int

property x_max: int

A property with getter and setter for the xMax field of the head table.

Returns:

The xMax value.

Return type:

int

property x_min: int

A property with getter and setter for the xMin field of the head table.

Returns:

The xMin value.

Return type:

int

property y_max: int

A property with getter and setter for the yMax field of the head table.

Returns:

The yMax value.

Return type:

int

property y_min: int

A property with getter and setter for the yMin field of the head table.

Returns:

The yMin value.

Return type:

int

class foundrytools.core.tables.head.MacStyle(head_table: HeadTable)[source]

Bases: object

A wrapper class for the macStyle field of the head table.

property bold: bool

A property with getter and setter for bit 0 (BOLD) in the macStyle field of the head table.

Returns:

True if bit 0 is set, False otherwise.

Return type:

bool

property italic: bool

A property with getter and setter for bit 1 (ITALIC) in the macStyle field of the head table.

Returns:

True if bit 1 is set, False otherwise.

Return type:

bool

foundrytools.core.tables.hhea module

class foundrytools.core.tables.hhea.HheaTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools hhea tables.

property advance_width_max: int

A property with getter and setter for the advanceWidthMax field of the hhea table.

Returns:

The advanceWidthMax value.

Return type:

int

property ascent: int

A property with getter and setter for the ascent field of the hhea table.

Returns:

The ascent value.

Return type:

int

calc_caret_slope_rise(italic_angle: int | float | None = None) int[source]

Calculate the caretSlopeRise field of the hhea table.

Parameters:

italic_angle (Optional[Union[int, float]]) – The italic to use for the calculation. If None, the italic angle from the post table will be used.

Returns:

The caret slope rise value.

Return type:

int

calc_caret_slope_run(italic_angle: int | float | None = None) int[source]

Calculate the caretSlopeRun field of the hhea table.

Parameters:

italic_angle (Optional[Union[int, float]]) – The italic to use for the calculation. If None, the italic angle from the post table will be used.

Returns:

The caret slope run value.

Return type:

int

property caret_offset: int

A property with getter and setter for the caretOffset field of the hhea table.

Returns:

The caretOffset value.

Return type:

int

property caret_slope_rise: int

A property with getter and setter for the caretSlopeRise field of the hhea table.

Returns:

The caretSlopeRise value.

Return type:

int

property caret_slope_run: int

A property with getter and setter for the caretSlopeRun field of the hhea table.

Returns:

The caretSlopeRun value.

Return type:

int

property descent: int

A property with getter and setter for the descent field of the hhea table.

Returns:

The descent value.

Return type:

int

property is_modified: bool

A read-only property that returns whether the hhea table has been modified.

Returns:

Whether the hhea table has been modified.

Return type:

bool

property line_gap: int

A property with getter and setter for the lineGap field of the hhea table.

Returns:

The lineGap value.

Return type:

int

property metric_data_format: int

A read-only property for the metricDataFormat field of the hhea table.

Returns:

The metricDataFormat value.

Return type:

int

property min_left_side_bearing: int

A read-only property for the minLeftSideBearing field of the hhea table.

Returns:

The minLeftSideBearing value.

Return type:

int

property min_right_side_bearing: int

A read-only property for the minRightSideBearing field of the hhea table.

Returns:

The minRightSideBearing value.

Return type:

int

property number_of_hmetrics: int

A read-only property for the numberOfHMetrics field of the hhea table.

Returns:

The numberOfHMetrics value.

Return type:

int

property run_rise_angle: float

Calculate the slope angle by dividing the caret slope run by the caret slope rise.

Returns:

The slope angle in degrees.

Return type:

float

property table: table__h_h_e_a

The wrapped table__h_h_e_a table object.

property x_max_extent: int

A read-only property for the xMaxExtent field of the hhea table.

Returns:

The xMaxExtent value.

Return type:

int

foundrytools.core.tables.hmtx module

class foundrytools.core.tables.hmtx.HmtxTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools hmtx table.

fix_non_breaking_space_width() bool[source]

Sets the width of the non-breaking space glyph to be the same as the space glyph.

Raises:

ValueError – If the space or non-breaking space glyphs do not exist.

property table: table__h_m_t_x

The wrapped table__h_m_t_x table object.

foundrytools.core.tables.kern module

class foundrytools.core.tables.kern.KernTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools kern table.

remove_unmapped_glyphs() bool[source]

Removes unmapped glyphs from the kern table.

property table: table__k_e_r_n

The wrapped table__k_e_r_n table object.

foundrytools.core.tables.name module

class foundrytools.core.tables.name.NameTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools name table.

_get_name_ids_for_filter(name_ids_to_process: Iterable | None = None, name_ids_to_skip: Iterable | None = None) set[int][source]

Returns a set of name IDs to be used for filtering.

append_prefix_suffix(name_ids: tuple[int], platform_id: int | None = None, language_string: str | None = None, prefix: str | None = None, suffix: str | None = None) None[source]

Appends a prefix, a suffix, or both to the NameRecords that match the nameID, platformID, and language string.

Parameters:
  • name_ids (tuple[int]) – A tuple of name IDs to process.

  • platform_id (Optional[int]) – The platform ID of the name records to process. Defaults to None, which means that NameRecords from all platforms are processed. If 1, only NameRecords with platformID 1 (Macintosh) are processed. If 3, only NameRecords with platformID 3 (Windows) are processed.

  • language_string (Optional[str]) – The language of the name records to process. Defaults to None, which means that NameRecords in all languages are processed.

  • prefix (Optional[str]) – The prefix to append to the NameRecords. Defaults to None.

  • suffix – The suffix to append to the NameRecords. Defaults to None.

build_full_font_name(platform_id: int | None = None) None[source]

Build the NameID 4 (Full Font Name) record based on the family name and subfamily name.

Parameters:

platform_id (Optional[int]) – The platform ID of the name record. Defaults to None. If None, the NameRecord is added to both platforms. If 1, the NameRecord is added to the Macintosh platform. If 3, the NameRecord is added to the Windows platform.

build_mac_names() None[source]

Build the Macintosh-specific NameRecords 1 (Font Family Name), 2 (Font Subfamily Name), 4 (Full Font Name), 5 (Version String), and 6 (PostScript Name).

build_postscript_name(platform_id: int | None = None) None[source]

Build the NameID 6 (PostScript Name) record based on the PostScript name.

Parameters:

platform_id (Optional[int]) – The platform ID of the name record. Defaults to None. If None, the NameRecord is added to both platforms. If 1, the NameRecord is added to the Macintosh platform. If 3, the NameRecord is added to the Windows platform.

build_unique_identifier(platform_id: int | None = None, alternate: bool = False) None[source]

Build the NameID 3 (Unique Font Identifier) record based on the font revision, vendor ID, and PostScript name.

Parameters:
  • platform_id (Optional[int]) – The platform ID of the name record. Defaults to None. If None, the NameRecord is added to both platforms. If 1, the NameRecord is added to the Macintosh platform. If 3, the NameRecord is added to the Windows platform.

  • alternate (bool) – Whether to build an alternate unique identifier. Defaults to False. If False, the unique identifier is built based on the font revision, vendor ID, and PostScript name. If True, the unique identifier is built based on the manufacturer name, family name, subfamily name, and year created.

build_version_string(platform_id: int | None = None) None[source]

Build the NameID 5 (Version String) record based on the font revision.

Parameters:

platform_id (Optional[int]) – The platform ID of the name record. Defaults to None. If None, the NameRecord is added to both platforms. If 1, the NameRecord is added to the Macintosh platform. If 3, the NameRecord is added to the Windows platform.

filter_names(name_ids: set[int] | None = None, platform_id: int | None = None, plat_enc_id: int | None = None, lang_id: int | None = None, lang_string: str | None = None) list[NameRecord][source]

Filters NameRecords based on the given parameters.

Parameters:
  • name_ids (Optional[set[int]]) – A set of NameIDs to filter. Defaults to None, which means that all NameIDs are filtered.

  • platform_id (Optional[int]) – The platform ID of the NameRecords to filter. Defaults to None, which means that NameRecords from all platforms are filtered. If 1, only NameRecords with platformID 1 (Macintosh) are filtered. If 3, only NameRecords with platformID 3 (Windows) are filtered.

  • plat_enc_id (Optional[int]) – The platform encoding ID of the NameRecords to filter. Defaults to None, which means that NameRecords from all platform encoding IDs are filtered.

  • lang_id (Optional[int]) – The language ID of the NameRecords to filter. Defaults to None, which means that NameRecords from all languages are filtered.

  • lang_string (Optional[str]) – The language string of the NameRecords to filter. Defaults to None, which means that NameRecords from all languages are filtered.

Returns:

The filtered NameRecords.

Return type:

list[NameRecord]

find_replace(old_string: str, new_string: str, name_ids_to_process: tuple[int] | None = None, name_ids_to_skip: tuple[int] | None = None, platform_id: int | None = None) None[source]

Finds and replaces occurrences of a string in the specified NameRecords of the name table of a font.

Parameters:
  • old_string (str) – The string to find.

  • new_string (str) – The string to replace the old string with.

  • name_ids_to_process (Optional[tuple[int]]) – A tuple of name IDs to process. Defaults to None, which means that all name IDs are processed.

  • name_ids_to_skip (Optional[tuple[int]]) – A tuple of name IDs to skip. Defaults to None, which means that no name IDs are skipped.

  • platform_id (Optional[int]) – The platform ID of the name records to process. Defaults to None, which means that NameRecords from all platforms are processed. If 1, only NameRecords with platformID 1 (Macintosh) are processed. If 3, only NameRecords with platformID 3 (Windows) are processed.

get_best_family_name() str[source]

Returns the best family name from the name table. The best family name is converted to string to handle cases where the family name is None.

Returns:

The best family name.

Return type:

str

get_best_subfamily_name() str[source]

Returns the best subfamily name from the name table. The best subfamily name is converted to string to handle cases where the subfamily name is None.

Returns:

The best subfamily name.

Return type:

str

get_debug_name(name_id: int) str[source]

Returns the NameRecord string with the specified NameID. The NameRecord is converted to string to handle cases where the NameRecord is None.

Parameters:

name_id (int) – The NameID of the NameRecord.

Returns:

The debug name of the NameRecord.

Return type:

str

property is_modified: bool

Compiles the original and current name tables and compares them to determine if the table has been modified.

Returns:

Whether the name table has been modified.

Return type:

bool

remap_name_ids() dict[int, int][source]

Remaps the NameIDs of the NameRecords in the name table.

remove_empty_names() None[source]

Removes all empty NameRecords from the name table.

remove_mac_names() None[source]

Removes all Macintosh-specific NameRecords from the name table.

remove_names(name_ids: Iterable[int], platform_id: int | None = None, language_string: str | None = None) None[source]

Deletes the specified NameRecords from the name table of a font.

Parameters:
  • name_ids (Iterable[int]) – A list of NameIDs to remove.

  • platform_id (Optional[int]) – The platform ID of the NameRecords to remove. Defaults to None, which means that NameRecords from all platforms are removed. If 1, only NameRecords with platformID 1 (Macintosh) are removed. If 3, only NameRecords with platformID 3 (Windows) are removed.

  • language_string (Optional[str]) – The language of the NameRecords to remove. Defaults to None, which means that NameRecords in all languages are removed.

remove_unused_names() set[int][source]

Removes unused NameRecords from the name table.

set_name(name_id: int, name_string: str, platform_id: int | None = None, language_string: str = 'en') None[source]

Adds a NameRecord to the name table of a font.

Parameters:
  • name_id (int) – The NameID of the NameRecord.

  • name_string (str) – The string to add to the NameRecord.

  • platform_id (Optional[int]) – The platform ID of the NameRecord. Defaults to None. If None, the NameRecord is added to both platforms. If 1, the NameRecord is added to the Macintosh platform. If 3, the NameRecord is added to the Windows platform.

  • language_string (str) – The language of the NameRecord. Defaults to “en”.

strip_names() None[source]

Removes leading and trailing spaces from all NameRecords in the name table.

property table: table__n_a_m_e

The wrapped table__n_a_m_e table object.

foundrytools.core.tables.os_2 module

class foundrytools.core.tables.os_2.FsSelection(os_2_table: OS2Table)[source]

Bases: object

A wrapper class for the fsSelection field of the OS/2 table.

property bold: bool

A property with getter and setter for bit 5 (BOLD) in the OS/2.fsSelection field.

Returns:

True if bit 5 is set, False otherwise.

Return type:

bool

property italic: bool

A property with getter and setter for bit 0 (ITALIC) in the OS/2.fsSelection field.

Returns:

True if bit 0 is set, False otherwise.

Return type:

bool

property negative: bool

A property with getter and setter for bit 2 (NEGATIVE) in the OS/2.fsSelection field.

Returns:

True if bit 2 is set, False otherwise.

Return type:

bool

property oblique: bool

A property with getter and setter for bit 9 (OBLIQUE) in the OS/2.fsSelection field.

Returns:

True if bit 9 is set, False otherwise.

Return type:

bool

property outlined: bool

A property with getter and setter for bit 3 (OUTLINED) in the OS/2.fsSelection field.

Returns:

True if bit 3 is set, False otherwise.

Return type:

bool

property regular: bool

A property with getter and setter for bit 6 (REGULAR) in the OS/2.fsSelection field.

Returns:

True if bit 6 is set, False otherwise.

Return type:

bool

property strikeout: bool

A property with getter and setter for bit 4 (STRIKEOUT) in the OS/2.fsSelection field.

Returns:

True if bit 4 is set, False otherwise.

Return type:

bool

property underscore: bool

A property with getter and setter for bit 1 (UNDERSCORE) in the OS/2.fsSelection field.

Returns:

True if bit 1 is set, False otherwise.

Return type:

bool

property use_typo_metrics: bool

A property with getter and setter for bit 7 (USE_TYPO_METRICS) in the OS/2.fsSelection

Returns:

True if bit 7 is set, False otherwise.

Return type:

bool

property wws_consistent: bool

A property with getter and setter for bit 8 (WWS) in the OS/2.fsSelection field.

Returns:

True if bit 8 is set, False otherwise.

Return type:

bool

exception foundrytools.core.tables.os_2.InvalidOS2VersionError[source]

Bases: Exception

Exception raised when trying to access a field that is not defined in the current OS/2 table version.

class foundrytools.core.tables.os_2.OS2Table(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools OS/2 table.

property bitmap_embed_only: bool

A property with getter and setter for bit 9 (BITMAP_EMBED_ONLY) in the OS/2.fsType field.

Returns:

True if bit 9 is set, False otherwise.

Return type:

bool

property cap_height: int | None

A property with getter and setter for the OS/2.sCapHeight field.

sCapHeight is only defined in OS/2 table versions 2 and up.

Returns:

The OS/2.sCapHeight value.

Return type:

int

property codepage_ranges: set[int]

A property with getter and setter for the OS/2.ulCodePageRange(1-2) fields.

Returns:

The code page ranges of the OS/2 table.

Return type:

set[int]

property embed_level: int

A property with getter and setter for the embedding level of the OS/2.fsType field.

The value can be 0, 2, 4 or 8.

  • 0: Installable Embedding

  • 2: Restricted License Embedding

  • 4: Preview & Print Embedding

  • 8: Editable Embedding

property is_modified: bool

A property that returns True if the OS/2 table has been modified.

Returns:

True if the OS/2 table has been modified, False otherwise.

Return type:

bool

property max_context: int | None

A property with getter and setter for the OS/2.usMaxContext field.

usMaxContext is only defined in OS/2 table versions 2 and up.

Returns:

The OS/2.usMaxContext value.

Return type:

int

property no_subsetting: bool

A property with getter and setter for bit 8 (NO_SUBSETTING) in the OS/2.fsType field.

Returns:

True if bit 8 is set, False otherwise.

Return type:

bool

recalc_avg_char_width() int[source]

Recalculates the OS/2.xAvgCharWidth value.

Returns:

The new OS/2.xAvgCharWidth value.

Return type:

int

recalc_code_page_ranges() None[source]

Recalculates the code page ranges of the OS/2 table.

recalc_max_context() None[source]

Recalculates the OS/2.usMaxContext value.

recalc_unicode_ranges(percentage: float = 33.0) set[tuple[int, str, str]][source]

Recalculates the OS/2.ulUnicodeRange(1-4) fields.

Parameters:

percentage (float) – The percentage of codepoints that must be present in a Unicode block for it to be enabled. Default is 33.0.

Returns:

A set of tuples with the modified Unicode ranges.

Return type:

set[tuple[int, str, str]]

Raises:

KeyError: If the font does not have a cmap table.

property table: table_O_S_2f_2

The wrapped table_O_S_2f_2 table object.

property typo_ascender: int

A property with getter and setter for the OS/2.sTypoAscender field.

Returns:

The OS/2.sTypoAscender value.

Return type:

int

property typo_descender: int

A property with getter and setter for the OS/2.sTypoDescender field.

Returns:

The OS/2.sTypoDescender value.

Return type:

int

property typo_line_gap: int

A property with getter and setter for the OS/2.sTypoLineGap field.

Returns:

The OS/2.sTypoLineGap value.

Return type:

int

property unicode_ranges: set[int]

A property with getter and setter for the OS/2.ulUnicodeRange(1-4) fields.

Returns:

The Unicode ranges of the OS/2 table.

Return type:

set[int]

upgrade(target_version: int) None[source]

Upgrades the OS/2 table to a more recent version.

Parameters:

target_version (int) – The target version to upgrade to.

Raises:

InvalidOS2VersionError: If the target version is less than the current version.

property us_break_char: int | None

A property with getter and setter for the OS/2.usBreakChar field.

Returns:

The OS/2.usBreakChar value.

Return type:

int

property us_default_char: int | None

A property with getter and setter for the OS/2.usDefaultChar field.

Returns:

The OS/2.usDefaultChar value.

Return type:

int

property us_lower_optical_point_size: int | None

A property with getter and setter for the OS/2.usLowerOpticalPointSize field.

Returns:

The OS/2.usLowerOpticalPointSize value.

Return type:

int

property us_upper_optical_point_size: int | None

A property with getter and setter for the OS/2.usUpperOpticalPointSize field.

Returns:

The OS/2.usUpperOpticalPointSize value.

Return type:

int

property vendor_id: str

A property with getter and setter for the OS/2.achVendID field.

When setting the property value, it is padded with spaces to a length of 4.

Returns:

The OS/2.achVendID value.

Return type:

str

property version: int

A property with getter and setter for the OS/2.version field.

Valid values are between 0 and 5.

Returns:

The OS/2.version value.

Return type:

int

property weight_class: int

A property with getter and setter for the OS/2.usWeightClass field.

The value can be an integer between 1 and 1000.

Returns:

The OS/2.usWeightClass value.

Return type:

int

property width_class: int

A property with getter and setter for the OS/2.usWidthClass field.

The value can be an integer between 1 and 9.

Returns:

The OS/2.usWidthClass value.

Return type:

int

property win_ascent: int

A property with getter and setter for the OS/2.usWinAscent field.

Returns:

The OS/2.usWinAscent value.

Return type:

int

property win_descent: int

A property with getter and setter for the OS/2.usWinDescent field.

Returns:

The OS/2.usWinDescent value.

Return type:

int

property x_height: int | None

A property with getter and setter for the OS/2.sxHeight field.

sxHeight is only defined in OS/2 table versions 2 and up.

Returns:

The OS/2.sxHeight value.

Return type:

int

foundrytools.core.tables.post module

class foundrytools.core.tables.post.PostTable(ttfont: TTFont)[source]

Bases: DefaultTbl

This class extends the fontTools post table.

property fixed_pitch: bool

A property with getter and setter for the post.isFixedPitch field.

Returns:

The isFixedPitch value.

Return type:

bool

property is_modified: bool

Checks if the table has been modified.

Returns:

True if the table has been modified, False otherwise.

Return type:

bool

property italic_angle: float

A property with getter and setter for the post.italicAngle field.

Returns:

The italic angle value.

Return type:

float

property table: table__p_o_s_t

The wrapped table__p_o_s_t table object.

property underline_position: int

A property with getter and setter for the post.underlinePosition field.

Returns:

The underline position value.

Return type:

int

property underline_thickness: int

A property with getter and setter for the post.underlineThickness field.

Returns:

The underline thickness value.

Return type:

int