panda3d.core.DynamicTextFont

from panda3d.core import DynamicTextFont
class DynamicTextFont

Bases: TextFont, FreetypeFont

A DynamicTextFont is a special TextFont object that rasterizes its glyphs from a standard font file (e.g. a TTF file) on the fly. It requires the FreeType 2.0 library (or any higher, backward-compatible version).

Inheritance diagram

Inheritance diagram of DynamicTextFont

__init__(copy: DynamicTextFont) → None
__init__(font_filename: Filename, face_index: int) → None

The constructor expects the name of some font file that FreeType can read, along with face_index, indicating which font within the file to load (usually 0).

__init__(font_data: str, data_length: int, face_index: int) → None

This constructor accepts a table of data representing the font file, loaded from some source other than a filename on disk.

makeCopy() → TextFont

Returns a new copy of the same font.

Return type

TextFont

getName() → str

Disambiguates the getName() method between that inherited from TextFont and that inherited from FreetypeFont.

setPointSize(point_size: float) → bool

Sets the point size of the font. This controls the apparent size of the font onscreen. By convention, a 10 point font is about 1 screen unit high.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

getPointSize() → float

Returns the point size of the font.

setPixelsPerUnit(pixels_per_unit: float) → bool

Set the resolution of the texture map, and hence the clarity of the resulting font. This sets the number of pixels in the texture map that are used for each onscreen unit.

Setting this number larger results in an easier to read font, but at the cost of more texture memory.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

getPixelsPerUnit() → float

Returns the resolution of the texture map. See setPixelsPerUnit().

setScaleFactor(scale_factor: float) → bool

Sets the factor by which the font is rendered larger by the FreeType library before being filtered down to its actual size in the texture as specified by setPixelsPerUnit(). This may be set to a number larger than 1.0 to improve the font’s antialiasing (since FreeType doesn’t really do a swell job of antialiasing by itself). There is some performance implication for setting this different than 1.0, but it is probably small.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

getScaleFactor() → float

Returns the antialiasing scale factor. See setScaleFactor().

setNativeAntialias(native_antialias: bool) → None

Sets whether the Freetype library’s built-in antialias mode is enabled. There are two unrelated ways to achieve antialiasing: with Freetype’s native antialias mode, and with the use of a scale_factor greater than one. By default, both modes are enabled.

At low resolutions, some fonts may do better with one mode or the other. In general, Freetype’s native antialiasing will produce less blurry results, but may introduce more artifacts.

getNativeAntialias() → bool

Returns whether Freetype’s built-in antialias mode is enabled. See setNativeAntialias().

getFontPixelSize() → int

This is used to report whether the requested pixel size is being only approximated by a fixed-pixel-size font. This returns 0 in the normal case, in which a scalable font is used, or the fixed-pixel-size font has exactly the requested pixel size.

If this returns non-zero, it is the pixel size of the font that we are using to approximate our desired size.

getLineHeight() → float

Returns the number of units high each line of text is.

getSpaceAdvance() → float

Returns the number of units wide a space is.

setTextureMargin(texture_margin: int) → None

Sets the number of pixels of padding that is added around the border of each glyph before adding it to the texture map. This reduces the bleed in from neighboring glyphs in the texture map.

getTextureMargin() → int

Returns the number of pixels of padding that is added around the border of each glyph in the texture map. See setTextureMargin().

setPolyMargin(poly_margin: float) → None

Sets the number of pixels of padding that is included around each glyph in the generated polygons. This helps prevent the edges of the glyphs from being cut off at small minifications. It is not related to the amount of extra pixels reserved in the texture map (but it should be set somewhat smaller than this number, which is controlled by setTextureMargin(), to prevent bleed-in from neighboring letters in the texture).

getPolyMargin() → float

Returns the number of pixels of padding that is included around each glyph in the generated polygons. See setPolyMargin().

setPageSize(page_size: LVecBase2i) → None

Sets the x, y size of the textures that are created for the DynamicTextFont.

setPageSize(x_size: int, y_size: int) → None

Sets the x, y size of the textures that are created for the DynamicTextFont.

getPageSize() → LVecBase2i

Returns the size of the textures that are created for the DynamicTextFont. See setPageSize().

Return type

LVecBase2i

getPageXSize() → int

Returns the x size of the textures that are created for the DynamicTextFont. See setPageSize().

getPageYSize() → int

Returns the y size of the textures that are created for the DynamicTextFont. See setPageSize().

setMinfilter(filter: FilterType) → None

Sets the filter type used when minimizing the textures created for this font.

getMinfilter() → FilterType

Returns the filter type used when minimizing the textures created for this font.

Return type

FilterType

setMagfilter(filter: FilterType) → None

Sets the filter type used when enlarging the textures created for this font.

getMagfilter() → FilterType

Returns the filter type used when enlarging the textures created for this font.

Return type

FilterType

setAnisotropicDegree(anisotropic_degree: int) → None

Enables or disables anisotropic filtering on the textures created for this font. The default value is specified by the text-anisotropic-degree variable. See Texture.setAnisotropicDegree().

getAnisotropicDegree() → int

Returns the current anisotropic degree for textures created for this font. See setAnisotropicDegree().

setRenderMode(render_mode: RenderMode) → None

Specifies the way the glyphs on this particular font are generated. The default is RM_texture, which is the only mode supported for bitmap fonts. Other modes are possible for most modern fonts.

getRenderMode() → RenderMode

Returns the way the glyphs on this particular font are generated. See setRenderMode().

Return type

RenderMode

setFg(fg: LColor) → None

Changes the color of the foreground pixels of the font as they are rendered into the font texture. The default is (1, 1, 1, 1), or opaque white, which allows text created with the font to be colored individually. Normally, you would not change this unless you really need a particular color effect to appear in the font itself.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

getFg() → LColor

Returns the color of the foreground pixels of the font as they are rendered into the font texture. See setFg().

Return type

LColor

setBg(bg: LColor) → None

Changes the color of the background pixels of the font as they are rendered into the font texture. The default is (1, 1, 1, 0), or transparent white, which allows text created with the font to be colored individually. (Note that it should not generally be (0, 0, 0, 0), which would tend to bleed into the foreground color, unless you have also specified a outline color of (0, 0, 0, 1)) .

Normally, you would not change this unless you really need a particular color effect to appear in the font itself.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

getBg() → LColor

Returns the color of the background pixels of the font as they are rendered into the font texture. See setBg().

Return type

LColor

setOutline(outline_color: LColor, outline_width: float, outline_feather: float) → None

Sets up the font to have an outline around each font letter. This is achieved via a Gaussian post-process as each letter is generated; there is some runtime cost for this effect, but it is minimal as each letter is normally generated only once and then cached.

The color is the desired color of the outline, width is the number of points beyond the letter that the outline extends (a typical font is 10 points high), and feather is a number in the range 0.0 .. 1.0 that controls the softness of the outline. Set the width to 0.0 to disable the outline.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

getOutlineColor() → LColor

Returns the color of the outline pixels of the font as they are rendered into the font texture. See setOutline().

Return type

LColor

getOutlineWidth() → float

Returns the width of the outline pixels of the font, as the number of points beyond each letter. See setOutline().

getOutlineFeather() → float

Returns the softness of the outline pixels of the font, as a value in the range 0.0 to 1.0. See setOutline().

getTexFormat() → Format

Returns the texture format used to render the individual pages. This is set automatically according to the colors selected.

Return type

Format

getNumPages() → int

Returns the number of pages associated with the font. Initially, the font has zero pages; when the first piece of text is rendered with the font, it will add additional pages as needed. Each page is a Texture object that contains the images for each of the glyphs currently in use somewhere.

getPage(n: int) → DynamicTextPage

Returns the nth page associated with the font. Initially, the font has zero pages; when the first piece of text is rendered with the font, it will add additional pages as needed. Each page is a Texture object that contains the images for each of the glyphs currently in use somewhere.

Return type

DynamicTextPage

garbageCollect() → int

Removes all of the glyphs from the font that are no longer being used by any Geoms. Returns the number of glyphs removed.

clear() → None

Drops all the glyphs out of the cache and frees any association with any previously-generated pages.

Calling this frequently can result in wasted texture memory, as any previously rendered text will still keep a pointer to the old, previously- generated pages. As long as the previously rendered text remains around, the old pages will also remain around.

write(out: ostream, indent_level: int) → None
static getClassType() → TypeHandle
Return type

TypeHandle

getPages() → list
property point_size
Getter

Returns the point size of the font.

Setter

Sets the point size of the font. This controls the apparent size of the font onscreen. By convention, a 10 point font is about 1 screen unit high.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Return type

float

property pixels_per_unit
Getter

Returns the resolution of the texture map. See setPixelsPerUnit().

Setter

Set the resolution of the texture map, and hence the clarity of the resulting font. This sets the number of pixels in the texture map that are used for each onscreen unit.

Setting this number larger results in an easier to read font, but at the cost of more texture memory.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Return type

float

property scale_factor
Getter

Returns the antialiasing scale factor. See setScaleFactor().

Setter

Sets the factor by which the font is rendered larger by the FreeType library before being filtered down to its actual size in the texture as specified by setPixelsPerUnit(). This may be set to a number larger than 1.0 to improve the font’s antialiasing (since FreeType doesn’t really do a swell job of antialiasing by itself). There is some performance implication for setting this different than 1.0, but it is probably small.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Return type

float

property native_antialias
Getter

Returns whether Freetype’s built-in antialias mode is enabled. See setNativeAntialias().

Setter

Sets whether the Freetype library’s built-in antialias mode is enabled. There are two unrelated ways to achieve antialiasing: with Freetype’s native antialias mode, and with the use of a scale_factor greater than one. By default, both modes are enabled.

At low resolutions, some fonts may do better with one mode or the other. In general, Freetype’s native antialiasing will produce less blurry results, but may introduce more artifacts.

Return type

bool

property font_pixel_size

This is used to report whether the requested pixel size is being only approximated by a fixed-pixel-size font. This returns 0 in the normal case, in which a scalable font is used, or the fixed-pixel-size font has exactly the requested pixel size.

If this returns non-zero, it is the pixel size of the font that we are using to approximate our desired size.

Return type

int

property texture_margin
Getter

Returns the number of pixels of padding that is added around the border of each glyph in the texture map. See setTextureMargin().

Setter

Sets the number of pixels of padding that is added around the border of each glyph before adding it to the texture map. This reduces the bleed in from neighboring glyphs in the texture map.

Return type

int

property poly_margin
Getter

Returns the number of pixels of padding that is included around each glyph in the generated polygons. See setPolyMargin().

Setter

Sets the number of pixels of padding that is included around each glyph in the generated polygons. This helps prevent the edges of the glyphs from being cut off at small minifications. It is not related to the amount of extra pixels reserved in the texture map (but it should be set somewhat smaller than this number, which is controlled by setTextureMargin(), to prevent bleed-in from neighboring letters in the texture).

Return type

float

property page_size
Getter

Returns the size of the textures that are created for the DynamicTextFont. See setPageSize().

Setter

Sets the x, y size of the textures that are created for the DynamicTextFont.

Sets the x, y size of the textures that are created for the DynamicTextFont.

Return type

LVecBase2i

property minfilter
Getter

Returns the filter type used when minimizing the textures created for this font.

Setter

Sets the filter type used when minimizing the textures created for this font.

Return type

FilterType

property magfilter
Getter

Returns the filter type used when enlarging the textures created for this font.

Setter

Sets the filter type used when enlarging the textures created for this font.

Return type

FilterType

property anisotropic_degree
Getter

Returns the current anisotropic degree for textures created for this font. See setAnisotropicDegree().

Setter

Enables or disables anisotropic filtering on the textures created for this font. The default value is specified by the text-anisotropic-degree variable. See Texture.setAnisotropicDegree().

Return type

int

property render_mode
Getter

Returns the way the glyphs on this particular font are generated. See setRenderMode().

Setter

Specifies the way the glyphs on this particular font are generated. The default is RM_texture, which is the only mode supported for bitmap fonts. Other modes are possible for most modern fonts.

Return type

RenderMode

property fg
Getter

Returns the color of the foreground pixels of the font as they are rendered into the font texture. See setFg().

Setter

Changes the color of the foreground pixels of the font as they are rendered into the font texture. The default is (1, 1, 1, 1), or opaque white, which allows text created with the font to be colored individually. Normally, you would not change this unless you really need a particular color effect to appear in the font itself.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Return type

LColor

property bg
Getter

Returns the color of the background pixels of the font as they are rendered into the font texture. See setBg().

Setter

Changes the color of the background pixels of the font as they are rendered into the font texture. The default is (1, 1, 1, 0), or transparent white, which allows text created with the font to be colored individually. (Note that it should not generally be (0, 0, 0, 0), which would tend to bleed into the foreground color, unless you have also specified a outline color of (0, 0, 0, 1)) .

Normally, you would not change this unless you really need a particular color effect to appear in the font itself.

This should only be called before any characters have been requested out of the font, or immediately after calling clear().

Return type

LColor

property tex_format

Returns the texture format used to render the individual pages. This is set automatically according to the colors selected.

Return type

Format

property pages

Returns the nth page associated with the font. Initially, the font has zero pages; when the first piece of text is rendered with the font, it will add additional pages as needed. Each page is a Texture object that contains the images for each of the glyphs currently in use somewhere.

Return type

Sequence[DynamicTextPage]