# TextAssembler

from pandac.PandaModules import TextAssembler

Class : TextAssembler
Description : 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:

TextAssembler:

## Methods of TextAssembler:

assembleText
calcC
calcIndex
calcR
calcRC
calcWidth
clear
getCharacter
getGraphic
getLr
getMaxRows
getNumCharacters
getNumCols
getNumRows
getPlainWtext
getProperties
getUl
getUsageHint
getWidth
getWordwrappedPlainWtext
getWordwrappedWtext
getWtext
getXpos
getYpos
operator =
setMaxRows
setProperties
setUsageHint
setWsubstr
setWtext

assembleText PointerTo< PandaNode > TextAssembler::assemble_text(void); Description: 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().

calcC int TextAssembler::calc_c(int n) const; Description: 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 int TextAssembler::calc_index(int r, int c) const; Description: 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 0.

calcR int TextAssembler::calc_r(int n) const; Description: 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).

calcRC bool TextAssembler::calc_r_c(int &r, int &c, int n) const; Description: Computes the row and column index of the nth character or graphic object in the text. Fills r and c accordingly. Returns true if the nth character is valid and has a corresponding r and c position, false otherwise (for instance, a soft-hyphen character, or a newline character, may not have a corresponding position). In either case, r and c will be filled in sensibly.

calcWidth static float TextAssembler::calc_width(wchar_t character, TextProperties const &properties); Description: Returns the width of a single character, according to its associated font. Description: 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. Description: Returns the width of a single TextGraphic image.

clear void TextAssembler::clear(void); Description: Reinitializes the contents of the TextAssembler.

getCharacter wchar_t TextAssembler::get_character(int n) const; Description: 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. Description: 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.

getGraphic TextGraphic const *TextAssembler::get_graphic(int n) const; Description: 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. Description: 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 LVector2f const &TextAssembler::get_lr(void) const; Description: Returns the lower-right corner of the assembled text, in 2-d text coordinates.

getMaxRows int TextAssembler::get_max_rows(void) const; Description: If max_rows is greater than zero, no more than max_rows will be accepted. Text beyond that will be truncated.

getNumCharacters int TextAssembler::get_num_characters(void) const; Description: Returns the number of characters of text, before wordwrapping.

getNumCols int TextAssembler::get_num_cols(int r) const; Description: Returns the number of characters and/or graphic objects in the nth row.

getNumRows int TextAssembler::get_num_rows(void) const; Description: Returns the number of rows of text after it has all been wordwrapped and assembled.

getPlainWtext basic_string< wchar_t > TextAssembler::get_plain_wtext(void) const; Description: 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 TextProperties const &TextAssembler::get_properties(void) const; Description: Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences. Description: Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped string. Description: Returns the TextProperties in effect for the object at the indicated position in the indicated row.

getUl LVector2f const &TextAssembler::get_ul(void) const; Description: Returns the upper-left corner of the assembled text, in 2-d text coordinates.

getUsageHint GeomEnums::UsageHint TextAssembler::get_usage_hint(void) const; Description: Returns the UsageHint that will be applied to generated geometry. See set_usage_hint().

getWidth float TextAssembler::get_width(int n) const; Description: Returns the width of the character or object at the indicated position in the pre-wordwrapped string. Description: Returns the width of the character or object at the indicated position in the indicated row.

getWordwrappedPlainWtext basic_string< wchar_t > TextAssembler::get_wordwrapped_plain_wtext(void) const; Description: 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 basic_string< wchar_t > TextAssembler::get_wordwrapped_wtext(void) const; Description: 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.

getWtext basic_string< wchar_t > TextAssembler::get_wtext(void) const; Description: 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 float TextAssembler::get_xpos(int r, int c) const; Description: 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 0.

getYpos float TextAssembler::get_ypos(int r, int c) const; Description: 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.

operator = void TextAssembler::operator =(TextAssembler const &copy); Description:

setMaxRows void TextAssembler::set_max_rows(int max_rows); Description: 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.

setProperties void TextAssembler::set_properties(TextProperties const &properties); Description: Specifies the default TextProperties that are applied to the text in the absence of any nested property change sequences.

setUsageHint void TextAssembler::set_usage_hint(GeomEnums::UsageHint usage_hint); Filename: textAssembler.I Created by: drose (06Apr04) PANDA 3D SOFTWARE Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved All use of this software is subject to the terms of the Panda 3d Software license. You should have received a copy of this license along with this source code; you will also find a current copy of the license at http://etc.cmu.edu/panda3d/docs/license/ . To contact the maintainers of this program write to panda3d-general@lists.sourceforge.net . Description: 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 bool TextAssembler::set_wsubstr(basic_string< wchar_t > const &wtext, int start, int count); Description: 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 bool TextAssembler::set_wtext(basic_string< wchar_t > const &wtext); Description: 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()).