Font

Must Override

BaseFont._close(**kwargs: Any) None[source]

Close the native font.

This is the environment implementation of BaseFont.close.

Parameters:

**kwargs – Additional keyword arguments.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._generate(format: str, path: str | None, environmentOptions: dict, **kwargs: object) None[source]

Generate the native font in another format.

This is the environment implementation of BaseFont.generate. Refer to the BaseFont.generateFormatToExtension documentation for the standard format identifiers.

Parameters:
  • format – The output format identifier. If the value given for format is not supported by the environment, the environment must raise FontPartsError.

  • path – The location where the generated file should be saved. The value will have been normalized with normalizers.normalizeFilePath.

  • environmentOptions – A dictionary of environment-specific options. These options are validated with BaseFont._isValidGenerateEnvironmentOption and the given values. These values are not passed through any normalization functions.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._getGuideline(index: int, **kwargs: Any) BaseGuideline[source]

Return the guideline at the given index.

Parameters:
  • index – The index of the guideline.

  • **kwargs – Additional keyword arguments.

Returns:

An instance of a BaseGuideline subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_defaultLayer() BaseLayer[source]

Get the native font’s default layer.

This is the environment implementation of the BaseFont.defaultLayer property getter.

Returns:

The default BaseLayer subclass instance. The value will be normalized with normalizers.normalizeLayer.

Important

Subclasses must override this method.

BaseFont._get_defaultLayerName() str[source]

Get the name of the native font’s default layer.

This is the environment implementation of BaseFont.defaultLayerName property getter. :return: The name of the current default :class`BaseLayer`

subclass instance. The value will be normalized with normalizers.normalizeDefaultLayerName.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_features() BaseFeatures[source]

Get the native font’s features object.

This is the environment implementation of BaseFont.features.

Returns:

An instance of a BaseFeatures subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_glyphOrder() tuple[str, ...][source]

Get the order of the glyphs in the native font.

This is the environment implementation of the BaseFont.glyphrOrder property getter.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

A tuple of layer names in their defined order. The value will be normalized with normalizers.normalizeGlyphOrder.

Raises:

NotImplementedError – If the method has not beenoverridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_groups() BaseGroups[source]

Get the native font’s groups object.

This is the environment implementation of BaseFont.groups.

Returns:

an instance of a BaseGroups subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_info() BaseInfo[source]

Get the native font’s info object.

This is the environment implementation of BaseFont.info.

Returns:

An instance of a BaseInfo subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_kerning() BaseKerning[source]

Get the native font’s kerning object.

This is the environment implementation of BaseFont.kerning.

Returns:

An instance of a BaseKerning subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_layerOrder(**kwargs: Any) tuple[str, ...][source]

Get the order of the layers in the native font.

This is the environment implementation of the BaseFont.layerOrder property getter.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

A list of layer names in their defined order. The value will be normalized with normalizers.normalizeLayerOrder.

Raises:

NotImplementedError – If the method has not beenoverridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_layers(**kwargs: Any) tuple[BaseLayer, ...][source]

Get the native font’s layer objects.

This is the environment implementation of BaseFont.layers.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

A tuple containing instances of the BaseLayer subclass. The items should be in the order defined by BaseFont.layerOrder.

Important

Subclasses must override this method.

BaseFont._get_lib() BaseLib[source]

Get the native font’s lib object.

This is the environment implementation of BaseFont.lib.

Returns:

An instance of a BaseLib subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_tempLib() BaseLib[source]

Get the native font’s temporary lib object.

This is the environment implementation of BaseFont.tempLib.

Returns:

A temporary instance of a BaseLib subclass.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_path(**kwargs: Any) str | None[source]

Get the path to the native font file.

This method is the environment implementation of BaseFont.path.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

A str defining the location of the file or None to indicate that the font does not have a file representation. If the value is not None it will be normalized with normalizers.normalizeFilePath.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._get_selected() bool

Get or the object’s selection state.

This is the environment implementation of BaseObject.selected property getter.

Returns:

True if the object is selected, False otherwise. The value will be normalized with normalizers.normalizeBoolean.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method if they implement object selection.

BaseFont._init(pathOrObject: str | BaseFont | None, showInterface: bool, **kwargs: Any) None[source]

Initialize the native font object.

This method is the environment implementation of BaseFont.__init__. It will wrap a native font object based on the value type of the pathOrObject parameter.

Parameters:
  • pathOrObject

    The source for initializing the font. Options are:

    Type

    Description

    None str native font object

    Create a new font. Open the font file located at the given location. Wrap the given object.

  • showInterface – Whether to display the graphical interface.

  • **kwargs – Additional keyword arguments.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._lenGuidelines(**kwargs: Any) int[source]

Return the number of font-level guidelines in the native font.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

An int indicating the number of font-level BaseGuideline subclass instances in the font.

Important

Subclasses must override this method.

BaseFont._newLayer(name: str, color: RGBALike | None, **kwargs: Any) BaseLayer[source]

Create a new layer in the native font.

This is the environment implementation of BaseFont.newLayer.

Parameters:
  • name – The name of the new layer to create. The value must be unique to the font and will have been normalized with normalizers.normalizeLayerName.

  • color – The color value to assign to the new layer. If the value is not None, it will have been normalized with normalizers.normalizeColor.

  • **kwargs – Additional keyword arguments.

Returns:

A newly created BaseLayer subclass instance.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._removeGuideline(index: int, **kwargs: Any) None[source]

Remove the guideline at the specified index.

This is the environment implementation of BaseFont.removeGuideline.

Parameters:

index – The index of the guideline to remove.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._removeLayer(name: str, **kwargs: Any) None[source]

Remove the specified layer from the native font.

This is the environment implementation of BaseFont.removeLayer.

Parameters:
  • name – The name of the layer to remove. The value will have been normalized with normalizers.normalizeLayerName.

  • **kwargs – Additional keyword arguments.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._save(path: str | None, showProgress: bool, formatVersion: int | None, fileStructure: str | None, **kwargs: Any) None[source]

Save the native font to the specified path.

This is the environment implementation of BaseFont.save.

Parameters:
  • path – The file path to save the data to. If not None, the value will have been normalized with normalizers.normalizeFilePath.

  • showProgress – Whether to display a progress bar during the operation. Environments are not required to display a progress bar even if value is True.

  • formatVersion – The file format version to write the data into. If not None, the value will have been normalized with normalizers.normalizeFileFormatVersion.

  • fileStructure – The file structure to use.

  • **kwargs – Additional keyword arguments.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._set_defaultLayer(value: BaseLayer) None[source]

Set the native font’s default layer.

This is the environment implementation of the BaseFont.defaultLayer property setter.

Parameters:

value – The desired default BaseLayer subclass instance. The value will have been normalized with normalizers.normalizeLayer.

Important

Subclasses must override this method.

BaseFont._set_defaultLayerName(value: str, **kwargs: Any) None[source]

Set the name of the native font’s default layer.

This is the environment implementation of BaseFont.defaultLayerName property setter. :param value: The name of the desired default :class`BaseLayer`

subclass instance. The name will have been normalized with normalizers.normalizeDefaultLayerName.

Parameters:

**kwargs – Additional keyword arguments.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._set_glyphOrder(value: list[str] | tuple[str, ...]) None[source]

Set the order of the glyphs in the native font.

This is the environment implementation of the BaseFont.glyphrOrder property setter.

Parameters:
Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._set_layerOrder(value: list[str] | tuple[str, ...], **kwargs: Any) None[source]

Set the order of the layers in the native font.

This is the environment implementation of the BaseFont.layerOrder property setter.

Parameters:
Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method.

BaseFont._set_selected(value: bool) None

Set the object’s selection state.

This is the environment implementation of the SelectionMixin.selected property setter.

Parameters:

value – Whether the object is selected. The value will have been normalized with normalizers.normalizeBoolean.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Important

Subclasses must override this method if they implement object selection.

May Override

BaseFont._appendGuideline(position: CoordinateLike, angle: float | None, name: str | None, color: RGBALike | None, **kwargs: Any) BaseGuideline[source]

Append a new guideline to the native font.

This is the environment implementation of BaseFont.appendGuideline.

Parameters:
  • position – The position for the guideline as a Coordinate.

  • angle – The angle for the guideline as a float.

  • name – The name for the guideline as a str.

  • color – The color for the guideline as a Color.

  • **kwargs – Additional keyword arguments.

Returns:

The newly appended instance of the BaseGuideline subclass.

Note

Subclasses may override this method.

BaseFont._autoUnicodes() None[source]

Use heuristics to set Unicode values in all native font glyphs.

This is the environment implementation of BaseFont.autoUnicodes.

Note

Subclasses may override this method.

BaseFont._clearGuidelines() None[source]

Clear all guidelines in the native font.

This is the environment implementation of BaseFont.clearGuidelines.

Note

Subclasses may override this method.

BaseFont._contains(name: str, **kwargs: Any) bool

Test if the native layer contains the specified glyph.

This is the environment implementation of BaseLayer.__contains__ and BaseFont.__contains__.

Parameters:
  • name – The name of the glyph to check. The value will have been normalized with normalizers.normalizeGlyphName.

  • **kwargs – Additional keyword arguments.

Returns:

True if the glyph exists in the layer, False otherwise.

Note

Subclasses may override this method.

BaseFont._duplicateLayer(layerName: str, newLayerName: str) BaseLayer[source]

Duplicate the specified layer in the native font.

This is the environment implementation of BaseFont.duplicateLayer.

Parameters:
  • layerName – The name of the layer to duplicate. The value will have been normalized with normalizers.normalizeLayerName and tested to make sure that it already exists in the font.

  • newLayerName – The new name to assign to the duplicated layer. The value will have been normalized with normalizers.normalizeLayerName and tested to make sure that it does not already exist in the font.

Returns:

The newly duplicated BaseLayer subclass instance.

Note

Subclasses may override this method.

BaseFont._getCharacterMapping() dict[int, tuple[str, ...]][source]

Get the native font’s character mapping.

This is the environment implementation of BaseFont.getCharacterMapping.

Returns:

A dict mapping Unicode values to tuple of glyph names.

Raises:

NotImplementedError – If the method has not been overridden by a subclass.

Note

Subclasses may override this method.

BaseFont._getFlatKerning() dict[tuple[str, str], tuple[str, str]][source]

Get the native font’s kerning as a flat dictionary.

This is the environment implementation of BaseFont.getFlatKerning.

Returns:

A dict of the font’s BaseKerning subclass keys mapped to their respective values.

Note

Subclasses may override this method.

BaseFont._getItem(name: str, **kwargs: Any) BaseGlyph[source]

Get the specified glyph from the native default layer.

This is the environment implementation of BaseFont.__getitem__.

Parameters:
  • name – The name of the glyph to retrieve from the default layer. The value will have been normalized with normalizers.normalizeGlyphName.

  • **kwargs – Additional keyword arguments.

Returns:

the specified instance of a BaseGlyph

subclass.

Note

Subclasses may override this method.

BaseFont._getLayer(name: str, **kwargs: Any) BaseLayer[source]

Get the named layer from the native font.

This is the environment implementation of BaseFont.getLayer.

Parameters:
  • name – The name of the BaseLayer subclass instance to retrieve.

  • **kwargs – Additional keyword arguments.

Returns:

The specified BaseLayer subclass instance. The value will have been normalized with normalizers.normalizeLayerName and verified as an existing layer.

Raises:

ValueError – If no layer with the given name exists in the font.

Note

Subclasses may override this method.

BaseFont._getReverseComponentMapping() dict[str, tuple[str, ...]][source]

Get a reversed map of all component references in the font.

This is the environment implementation of BaseFont.getReverseComponentMapping.

Note

Subclasses may override this method.

BaseFont._get_selectedGlyphs() tuple[BaseGlyph, ...]

Get the selected glyphs in the native layer.

This is the environment implementation of the BaseLayer.selectedGlyphs property getter.

Returns:

An unordered tuple of selected BaseGlyph subclass instances. Each value item will be normalized with normalizers.normalizeGlyph.

Note

Subclasses may override this method.

BaseFont._get_selectedGlyphNames() tuple[str, ...]

Get the selected glyph names in the layer.

This is the environment implementation of the BaseLayer.selectedGlyphNames property getter.

Returns:

An unordered tuple of glyph names representing the currently selected BaseGlyph subclass instances. Each value item will be normalized with normalizers.normalizeGlyphName.

Note

Subclasses may override this method.

BaseFont._get_selectedGuidelines() tuple[BaseGuideline, ...][source]

Get the selected guidelines in the native font.

This is the environment implementation of the BaseFont.selectedGuidelines property getter.

Returns:

A tuple of currently selected BaseGuideline instances. Each value item will be normalized with normalizers.normalizeGuideline.

Note

Subclasses may override this method.

BaseFont._get_selectedLayers() tuple[BaseLayer, ...][source]

Get the selected glyph layers in the native default font layer.

This is the environment implementation of the BaseFont.selectedLayers property getter.

Returns:

A tuple of currently selected BaseLayer instances. Each value item will be normalized with normalizers.normalizeLayer.

Note

Subclasses may override this method.

BaseFont._get_selectedLayerNames() tuple[str, ...][source]

Get the selected glyph layer names in the native font layer.

This is the environment implementation of the BaseFont.selectedLayerNames property getter.

Returns:

A tuple of layer names representing the currently selected BaseLayer instances. Each value item will be normalized with normalizers.normalizeLayerName.

Note

Subclasses may override this method.

BaseFont._get_guidelines() tuple[BaseGuideline, ...][source]

Get the native font-level guideline objects.

This is the environment implementation of BaseFont.guidelines.

Returns:

A tuple containing instances of the BaseGuideline subclass.

Note

Subclasses may override this method.

BaseFont._insertGlyph(glyph: BaseGlyph, name: str, **kwargs: Any) BaseGlyph

Insert a specified glyph into the native layer.

This is the environment implementation of BaseLayer.__setitem__ and BaseFont.__setitem__.

An environment must not insert glyph directly, but rather copy it’s data to a new layer.

Parameters:
  • glyph – A glyph object with the attributes necessary for copying as defined in BaseGlyph.copy

  • name – The name to assign to the new glyph after insertion. The value will have been normalized with normalizers.normalizeGlyphName and tested to make sure that it is unique to the layer.

  • **kwargs – Additional keyword arguments.

Returns:

The newly inserted BaseLayer subclass instance.

Note

Subclasses may override this method.

BaseFont._insertLayer(layer: BaseLayer, name: str, **kwargs: Any) BaseLayer[source]

Insert a specified layer into the native font.

This is the environment implementation of BaseFont.insertLayer.

An environment must not insert layer directly, but rather copy it’s data to a new layer.

Parameters:
  • layer – A layer object with the attributes necessary for copying as defined in BaseLayer.copy.

  • name – The name to assign to the new layer after insertion. The value will have been normalized with normalizers.normalizeLayerName and tested to make sure that it is unique to the font.

  • **kwargs – Additional keyword arguments.

Returns:

The newly inserted BaseLayer subclass instance.

Note

Subclasses may override this method.

BaseFont._interpolate(factor: list[int | float] | tuple[float, float], minFont: BaseFont, maxFont: BaseFont, round: bool, suppressError: bool) None[source]

Interpolate all possible data in the native font.

This is the environment implementation of BaseFont.interpolate.

Parameters:
  • factor – The interpolation value as a single int or float or a tuple of two int or float values representing the factors (x, y).

  • minFont – The BaseFont subclass instance corresponding to the 0.0 position in the interpolation.

  • maxFont – The BaseFont subclass instance corresponding to the 1.0 position in the interpolation.

  • round – A boolean indicating whether the result should be rounded to integers.

  • suppressError – A boolean indicating whether to ignore incompatible data or raise an error when such incompatibilities are found.

Raises:

TypeError – If minFont or maxFont are not instances of BaseFont.

Note

Subclasses may override this method.

BaseFont._isCompatible(other: BaseFont, reporter: FontCompatibilityReporter) None[source]

Evaluate interpolation compatibility with another native font.

This is the environment implementation of BaseFont.isCompatible.

Parameters:
  • other – The other BaseFont subclass instance to check compatibility with.

  • reporter – An object used to report compatibility issues.

Note

Subclasses may override this method.

static BaseFont._isValidGenerateEnvironmentOption(name: str) bool[source]

Validate if the environment option is supported.

Any unknown keyword arguments given to BaseFont.generate are passed to this method. name is the name used for the argument. Environments may evaluate if name is a supported option.

Parameters:

name – The name of the environment option to validate.

Returns:

True if the environment option is supported, otherwise False.

Note

Subclasses may override this method.

BaseFont._iter(**kwargs: Any) Iterator[BaseGlyph]

Iterate through the glyphs in the native layer.

This is the environment implementation of BaseLayer.__iter__ and BaseFont.__iter__.

Returns:

An iterator over instances of a BaseGlyph subclass.

Note

Subclasses may override this method.

BaseFont._keys(**kwargs: Any) tuple[str, ...][source]

Get a list of all glyph names in the native default layer.

This is the environment implementation of BaseFont.keys.

Parameters:

**kwargs – Additional keyword arguments.

Returns:

A tuple of glyph names as str.

Note

Subclasses may override this method.

BaseFont._len(**kwargs: Any) int

Return the number of glyphs in the native layer.

This is the environment implementation of BaseLayer.__len__ and BaseFont.__len__

Parameters:

**kwargs – Additional keyword arguments.

Returns:

The number of BaseGlyph subclass instances in the layer as an int.

Note

Subclasses may override this method.

BaseFont._newGlyph(name: str, **kwargs: Any) BaseGlyph[source]

Create a new glyph in the native default layer.

This is the environment implementation of :meth:`BaseFont.newGlyph.

Parameters:
  • name – The name to assign to the new glyph. The value will have been normalized with normalizers.normalizeGlyphName and verified as unique within the default layer.

  • **kwargs – Additional keyword arguments.

Returns:

An instance of a BaseGlyph subclass representing the new glyph.

Note

Subclasses may override this method.

BaseFont._removeGlyph(name: str, **kwargs: Any) None[source]

Remove the specified glyph from the default layer.

This is the environment implementation of BaseFont.removeGlyph.

Parameters:
  • name – The name of the glyph to remove. The value will be normalized with normalizers.normalizeGlyphName.

  • **kwargs – Additional keyword arguments.

Note

Subclasses may override this method.

BaseFont._round() None[source]

Round all appropriate native font data to integers.

This is the environment implementation of BaseFont.round.

Note

Subclasses may override this method.

BaseFont._set_selectedGuidelines(value: list[BaseGuideline | int]) None[source]

Set the selected guidelines in the native font.

This is the environment implementation of the BaseFont.selectedGuidelines property setter.

Parameters:

value – The list of BaseGuideline instances to select. Each value item will have been normalized with normalizers.normalizeGuideline.

Note

Subclasses may override this method.

BaseFont._set_selectedLayerNames(value: list[str]) None[source]

Set the selected glyph layer names in the native font layer.

This is the environment implementation of the BaseFont.selectedLayerNames property setter.

Parameters:

value – The list of layer names representing the BaseLayer instances to select. Each value item will have been normalized with normalizers.normalizeLayerName.

Note

Subclasses may override this method.

BaseFont._set_selectedLayers(value: list[BaseLayer]) None[source]

Set the selected glyph layers in the native default font layer.

This is the environment implementation of the BaseFont.selectedLayers property setter.

Parameters:

value – The list of BaseLayer instances to select. Each value item will have been normalized with normalizers.normalizeLayer.

Note

Subclasses may override this method.