Panda3D
Public Types | Public Member Functions | Static Public Member Functions | 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. (Properties which affect the overall block of text can only be specified on the TextNode directly). More...

Inheritance diagram for TextProperties:
TextNode FrameRateMeter SceneGraphAnalyzerMeter

Public Types

enum  Alignment {
  A_left = 0, A_right = 1, A_center = 2, A_boxed_left = 3,
  A_boxed_right = 4, A_boxed_center = 5
}
 

Public Member Functions

 __init__ ()
 
 __init__ (const TextProperties copy)
 
 addProperties (const TextProperties other)
 Sets any properties that are explicitly specified in other on this object. Leaves other properties unchanged. More...
 
 clear ()
 Unsets all properties that have been specified so far, and resets the TextProperties structure to its initial empty state. More...
 
 clearAlign ()
 Restores the default alignment of the text. More...
 
 clearBin ()
 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. More...
 
 clearDrawOrder ()
 
 clearFont ()
 Restores the default font to the text. More...
 
 clearGlyphScale ()
 
 clearGlyphShift ()
 
 clearIndent ()
 Removes the indent setting from the text. Text will be as wide as it is. More...
 
 clearPreserveTrailingWhitespace ()
 
 clearShadow ()
 Specifies that a shadow will not be drawn behind the text. More...
 
 clearShadowColor ()
 Removes the shadow color specification. More...
 
 clearSlant ()
 
 clearSmallCaps ()
 
 clearSmallCapsScale ()
 
 clearTabWidth ()
 
 clearTextColor ()
 Removes the text color specification; the text will be colored whatever it was in the source font file. More...
 
 clearTextScale ()
 
 clearUnderscore ()
 
 clearUnderscoreHeight ()
 
 clearWordwrap ()
 Removes the wordwrap setting from the text. Text will be as wide as it is. More...
 
TextProperties::Alignment getAlign ()
 
str getBin ()
 Returns the drawing bin set with set_bin(), or empty string if no bin has been set. More...
 
int getDrawOrder ()
 Returns the drawing order set with set_draw_order(). More...
 
TextFont getFont ()
 Returns the font currently in use, if any. If no font is in use, this returns the default font. More...
 
float getGlyphScale ()
 Returns the scale factor of each letter as specified by set_glyph_scale(). More...
 
float getGlyphShift ()
 Returns the vertical shift of each letter as specified by set_glyph_shift(). More...
 
float getIndent ()
 
bool getPreserveTrailingWhitespace ()
 Returns the preserve_trailing_whitespace flag. See set_preserve_trailing_whitespace(). More...
 
LVector2 getShadow ()
 Returns the offset of the shadow as set by set_shadow(). It is an error to call this if has_shadow() is false. More...
 
LColor getShadowColor ()
 
float getSlant ()
 Returns the factor by which the text is specified to slant to the right. More...
 
bool getSmallCaps ()
 Returns the small_caps flag. See set_small_caps(). More...
 
float getSmallCapsScale ()
 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(). More...
 
float getTabWidth ()
 Returns the width set via set_tab_width(). More...
 
LColor getTextColor ()
 
float getTextScale ()
 Returns the scale factor of the text as specified by set_text_scale(). More...
 
bool getUnderscore ()
 Returns the underscore flag. See set_underscore(). More...
 
float getUnderscoreHeight ()
 Returns the vertical height of the underscore; see set_underscore_height(). More...
 
float getWordwrap ()
 
bool hasAlign ()
 
bool hasBin ()
 Returns true if an explicit drawing bin has been set via set_bin(), false otherwise. More...
 
bool hasDrawOrder ()
 
bool hasFont ()
 
bool hasGlyphScale ()
 
bool hasGlyphShift ()
 
bool hasIndent ()
 
bool hasPreserveTrailingWhitespace ()
 
bool hasShadow ()
 
bool hasShadowColor ()
 
bool hasSlant ()
 
bool hasSmallCaps ()
 
bool hasSmallCapsScale ()
 
bool hasTabWidth ()
 
bool hasTextColor ()
 
bool hasTextScale ()
 
bool hasUnderscore ()
 
bool hasUnderscoreHeight ()
 
bool hasWordwrap ()
 
bool isAnySpecified ()
 Returns true if any properties have been specified, false otherwise. More...
 
bool operator!= (const TextProperties other)
 
TextProperties operator= (const TextProperties copy)
 
bool operator== (const TextProperties other)
 
 setAlign (TextProperties::Alignment align_type)
 Specifies the alignment of the text within its margins. More...
 
 setBin (str bin)
 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. More...
 
int setDrawOrder (int draw_order)
 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. More...
 
 setFont (TextFont font)
 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(). More...
 
 setGlyphScale (float 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(). This can be used (possibly in conjunction with set_glyph_shift()) to implement superscripting or subscripting. More...
 
 setGlyphShift (float glyph_shift)
 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. More...
 
 setIndent (float indent)
 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. More...
 
 setPreserveTrailingWhitespace (bool preserve_trailing_whitespace)
 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. More...
 
 setShadow (const LVecBase2 shadow_offset)
 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...
 
 setShadow (float xoffset, float yoffset)
 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...
 
 setShadowColor (const LColor shadow_color)
 
 setShadowColor (float r, float g, float b, float a)
 
 setSlant (float slant)
 Specifies the factor by which the text slants to the right. More...
 
 setSmallCaps (bool small_caps)
 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. More...
 
 setSmallCapsScale (float small_caps_scale)
 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. More...
 
 setTabWidth (float tab_width)
 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. More...
 
 setTextColor (const LColor text_color)
 
 setTextColor (float r, float g, float b, float a)
 
 setTextScale (float 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...
 
 setUnderscore (bool underscore)
 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. More...
 
 setUnderscoreHeight (float underscore_height)
 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(). More...
 
 setWordwrap (float wordwrap)
 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. More...
 
 write (Ostream out, int indent_level)
 

Static Public Member Functions

static TypeHandle getClassType ()
 
static TextFont getDefaultFont ()
 Specifies the default font to be used for any TextNode whose font is uninitialized or NULL. See set_font(). More...
 
static setDefaultFont (TextFont)
 Specifies the default font to be used for any TextNode whose font is uninitialized or NULL. See set_font(). 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.

Member Enumeration Documentation

◆ Alignment

enum Alignment
Enumerator
A_left 
A_right 
A_center 
A_boxed_left 
A_boxed_right 
A_boxed_center 

Member Function Documentation

◆ __init__() [1/2]

__init__ ( )

◆ __init__() [2/2]

__init__ ( const TextProperties  copy)

◆ addProperties()

addProperties ( const TextProperties  other)

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

◆ clear()

clear ( )

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

◆ clearAlign()

clearAlign ( )

Restores the default alignment of the text.

◆ clearBin()

clearBin ( )

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.

◆ clearDrawOrder()

clearDrawOrder ( )

◆ clearFont()

clearFont ( )

Restores the default font to the text.

◆ clearGlyphScale()

clearGlyphScale ( )

◆ clearGlyphShift()

clearGlyphShift ( )

◆ clearIndent()

clearIndent ( )

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

◆ clearPreserveTrailingWhitespace()

clearPreserveTrailingWhitespace ( )

◆ clearShadow()

clearShadow ( )

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

◆ clearShadowColor()

clearShadowColor ( )

Removes the shadow color specification.

◆ clearSlant()

clearSlant ( )

◆ clearSmallCaps()

clearSmallCaps ( )

◆ clearSmallCapsScale()

clearSmallCapsScale ( )

◆ clearTabWidth()

clearTabWidth ( )

◆ clearTextColor()

clearTextColor ( )

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

◆ clearTextScale()

clearTextScale ( )

◆ clearUnderscore()

clearUnderscore ( )

◆ clearUnderscoreHeight()

clearUnderscoreHeight ( )

◆ clearWordwrap()

clearWordwrap ( )

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

◆ getAlign()

◆ getBin()

str getBin ( )

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

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getDefaultFont()

static TextFont getDefaultFont ( )
static

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

◆ getDrawOrder()

int getDrawOrder ( )

Returns the drawing order set with set_draw_order().

◆ getFont()

TextFont getFont ( )

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

◆ getGlyphScale()

float getGlyphScale ( )

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

◆ getGlyphShift()

float getGlyphShift ( )

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

◆ getIndent()

float getIndent ( )

◆ getPreserveTrailingWhitespace()

bool getPreserveTrailingWhitespace ( )

Returns the preserve_trailing_whitespace flag. See set_preserve_trailing_whitespace().

◆ getShadow()

LVector2 getShadow ( )

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

◆ getShadowColor()

LColor getShadowColor ( )

◆ getSlant()

float getSlant ( )

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

◆ getSmallCaps()

bool getSmallCaps ( )

Returns the small_caps flag. See set_small_caps().

◆ getSmallCapsScale()

float getSmallCapsScale ( )

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

◆ getTabWidth()

float getTabWidth ( )

Returns the width set via set_tab_width().

◆ getTextColor()

LColor getTextColor ( )

◆ getTextScale()

float getTextScale ( )

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

◆ getUnderscore()

bool getUnderscore ( )

Returns the underscore flag. See set_underscore().

◆ getUnderscoreHeight()

float getUnderscoreHeight ( )

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

◆ getWordwrap()

float getWordwrap ( )

◆ hasAlign()

bool hasAlign ( )

◆ hasBin()

bool hasBin ( )

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

◆ hasDrawOrder()

bool hasDrawOrder ( )

◆ hasFont()

bool hasFont ( )

◆ hasGlyphScale()

bool hasGlyphScale ( )

◆ hasGlyphShift()

bool hasGlyphShift ( )

◆ hasIndent()

bool hasIndent ( )

◆ hasPreserveTrailingWhitespace()

bool hasPreserveTrailingWhitespace ( )

◆ hasShadow()

bool hasShadow ( )

◆ hasShadowColor()

bool hasShadowColor ( )

◆ hasSlant()

bool hasSlant ( )

◆ hasSmallCaps()

bool hasSmallCaps ( )

◆ hasSmallCapsScale()

bool hasSmallCapsScale ( )

◆ hasTabWidth()

bool hasTabWidth ( )

◆ hasTextColor()

bool hasTextColor ( )

◆ hasTextScale()

bool hasTextScale ( )

◆ hasUnderscore()

bool hasUnderscore ( )

◆ hasUnderscoreHeight()

bool hasUnderscoreHeight ( )

◆ hasWordwrap()

bool hasWordwrap ( )

◆ isAnySpecified()

bool isAnySpecified ( )

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

◆ operator!=()

bool operator!= ( const TextProperties  other)

◆ operator=()

TextProperties operator= ( const TextProperties  copy)

◆ operator==()

bool operator== ( const TextProperties  other)

◆ setAlign()

setAlign ( TextProperties::Alignment  align_type)

Specifies the alignment of the text within its margins.

◆ setBin()

setBin ( str  bin)

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

◆ setDefaultFont()

static setDefaultFont ( TextFont  )
static

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

◆ setDrawOrder()

int setDrawOrder ( int  draw_order)

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.

◆ setFont()

setFont ( TextFont  font)

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

◆ setGlyphScale()

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

◆ setGlyphShift()

setGlyphShift ( float  glyph_shift)

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.

◆ setIndent()

setIndent ( float  indent)

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.

◆ setPreserveTrailingWhitespace()

setPreserveTrailingWhitespace ( bool  preserve_trailing_whitespace)

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.

◆ setShadow() [1/2]

setShadow ( const LVecBase2  shadow_offset)

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() [2/2]

setShadow ( float  xoffset,
float  yoffset 
)

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.

◆ setShadowColor() [1/2]

setShadowColor ( const LColor  shadow_color)

◆ setShadowColor() [2/2]

setShadowColor ( float  r,
float  g,
float  b,
float  a 
)

◆ setSlant()

setSlant ( float  slant)

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

◆ setSmallCaps()

setSmallCaps ( bool  small_caps)

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

◆ setSmallCapsScale()

setSmallCapsScale ( float  small_caps_scale)

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.

◆ setTabWidth()

setTabWidth ( float  tab_width)

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.

◆ setTextColor() [1/2]

setTextColor ( const LColor  text_color)

◆ setTextColor() [2/2]

setTextColor ( float  r,
float  g,
float  b,
float  a 
)

◆ setTextScale()

setTextScale ( float  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.

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

◆ setUnderscore()

setUnderscore ( bool  underscore)

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.

◆ setUnderscoreHeight()

setUnderscoreHeight ( float  underscore_height)

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

◆ setWordwrap()

setWordwrap ( float  wordwrap)

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

write ( Ostream  out,
int  indent_level 
)