panda3d.core.TextProperties

from panda3d.core import TextProperties
class TextProperties

This defines the set of visual properties that may be assigned to the individual characters of the text. (Properties which affect the overall block of text can only be specified on the TextNode directly).

Typically, there is just one set of properties on a given block of text, which is set directly on the TextNode (TextNode inherits from TextProperties). That makes all of the text within a particular block have the same appearance.

This separate class exists in order to implement multiple different kinds of text appearing within one block. The text string itself may reference a TextProperties structure by name using the 1 and 2 tokens embedded within the string; each nested TextProperties structure modifies the appearance of subsequent text within the block.

Inheritance diagram

Inheritance diagram of TextProperties

__init__() → None
__init__(copy: TextProperties) → None
assign(copy: TextProperties) → TextProperties
Return type

TextProperties

clear() → None

Unsets all properties that have been specified so far, and resets the TextProperties structure to its initial empty state.

isAnySpecified() → bool

Returns true if any properties have been specified, false otherwise.

static setDefaultFont(param0: TextFont) → None

Specifies the default font to be used for any TextNode whose font is uninitialized or NULL. See setFont().

static getDefaultFont() → TextFont

Specifies the default font to be used for any TextNode whose font is uninitialized or NULL. See setFont().

Return type

TextFont

setFont(font: TextFont) → None

Sets the font that will be used when making text. If this is set to NULL, the default font will be used, which can be set via setDefaultFont().

clearFont() → None

Restores the default font to the text.

hasFont() → bool
getFont() → TextFont

Returns the font currently in use, if any. If no font is in use, this returns the default font.

Return type

TextFont

setSmallCaps(small_caps: bool) → None

Sets the small_caps flag. When this is set, lowercase letters are generated as scaled-down versions of their uppercase equivalents. This is particularly useful to set for fonts that do not have lowercase letters.

It is also a good idea to set this for a (dynamic) font that has already implemented lowercase letters as scaled-down versions of their uppercase equivalents, since without this flag the texture memory may needlessly duplicate equivalent glyphs for upper and lowercase letters. Setting this flag causes the texture memory to share the mixed-case letters.

The amount by which the lowercase letters are scaled is specified by setSmallCapsScale().

clearSmallCaps() → None
hasSmallCaps() → bool
getSmallCaps() → bool

Returns the small_caps flag. See setSmallCaps().

setSmallCapsScale(small_caps_scale: float) → None

Sets the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect. See setSmallCaps(). Normally, this will be a number less than one.

clearSmallCapsScale() → None
hasSmallCapsScale() → bool
getSmallCapsScale() → float

Returns the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect. See setSmallCaps() and setSmallCapsScale().

setSlant(slant: float) → None

Specifies the factor by which the text slants to the right.

clearSlant() → None
hasSlant() → bool
getSlant() → float

Returns the factor by which the text is specified to slant to the right.

setUnderscore(underscore: bool) → None

Sets the underscore flag. When this is set, the text is underscored with a one-pixel line the same color as the text foreground, drawn at the baseline.

clearUnderscore() → None
hasUnderscore() → bool
getUnderscore() → bool

Returns the underscore flag. See setUnderscore().

setUnderscoreHeight(underscore_height: float) → None

Specifies the vertical height of the underscore, relative to the text baseline. This only has meaning if the underscore mode is enabled with setUnderscore().

clearUnderscoreHeight() → None
hasUnderscoreHeight() → bool
getUnderscoreHeight() → float

Returns the vertical height of the underscore; see setUnderscoreHeight().

setAlign(align_type: Alignment) → None

Specifies the alignment of the text within its margins.

clearAlign() → None

Restores the default alignment of the text.

hasAlign() → bool
getAlign() → Alignment
Return type

Alignment

setIndent(indent: float) → None

Specifies the amount of extra space that is inserted before the first character of each line. This can be thought of as a left margin.

clearIndent() → None

Removes the indent setting from the text. Text will be as wide as it is.

hasIndent() → bool
getIndent() → float
setWordwrap(wordwrap: float) → None

Sets the text up to automatically wordwrap when it exceeds the indicated width. This can be thought of as a right margin or margin width.

clearWordwrap() → None

Removes the wordwrap setting from the text. Text will be as wide as it is.

hasWordwrap() → bool
getWordwrap() → float
setPreserveTrailingWhitespace(preserve_trailing_whitespace: bool) → None

Sets the preserve_trailing_whitespace flag. When this is set, trailing whitespace at the end of the line is not stripped when the text is wordwrapped (it is stripped by default). Since the trailing whitespace is invisible, this is important primarily for determining the proper width of a frame or card behind the text.

clearPreserveTrailingWhitespace() → None
hasPreserveTrailingWhitespace() → bool
getPreserveTrailingWhitespace() → bool

Returns the preserve_trailing_whitespace flag. See setPreserveTrailingWhitespace().

setTextColor(text_color: LColor) → None
setTextColor(r: float, g: float, b: float, a: float) → None
clearTextColor() → None

Removes the text color specification; the text will be colored whatever it was in the source font file.

hasTextColor() → bool
getTextColor() → LColor
Return type

LColor

setShadowColor(shadow_color: LColor) → None
setShadowColor(r: float, g: float, b: float, a: float) → None
clearShadowColor() → None

Removes the shadow color specification.

hasShadowColor() → bool
getShadowColor() → LColor
Return type

LColor

setShadow(shadow_offset: LVecBase2) → None

Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offsetting it slightly behind the first.

setShadow(xoffset: float, yoffset: float) → None

Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offsetting it slightly behind the first.

clearShadow() → None

Specifies that a shadow will not be drawn behind the text.

hasShadow() → bool
getShadow() → LVector2

Returns the offset of the shadow as set by setShadow(). It is an error to call this if hasShadow() is false.

Return type

LVector2

setBin(bin: str) → None

Names the CullBin that the text geometry should be assigned to. If this is set, then a CullBinAttrib will be created to explicitly place each component in the named bin.

The draw_order value will also be passed to each CullBinAttrib as appropriate; this is particularly useful if this names a CullBinFixed, e.g. “fixed”.

clearBin() → None

Removes the effect of a previous call to setBin(). Text will be drawn in whatever bin it would like to be drawn in, with no explicit ordering.

hasBin() → bool

Returns true if an explicit drawing bin has been set via setBin(), false otherwise.

getBin() → str

Returns the drawing bin set with setBin(), or empty string if no bin has been set.

setDrawOrder(draw_order: int) → int

Sets the drawing order of text created by the TextNode. This is actually the draw order of the card and frame. The shadow is drawn at _draw_order+1, and the text at _draw_order+2.

This affects the sorting order assigned to the nodes as they are created, and also is passed to whatever bin may be assigned via setBin().

The return value is the first unused draw_order number, e.g. _draw_order + 3.

clearDrawOrder() → None
hasDrawOrder() → bool
getDrawOrder() → int

Returns the drawing order set with setDrawOrder().

setTabWidth(tab_width: float) → None

Sets the width of each tab stop, in screen units. A tab character embedded in the text will advance the horizontal position to the next tab stop.

clearTabWidth() → None
hasTabWidth() → bool
getTabWidth() → float

Returns the width set via setTabWidth().

setGlyphScale(glyph_scale: float) → None

Specifies the factor by which to scale each letter of the text as it is placed, in addition to any scales inherited from the node or from setTextScale(). This can be used (possibly in conjunction with setGlyphShift()) to implement superscripting or subscripting.

The glyph scale is cumulative when applied to nested TextProperties. It is intended primarily for implementing superscripts, not for scaling the text in general. See also setTextScale(), which is intended primarily for scaling the text in general, and is not cumulative.

clearGlyphScale() → None
hasGlyphScale() → bool
getGlyphScale() → float

Returns the scale factor of each letter as specified by setGlyphScale().

setGlyphShift(glyph_shift: float) → None

Specifies a vertical amount to shift each letter of the text as it is placed. This can be used (possibly in conjunction with setGlyphScale()) to implement superscripting or subscripting.

clearGlyphShift() → None
hasGlyphShift() → bool
getGlyphShift() → float

Returns the vertical shift of each letter as specified by setGlyphShift().

setTextScale(text_scale: float) → None

Specifies the factor by which to scale the text, in addition to any scalings imposed by the node, as well as in addition to the glyph scale.

The text scale is not cumulative when applied to nested TextProperties. See also setGlyphScale(), which is cumulative.

clearTextScale() → None
hasTextScale() → bool
getTextScale() → float

Returns the scale factor of the text as specified by setTextScale().

setDirection(direction: Direction) → None

Specifies the text direction. If none is specified, it will be guessed based on the contents of the string.

New in version 1.10.0.

clearDirection() → None

Clears the text direction setting. If no text direction is specified, it will be guessed based on the contents of the string.

New in version 1.10.0.

hasDirection() → bool

New in version 1.10.0.

getDirection() → Direction

Returns the direction of the text as specified by setDirection().

New in version 1.10.0.

Return type

Direction

addProperties(other: TextProperties) → None

Sets any properties that are explicitly specified in other on this object. Leaves other properties unchanged.

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

TypeHandle

property font
Getter

Returns the font currently in use, if any. If no font is in use, this returns the default font.

Setter

Sets the font that will be used when making text. If this is set to NULL, the default font will be used, which can be set via setDefaultFont().

Return type

TextFont

property small_caps
Getter

Returns the small_caps flag. See setSmallCaps().

Setter

Sets the small_caps flag. When this is set, lowercase letters are generated as scaled-down versions of their uppercase equivalents. This is particularly useful to set for fonts that do not have lowercase letters.

It is also a good idea to set this for a (dynamic) font that has already implemented lowercase letters as scaled-down versions of their uppercase equivalents, since without this flag the texture memory may needlessly duplicate equivalent glyphs for upper and lowercase letters. Setting this flag causes the texture memory to share the mixed-case letters.

The amount by which the lowercase letters are scaled is specified by setSmallCapsScale().

Return type

bool

property small_caps_scale
Getter

Returns the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect. See setSmallCaps() and setSmallCapsScale().

Setter

Sets the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect. See setSmallCaps(). Normally, this will be a number less than one.

Return type

float

property slant
Getter

Returns the factor by which the text is specified to slant to the right.

Setter

Specifies the factor by which the text slants to the right.

Return type

float

property underscore
Getter

Returns the underscore flag. See setUnderscore().

Setter

Sets the underscore flag. When this is set, the text is underscored with a one-pixel line the same color as the text foreground, drawn at the baseline.

Return type

bool

property underscore_height
Getter

Returns the vertical height of the underscore; see setUnderscoreHeight().

Setter

Specifies the vertical height of the underscore, relative to the text baseline. This only has meaning if the underscore mode is enabled with setUnderscore().

Return type

float

property align

Getter Setter

Specifies the alignment of the text within its margins.

Return type

Alignment

property indent

Getter Setter

Specifies the amount of extra space that is inserted before the first character of each line. This can be thought of as a left margin.

Return type

float

property wordwrap

Getter Setter

Sets the text up to automatically wordwrap when it exceeds the indicated width. This can be thought of as a right margin or margin width.

Return type

float

property preserve_trailing_whitespace
Getter

Returns the preserve_trailing_whitespace flag. See setPreserveTrailingWhitespace().

Setter

Sets the preserve_trailing_whitespace flag. When this is set, trailing whitespace at the end of the line is not stripped when the text is wordwrapped (it is stripped by default). Since the trailing whitespace is invisible, this is important primarily for determining the proper width of a frame or card behind the text.

Return type

bool

property text_color

Getter Setter

Return type

LColor

property shadow_color

Getter Setter

Return type

LColor

property shadow
Getter

Returns the offset of the shadow as set by setShadow(). It is an error to call this if hasShadow() is false.

Setter

Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offsetting it slightly behind the first.

Specifies that the text should be drawn with a shadow, by creating a second copy of the text and offsetting it slightly behind the first.

Return type

LVector2

property bin
Getter

Returns the drawing bin set with setBin(), or empty string if no bin has been set.

Setter

Names the CullBin that the text geometry should be assigned to. If this is set, then a CullBinAttrib will be created to explicitly place each component in the named bin.

The draw_order value will also be passed to each CullBinAttrib as appropriate; this is particularly useful if this names a CullBinFixed, e.g. “fixed”.

Return type

string

property draw_order
Getter

Returns the drawing order set with setDrawOrder().

Setter

Sets the drawing order of text created by the TextNode. This is actually the draw order of the card and frame. The shadow is drawn at _draw_order+1, and the text at _draw_order+2.

This affects the sorting order assigned to the nodes as they are created, and also is passed to whatever bin may be assigned via setBin().

The return value is the first unused draw_order number, e.g. _draw_order + 3.

Return type

int

property tab_width
Getter

Returns the width set via setTabWidth().

Setter

Sets the width of each tab stop, in screen units. A tab character embedded in the text will advance the horizontal position to the next tab stop.

Return type

float

property glyph_scale
Getter

Returns the scale factor of each letter as specified by setGlyphScale().

Setter

Specifies the factor by which to scale each letter of the text as it is placed, in addition to any scales inherited from the node or from setTextScale(). This can be used (possibly in conjunction with setGlyphShift()) to implement superscripting or subscripting.

The glyph scale is cumulative when applied to nested TextProperties. It is intended primarily for implementing superscripts, not for scaling the text in general. See also setTextScale(), which is intended primarily for scaling the text in general, and is not cumulative.

Return type

float

property glyph_shift
Getter

Returns the vertical shift of each letter as specified by setGlyphShift().

Setter

Specifies a vertical amount to shift each letter of the text as it is placed. This can be used (possibly in conjunction with setGlyphScale()) to implement superscripting or subscripting.

Return type

float

property text_scale
Getter

Returns the scale factor of the text as specified by setTextScale().

Setter

Specifies the factor by which to scale the text, in addition to any scalings imposed by the node, as well as in addition to the glyph scale.

The text scale is not cumulative when applied to nested TextProperties. See also setGlyphScale(), which is cumulative.

Return type

float

property direction
Getter

Returns the direction of the text as specified by setDirection().

New in version 1.10.0.

Setter

Specifies the text direction. If none is specified, it will be guessed based on the contents of the string.

New in version 1.10.0.

Return type

Direction

enum Alignment
enumerator A_left = 0
enumerator A_right = 1
enumerator A_center = 2
enumerator A_boxed_left = 3
enumerator A_boxed_right = 4
enumerator A_boxed_center = 5
enum Direction
enumerator D_ltr = 0
enumerator D_rtl = 1