TextProperties

from panda3d.core import TextProperties
class TextProperties

Bases:

Bases: MemoryBase

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

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
__eq__(other: TextProperties) bool
__init__()
__init__(copy: TextProperties)
__ne__(other: TextProperties) bool
add_properties(other: TextProperties)

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

property align Alignment

Getter Setter

Specifies the alignment of the text within its margins.

assign(copy: TextProperties) TextProperties
property bin string
Getter

Returns the drawing bin set with set_bin(), 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”.

clear()

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

clear_align()

Restores the default alignment of the text.

clear_bin()

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

clear_direction()

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.

clear_draw_order()
clear_font()

Restores the default font to the text.

clear_glyph_scale()
clear_glyph_shift()
clear_indent()

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

clear_preserve_trailing_whitespace()
clear_shadow()

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

clear_shadow_color()

Removes the shadow color specification.

clear_slant()
clear_small_caps()
clear_small_caps_scale()
clear_tab_width()
clear_text_color()

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

clear_text_scale()
clear_underscore()
clear_underscore_height()
clear_wordwrap()

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

property direction Direction
Getter

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

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.

property draw_order int
Getter

Returns the drawing order set with set_draw_order().

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 set_bin().

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

property font TextFont
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 set_default_font().

get_align() Alignment
get_bin() str

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

static get_class_type() TypeHandle
static get_default_font() TextFont

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

get_direction() Direction

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

New in version 1.10.0.

get_draw_order() int

Returns the drawing order set with set_draw_order().

get_font() TextFont

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

get_glyph_scale() float

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

get_glyph_shift() float

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

get_indent() float
get_preserve_trailing_whitespace() bool

Returns the preserve_trailing_whitespace flag. See set_preserve_trailing_whitespace().

get_shadow() LVector2

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

get_shadow_color() LColor
get_slant() float

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

get_small_caps() bool

Returns the small_caps flag. See set_small_caps().

get_small_caps_scale() float

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

get_tab_width() float

Returns the width set via set_tab_width().

get_text_color() LColor
get_text_scale() float

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

get_underscore() bool

Returns the underscore flag. See set_underscore().

get_underscore_height() float

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

get_wordwrap() float
property glyph_scale float
Getter

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

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 set_text_scale(). This can be used (possibly in conjunction with set_glyph_shift()) 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 set_text_scale(), which is intended primarily for scaling the text in general, and is not cumulative.

property glyph_shift float
Getter

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

Setter

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

has_align() bool
has_bin() bool

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

has_direction() bool

New in version 1.10.0.

has_draw_order() bool
has_font() bool
has_glyph_scale() bool
has_glyph_shift() bool
has_indent() bool
has_preserve_trailing_whitespace() bool
has_shadow() bool
has_shadow_color() bool
has_slant() bool
has_small_caps() bool
has_small_caps_scale() bool
has_tab_width() bool
has_text_color() bool
has_text_scale() bool
has_underscore() bool
has_underscore_height() bool
has_wordwrap() bool
property indent float

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.

is_any_specified() bool

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

property preserve_trailing_whitespace bool
Getter

Returns the preserve_trailing_whitespace flag. See set_preserve_trailing_whitespace().

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.

set_align(align_type: Alignment)

Specifies the alignment of the text within its margins.

set_bin(bin: str)

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”.

static set_default_font(param0: TextFont)

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

set_direction(direction: Direction)

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.

set_draw_order(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 set_bin().

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

set_font(font: TextFont)

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 set_default_font().

set_glyph_scale(glyph_scale: float)

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 set_text_scale(). This can be used (possibly in conjunction with set_glyph_shift()) 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 set_text_scale(), which is intended primarily for scaling the text in general, and is not cumulative.

set_glyph_shift(glyph_shift: float)

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

set_indent(indent: float)

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.

set_preserve_trailing_whitespace(preserve_trailing_whitespace: bool)

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.

set_shadow(shadow_offset: LVecBase2)

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.

set_shadow(xoffset: float, yoffset: float)

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.

set_shadow_color(shadow_color: LColor)
set_shadow_color(r: float, g: float, b: float, a: float)
set_slant(slant: float)

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

set_small_caps(small_caps: bool)

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 set_small_caps_scale().

set_small_caps_scale(small_caps_scale: float)

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

set_tab_width(tab_width: float)

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.

set_text_color(text_color: LColor)
set_text_color(r: float, g: float, b: float, a: float)
set_text_scale(text_scale: float)

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 set_glyph_scale(), which is cumulative.

set_underscore(underscore: bool)

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.

set_underscore_height(underscore_height: float)

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

set_wordwrap(wordwrap: float)

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.

property shadow LVector2
Getter

Returns the offset of the shadow as set by set_shadow(). It is an error to call this if has_shadow() 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.

property shadow_color LColor

Getter Setter

property slant float
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.

property small_caps bool
Getter

Returns the small_caps flag. See set_small_caps().

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 set_small_caps_scale().

property small_caps_scale float
Getter

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

Setter

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

property tab_width float
Getter

Returns the width set via set_tab_width().

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.

property text_color LColor

Getter Setter

property text_scale float
Getter

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

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 set_glyph_scale(), which is cumulative.

property underscore bool
Getter

Returns the underscore flag. See set_underscore().

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.

property underscore_height float
Getter

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

Setter

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

property wordwrap float

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.

write(out: ostream, indent_level: int)