TextAssembler

from panda3d.core import TextAssembler
class TextAssembler

Bases: DTOOL_SUPER_BASE

This class is not normally used directly by user code, but is used by the TextNode to lay out a block of text and convert it into rows of Geoms according to the TextProperties. However, user code may take advantage of it, if desired, for very low-level text operations.

Inheritance diagram

Inheritance diagram of TextAssembler

__init__(*args, **kwargs)
assembleText()

C++ Interface: assemble_text(const TextAssembler self)

/**
  • Actually assembles all of the text into a GeomNode, and returns the node

  • (or possibly a parent of the node, to keep the shadow separate). Once this

  • has been called, you may query the extents of the text via get_ul(),

  • get_lr().

*/

assemble_text()

C++ Interface: assemble_text(const TextAssembler self)

/**
  • Actually assembles all of the text into a GeomNode, and returns the node

  • (or possibly a parent of the node, to keep the shadow separate). Once this

  • has been called, you may query the extents of the text via get_ul(),

  • get_lr().

*/

assign()

C++ Interface: assign(const TextAssembler self, const TextAssembler copy)

calcC()

C++ Interface: calc_c(TextAssembler self, int n)

/**
  • Computes the column index of the nth character or graphic object in the

  • text and returns it.

  • If the nth character is not a normal printable character with a position in

  • the wordwrapped string, returns -1 (for instance, a soft-hyphen character,

  • or a newline character, may not have a corresponding position).

*/

calcIndex()

C++ Interface: calc_index(TextAssembler self, int r, int c)

/**
  • Computes the character index of the character at the rth row and cth column

  • position. This is the inverse of calc_r_c().

  • It is legal for c to exceed the index number of the last column by 1, and

  • it is legal for r to exceed the index number of the last row by 1, if c is

*/

calcR()

C++ Interface: calc_r(TextAssembler self, int n)

/**
  • Computes the row index of the nth character or graphic object in the text

  • and returns it.

  • If the nth character is not a normal printable character with a position in

  • the wordwrapped string, returns -1 (for instance, a soft-hyphen character,

  • or a newline character, may not have a corresponding position).

*/

calcWidth()

C++ Interface: calc_width(const TextGraphic graphic, const TextProperties properties) calc_width(int character, const TextProperties properties) calc_width(unicode char character, const TextProperties properties)

/**
  • Returns the width of a single character, according to its associated font.

*/

/**
  • Returns the width of a single character, according to its associated font.

  • This also correctly calculates the width of cheesy ligatures and accented

  • characters, which may not exist in the font as such.

  • This does not take kerning into account, however.

*/

/**
  • Returns the width of a single character, according to its associated font.

  • This also correctly calculates the width of cheesy ligatures and accented

  • characters, which may not exist in the font as such.

  • This does not take kerning into account, however.

*/

/**
  • Returns the width of a single TextGraphic image.

*/

calc_c()

C++ Interface: calc_c(TextAssembler self, int n)

/**
  • Computes the column index of the nth character or graphic object in the

  • text and returns it.

  • If the nth character is not a normal printable character with a position in

  • the wordwrapped string, returns -1 (for instance, a soft-hyphen character,

  • or a newline character, may not have a corresponding position).

*/

calc_index()

C++ Interface: calc_index(TextAssembler self, int r, int c)

/**
  • Computes the character index of the character at the rth row and cth column

  • position. This is the inverse of calc_r_c().

  • It is legal for c to exceed the index number of the last column by 1, and

  • it is legal for r to exceed the index number of the last row by 1, if c is

*/

calc_r()

C++ Interface: calc_r(TextAssembler self, int n)

/**
  • Computes the row index of the nth character or graphic object in the text

  • and returns it.

  • If the nth character is not a normal printable character with a position in

  • the wordwrapped string, returns -1 (for instance, a soft-hyphen character,

  • or a newline character, may not have a corresponding position).

*/

calc_width()

C++ Interface: calc_width(const TextGraphic graphic, const TextProperties properties) calc_width(int character, const TextProperties properties) calc_width(unicode char character, const TextProperties properties)

/**
  • Returns the width of a single character, according to its associated font.

*/

/**
  • Returns the width of a single character, according to its associated font.

  • This also correctly calculates the width of cheesy ligatures and accented

  • characters, which may not exist in the font as such.

  • This does not take kerning into account, however.

*/

/**
  • Returns the width of a single character, according to its associated font.

  • This also correctly calculates the width of cheesy ligatures and accented

  • characters, which may not exist in the font as such.

  • This does not take kerning into account, however.

*/

/**
  • Returns the width of a single TextGraphic image.

*/

clear()

C++ Interface: clear(const TextAssembler self)

/**
  • Reinitializes the contents of the TextAssembler.

*/

dynamic_merge
getCharacter()

C++ Interface: get_character(TextAssembler self, int n) get_character(TextAssembler self, int r, int c)

/**
  • Returns the character at the indicated position in the pre-wordwrapped

  • string. If the object at this position is a graphic object instead of a

  • character, returns 0.

*/

/**
  • Returns the character at the indicated position in the indicated row. If

  • the object at this position is a graphic object instead of a character,

  • returns 0.

*/

getDynamicMerge()

C++ Interface: get_dynamic_merge(TextAssembler self)

/**
  • Returns the dynamic_merge flag. See TextNode::set_flatten_flags().

*/

getGraphic()

C++ Interface: get_graphic(TextAssembler self, int n) get_graphic(TextAssembler self, int r, int c)

/**
  • Returns the graphic object at the indicated position in the pre-wordwrapped

  • string. If the object at this position is a character instead of a graphic

  • object, returns NULL.

*/

/**
  • Returns the graphic object at the indicated position in the indicated row.

  • If the object at this position is a character instead of a graphic object,

  • returns NULL.

*/

getLr()

C++ Interface: get_lr(TextAssembler self)

/**
  • Returns the lower-right corner of the assembled text, in 2-d text

  • coordinates.

*/

getMaxRows()

C++ Interface: get_max_rows(TextAssembler self)

/**
  • If max_rows is greater than zero, no more than max_rows will be accepted.

  • Text beyond that will be truncated.

*/

getMultilineMode()

C++ Interface: get_multiline_mode(TextAssembler self)

/**
  • Returns the multline_mode flag. See TextNode::set_multiline_mode().

*/

getNumCharacters()

C++ Interface: get_num_characters(TextAssembler self)

/**
  • Returns the number of characters of text, before wordwrapping.

*/

getNumCols()

C++ Interface: get_num_cols(TextAssembler self, int r)

/**
  • Returns the number of characters and/or graphic objects in the nth row.

*/

getNumRows()

C++ Interface: get_num_rows(TextAssembler self)

/**
  • Returns the number of rows of text after it has all been wordwrapped and

  • assembled.

*/

getPlainWtext()

C++ Interface: get_plain_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text, without any

  • embedded properties characters. If there is an embedded graphic object, a

  • zero value is inserted in that position.

  • This string has the same length as get_num_characters(), and the characters

  • in this string correspond one-to-one with the characters returned by

  • get_character(n).

*/

getProperties()

C++ Interface: get_properties(TextAssembler self) get_properties(TextAssembler self, int n) get_properties(TextAssembler self, int r, int c)

/**
  • Returns the default TextProperties that are applied to the text in the

  • absence of any nested property change sequences.

*/

/**
  • Returns the TextProperties in effect for the object at the indicated

  • position in the pre-wordwrapped string.

*/

/**
  • Returns the TextProperties in effect for the object at the indicated

  • position in the indicated row.

*/

getUl()

C++ Interface: get_ul(TextAssembler self)

/**
  • Returns the upper-left corner of the assembled text, in 2-d text

  • coordinates.

*/

getUsageHint()

C++ Interface: get_usage_hint(TextAssembler self)

/**
  • Returns the UsageHint that will be applied to generated geometry. See

  • set_usage_hint().

*/

getWidth()

C++ Interface: get_width(TextAssembler self, int n) get_width(TextAssembler self, int r, int c)

/**
  • Returns the width of the character or object at the indicated position in

  • the pre-wordwrapped string.

*/

/**
  • Returns the width of the character or object at the indicated position in

  • the indicated row.

*/

getWordwrappedPlainWtext()

C++ Interface: get_wordwrapped_plain_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text, with newlines

  • inserted according to the wordwrapping. The string will contain no

  • embedded properties characters. If there is an embedded graphic object, a

  • zero value is inserted in that position.

  • This string has the same number of newline characters as get_num_rows(),

  • and the characters in this string correspond one-to-one with the characters

  • returned by get_character(r, c).

*/

getWordwrappedWtext()

C++ Interface: get_wordwrapped_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text, with newlines

  • inserted according to the wordwrapping.

  • The string will contain embedded properties characters, which may not

  • exactly match the embedded properties characters of the original string,

  • but it will encode the same way.

  • Embedded properties characters will be closed before every newline, then

  • reopened (if necessary) on the subsequent character following the newline.

  • This means it will be safe to divide the text up at the newline characters

  • and treat each line as an independent piece.

*/

getWtext()

C++ Interface: get_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text.

  • The string will contain embedded properties characters, which may not

  • exactly match the embedded properties characters of the original string,

  • but it will encode the same way.

*/

getXpos()

C++ Interface: get_xpos(TextAssembler self, int r, int c)

/**
  • Returns the x position of the origin of the character or graphic object at

  • the indicated position in the indicated row.

  • It is legal for c to exceed the index number of the last column by 1, and

  • it is legal for r to exceed the index number of the last row by 1, if c is

*/

getYpos()

C++ Interface: get_ypos(TextAssembler self, int r, int c)

/**
  • Returns the y position of the origin of all of the characters or graphic

  • objects in the indicated row.

  • It is legal for r to exceed the index number of the last row by 1. The

  • value of c is presently ignored.

*/

get_character()

C++ Interface: get_character(TextAssembler self, int n) get_character(TextAssembler self, int r, int c)

/**
  • Returns the character at the indicated position in the pre-wordwrapped

  • string. If the object at this position is a graphic object instead of a

  • character, returns 0.

*/

/**
  • Returns the character at the indicated position in the indicated row. If

  • the object at this position is a graphic object instead of a character,

  • returns 0.

*/

get_dynamic_merge()

C++ Interface: get_dynamic_merge(TextAssembler self)

/**
  • Returns the dynamic_merge flag. See TextNode::set_flatten_flags().

*/

get_graphic()

C++ Interface: get_graphic(TextAssembler self, int n) get_graphic(TextAssembler self, int r, int c)

/**
  • Returns the graphic object at the indicated position in the pre-wordwrapped

  • string. If the object at this position is a character instead of a graphic

  • object, returns NULL.

*/

/**
  • Returns the graphic object at the indicated position in the indicated row.

  • If the object at this position is a character instead of a graphic object,

  • returns NULL.

*/

get_lr()

C++ Interface: get_lr(TextAssembler self)

/**
  • Returns the lower-right corner of the assembled text, in 2-d text

  • coordinates.

*/

get_max_rows()

C++ Interface: get_max_rows(TextAssembler self)

/**
  • If max_rows is greater than zero, no more than max_rows will be accepted.

  • Text beyond that will be truncated.

*/

get_multiline_mode()

C++ Interface: get_multiline_mode(TextAssembler self)

/**
  • Returns the multline_mode flag. See TextNode::set_multiline_mode().

*/

get_num_characters()

C++ Interface: get_num_characters(TextAssembler self)

/**
  • Returns the number of characters of text, before wordwrapping.

*/

get_num_cols()

C++ Interface: get_num_cols(TextAssembler self, int r)

/**
  • Returns the number of characters and/or graphic objects in the nth row.

*/

get_num_rows()

C++ Interface: get_num_rows(TextAssembler self)

/**
  • Returns the number of rows of text after it has all been wordwrapped and

  • assembled.

*/

get_plain_wtext()

C++ Interface: get_plain_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text, without any

  • embedded properties characters. If there is an embedded graphic object, a

  • zero value is inserted in that position.

  • This string has the same length as get_num_characters(), and the characters

  • in this string correspond one-to-one with the characters returned by

  • get_character(n).

*/

get_properties()

C++ Interface: get_properties(TextAssembler self) get_properties(TextAssembler self, int n) get_properties(TextAssembler self, int r, int c)

/**
  • Returns the default TextProperties that are applied to the text in the

  • absence of any nested property change sequences.

*/

/**
  • Returns the TextProperties in effect for the object at the indicated

  • position in the pre-wordwrapped string.

*/

/**
  • Returns the TextProperties in effect for the object at the indicated

  • position in the indicated row.

*/

get_ul()

C++ Interface: get_ul(TextAssembler self)

/**
  • Returns the upper-left corner of the assembled text, in 2-d text

  • coordinates.

*/

get_usage_hint()

C++ Interface: get_usage_hint(TextAssembler self)

/**
  • Returns the UsageHint that will be applied to generated geometry. See

  • set_usage_hint().

*/

get_width()

C++ Interface: get_width(TextAssembler self, int n) get_width(TextAssembler self, int r, int c)

/**
  • Returns the width of the character or object at the indicated position in

  • the pre-wordwrapped string.

*/

/**
  • Returns the width of the character or object at the indicated position in

  • the indicated row.

*/

get_wordwrapped_plain_wtext()

C++ Interface: get_wordwrapped_plain_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text, with newlines

  • inserted according to the wordwrapping. The string will contain no

  • embedded properties characters. If there is an embedded graphic object, a

  • zero value is inserted in that position.

  • This string has the same number of newline characters as get_num_rows(),

  • and the characters in this string correspond one-to-one with the characters

  • returned by get_character(r, c).

*/

get_wordwrapped_wtext()

C++ Interface: get_wordwrapped_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text, with newlines

  • inserted according to the wordwrapping.

  • The string will contain embedded properties characters, which may not

  • exactly match the embedded properties characters of the original string,

  • but it will encode the same way.

  • Embedded properties characters will be closed before every newline, then

  • reopened (if necessary) on the subsequent character following the newline.

  • This means it will be safe to divide the text up at the newline characters

  • and treat each line as an independent piece.

*/

get_wtext()

C++ Interface: get_wtext(TextAssembler self)

/**
  • Returns a wstring that represents the contents of the text.

  • The string will contain embedded properties characters, which may not

  • exactly match the embedded properties characters of the original string,

  • but it will encode the same way.

*/

get_xpos()

C++ Interface: get_xpos(TextAssembler self, int r, int c)

/**
  • Returns the x position of the origin of the character or graphic object at

  • the indicated position in the indicated row.

  • It is legal for c to exceed the index number of the last column by 1, and

  • it is legal for r to exceed the index number of the last row by 1, if c is

*/

get_ypos()

C++ Interface: get_ypos(TextAssembler self, int r, int c)

/**
  • Returns the y position of the origin of all of the characters or graphic

  • objects in the indicated row.

  • It is legal for r to exceed the index number of the last row by 1. The

  • value of c is presently ignored.

*/

hasCharacter()

C++ Interface: has_character(unicode char character, const TextProperties properties)

/**
  • Returns true if the named character exists in the font or can be

  • synthesized by Panda, false otherwise. (Panda can synthesize some accented

  • characters by combining similar-looking glyphs from the font.)

  • This returns true for whitespace and Unicode whitespace characters (if they

  • exist in the font), but returns false for characters that would render with

  • the “invalid glyph”.

*/

hasExactCharacter()

C++ Interface: has_exact_character(unicode char character, const TextProperties properties)

/**
  • Returns true if the named character exists in the font exactly as named,

  • false otherwise. Note that because Panda can assemble glyphs together

  • automatically using cheesy accent marks, this is not a reliable indicator

  • of whether a suitable glyph can be rendered for the character. For that,

  • use has_character() instead.

  • This returns true for whitespace and Unicode whitespace characters (if they

  • exist in the font), but returns false for characters that would render with

  • the “invalid glyph”. It also returns false for characters that would be

  • synthesized within Panda, but see has_character().

*/

has_character()

C++ Interface: has_character(unicode char character, const TextProperties properties)

/**
  • Returns true if the named character exists in the font or can be

  • synthesized by Panda, false otherwise. (Panda can synthesize some accented

  • characters by combining similar-looking glyphs from the font.)

  • This returns true for whitespace and Unicode whitespace characters (if they

  • exist in the font), but returns false for characters that would render with

  • the “invalid glyph”.

*/

has_exact_character()

C++ Interface: has_exact_character(unicode char character, const TextProperties properties)

/**
  • Returns true if the named character exists in the font exactly as named,

  • false otherwise. Note that because Panda can assemble glyphs together

  • automatically using cheesy accent marks, this is not a reliable indicator

  • of whether a suitable glyph can be rendered for the character. For that,

  • use has_character() instead.

  • This returns true for whitespace and Unicode whitespace characters (if they

  • exist in the font), but returns false for characters that would render with

  • the “invalid glyph”. It also returns false for characters that would be

  • synthesized within Panda, but see has_character().

*/

isWhitespace()

C++ Interface: is_whitespace(unicode char character, const TextProperties properties)

/**
  • Returns true if the indicated character represents whitespace in the font,

  • or false if anything visible will be rendered for it.

  • This returns true for whitespace and Unicode whitespace characters (if they

  • exist in the font), and returns false for any other characters, including

  • characters that do not exist in the font (these would be rendered with the

  • “invalid glyph”, which is visible).

  • Note that this function can be reliably used to identify Unicode whitespace

  • characters only if the font has all of the whitespace characters defined.

  • It will return false for any character not in the font, even if it is an

  • official Unicode whitespace character.

*/

is_whitespace()

C++ Interface: is_whitespace(unicode char character, const TextProperties properties)

/**
  • Returns true if the indicated character represents whitespace in the font,

  • or false if anything visible will be rendered for it.

  • This returns true for whitespace and Unicode whitespace characters (if they

  • exist in the font), and returns false for any other characters, including

  • characters that do not exist in the font (these would be rendered with the

  • “invalid glyph”, which is visible).

  • Note that this function can be reliably used to identify Unicode whitespace

  • characters only if the font has all of the whitespace characters defined.

  • It will return false for any character not in the font, even if it is an

  • official Unicode whitespace character.

*/

max_rows
multiline_mode
properties
setDynamicMerge()

C++ Interface: set_dynamic_merge(const TextAssembler self, bool dynamic_merge)

/**
  • Sets the dynamic_merge flag. See TextNode::set_flatten_flags().

*/

setMaxRows()

C++ Interface: set_max_rows(const TextAssembler self, int max_rows)

/**
  • If max_rows is greater than zero, no more than max_rows will be accepted.

  • Text beyond that will be truncated.

  • Setting this will not truncate text immediately. You must follow this up

  • with a call to set_wtext() to truncate the existing text.

*/

setMultilineMode()

C++ Interface: set_multiline_mode(const TextAssembler self, bool flag)

/**
  • Sets the multiline mode flag. Set the multiline mode to allow text to

  • wrap. It defaults to true.

*/

setProperties()

C++ Interface: set_properties(const TextAssembler self, const TextProperties properties)

/**
  • Specifies the default TextProperties that are applied to the text in the

  • absence of any nested property change sequences.

*/

setUsageHint()

C++ Interface: set_usage_hint(const TextAssembler self, int usage_hint)

/**
  • Specifies the UsageHint that will be applied to generated geometry. The

  • default is UH_static, which is probably the right setting, but if you know

  • the TextNode’s geometry will have a short lifespan, it may be better to set

  • it to UH_stream. See geomEnums.h.

*/

setWsubstr()

C++ Interface: set_wsubstr(const TextAssembler self, unicode wtext, int start, int count)

/**
  • Replaces the ‘count’ characters from ‘start’ of the current text with the

  • indicated replacement text. If the replacement text does not have count

  • characters, the length of the string will be changed accordingly.

  • The substring may include nested formatting characters, but they must be

  • self-contained and self-closed. The formatting characters are not

  • literally saved in the internal string; they are parsed at the time of the

  • set_wsubstr() call.

  • The return value is true if all the text is accepted, or false if some was

  • truncated (see set_max_rows()).

*/

setWtext()

C++ Interface: set_wtext(const TextAssembler self, unicode wtext)

/**
  • Accepts a new text string and associated properties structure, and

  • precomputes the wordwrapping layout appropriately. After this call,

  • get_wordwrapped_wtext() and get_num_rows() can be called.

  • The return value is true if all the text is accepted, or false if some was

  • truncated (see set_max_rows()).

*/

set_dynamic_merge()

C++ Interface: set_dynamic_merge(const TextAssembler self, bool dynamic_merge)

/**
  • Sets the dynamic_merge flag. See TextNode::set_flatten_flags().

*/

set_max_rows()

C++ Interface: set_max_rows(const TextAssembler self, int max_rows)

/**
  • If max_rows is greater than zero, no more than max_rows will be accepted.

  • Text beyond that will be truncated.

  • Setting this will not truncate text immediately. You must follow this up

  • with a call to set_wtext() to truncate the existing text.

*/

set_multiline_mode()

C++ Interface: set_multiline_mode(const TextAssembler self, bool flag)

/**
  • Sets the multiline mode flag. Set the multiline mode to allow text to

  • wrap. It defaults to true.

*/

set_properties()

C++ Interface: set_properties(const TextAssembler self, const TextProperties properties)

/**
  • Specifies the default TextProperties that are applied to the text in the

  • absence of any nested property change sequences.

*/

set_usage_hint()

C++ Interface: set_usage_hint(const TextAssembler self, int usage_hint)

/**
  • Specifies the UsageHint that will be applied to generated geometry. The

  • default is UH_static, which is probably the right setting, but if you know

  • the TextNode’s geometry will have a short lifespan, it may be better to set

  • it to UH_stream. See geomEnums.h.

*/

set_wsubstr()

C++ Interface: set_wsubstr(const TextAssembler self, unicode wtext, int start, int count)

/**
  • Replaces the ‘count’ characters from ‘start’ of the current text with the

  • indicated replacement text. If the replacement text does not have count

  • characters, the length of the string will be changed accordingly.

  • The substring may include nested formatting characters, but they must be

  • self-contained and self-closed. The formatting characters are not

  • literally saved in the internal string; they are parsed at the time of the

  • set_wsubstr() call.

  • The return value is true if all the text is accepted, or false if some was

  • truncated (see set_max_rows()).

*/

set_wtext()

C++ Interface: set_wtext(const TextAssembler self, unicode wtext)

/**
  • Accepts a new text string and associated properties structure, and

  • precomputes the wordwrapping layout appropriately. After this call,

  • get_wordwrapped_wtext() and get_num_rows() can be called.

  • The return value is true if all the text is accepted, or false if some was

  • truncated (see set_max_rows()).

*/

usage_hint