pyglet.font.group

class FontGroup(name: str) → None

An ordered set of fallback font families.

Each character is rendered by the first added family that contains it. If no family contains a character, the first family supplies its normal missing-glyph representation.

Added in version 3.0.

add(family: str) → FontGroup

Add a font family to the fallback chain.

Families are checked in the order in which they are added.

Return type:

FontGroup

class FontGroupBase(name: str) → None

Base class for a collection of fonts used as one font.

Applications normally use FontGroup for ordered glyph fallback, or FontRangeGroup when they need explicit Unicode-range routing.

get_font(
size: float | None,
weight: Weight | str | None = Weight.NORMAL,
style: Style | str | None = Style.NORMAL,
stretch: Stretch | str | None = Stretch.NORMAL,
dpi: int | None = None,
) → FontGroupInstance
Return type:

FontGroupInstance

class FontGroupInstance(
group: FontGroupBase,
size: float,
weight: Weight | str,
style: Style | str,
stretch: Stretch | str,
dpi: int | None,
) → None

A font instance based on a FontGroupBase.

Initialize a font that can be used with Pyglet.

Parameters:
  • name – Font family, for example, “Times New Roman”. If a list of names is provided, the first one matching a known font is used. If no font can be matched to the name(s), a default font is used. The default font will be platform dependent.

  • size (float) – Size of the font, in points. The returned font may be an exact match or the closest available.

  • weight (Weight | str) – If set, a specific weight variant is returned if one exists for the given font family and size. The weight is provided as a string. For example: “bold” or “light”.

  • style (Style | str) – Font slant, as a string or Style value: “normal”, “italic”, or “oblique”.

  • stretch (Stretch | str) – If True, a stretch variant is returned, if one exists for the given family and size. Currently only supported by Windows through the DirectWrite font renderer. For example, “condensed” or “expanded”.

  • dpi (int | None) – int The assumed resolution of the display device, for the purposes of determining the pixel size of the font. Defaults to 96.

classmethod add_font_data(
data: bytes,
manager: FontManager,
) → None

Font groups are composite fonts and cannot register font data.

Return type:

None

classmethod have_font(name: str) → bool

Font groups do not represent an installed system font.

Return type:

bool

get_glyphs(
text: str,
shaping: bool = False,
) → tuple[list[Glyph], list[GlyphPosition]]

Create and return a list of Glyphs for text.

If any characters do not have a known glyph representation in this font, a substitution will be made.

Parameters:
  • text (str) – Text to render.

  • shaping (bool) – If the text will be shaped using the global option. If False, no text shaping will occur and positioning will instead be based on glyph dimensions.

Return type:

tuple[list[Glyph], list[GlyphPosition]]

get_text_size(text: str) → tuple[int, int]

Return estimated text width and height in pixels, rounded up to integers.

Uses glyph metrics without rendering and does not take into account any shaping.

Return type:

tuple[int, int]

has_character(character: str) → bool

Return whether this font face contains a glyph for one character.

This query only considers the selected face. It does not report glyphs that a platform renderer might obtain through system font fallback.

Added in version 3.0.0.

Parameters:

character (str) – A single Unicode character.

Return type:

bool

character must contain exactly one Unicode character.

class FontRangeGroup(name: str) → None

A collection of fonts selected by explicit Unicode ranges.

The first matching range chooses the family. If no range matches, the first added family is used. Unlike FontGroup, this class does not probe subsequent families for missing characters.

Added in version 3.0.

add(
family: str,
start: int | str,
end: int | str,
) → FontRangeGroup

Add a font family responsible for a range of characters.

Return type:

FontRangeGroup