Groups¶
Description¶
Groups are collections of glyphs. Groups are used for many things, from OpenType features, kerning, or just keeping track of a collection of related glyphs. The name of the group must be at least one character, with no limit to the maximum length for the name, nor any limit on the characters used in a name. With the exception of the kerning groups defined below, glyphs may be in more than one group and they may appear within the same group more than once. Glyphs in the groups are not required to be in the font.
Groups behave like a Python dictionary. Anything you can do with a dictionary in Python, you can do with Groups.
font = CurrentFont()
for name, members in font.groups.items():
print(name)
print(members)
It is important to understand that any changes to the returned group contents will not be reflected in the groups object. This means that the following will not update the font’s groups:
group = list(font.groups["myGroup"])
group.remove("A")
If one wants to make a change to the group contents, one should do the following instead:
group = list(font.groups["myGroup"])
group.remove("A")
font.groups["myGroup"] = group
Kerning Groups¶
Groups may be used as members of kerning pairs in BaseKerning. These groups are divided into two types: groups that appear on the first side of a kerning pair and groups that appear on the second side of a kerning pair.
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 the current object into a new object of the same type. |
|
|
Get or set the groups' parent font object. |
Check if the given key exists in the groups. |
|
Remove the given group from the current groups instance. |
|
Get the contents of the given group. |
|
Return an iterator over the keys in the current groups instance. |
|
Return the number of groups in the current groups instance. |
|
Set the glyph names for a given group in the current groups instance. |
|
Remove all groups from the current groups instance. |
|
Get the contents for the given group in the current groups instance. |
|
Return the items in the current groups instance. |
|
Return the group names (keys) in the current groups instance. |
|
Remove the specified group and return its associated contents. |
|
Update the current groups instance with key-value pairs from another. |
|
Return the values in the current groups instance. |
|
Retrieve the groups associated with the given glyph. |
|
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.BaseGroups(*args: Any, **kwargs: Any)[source]¶
Represent the basis for a groups 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.normalizeGroupKeyvalueNormalizer – A function to normalize the value of the dictionary. Defaults to
normalizers.normalizeGroupValue
This object is normally created as part of a
BaseFont. An orphanBaseGroupsobject instance can be created like this:>>> groups = RGroups()
Copy¶
- BaseGroups.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¶
fontThe groups’ parentBaseFont.
Dictionary¶
- BaseGroups.__contains__(groupName: str) bool[source]¶
Check if the given key exists in the groups.
- Parameters:
groupName – The group name to check for existence as a
str.- Returns:
Trueif the groupName exists in the groups,Falseotherwise.
Example:
>>> "myGroup" in font.groups True
- BaseGroups.__delitem__(groupName: str) None[source]¶
Remove the given group from the current groups instance.
- Parameters:
groupName – The name of the group to remove as a
str.
Example:
>>> del font.groups["myGroup"]
- BaseGroups.__getitem__(groupName: str) tuple[str, ...][source]¶
Get the contents of the given group.
- Parameters:
groupName – The group name to retrieve the value for as a
str.- Returns:
- Raises:
KeyError – If the specified groupName does not exist.
Example:
>>> font.groups["myGroup"] ("A", "B", "C")
Note
Any changes to the returned lib contents will not be reflected in it’s
BaseGroupsinstance. To make changes to this content, do the following:>>> group = font.groups["myGroup"] >>> group.remove("A") >>> font.groups["myGroup"] = group
- BaseGroups.__iter__() Iterator[str][source]¶
Return an iterator over the keys in the current groups instance.
The iteration order is not fixed.
- Returns:
An
Iteratorover thestrkeys.
Example:
>>> for groupName in font.groups: >>> print groupName "myGroup" "myGroup3" "myGroup2"
- BaseGroups.__len__() int[source]¶
Return the number of groups in the current groups instance.
- Returns:
An
intrepresenting the number of groups in the current groups instance.
Example:
>>> len(font.groups) 5
- BaseGroups.__setitem__(groupName: str, glyphNames: list[str] | tuple[str, ...]) None[source]¶
Set the glyph names for a given group in the current groups instance.
- Parameters:
Example:
>>> font.groups["myGroup"] = ["A", "B", "C"]
- BaseGroups.clear() None[source]¶
Remove all groups from the current groups instance.
This will reset the
BaseGroupsinstance to an empty dictionary.Example:
>>> font.groups.clear()
- BaseGroups.get(groupName: str, default: list[str] | tuple[str, ...] | None = None) tuple[str, ...] | None[source]¶
Get the contents for the given group in the current groups instance.
If the given groupName is not found, The specified default will be returned.
- Parameters:
- Returns:
The contents of the given group as a
tupleofstritems, or the default value if the group is not found.
Example:
>>> font.groups["myGroup"] ("A", "B", "C")
..note:
Any changes to the returned lib contents will not be reflected in it's :class:`BaseGroups` instance. To make changes to this content, do the following:: >>> group = font.groups["myGroup"] >>> group.remove("A") >>> font.groups["myGroup"] = group
- BaseGroups.items() BaseItems[str, ValueType][source]¶
Return the items in the current groups instance.
- Each item is represented as a
tupleof key-value pairs, where:
- Returns:
A type-view of the groups’
(key, value)pairs.
Example:
>>> font.groups.items() BaseGroups_items([("myGroup", ("A", "B", "C")), ("myGroup2", ("D", "E", "F")), ...])
- Each item is represented as a
- BaseGroups.keys() BaseKeys[source]¶
Return the group names (keys) in the current groups instance.
- Returns:
A type-view of
stritems representing the groups’ keys.
Example:
>>> font.groups.keys() BaseGroups_keys(["myGroup4", "myGroup1", "myGroup5", ...])
- BaseGroups.pop(groupName: str, default: list[str] | tuple[str, ...] | None = None) tuple[str, ...] | None[source]¶
Remove the specified group and return its associated contents.
If the groupName does not exist, the default value is returned.
- Parameters:
- Returns:
The contents of the given group as a
tupleofstritems, or the default value if the group is not found.
Example:
>>> font.groups.pop("myGroup") ("A", "B", "C")
- BaseGroups.update(otherGroups: MutableMapping[str, list[str] | tuple[str, ...]]) None[source]¶
Update the current groups instance with key-value pairs from another.
- For each group in otherGroups:
If the group exists in the current groups instance, its value is replaced with the value from otherGroups.
If the key does not exist in the current groups instance, it is added.
Keys that exist in the current groups instance but are not in otherLib remain unchanged.
- Parameters:
otherLib – A
MutableMappingofstrgroup names mapped to atupleofstrglyph names to update the current groups instance with.
Example:
>>> font.groups.update(newGroups)
Queries¶
Environment¶
- BaseGroups.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()