Plush

FontCollection#

plupy · Type index

Module: plupy · obtained from plupy.data.fonts

plupy.data.fonts: fonts for Text components, imported from .ttf or .otf files.

class FontCollection(DataCollection)

Inherits DataCollection: its members are documented there.

Usage and examples

Members: import_file

import_file#

import_file(path: str) -> DataBlock

Copy a .ttf/.otf into Assets/Fonts and return its font datablock (an identical file returns the existing one).

Copies a .ttf or .otf into Assets/Fonts and creates a font datablock named after the file, the same as the editor's Import font. path is absolute or relative to the script's working directory (the project root). Importing a file identical to one already in the project returns the existing font. An invalid or unsupported file raises PlupyError and creates no data. Assign the result to a Text component's text.font property:

font = plupy.data.fonts.import_file("Source/DejaVuSans.ttf")
label = plupy.data.objects.new("Label")
text = label.components.add("text")
text.props["text.font"] = font
text.props["text.content"] = "x ÷ 2 = 3"

The copied file stays in Assets/Fonts if the edit is cancelled or undone; importing it again reuses it.

DataBlock · DataCollection · PlupyError · edit

Source#