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 tuple or list containing two items representing the left and right kerning key groups. Each item in value: - must be a str. - must be at least one character long.

Returns:

The normalized kerning key as a tuple of str items.

Raises:
  • TypeError

    • If value is not a list or tuple.

    • If any value item is not a str.

  • ValueError

    • 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.’.

fontParts.base.normalizers.normalizeKerningValue(value: int | float) int | float[source]

Normalize a kerning value.

Parameters:

value – The kerning value to normalize as an int or float.

Returns:

An int or flaot representing the normalized kerning value.

raises TypeError: If value is not an int or a float.

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 str representing 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.

Parameters:

value – The group value to normalize as a list or tuple of str items representing the names of the glyphs in the group. All value items must normalize normalizeGlyphName.

Returns:

A tuple of str items representing the normalized gorup value.

Raises:

TyypeError – If value is not a list or tuple.

Features

fontParts.base.normalizers.normalizeFeatureText(value: str) str[source]

Normalize feature text.

Parameters:

value – The feature text to normalize as a str.

Returns:

A str representing the normalized feature text.

Raises:

TypeError – If value is not a str.

Lib

fontParts.base.normalizers.normalizeLibKey(value: str) str[source]

Normalize a lib key.

Parameters:

value – The lib key to normalize as a non-empty str.

Returns:

A str representing the normalized lib key.

Raises:
fontParts.base.normalizers.normalizeLibValue(value: LibValue) LibValue[source]

Normalize a lib value.

If value is a collection (list, tuple, or dict), 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 plistlib module.

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 list or tuple of layer names. Each item in value: - must normalize with normalizeLayerName. - 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 tuple of layer names in their normalized order.

Raises:
  • TypeError

    • If value is not a list or tuple.

    • If any value item is not a str.

  • ValueError

    • If value contains duplicate values.

    • If any value item does not exist in font.

    • If any value item is an empty str.

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 with normalizeLayerName. - must be a layer in font.

  • font – The BaseFont (subclass) instance to which the normalization applies.

Returns:

A str representing the normalized default layer name.

Raises:
fontParts.base.normalizers.normalizeLayerName(value: str) str[source]

Normalize a layer name.

Parameters:

value – The layer name to normalize as a non-empty str.

Returns:

A str representing the normalized layer name.

Raises:

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 BaseGlyph instance.

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 list or tuple of glyph names. Each item in value: - must normalize as glyph names with normalizeGlyphName. - must be unique (no duplicates are allowed).

Returns:

A tuple of 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 str representing the normalized glyph name.

Raises:
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 list or tuple of Unicode values. Each item in value: - must normalize as glyph unicodes with normalizeGlyphUnicode. - must be unique (no duplicates are allowed).

Returns:

A tuple of int values representing the normalized glyph unicodes.

Raises:
  • TypeError – If value is not a list or tuple.

  • ValueError

    • 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.

Parameters:

value – The glyph Unicode value to normalize as an int or a hexadecimal str. The value must be within the unicode range.

Returns:

An int representing the normalized unicode value.

Raises:
  • TypeError – If value is not and int or a str.

  • ValueError

    • If value is not a valid hexadecimal value.

    • If value is not within the unicode range.

Metrics

fontParts.base.normalizers.normalizeGlyphWidth(value: int | float) int | float[source]

Normalize a glyph’s width.

Parameters:

value – The glyph width to normalize as an int or float.

Returns:

The normalized glyph width, of the same type as value.

Raises:

TypeError – if value is not an int or a float.

fontParts.base.normalizers.normalizeGlyphLeftMargin(value: int | float | None) int | float | None[source]

Normalize a glyph’s left margin.

Parameters:

value – The glyph left margin to normalize as an int, float, or None.

Returns:

The normalized glyph left margin, of the same type as value.

Raises:

TypeError – if value is not an int or a float.

fontParts.base.normalizers.normalizeGlyphRightMargin(value: int | float | None) int | float | None[source]

Normalize a glyph’s right margin.

Parameters:

value – The glyph right margin to normalize as an int, float, or None.

Returns:

The normalized glyph right margin, of the same type as value.

Raises:

TypeError – if value is not an int or a float.

fontParts.base.normalizers.normalizeGlyphHeight(value: int | float) int | float[source]

Normalize a glyph’s height.

Parameters:

value – The glyph height to normalize as an int or float.

Returns:

The normalized glyph height, of the same type as value.

Raises:

TypeError – if value is not an int or a float.

fontParts.base.normalizers.normalizeGlyphBottomMargin(value: int | float | None) int | float | None[source]

Normalize a glyph’s bottom margin.

Parameters:

value – The glyph bottom margin to normalize as an int, float, or None.

Returns:

The normalized glyph bottom margin, of the same type as value.

Raises:

TypeError – if value is not an int or a float.

fontParts.base.normalizers.normalizeGlyphTopMargin(value: int | float | None) int | float | None[source]

Normalize a glyph’s top margin.

Parameters:

value – The glyph top margin to normalize as an int, float, or None.

Returns:

The normalized glyph top margin, of the same type as value.

Raises:

TypeError – If value is not an int or a float.

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 BaseContour instance.

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 str containing 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 str representing the normalized point type.

Raises:
fontParts.base.normalizers.normalizePointName(value: str) str[source]

Normalize a point name.

Parameters:

value – The point name to normalize as a non-empty str.

Returns:

A str representing the normalized point name.

Raises:

Segments

fontParts.base.normalizers.normalizeSegmentType(value: str) str[source]

Normalize a segment type.

Parameters:

value

The segment type to normalize as a str containing 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 str representing the normalized segment type.

Raises:

BPoints

fontParts.base.normalizers.normalizeBPointType(value: str) str[source]

Normalize a bPoint type.

Parameters:

value

The bPoint type to normalize as a str containing 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 str representing the normalized bPoint type.

Raises:

Components

fontParts.base.normalizers.normalizeComponentScale(value: list[int | float] | tuple[float, float]) tuple[float, float][source]

Normalize a component scale.

Parameters:

value – The component scale to normalize as a list or tuple of two int or float values.

Returns:

A tuple of two float values representing the normalized component scale.

Anchors

fontParts.base.normalizers.normalizeAnchorName(value: str) str[source]

Normalize an anchor name.

Parameters:

value – The anchor name to normalize as a non-empty str, or None.

Returns:

A str representing the normalized anchor name, or None.

Raises:

Note

fontParts.base.normalizers.normalizeGlyphNote(value: str) str[source]

Normalize a glyph note.

Parameters:

value – The glyph note to normalize as a str.

Returns:

A str representing the normalized glyph note.

:raises TypeError if value is not a str.

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 BaseGuideline instance.

Raises:

TypeError – If value is not an instance of BaseGuideline.

fontParts.base.normalizers.normalizeGuidelineName(value: str) str[source]

Normalize a guideline name.

Parameters:

value – The guideline name to normalize as a non-empty str

Returns:

A str representing the normalized guideline name.

Raises:

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.

Parameters:

value – The x-coordinate to normalize as an int or float.

Returns:

The normalized glyph top margin, of the same type as value.

Raises:

TypeError – If value is not an int or a float.

fontParts.base.normalizers.normalizeY(value: int | float) int | float[source]

Normalize a y-coordinate.

Parameters:

value – The y-coordinate to normalize as an int or float.

Returns:

The normalized glyph top margin, of the same type as value.

Raises:

TypeError – If value is not an int or a float.

fontParts.base.normalizers.normalizeCoordinateTuple(value: list[int | float] | tuple[int | float, int | float]) tuple[int | float, int | float][source]

Normalize a coordinate tuple.

Parameters:

value – The coordinate tuple to normalize as a list or tuple of two int or float values.

Returns:

return:

A tuple of two values of the same type as the

items in value, representing the normalized coordinates.

Raises:
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 list or tuple of four int or float values 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 tuple of four float values representing the normalized bounding box.

Raises:
  • TypeError

  • ValueError

    • If value does not contain exactly four items.

    • If xMin is greater than xMax.

    • If yMin is greater than yMax.

Identification

fontParts.base.normalizers.normalizeIndex(value: int | None) int | None[source]

Normalize an index.

Parameters:

value – The index to normalize as an int, or None.

Returns:

The normalized index, of the same type as value.

Raises:

ValueError – If value is not an int or None.

fontParts.base.normalizers.normalizeIdentifier(value: str | None) str | None[source]

Normalize an identifier.

Parameters:

value – The identifier to normalize as a non-empty str, or None. The value: - must not be longer than 100 characters. - must not contain a character out of the range 0x20 - 0x7E.

Returns:

The normalized identifier, of the same type as value.

Raises:
  • TypeError – If value is not a str or None.

  • ValueError

    • 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.

Parameters:

value – The color to normalize as a list or tuple of four int or float values between 0 and 1, corresponding to the red, green, blue, and alpha (RGBA) channels, in that order.

Returns:

A tuple of four float values representing the normalized color.

Raises:
  • TypeError

  • ValueError

    • If value does not contain exactly four items.

    • If any value item is not between 0 and 1.

Interpolation

fontParts.base.normalizers.normalizeInterpolationFactor(value: int | float | list[int | float] | tuple[float, float]) tuple[float, float][source]

Normalize an interpolation factor.

Parameters:

value – The interpolation factor to normalize as a single int or float, or a tuple or list of two int or float values.

Returns:

A tuple of two float values representing the normalized interpolation factor.

Raises:

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.

Parameters:

value – The transformation matrix to normalize as a list or tuple of six int or float values.

Returns:

A tuple of six float values representing the normalized transformation matrix.

Raises:
fontParts.base.normalizers.normalizeTransformationOffset(value: list[int | float] | tuple[int | float, int | float]) tuple[int | float, int | float][source]

Normalize a transformation offset.

Parameters:

value – The transformation offset to normalize as a list or tuple of two int or float values.

Returns:

A tuple of two float values representing the normalized transformation offset.

Raises:
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 int or float, or a tuple or list of two int or float values. Each value must be between -360 and ``360. If the value is negative, it is normalized by adding it to 360.

Returns:

A tuple of two float values between 0.0 and 360.0 representing 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.

Parameters:

value – The scale to normalize as a single int or float, or a tuple or list of two int or float values.

Returns:

A tuple of two float values representing the normalized scale.

Raises:

Files

fontParts.base.normalizers.normalizeFilePath(value: str | Path) str[source]

Normalize a file path.

Parameters:

value – The file path to normalize as a str or pathlib.Path.

Returns:

A str representing the normalized file path.

:raises TypeError if value is not a str or pathlib.Path. :raises FileNotFoundError: If the file path cannot be resolved because it does not exist.

fontParts.base.normalizers.normalizeFileFormatVersion(value: int) int[source]

Normalize a font’s file format version.

Parameters:

value – The file format version of the font as an int.

Returns:

An int representing the normalized file format version.

Raises:

TypeError – If value is not of type int.

Standard

fontParts.base.normalizers.normalizeBoolean(value: int) bool[source]

Normalize a boolean.

Parameters:

value – The boolean to normalize as an int of 0 or 1, or a bool.

Returns:

A bool representing the normalized value.

Raises:

ValueError – If value is not a valid bool or int.

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.

Parameters:

value – The value to round as an int or a float.

Returns:

An int representing the normalized rounding.

Raises:

TypeError – If value is not an int or a float.