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 this object into a new object of the same type.

Parents

BaseKerning.font

The Kerning's parent BaseFont.

Dictionary

BaseKerning.__len__

Returns the number of pairs in Kerning as an int..

BaseKerning.keys

Returns a list of all the pairs in Kerning. This list will be unordered.::.

BaseKerning.items

Returns a list of tuples of each pair and value.

BaseKerning.values

Returns a list of each pair's values, the values will be Integer/Floats.

BaseKerning.__contains__

Tests to see if a pair is in the Kerning.

BaseKerning.__setitem__

Sets the pair to the list of value.

BaseKerning.__getitem__

Returns the kerning value of the pair.

BaseKerning.get

Returns the value for the kerning pair. pair is a tuple of two Strings, and the returned values will either be Integer/Float or None if no pair was found. ::.

BaseKerning.find

Returns the value for the kerning pair - even if the pair only exists implicitly (one or both sides may be members of a kerning group).

BaseKerning.__delitem__

Removes pair from the Kerning. pair is a tuple of two Strings.::.

BaseKerning.pop

Removes the pair from the Kerning and returns the value as an int.

BaseKerning.__iter__

Iterates through the Kerning, giving the pair for each iteration. The order that the Kerning will iterate though is not fixed nor is it ordered.::.

BaseKerning.update

Updates the Kerning based on otherKerning.

BaseKerning.clear

Removes all information from Kerning, resetting the Kerning to an empty dictionary. ::.

Transformations

BaseKerning.scaleBy

Scales all kerning values by factor.

Interpolation

BaseKerning.interpolate

Interpolates all pairs between two BaseKerning objects:

Normalization

BaseKerning.round

Rounds the kerning values to increments of multiple, which will be an int.

Environment

BaseKerning.naked

Return the environment's native object that has been wrapped by this object.

BaseKerning.changed

Tell the environment that something has changed in the object.

Reference

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

A Kerning object. This object normally created as part of a BaseFont. An orphan Kerning object can be created like this:

>>> groups = RKerning()

This object behaves like a Python dictionary. Most of the dictionary functionality comes from BaseDict, look at that object for the required environment implementation details.

Kerning uses normalizers.normalizeKerningKey to normalize the key of the dict, and normalizers.normalizeKerningValue to normalize the the value of the dict.

Copy

BaseKerning.copy()

Copy this object into a new object of the same type. The returned object will not have a parent object.

Parents

BaseKerning.font

The Kerning’s parent BaseFont.

Dictionary

BaseKerning.__len__()[source]

Returns the number of pairs in Kerning as an int.:

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

Returns a list of all the pairs in Kerning. This list will be unordered.:

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

Returns a list of tuples of each pair and value. Pairs are a tuple of two Strings and values are Integer/Float.

The initial list will be unordered.

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

Returns a list of each pair’s values, the values will be Integer/Floats.

The list will be unordered.

>>> font.kerning.items()
[-20, -15, 5, 3.5]
BaseKerning.__contains__(pair)[source]

Tests to see if a pair is in the Kerning. pair will be a tuple of two Strings.

This returns a bool indicating if the pair is in the Kerning.

>>> ("A", "V") in font.kerning
True
BaseKerning.__setitem__(pair, value)[source]

Sets the pair to the list of value. pair is the pair as a tuple of two Strings and value

is a Integer/Float.

>>> font.kerning[("A", "V")] = -20
>>> font.kerning[("A", "W")] = -10.5
BaseKerning.__getitem__(pair)[source]

Returns the kerning value of the pair. pair is a tuple of two Strings.

The returned value will be a Integer/Float.:

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

It is important to understand that any changes to the returned value will not be reflected in the Kerning object. If one wants to make a change to the value, one should do the following:

>>> value = font.kerning[("A", "V")]
>>> value += 10
>>> font.kerning[("A", "V")] = value
BaseKerning.get(pair, default=None)[source]

Returns the value for the kerning pair. pair is a tuple of two Strings, and the returned values will either be Integer/Float or None if no pair was found.

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

It is important to understand that any changes to the returned value will not be reflected in the Kerning object. If one wants to make a change to the value, one should do the following:

>>> value = font.kerning[("A", "V")]
>>> value += 10
>>> font.kerning[("A", "V")] = value
BaseKerning.find(pair, default=None)[source]

Returns the value for the kerning pair - even if the pair only exists implicitly (one or both sides may be members of a kerning group).

pair is a tuple of two Strings, and the returned values will either be Integer/Float or None if no pair was found.

>>> font.kerning[("A", "V")]
-25
BaseKerning.__delitem__(pair)[source]

Removes pair from the Kerning. pair is a tuple of two Strings.:

>>> del font.kerning[("A","V")]
BaseKerning.pop(pair, default=None)[source]

Removes the pair from the Kerning and returns the value as an int. If no pair is found, default is returned. pair is a tuple of two Strings. This must return either

default or a Integer/Float.

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

Iterates through the Kerning, giving the pair for each iteration. The order that the Kerning will iterate though is not fixed nor is it ordered.:

>>> for pair in font.kerning:
>>>     print pair
("A", "Y")
("A", "V")
("A", "W")
BaseKerning.update(otherKerning)[source]

Updates the Kerning based on otherKerning. otherKerning is a dict of kerning information. If a pair from otherKerning is in Kerning, the pair value will be replaced by the value from otherKerning. If a pair from otherKerning is not in the Kerning, it is added to the pairs. If Kerning contains a pair that is not in otherKerning, it is not changed.

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

Removes all information from Kerning, resetting the Kerning to an empty dictionary.

>>> font.kerning.clear()

Transformations

BaseKerning.scaleBy(factor)[source]

Scales all kerning values by factor. factor will be an Integer/Float, tuple or list. The first value of the factor will be used to scale the kerning values.

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

Interpolation

BaseKerning.interpolate(factor, minKerning, maxKerning, round=True, suppressError=True)[source]

Interpolates all pairs between two BaseKerning objects:

>>> myKerning.interpolate(kerningOne, kerningTwo)

minKerning and maxKerning. The interpolation occurs on a 0 to 1.0 range where minKerning is located at 0 and maxKerning is located at 1.0. The kerning data is replaced by the interpolated kerning.

  • factor is the interpolation value. It may be less than 0 and greater than 1.0. It may be an Integer/Float, tuple or list. If it is a tuple or list, the first number indicates the x factor and the second number indicates the y factor.

  • round is a bool indicating if the result should be rounded to ints. The default behavior is to round interpolated kerning.

  • suppressError is a bool indicating if incompatible data should be ignored or if an error should be raised when such incompatibilities are found. The default behavior is to ignore incompatible data.

Normalization

BaseKerning.round(multiple=1)[source]

Rounds the kerning values to increments of multiple, which will be an int.

The default behavior is to round to increments of 1.

Environment

BaseKerning.naked()

Return the environment’s native object that has been wrapped by this object.

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

Tell the environment that something has changed in the object. The behavior of this method will vary from environment to environment.

>>> obj.changed()