Normalizers¶
Kerning¶
- fontParts.base.normalizers.normalizeKerningKey(value: list[str] | tuple[str, str]) tuple[str, str][source]¶
Normalize a kerning key.
- Parameters:
value – The kerning key to normalize as a
tupleorlistcontaining two items representing the left and right kerning key groups. Each item in value: - must be astr. - must be at least one character long.- Returns:
- Raises:
If value does not a contain a pair of items.
If any value item is an empty
str.If the left kerning key group starts with ‘public.’ but does not start with ‘public.kern1.’.
If the right kerning key group starts with ‘public.’ but does not start with ‘public.kern2.’.
Groups¶
- fontParts.base.normalizers.normalizeGroupKey(value: str) str[source]¶
Normalize a group key.
- Parameters:
value – The group key to normalize as a non-empty
str.- Returns:
A
strrepresenting the normalized group key.- Raises:
TyypeError – If value is not a
str.
raises ValueError: If value is an empty
str.
- fontParts.base.normalizers.normalizeGroupValue(value: list[str] | tuple[str, ...]) tuple[str, ...][source]¶
Normalize a group value.
Features¶
Lib¶
- fontParts.base.normalizers.normalizeLibValue(value: LibValue) LibValue[source]¶
Normalize a lib value.
If value is a collection (
list,tuple, ordict), its elements will be normalized recursively.- Parameters:
value – The lib value to normalize. The value and any value items must be a type compatible with the
plistlibmodule.- Returns:
The normalized lib value, of the same type as value.
- Raises:
ValueError – If value or any of it’s items is
None.
Layers¶
- fontParts.base.normalizers.normalizeLayerOrder(value: list[str] | tuple[str, ...], font) tuple[str, ...][source]¶
Normalize layer order.
- Parameters:
value – The layer order to normalize as a
listortupleof layer names. Each item in value: - must normalize withnormalizeLayerName. - must correspond to an existing layer name in the font. - must be unique (no duplicates are allowed).font – The
BaseFont(subclass) instance to which the normalization applies.
- Returns:
A
tupleof layer names in their normalized order.- Raises:
- fontParts.base.normalizers.normalizeDefaultLayerName(value: str, font) str[source]¶
Normalize a default layer name.
- Parameters:
value – The layer name to normalize as a
str. The value: - must normalize as layer name withnormalizeLayerName. - must be a layer in font.font – The
BaseFont(subclass) instance to which the normalization applies.
- Returns:
A
strrepresenting the normalized default layer name.- Raises:
If value does not exist in font.
If value is an empty
str.
Glyphs¶
- fontParts.base.normalizers.normalizeGlyph(value: BaseGlyph) BaseGlyph[source]¶
Normalize a glyph.
- Parameters:
value – The glyph to normalize as an instance of
BaseGlyph.- Returns:
The normalized
BaseGlyphinstance.- Raises:
TypeError – If value is not an instance of
BaseGlyph.
- fontParts.base.normalizers.normalizeGlyphOrder(value: list[str] | tuple[str, ...]) tuple[str, ...][source]¶
Normalize glyph order.
- Parameters:
value – The glyph order to normalize as a
listortupleof glyph names. Each item in value: - must normalize as glyph names withnormalizeGlyphName. - must be unique (no duplicates are allowed).- Returns:
A
tupleof glyph names in their normalized order.- Raises:
Identification¶
- fontParts.base.normalizers.normalizeGlyphName(value: str) str[source]¶
Normalize a glyph’s name.
- Parameters:
value – The glyph name to normalize as a non-empty
str.- Returns:
A
strrepresenting the normalized glyph name.- Raises:
ValueError – If value is an empty string.
- fontParts.base.normalizers.normalizeGlyphUnicodes(value: list[int] | tuple[int, ...]) tuple[int, ...][source]¶
Normalize a glyph’s unicodes.
- Parameters:
value – The glyph unicodes to normalize as a
listortupleof Unicode values. Each item in value: - must normalize as glyph unicodes withnormalizeGlyphUnicode. - must be unique (no duplicates are allowed).- Returns:
A
tupleofintvalues representing the normalized glyph unicodes.- Raises:
If value contains duplicate values.
If any value item is not a valid hexadecimal value.
If any value item is not within the unicode range.
- fontParts.base.normalizers.normalizeGlyphUnicode(value: int | str) int[source]¶
Normalize a glyph’s unicode.
Metrics¶
- fontParts.base.normalizers.normalizeGlyphWidth(value: int | float) int | float[source]¶
Normalize a glyph’s width.
- fontParts.base.normalizers.normalizeGlyphLeftMargin(value: int | float | None) int | float | None[source]¶
Normalize a glyph’s left margin.
- fontParts.base.normalizers.normalizeGlyphRightMargin(value: int | float | None) int | float | None[source]¶
Normalize a glyph’s right margin.
- fontParts.base.normalizers.normalizeGlyphHeight(value: int | float) int | float[source]¶
Normalize a glyph’s height.
- fontParts.base.normalizers.normalizeGlyphBottomMargin(value: int | float | None) int | float | None[source]¶
Normalize a glyph’s bottom margin.
Contours¶
- fontParts.base.normalizers.normalizeContour(value: BaseContour) BaseContour[source]¶
Normalize a contour.
- Parameters:
value – The contour to normalize as an instance of
BaseContour.- Returns:
The normalized
BaseContourinstance.- Raises:
TypeError – If value is not an instance of
BaseContour.
Points¶
- fontParts.base.normalizers.normalizePointType(value: str) str[source]¶
Normalize a point type.
- Parameters:
value –
The point type to normalize as a
strcontaining one of the following values:Value
Description
'move''line''offcurve''curve''qcurve'The first point in an open contour. A straight line from the previous point. A control point in a curve or qcurve. A cubic Bézier curve from the previous point. A quadratic Bézier curve from the previous point.
- Returns:
A
strrepresenting the normalized point type.- Raises:
ValueError – If value is not one of the allowed types.
Segments¶
- fontParts.base.normalizers.normalizeSegmentType(value: str) str[source]¶
Normalize a segment type.
- Parameters:
value –
The segment type to normalize as a
strcontaining one of the following values:Value
Description
'move''line''curve''qcurve'The start of an open contour. A straight segment between two on-curve points. A cubic Bézier curve segment. A quadratic Bézier curve segment.
- Returns:
A
strrepresenting the normalized segment type.- Raises:
ValueError – If value is not one of the allowed types.
BPoints¶
- fontParts.base.normalizers.normalizeBPointType(value: str) str[source]¶
Normalize a bPoint type.
- Parameters:
value –
The bPoint type to normalize as a
strcontaining one of the following values:Value
Description
'curve''corner'A point where bcpIn and bcpOut are smooth (linked). A point where bcpIn and bcpOut are not smooth (linked).
- Returns:
A
strrepresenting the normalized bPoint type.- Raises:
ValueError – If value is not one of the allowed types.
Components¶
Anchors¶
Note¶
Guidelines¶
- fontParts.base.normalizers.normalizeGuideline(value: BaseGuideline) BaseGuideline[source]¶
Normalize a guideline.
- Parameters:
value – The contour to normalize as an instance of
BaseGuideline.- Returns:
The normalized
BaseGuidelineinstance.- Raises:
TypeError – If value is not an instance of
BaseGuideline.
Generic¶
- fontParts.base.normalizers.normalizeInternalObjectType(value: object, cls: type[T], name: str) T[source]¶
Normalize an internal object type.
- Parameters:
value – The object instance to normalize.
cls – The class against which to check the type of value.
name – The name of the variable being checked (for error messages).
- Returns:
The normalized object, of the same type as value.
- Raises:
TypeError – If value is not an instance of cls.
Positions¶
- fontParts.base.normalizers.normalizeX(value: int | float) int | float[source]¶
Normalize an x-coordinate.
- fontParts.base.normalizers.normalizeY(value: int | float) int | float[source]¶
Normalize a y-coordinate.
- fontParts.base.normalizers.normalizeCoordinateTuple(value: list[int | float] | tuple[int | float, int | float]) tuple[int | float, int | float][source]¶
Normalize a coordinate tuple.
- fontParts.base.normalizers.normalizeBoundingBox(value: list[int | float] | tuple[float, float, float, float]) tuple[float, float, float, float][source]¶
Normalize a bounding box.
- Parameters:
value – The bounding box to normalize as a
listortupleof fourintorfloatvalues representing the coordinates (in order) xMin, yMin, xMax, and yMax. The xMin and yMin values must be less than or equal to the corresponding xMax, yMax values.- Returns:
A
tupleof fourfloatvalues representing the normalized bounding box.- Raises:
Identification¶
- fontParts.base.normalizers.normalizeIndex(value: int | None) int | None[source]¶
Normalize an index.
- Parameters:
- Returns:
The normalized index, of the same type as value.
- Raises:
ValueError – If value is not an
intorNone.
- fontParts.base.normalizers.normalizeIdentifier(value: str | None) str | None[source]¶
Normalize an identifier.
- Parameters:
value – The identifier to normalize as a non-empty
str, orNone. The value: - must not be longer than 100 characters. - must not contain a character out of the range0x20-0x7E.- Returns:
The normalized identifier, of the same type as value.
- Raises:
If value is an empty
str.If value is longer than 100 characters.
If value contains a character outside the range
0x20-0x7E.
- fontParts.base.normalizers.normalizeColor(value: list[int | float] | tuple[float, float, float, float]) tuple[float, float, float, float][source]¶
Normalize a color.
Interpolation¶
- fontParts.base.normalizers.normalizeInterpolationFactor(value: int | float | list[int | float] | tuple[float, float]) tuple[float, float][source]¶
Normalize an interpolation factor.
Transformations¶
- fontParts.base.normalizers.normalizeTransformationMatrix(value: list[int | float] | tuple[float, float, float, float, float, float]) tuple[float, float, float, float, float, float][source]¶
Normalize a transformation matrix.
- fontParts.base.normalizers.normalizeTransformationOffset(value: list[int | float] | tuple[int | float, int | float]) tuple[int | float, int | float][source]¶
Normalize a transformation offset.
- fontParts.base.normalizers.normalizeTransformationSkewAngle(value: int | float | list[int | float] | tuple[float, float]) tuple[float, float][source]¶
Normalize a transformation skew angle.
- Parameters:
value – The skew angle to normalize as a single
intorfloat, or atupleorlistof twointorfloatvalues. Each value must be between-360 and ``360. If the value is negative, it is normalized by adding it to360.- Returns:
A
tupleof twofloatvalues between0.0and360.0representing the normalized skew angle.- Raises:
- fontParts.base.normalizers.normalizeTransformationScale(value: int | float | list[int | float] | tuple[float, float]) tuple[float, float][source]¶
Normalize a transformation scale.
Files¶
- fontParts.base.normalizers.normalizeFilePath(value: str | Path) str[source]¶
Normalize a file path.
- Parameters:
value – The file path to normalize as a
strorpathlib.Path.- Returns:
A
strrepresenting the normalized file path.
:raises TypeError if value is not a
strorpathlib.Path. :raises FileNotFoundError: If the file path cannot be resolved because it does not exist.
Standard¶
- fontParts.base.normalizers.normalizeVisualRounding(value: int | float) int[source]¶
Normalize rounding.
Python 3 uses banker’s rounding, meaning anything that is at 0.5 will round to the nearest even number. This isn’t always ideal for point coordinates, so instead, this function rounds to the higher number with
fontTools.misc.roundTools.otRound.