fontParts.world

Note

We still need to decide if we need a world module or if we should recommend namespace injection.

fontParts.world.AllFonts(sortOptions: list[str] | tuple[str, ...] | None = None) BaseFontList[source]

Get a list of all open fonts.

Optionally, provide a value for sortOptions to sort the fonts. See BaseFontList.sortBy for options.

Parameters:

sortOptions – The optional list or tuple of str sort options to apply to the list. Defaults to None.

Returns:

A BaseFontList instance representing all open fonts.

Example:

from fontParts.world import AllFonts

fonts = AllFonts()
for font in fonts:
    # do something

fonts = AllFonts("magic")
for font in fonts:
    # do something

fonts = AllFonts(["familyName", "styleName"])
for font in fonts:
    # do something
fontParts.world.NewFont(familyName: str | None = None, styleName: str | None = None, showInterface: bool = True) BaseFont[source]

Create a new font.

Parameters:
  • familyName – The optional BaseInfo.familyName to apply to the font as a str.

  • styleName – The optional BaseInfo.styleName to apply to the font as a str.

  • showInterface – A bool indicating whether to show the graphical interface. If False, the font should be opened without a graphical interface. Defaults to True.

Returns:

The newly created BaseFont instance.

Example:

from fontParts.world import NewFont

font = NewFont()
font = NewFont(familyName="My Family", styleName="My Style")
font = NewFont(showInterface=False)
fontParts.world.OpenFont(path: str, showInterface: bool = True) BaseFont[source]

Open font located at the specified path.

Parameters:
  • path – The path to the font file to be opened as a str

  • showInterface – A bool indicating whether to show the graphical interface. If False, the font should be opened without a graphical interface. Defaults to True.

Returns:

The newly opened BaseFont instance.

Example:

from fontParts.world import OpenFont

font = OpenFont("/path/to/my/font.ufo")
font = OpenFont("/path/to/my/font.ufo", showInterface=False)
fontParts.world.OpenFonts(directory: str | CollectionType[str] | None = None, showInterface: bool = True, fileExtensions: CollectionType[str] | None = None) Generator[BaseFont][source]

Open all fonts located in the specified directories.

The fonts are located within the directory using the glob module. The patterns are created with os.path.join(directory, "*" + fileExtension) for every file extension in fileExtensions.

Parameters:
  • directory – The optional directory str or the list or tuple of directories to search for fonts. If None (default), a dialog for selecting a directory will be opened.

  • showInterface – A bool indicating whether to show the graphical interface. If False, the font should be opened without a graphical interface. Defaults to True.

  • fileExtensions – The optional file extensions to search for as a list or tuple of str items. If None (default), the default file extensions will be used.

Returns:

A generator yielding the opened fonts.

Example:

from fontParts.world import OpenFonts

fonts = OpenFonts()
fonts = OpenFonts(showInterface=False)
fontParts.world.CurrentFont() BaseFont[source]

Get the currently active font.

Returns:

A BaseFont subclass instance representing the currently active font.

fontParts.world.CurrentLayer() BaseLayer[source]

Get the currently active layer from CurrentGlyph.

Returns:

A BaseLayer subclass instance representing the currently active glyph layer.

Example:

from fontParts.world import CurrentLayer

layer = CurrentLayer()
fontParts.world.CurrentGlyph() BaseGlyph[source]

Get the currently active glyph from CurrentFont.

Returns:

A BaseGlyph subclass instance representing the currently active glyph.

Example:

from fontParts.world import CurrentGlyph

glyph = CurrentGlyph()
fontParts.world.CurrentContours() tuple[BaseContour, ...][source]

Get the currently selected contours from CurrentGlyph.

Returns:

A tuple of BaseContour subclass instances representing the currently selected glyph contours. If nothing is selected, the tuple will be empty.

Example:

from fontParts.world import CurrentContours

contours = CurrentContours()
fontParts.world.CurrentSegments() tuple[BaseSegment, ...][source]

Get the currently selected segments from CurrentContours.

Returns:

A tuple of BaseSegments subclass instances representing the currently selected contour segments. If nothing is selected, the tuple will be empty.

Example:

from fontParts.world import CurrentSegments

segments = CurrentSegments()
fontParts.world.CurrentPoints() tuple[BasePoint, ...][source]

Get the currently selected points from CurrentContours.

Returns:

A tuple of BasePoint subclass instances representing the currently selected contour points. If nothing is selected, the tuple will be empty.

Example:

from fontParts.world import CurrentPoints

points = CurrentPoints()
fontParts.world.CurrentComponents() tuple[BaseComponent, ...][source]

Get the currently selected components from CurrentGlyph.

Returns:

A tuple of BaseComponent subclass instances representing the currently selected glyph components. If nothing is selected, the tuple will be empty.

Example:

from fontParts.world import CurrentComponents

components = CurrentComponents()
fontParts.world.CurrentAnchors() tuple[BaseAnchor, ...][source]

Get the currently selected anchors from CurrentGlyph.

Returns:

A tuple of BaseAnchor subclass instances representing the currently selected glyph anchors. If nothing is selected, the tuple will be empty.

Example:

from fontParts.world import CurrentAnchors

anchors = CurrentAnchors()
fontParts.world.CurrentGuidelines() tuple[BaseGuideline, ...][source]

Get the currently selected guidelines from CurrentGlyph.

This will include both font level and glyph level guidelines.

Returns:

A tuple of BaseGuideline subclass instances representing the currently selected guidelines. If nothing is selected, the tuple will be empty.

Example:

from fontParts.world import CurrentGuidelines

guidelines = CurrentGuidelines()
fontParts.world.FontList(fonts: Iterable[T] | None = None)[source]

Get a list with font-specific methods.

Returns:

A BaseFontList instance.

Example:

from fontParts.world import FontList

fonts = FontList()

Refer to BaseFontList for full documentation.

class fontParts.world.BaseFontList(iterable=(), /)[source]

Represent a list with font-specific methods.