Panda3D

Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
TextProperties Class Reference

This defines the set of visual properties that may be assigned to the individual characters of the text. More...

`#include "textProperties.h"`

Inheritance diagram for TextProperties:

## Public Types
enum | Alignment { A_left , A_right , A_center , A_boxed_left , A_boxed_right , A_boxed_center }
enum | Direction { D_ltr , D_rtl }

## Public Member Functions
| TextProperties (const TextProperties &copy)
void | add_properties (const TextProperties &other)
| Sets any properties that are explicitly specified in other on this object. More...
void | clear ()
| Unsets all properties that have been specified so far, and resets the TextProperties structure to its initial empty state. More...
void | clear_align ()
void | clear_bin ()
void | clear_direction ()
void | clear_draw_order ()
void | clear_font ()
void | clear_glyph_scale ()
void | clear_glyph_shift ()
void | clear_indent ()
void | clear_preserve_trailing_whitespace ()
void | clear_shadow ()
void | clear_shadow_color ()
void | clear_slant ()
void | clear_small_caps ()
void | clear_small_caps_scale ()
void | clear_tab_width ()
void | clear_text_color ()
void | clear_text_scale ()
void | clear_underscore ()
void | clear_underscore_height ()
void | clear_wordwrap ()
Alignment | get_align () const
const std::string & | get_bin () const
Direction | get_direction () const
int | get_draw_order () const
TextFont * | get_font () const
PN_stdfloat | get_glyph_scale () const
PN_stdfloat | get_glyph_shift () const
PN_stdfloat | get_indent () const
bool | get_preserve_trailing_whitespace () const
LVector2 | get_shadow () const
LColor | get_shadow_color () const
const RenderState * | get_shadow_state () const
| Returns a RenderState object suitable for rendering the shadow of this text with these properties. More...
PN_stdfloat | get_slant () const
bool | get_small_caps () const
PN_stdfloat | get_small_caps_scale () const
PN_stdfloat | get_tab_width () const
LColor | get_text_color () const
PN_stdfloat | get_text_scale () const
const RenderState * | get_text_state () const
| Returns a RenderState object suitable for rendering text with these properties. More...
bool | get_underscore () const
PN_stdfloat | get_underscore_height () const
PN_stdfloat | get_wordwrap () const
bool | has_align () const
bool | has_bin () const
bool | has_direction () const
bool | has_draw_order () const
bool | has_font () const
bool | has_glyph_scale () const
bool | has_glyph_shift () const
bool | has_indent () const
bool | has_preserve_trailing_whitespace () const
bool | has_shadow () const
bool | has_shadow_color () const
bool | has_slant () const
bool | has_small_caps () const
bool | has_small_caps_scale () const
bool | has_tab_width () const
bool | has_text_color () const
bool | has_text_scale () const
bool | has_underscore () const
bool | has_underscore_height () const
bool | has_wordwrap () const
bool | is_any_specified () const
| Returns true if any properties have been specified, false otherwise. More...
bool | operator!= (const TextProperties &other) const
void | operator= (const TextProperties &copy)
bool | operator== (const TextProperties &other) const
void | set_align (Alignment align_type)
void | set_bin (const std::string &bin)
void | set_direction (Direction direction)
int | set_draw_order (int draw_order)
void | set_font (TextFont *font)
void | set_glyph_scale (PN_stdfloat glyph_scale)
void | set_glyph_shift (PN_stdfloat glyph_shift)
void | set_indent (PN_stdfloat indent)
void | set_preserve_trailing_whitespace (bool preserve_trailing_whitespace)
void | set_shadow (const LVecBase2 &shadow_offset)
void | set_shadow (PN_stdfloat xoffset, PN_stdfloat yoffset)
void | set_shadow_color (const LColor &shadow_color)
void | set_shadow_color (PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a)
void | set_slant (PN_stdfloat slant)
void | set_small_caps (bool small_caps)
void | set_small_caps_scale (PN_stdfloat small_caps_scale)
void | set_tab_width (PN_stdfloat tab_width)
void | set_text_color (const LColor &text_color)
void | set_text_color (PN_stdfloat r, PN_stdfloat g, PN_stdfloat b, PN_stdfloat a)
void | set_text_scale (PN_stdfloat text_scale)
void | set_underscore (bool underscore)
void | set_underscore_height (PN_stdfloat underscore_height)
void | set_wordwrap (PN_stdfloat wordwrap)
void | write (std::ostream &out, int indent_level=0) const

## Static Public Member Functions
static TypeHandle | get_class_type ()
static TextFont * | get_default_font ()
| Specifies the default font to be used for any TextNode whose font is uninitialized or NULL. More...
static void | init_type ()
static void | set_default_font (TextFont *)
| Specifies the default font to be used for any TextNode whose font is uninitialized or NULL. More...

## Public Attributes
| clear_align
| Restores the default alignment of the text. More...
| clear_bin
| Removes the effect of a previous call to set_bin(). More...
| clear_direction
| Clears the text direction setting. More...
| clear_draw_order
| clear_font
| Restores the default font to the text. More...
| clear_glyph_scale
| clear_glyph_shift
| clear_indent
| Removes the indent setting from the text. More...
| clear_preserve_trailing_whitespace
| clear_shadow
| Specifies that a shadow will not be drawn behind the text. More...
| clear_shadow_color
| Removes the shadow color specification. More...
| 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. More...
| clear_text_scale
| clear_underscore
| clear_underscore_height
| clear_wordwrap
| Removes the wordwrap setting from the text. More...
| get_align
| get_bin
| Returns the drawing bin set with set_bin(), or empty string if no bin has been set. More...
| get_direction
| Returns the direction of the text as specified by set_direction(). More...
| get_draw_order
| Returns the drawing order set with set_draw_order(). More...
| get_font
| Returns the font currently in use, if any. More...
| get_glyph_scale
| Returns the scale factor of each letter as specified by set_glyph_scale(). More...
| get_glyph_shift
| Returns the vertical shift of each letter as specified by set_glyph_shift(). More...
| get_indent
| get_preserve_trailing_whitespace
| Returns the preserve_trailing_whitespace flag. More...
| get_shadow
| Returns the offset of the shadow as set by set_shadow(). More...
| get_shadow_color
| get_slant
| Returns the factor by which the text is specified to slant to the right. More...
| get_small_caps
| Returns the small_caps flag. More...
| get_small_caps_scale
| Returns the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect. More...
| get_tab_width
| Returns the width set via set_tab_width(). More...
| get_text_color
| get_text_scale
| Returns the scale factor of the text as specified by set_text_scale(). More...
| get_underscore
| Returns the underscore flag. More...
| get_underscore_height
| Returns the vertical height of the underscore; see set_underscore_height(). More...
| get_wordwrap
| has_align
| has_bin
| Returns true if an explicit drawing bin has been set via set_bin(), false otherwise. More...
| has_direction
| has_draw_order
| has_font
| has_glyph_scale
| has_glyph_shift
| has_indent
| has_preserve_trailing_whitespace
| has_shadow
| has_shadow_color
| has_slant
| has_small_caps
| has_small_caps_scale
| has_tab_width
| has_text_color
| has_text_scale
| has_underscore
| has_underscore_height
| has_wordwrap
| set_align
| Specifies the alignment of the text within its margins. More...
| set_bin
| Names the CullBin that the text geometry should be assigned to. More...
| set_direction
| Specifies the text direction. More...
| set_draw_order
| Sets the drawing order of text created by the TextNode. More...
| set_font
| Sets the font that will be used when making text. More...
| set_glyph_scale
| 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(). More...
| set_glyph_shift
| Specifies a vertical amount to shift each letter of the text as it is placed. More...
| set_indent
| Specifies the amount of extra space that is inserted before the first character of each line. More...
| set_preserve_trailing_whitespace
| Sets the preserve_trailing_whitespace flag. More...
| set_shadow
| 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. More...
| set_shadow_color
| set_slant
| Specifies the factor by which the text slants to the right. More...
| set_small_caps
| Sets the small_caps flag. More...
| set_small_caps_scale
| Sets the scale factor applied to lowercase letters from their uppercase equivalents, when the small_caps flag is in effect. More...
| set_tab_width
| Sets the width of each tab stop, in screen units. More...
| set_text_color
| set_text_scale
| 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. More...
| set_underscore
| Sets the underscore flag. More...
| set_underscore_height
| Specifies the vertical height of the underscore, relative to the text baseline. More...
| set_wordwrap
| Sets the text up to automatically wordwrap when it exceeds the indicated width. More...

## Detailed Description

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.

Definition at line 41 of file textProperties.h.

## Member Function Documentation

## ◆ add_properties()

void TextProperties::add_properties | ( | const TextProperties & | other | ) |

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

Leaves other properties unchanged.

Definition at line 187 of file textProperties.cxx.

References get_bin, get_direction, get_draw_order, get_font, get_glyph_scale, get_glyph_shift, get_shadow, get_slant, get_small_caps, get_small_caps_scale, get_tab_width, get_text_scale, get_underscore, get_underscore_height, has_bin, has_direction, set_align, set_bin, set_direction, set_draw_order, set_font, set_glyph_scale, set_glyph_shift, set_indent, set_shadow, set_slant, set_small_caps, set_small_caps_scale, set_tab_width, set_text_scale, set_underscore, set_underscore_height, and set_wordwrap.

## ◆ clear()

void TextProperties::clear | ( |  | ) |

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

Definition at line 178 of file textProperties.cxx.

## ◆ get_default_font()

TextFont * TextProperties::get_default_font | ( |  | ) |
| inline static

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

See set_font().

Definition at line 46 of file textProperties.I.

## ◆ get_shadow_state()

const RenderState * TextProperties::get_shadow_state | ( |  | ) | const

Returns a RenderState object suitable for rendering the shadow of this text with these properties.

Definition at line 419 of file textProperties.cxx.

References get_bin, get_draw_order, and has_bin.

## ◆ get_text_state()

const RenderState * TextProperties::get_text_state | ( |  | ) | const

Returns a RenderState object suitable for rendering text with these properties.

Definition at line 392 of file textProperties.cxx.

References get_bin, get_draw_order, and has_bin.

## ◆ is_any_specified()

bool TextProperties::is_any_specified | ( |  | ) | const
| inline

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

Definition at line 25 of file textProperties.I.

## ◆ set_default_font()

void TextProperties::set_default_font | ( | TextFont * | font | ) |
| inline static

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

See set_font().

Definition at line 34 of file textProperties.I.

## Member Data Documentation

## ◆ clear_align

void TextProperties::clear_align
| inline

Restores the default alignment of the text.

Definition at line 188 of file textProperties.h.

## ◆ clear_bin

void TextProperties::clear_bin
| inline

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.

Definition at line 199 of file textProperties.h.

## ◆ clear_direction

void TextProperties::clear_direction
| inline

Clears the text direction setting.

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

Since
  1.10.0

Definition at line 211 of file textProperties.h.

## ◆ clear_font

void TextProperties::clear_font
| inline

Restores the default font to the text.

Definition at line 178 of file textProperties.h.

## ◆ clear_indent

void TextProperties::clear_indent
| inline

Removes the indent setting from the text.

Text will be as wide as it is.

Definition at line 189 of file textProperties.h.

## ◆ clear_shadow

void TextProperties::clear_shadow
| inline

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

Definition at line 198 of file textProperties.h.

## ◆ clear_shadow_color

void TextProperties::clear_shadow_color
| inline

Removes the shadow color specification.

Definition at line 197 of file textProperties.h.

## ◆ clear_text_color

void TextProperties::clear_text_color
| inline

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

Definition at line 195 of file textProperties.h.

## ◆ clear_wordwrap

void TextProperties::clear_wordwrap
| inline

Removes the wordwrap setting from the text.

Text will be as wide as it is.

Definition at line 190 of file textProperties.h.

## ◆ get_bin

const std::string & TextProperties::get_bin
| inline

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

Definition at line 199 of file textProperties.h.

Referenced by add_properties(), get_shadow_state(), and get_text_state().

## ◆ get_direction

TextProperties::Direction TextProperties::get_direction
| inline

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

Since
  1.10.0

Definition at line 211 of file textProperties.h.

Referenced by add_properties().

## ◆ get_draw_order

int TextProperties::get_draw_order
| inline

Returns the drawing order set with set_draw_order().

Definition at line 201 of file textProperties.h.

Referenced by add_properties(), get_shadow_state(), and get_text_state().

## ◆ get_font

TextFont * TextProperties::get_font
| inline

Returns the font currently in use, if any.

If no font is in use, this returns the default font.

Definition at line 178 of file textProperties.h.

Referenced by add_properties(), TextAssembler::calc_width(), TextAssembler::has_exact_character(), and TextAssembler::is_whitespace().

## ◆ get_glyph_scale

PN_stdfloat TextProperties::get_glyph_scale
| inline

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

Definition at line 205 of file textProperties.h.

Referenced by add_properties(), and TextAssembler::calc_width().

## ◆ get_glyph_shift

PN_stdfloat TextProperties::get_glyph_shift
| inline

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

Definition at line 207 of file textProperties.h.

Referenced by add_properties().

## ◆ get_preserve_trailing_whitespace

bool TextProperties::get_preserve_trailing_whitespace
| inline

Returns the preserve_trailing_whitespace flag.

See set_preserve_trailing_whitespace().

Definition at line 193 of file textProperties.h.

## ◆ get_shadow

LVector2 TextProperties::get_shadow
| inline

Returns the offset of the shadow as set by set_shadow().

It is an error to call this if has_shadow() is false.

Definition at line 198 of file textProperties.h.

Referenced by add_properties().

## ◆ get_slant

PN_stdfloat TextProperties::get_slant
| inline

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

Definition at line 183 of file textProperties.h.

Referenced by add_properties().

## ◆ get_small_caps

bool TextProperties::get_small_caps
| inline

Returns the small_caps flag.

See set_small_caps().

Definition at line 180 of file textProperties.h.

Referenced by add_properties().

## ◆ get_small_caps_scale

PN_stdfloat TextProperties::get_small_caps_scale
| inline

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

Definition at line 182 of file textProperties.h.

Referenced by add_properties().

## ◆ get_tab_width

PN_stdfloat TextProperties::get_tab_width
| inline

Returns the width set via set_tab_width().

Definition at line 203 of file textProperties.h.

Referenced by add_properties().

## ◆ get_text_scale

PN_stdfloat TextProperties::get_text_scale
| inline

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

Definition at line 209 of file textProperties.h.

Referenced by add_properties(), and TextAssembler::calc_width().

## ◆ get_underscore

bool TextProperties::get_underscore
| inline

Returns the underscore flag.

See set_underscore().

Definition at line 185 of file textProperties.h.

Referenced by add_properties().

## ◆ get_underscore_height

PN_stdfloat TextProperties::get_underscore_height
| inline

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

Definition at line 187 of file textProperties.h.

Referenced by add_properties().

## ◆ has_bin

bool TextProperties::has_bin
| inline

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

Definition at line 199 of file textProperties.h.

Referenced by add_properties(), get_shadow_state(), and get_text_state().

## ◆ has_direction

bool TextProperties::has_direction
| inline

Since
  1.10.0

Definition at line 211 of file textProperties.h.

Referenced by add_properties().

## ◆ set_align

void TextProperties::set_align
| inline

Specifies the alignment of the text within its margins.

Definition at line 188 of file textProperties.h.

Referenced by add_properties().

## ◆ set_bin

void TextProperties::set_bin
| inline

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

Definition at line 199 of file textProperties.h.

Referenced by add_properties().

## ◆ set_direction

void TextProperties::set_direction
| inline

Specifies the text direction.

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

Since
  1.10.0

Definition at line 211 of file textProperties.h.

Referenced by add_properties().

## ◆ set_draw_order

int TextProperties::set_draw_order
| inline

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.

Definition at line 201 of file textProperties.h.

Referenced by add_properties().

## ◆ set_font

void TextProperties::set_font
| inline

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

Definition at line 178 of file textProperties.h.

Referenced by add_properties().

## ◆ set_glyph_scale

void TextProperties::set_glyph_scale
| inline

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.

Definition at line 205 of file textProperties.h.

Referenced by add_properties().

## ◆ set_glyph_shift

void TextProperties::set_glyph_shift
| inline

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.

Definition at line 207 of file textProperties.h.

Referenced by add_properties().

## ◆ set_indent

void TextProperties::set_indent
| inline

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.

Definition at line 189 of file textProperties.h.

Referenced by add_properties().

## ◆ set_preserve_trailing_whitespace

void TextProperties::set_preserve_trailing_whitespace
| inline

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.

Definition at line 193 of file textProperties.h.

## ◆ set_shadow

void TextProperties::set_shadow
| inline

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.

Definition at line 198 of file textProperties.h.

Referenced by add_properties().

## ◆ set_slant

void TextProperties::set_slant
| inline

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

Definition at line 183 of file textProperties.h.

Referenced by add_properties().

## ◆ set_small_caps

void TextProperties::set_small_caps
| inline

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

Definition at line 180 of file textProperties.h.

Referenced by add_properties().

## ◆ set_small_caps_scale

void TextProperties::set_small_caps_scale
| inline

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.

Definition at line 182 of file textProperties.h.

Referenced by add_properties().

## ◆ set_tab_width

void TextProperties::set_tab_width
| inline

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.

Definition at line 203 of file textProperties.h.

Referenced by add_properties().

## ◆ set_text_scale

void TextProperties::set_text_scale
| inline

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.

Definition at line 209 of file textProperties.h.

Referenced by add_properties().

## ◆ set_underscore

void TextProperties::set_underscore
| inline

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.

Definition at line 185 of file textProperties.h.

Referenced by add_properties().

## ◆ set_underscore_height

void TextProperties::set_underscore_height
| inline

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

Definition at line 187 of file textProperties.h.

Referenced by add_properties().

## ◆ set_wordwrap

void TextProperties::set_wordwrap
| inline

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.

Definition at line 190 of file textProperties.h.

Referenced by add_properties().

The documentation for this class was generated from the following files:

- panda/src/text/textProperties.h
- panda/src/text/textProperties.cxx
- panda/src/text/textProperties.I