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:
Kerning group names must begin with the appropriate prefix.
Only kerning groups are allowed to use the kerning group prefixes in their names.
Kerning groups are not required to appear in the kerning pairs.
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¶
Copy the current object into a new object of the same type. |
Parents¶
Get or set the kerning's parent font object. |
Dictionary¶
Return the number of pairs in the kerning. |
|
Return the kerning's pairs (keys). |
|
Return the kerning's items. |
|
Return the kerning's values. |
|
Check if the given pair exists in the kerning. |
|
Set the value for the given kerning pair. |
|
Get the value associated with the given kerning pair. |
|
Get the value for the given kerning pair. |
|
Get the value for the given explicit or implicit kerning pair. |
|
Remove the given pair from the kerning. |
|
Remove the specified kerning pair and return its associated value. |
|
Return an iterator over the pairs in the kerning. |
|
Update the current kerning with key-value pairs from another. |
|
Remove all information from kerning. |
Transformations¶
Scale all kerning values by the specified factor. |
Interpolation¶
Interpolate all kerning pairs in the font. |
Normalization¶
Round the kerning values to the specified increments. |
Environment¶
Return the environment's native object wrapped by the current object. |
|
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
dictobject. Most of the dictionary functionality comes fromBaseDict. Consult that object’s documentation for the required environment implementation details.- Variables:
keyNormalizer – A function to normalize the key of the dictionary. Defaults to
normalizers.normalizeKerningKey.valueNormalizer – A function to normalize the value of the dictionary. Defaults to
normalizers.normalizeKerningValue.
This object is normally created as part of a
BaseFont. An orphanBaseKerningobject 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
BaseObjectsubclass instance with the same attributes.
Parents¶
- BaseKerning.font: dynamicProperty¶
Get or set the kerning’s parent font object.
The value must be a
BaseFontinstance orNone.- Returns:
- 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
intrepresenting the number of pairs in the kerning.
Example:
>>> len(font.kerning) 5
- BaseKerning.keys() BaseKeys[KerningPair][source]¶
Return the kerning’s pairs (keys).
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
tupleof 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)])
- Each item is represented as a
- BaseKerning.values() BaseValues[IntFloatType][source]¶
Return the kerning’s 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
tupleof twostrvalues.- Returns:
Trueif the groupName exists in the groups,Falseotherwise.
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:
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:
- Returns:
Example:
>>> font.kerning[("A", "V")] -15
Note
Any changes to the returned kerning value will not be reflected in it’s
BaseKerninginstance. 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:
- Returns:
A
tupleof twostrvalues 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
BaseKerninginstance. 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:
- Returns:
A
tupleof twostrvalues 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.
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:
- Returns:
The value for the given pair as an
intorfloat, 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.
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
MutableMappingof key-value pairs to update the current lib with. Keys must be atupleof twostrvalues. Values must be anintor afloat.
Example:
>>> font.kerning.update(newKerning)
- BaseKerning.clear() None[source]¶
Remove all information from kerning.
This will reset the
BaseKerninginstance 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
intorfloator atupleor :class`list` of twointorfloatvalues 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
intorfloator alistortupleof twointorfloatvalues representing the factors(x, y).minKerning – The
BaseKerninginstance corresponding to the 0.0 position in the interpolation.maxKerning – The
BaseKerninginstance corresponding to the 1.0 position in the interpolation.round – A
boolindicating whether the result should be rounded to integers. Defaults toTrue.suppressError – A
boolindicating whether to ignore incompatible data or raise an error when such incompatibilities are found. Defaults toTrue.
- Raises:
TypeError – If minGlyph or maxGlyph are not instances of
BaseKerning.
Example:
>>> myKerning.interpolate(kerningOne, kerningTwo)
Normalization¶
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()