Kerning

Description

Kerning groups must begin with standard prefixes. The prefix for groups intended for use in the first side of a kerning pair is public.kern1.. The prefix for groups intended for use in the second side of a kerning pair is public.kern2.. One or more characters must follow the prefix.

Kerning groups must strictly adhere to the following rules:

  1. Kerning group names must begin with the appropriate prefix.

  2. Only kerning groups are allowed to use the kerning group prefixes in their names.

  3. Kerning groups are not required to appear in the kerning pairs.

  4. Glyphs must not appear in more than one kerning group per side.

These rules come from the Unified Font Object, more information on implementation details for application developers can be found there.

Overview

Copy

BaseKerning.copy

Copy the current object into a new object of the same type.

Parents

BaseKerning.font

Get or set the kerning's parent font object.

Dictionary

BaseKerning.__len__

Return the number of pairs in the kerning.

BaseKerning.keys

Return the kerning's pairs (keys).

BaseKerning.items

Return the kerning's items.

BaseKerning.values

Return the kerning's values.

BaseKerning.__contains__

Check if the given pair exists in the kerning.

BaseKerning.__setitem__

Set the value for the given kerning pair.

BaseKerning.__getitem__

Get the value associated with the given kerning pair.

BaseKerning.get

Get the value for the given kerning pair.

BaseKerning.find

Get the value for the given explicit or implicit kerning pair.

BaseKerning.__delitem__

Remove the given pair from the kerning.

BaseKerning.pop

Remove the specified kerning pair and return its associated value.

BaseKerning.__iter__

Return an iterator over the pairs in the kerning.

BaseKerning.update

Update the current kerning with key-value pairs from another.

BaseKerning.clear

Remove all information from kerning.

Transformations

BaseKerning.scaleBy

Scale all kerning values by the specified factor.

Interpolation

BaseKerning.interpolate

Interpolate all kerning pairs in the font.

Normalization

BaseKerning.round

Round the kerning values to the specified increments.

Environment

BaseKerning.naked

Return the environment's native object wrapped by the current object.

BaseKerning.changed

Tell the environment that something has changed in the object.

Reference

class fontParts.base.BaseKerning(*args: Any, **kwargs: Any)[source]

Represent the basis for a kerning object.

This object behaves like a Python dict object. Most of the dictionary functionality comes from BaseDict. Consult that object’s documentation for the required environment implementation details.

Variables:

This object is normally created as part of a BaseFont. An orphan BaseKerning object instance can be created like this:

>>> groups = RKerning()

Copy

BaseKerning.copy() BaseObjectType

Copy the current object into a new object of the same type.

The returned object will not have a parent object.

Returns:

A new BaseObject subclass instance with the same attributes.

Parents

BaseKerning.font: dynamicProperty

Get or set the kerning’s parent font object.

The value must be a BaseFont instance or None.

Returns:

The BaseFont instance containing the kerning or None.

Raises:

AssertionError – If attempting to set the font when it has already been set and is not the same as the provided font.

Example:

>>> font = kerning.font

Dictionary

BaseKerning.__len__() int[source]

Return the number of pairs in the kerning.

Returns:

An int representing the number of pairs in the kerning.

Example:

>>> len(font.kerning)
5
BaseKerning.keys() BaseKeys[KerningPair][source]

Return the kerning’s pairs (keys).

Returns:

A type-view of the kerning’s pairs as tuple instances of two str values.

Example:

>>> font.kerning.keys()
BaseKerning_keys([("A", "Y"), ("A", "V"), ("A", "W")])
BaseKerning.items() BaseItems[KerningPair, IntFloatType][source]

Return the kerning’s items.

Each item is represented as a tuple of key-value pairs, where:
Returns:

A type-view of the kerning’s (key, value) pairs.

Example:

>>> font.kerning.items()
BaseKerning_items([(("A", "V"), -30), (("A", "W"), -10)])
BaseKerning.values() BaseValues[IntFloatType][source]

Return the kerning’s values.

Returns:

A type-view of int or float values.

Example:

>>> font.kerning.values()
BaseKerning_values([-20, -15, 5, 3.5])
BaseKerning.__contains__(pair: list[str] | tuple[str, str]) bool[source]

Check if the given pair exists in the kerning.

Parameters:

pair – The kerning pair to check for existence as a tuple of two str values.

Returns:

True if the groupName exists in the groups, False otherwise.

Example:

>>> ("A", "V") in font.kerning
True
BaseKerning.__setitem__(pair: list[str] | tuple[str, str], value: int | float) None[source]

Set the value for the given kerning pair.

Parameters:
  • pair – The pair to set as a tuple of two str values.

  • value – The value to set as an int or float.

Example:

>>> font.kerning[("A", "V")] = -20
>>> font.kerning[("A", "W")] = -10.5
BaseKerning.__getitem__(pair: list[str] | tuple[str, str]) int | float[source]

Get the value associated with the given kerning pair.

Parameters:

pair – The pair to remove as a tuple of two str values.

Returns:

The kerning value as an int or float.

Example:

>>> font.kerning[("A", "V")]
-15

Note

Any changes to the returned kerning value will not be reflected in it’s BaseKerning instance. To make changes to this value, do the following:

>>> value = font.kerning[("A", "V")]
>>> value += 10
>>> font.kerning[("A", "V")] = value
BaseKerning.get(pair: list[str] | tuple[str, str], default: int | float | None = None) int | float | None[source]

Get the value for the given kerning pair.

If the given pair is not found, The specified default will be returned.

Parameters:
  • pair – The pair to get as a tuple of two str values.

  • default – The optional default value to return if the pair is not found.

Returns:

A tuple of two str values representing the value for the given pair, or the default value if the pair is not found.

Example:

>>> font.kerning.get(("A", "V"))
-25

Note

Any changes to the returned kerning value will not be reflected in it’s BaseKerning instance. To make changes to this value, do the following:

>>> value = font.kerning[("A", "V")]
>>> value += 10
>>> font.kerning[("A", "V")] = value
BaseKerning.find(pair: list[str] | tuple[str, str], default: int | float | None = None) int | float | None[source]

Get the value for the given explicit or implicit kerning pair.

This method will return the value for the given pair, even if it only exists implicitly (one or both sides may be members of a kerning group). If the pair is not found, the specified default will be returned.

Parameters:
  • pair – The pair to get as a tuple of two str values.

  • default – The optional default value to return if the pair is not found.

Returns:

A tuple of two str values representing the value for the given pair, or the default value if the pair is not found.

Example:

>>> font.kerning.find(("A", "V"))
-25
BaseKerning.__delitem__(pair: list[str] | tuple[str, str]) None[source]

Remove the given pair from the kerning.

Parameters:

pair – The pair to remove as a tuple of two str values.

Example:

>>> del font.kerning[("A","V")]
BaseKerning.pop(pair: list[str] | tuple[str, str], default: int | float | None = None) int | float | None[source]

Remove the specified kerning pair and return its associated value.

If the pair does not exist, the default value is returned.

Parameters:
  • pair – The pair to remove as a tuple of two str values.

  • default – The optional default value to return if the pair is not found`. The value must be an int, a float or None. Defaults to None.

Returns:

The value for the given pair as an int or float, or the default value if the pair is not found.

Example:

>>> font.kerning.pop(("A", "V"))
-20
>>> font.kerning.pop(("A", "W"))
-10.5
BaseKerning.__iter__() Iterator[tuple[str, str]][source]

Return an iterator over the pairs in the kerning.

The iteration order is not fixed.

Returns:

An Iterator over tuple instances containing two str values.

Example:

>>> for pair in font.kerning:
>>>     print pair
("A", "Y")
("A", "V")
("A", "W")
BaseKerning.update(otherKerning: MutableMapping[tuple[str, str], int | float]) None[source]

Update the current kerning with key-value pairs from another.

For each pair in otherKerning:
  • If the pair exists in the current kerning, its value is replaced with the value from otherKerning.

  • If the pair does not exist in the current kerning, it is added.

Pairs that exist in the current kerning but are not in otherLib remain unchanged.

Parameters:

otherKerning – A MutableMapping of key-value pairs to update the current lib with. Keys must be a tuple of two str values. Values must be an int or a float.

Example:

>>> font.kerning.update(newKerning)
BaseKerning.clear() None[source]

Remove all information from kerning.

This will reset the BaseKerning instance to an empty dictionary.

Example:

>>> font.kerning.clear()

Transformations

BaseKerning.scaleBy(factor: int | float | list[int | float] | tuple[float, float]) None[source]

Scale all kerning values by the specified factor.

Parameters:

factor – The factor by which to scale the kerning. The value may be a single int or float or a tuple or :class`list` of two int or float values representing the factors (x, y). In the latter case, the first value is used to scale the kerning values.

Example:

>>> myKerning.scaleBy(2)
>>> myKerning.scaleBy((2, 3))

Interpolation

BaseKerning.interpolate(factor: int | float | list[int | float] | tuple[float, float], minKerning: BaseKerningType, maxKerning: BaseKerningType, round: bool = True, suppressError: bool = True) None[source]

Interpolate all kerning pairs in the font.

The kerning data will be replaced by the interpolated kerning.

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

  • minKerning – The BaseKerning instance corresponding to the 0.0 position in the interpolation.

  • maxKerning – The BaseKerning instance corresponding to the 1.0 position in the interpolation.

  • round – A bool indicating whether the result should be rounded to integers. Defaults to True.

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

Raises:

TypeError – If minGlyph or maxGlyph are not instances of BaseKerning.

Example:

>>> myKerning.interpolate(kerningOne, kerningTwo)

Normalization

BaseKerning.round(multiple: int = 1) None[source]

Round the kerning values to the specified increments.

Parameters:

multiple – The increment to which the kerning values should be rounded as an int. Defaults to 1.

Example:

>>> myKerning.round(2)

Environment

BaseKerning.naked() Any

Return the environment’s native object wrapped by the current object.

Raises:

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

Example:

>>> loweLevelObj = obj.naked()
BaseKerning.changed(*args: Any, **kwargs: Any) None

Tell the environment that something has changed in the object.

The behavior of this method will vary from environment to environment.

Parameters:
  • *args – Any positional arguments.

  • **kwargs – Any keyword arguments.

Example:

>>> obj.changed()