Object Reference

FontParts scripts are built on with objects that represent fonts, glyphs, contours and so on. The objects are obtained through fontParts.world.

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=None)

Get a list of all open fonts. Optionally, provide a value for sortOptions to sort the fonts. See world.FontList.sortBy for options.

from fontParts.world import *

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=None, styleName=None, showInterface=True)

Create a new font. familyName will be assigned to font.info.familyName and styleName will be assigned to font.info.styleName. These are optional and default to None. If showInterface is False, the font should be created without graphical interface. The default for showInterface is True.

from fontParts.world import *

font = NewFont()
font = NewFont(familyName="My Family", styleName="My Style")
font = NewFont(showInterface=False)
fontParts.world.OpenFont(path, showInterface=True)

Open font located at path. If showInterface is False, the font should be opened without graphical interface. The default for showInterface is True.

from fontParts.world import *

font = OpenFont("/path/to/my/font.ufo")
font = OpenFont("/path/to/my/font.ufo", showInterface=False)
fontParts.world.CurrentFont()

Get the “current” font.

fontParts.world.CurrentLayer()

Get the “current” layer from CurrentGlyph.

from fontParts.world import *

layer = CurrentLayer()
fontParts.world.CurrentGlyph()

Get the “current” glyph from CurrentFont.

from fontParts.world import *

glyph = CurrentGlyph()
fontParts.world.CurrentContours()

Get the “currently” selected contours from CurrentGlyph.

from fontParts.world import *

contours = CurrentContours()

This returns an immutable list, even when nothing is selected.

fontParts.world.CurrentSegments()

Get the “currently” selected segments from CurrentContours.

from fontParts.world import *

segments = CurrentSegments()

This returns an immutable list, even when nothing is selected.

fontParts.world.CurrentPoints()

Get the “currently” selected points from CurrentContours.

from fontParts.world import *

points = CurrentPoints()

This returns an immutable list, even when nothing is selected.

fontParts.world.CurrentComponents()

Get the “currently” selected components from CurrentGlyph.

from fontParts.world import *

components = CurrentComponents()

This returns an immutable list, even when nothing is selected.

fontParts.world.CurrentAnchors()

Get the “currently” selected anchors from CurrentGlyph.

from fontParts.world import *

anchors = CurrentAnchors()

This returns an immutable list, even when nothing is selected.

fontParts.world.CurrentGuidelines()

Get the “currently” selected guidelines from CurrentGlyph. This will include both font level and glyph level guidelines.

from fontParts.world import *

guidelines = CurrentGuidelines()

This returns an immutable list, even when nothing is selected.