Panda3D
|
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. More...
#include "textAssembler.h"
Public Member Functions | |
TextAssembler (TextEncoder *encoder) | |
TextAssembler (const TextAssembler ©) | |
int | calc_c (int n) const |
Computes the column index of the nth character or graphic object in the text and returns it. More... | |
int | calc_index (int r, int c) const |
Computes the character index of the character at the rth row and cth column position. More... | |
int | calc_r (int n) const |
Computes the row index of the nth character or graphic object in the text and returns it. More... | |
bool | calc_r_c (int &r, int &c, int n) const |
Computes the row and column index of the nth character or graphic object in the text. More... | |
void | clear () |
Reinitializes the contents of the TextAssembler. More... | |
wchar_t | get_character (int n) const |
Returns the character at the indicated position in the pre-wordwrapped string. More... | |
wchar_t | get_character (int r, int c) const |
Returns the character at the indicated position in the indicated row. More... | |
bool | get_dynamic_merge () const |
Returns the dynamic_merge flag. More... | |
const TextGraphic * | get_graphic (int n) const |
Returns the graphic object at the indicated position in the pre-wordwrapped string. More... | |
const TextGraphic * | get_graphic (int r, int c) const |
Returns the graphic object at the indicated position in the indicated row. More... | |
const LVector2 & | get_lr () const |
Returns the lower-right corner of the assembled text, in 2-d text coordinates. More... | |
int | get_max_rows () const |
If max_rows is greater than zero, no more than max_rows will be accepted. More... | |
bool | get_multiline_mode () const |
Returns the multline_mode flag. More... | |
int | get_num_characters () const |
Returns the number of characters of text, before wordwrapping. More... | |
int | get_num_cols (int r) const |
Returns the number of characters and/or graphic objects in the nth row. More... | |
int | get_num_rows () const |
Returns the number of rows of text after it has all been wordwrapped and assembled. More... | |
wstring | get_plain_wtext () const |
Returns a wstring that represents the contents of the text, without any embedded properties characters. More... | |
const TextProperties & | get_properties () const |
Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences. More... | |
const TextProperties & | get_properties (int n) const |
Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped string. More... | |
const TextProperties & | get_properties (int r, int c) const |
Returns the TextProperties in effect for the object at the indicated position in the indicated row. More... | |
const LVector2 & | get_ul () const |
Returns the upper-left corner of the assembled text, in 2-d text coordinates. More... | |
Geom::UsageHint | get_usage_hint () const |
Returns the UsageHint that will be applied to generated geometry. More... | |
PN_stdfloat | get_width (int n) const |
Returns the width of the character or object at the indicated position in the pre-wordwrapped string. More... | |
PN_stdfloat | get_width (int r, int c) const |
Returns the width of the character or object at the indicated position in the indicated row. More... | |
wstring | get_wordwrapped_plain_wtext () const |
Returns a wstring that represents the contents of the text, with newlines inserted according to the wordwrapping. More... | |
wstring | get_wordwrapped_wtext () const |
Returns a wstring that represents the contents of the text, with newlines inserted according to the wordwrapping. More... | |
wstring | get_wtext () const |
Returns a wstring that represents the contents of the text. More... | |
PN_stdfloat | get_xpos (int r, int c) const |
Returns the x position of the origin of the character or graphic object at the indicated position in the indicated row. More... | |
PN_stdfloat | get_ypos (int r, int c) const |
Returns the y position of the origin of all of the characters or graphic objects in the indicated row. More... | |
void | operator= (const TextAssembler ©) |
PT (PandaNode) assemble_text() | |
void | set_dynamic_merge (bool dynamic_merge) |
Sets the dynamic_merge flag. More... | |
void | set_max_rows (int max_rows) |
If max_rows is greater than zero, no more than max_rows will be accepted. More... | |
void | set_multiline_mode (bool flag) |
Sets the multiline mode flag. More... | |
void | set_properties (const TextProperties &properties) |
Specifies the default TextProperties that are applied to the text in the absence of any nested property change sequences. More... | |
void | set_usage_hint (Geom::UsageHint usage_hint) |
Specifies the UsageHint that will be applied to generated geometry. More... | |
bool | set_wsubstr (const wstring &wtext, int start, int count) |
Replaces the 'count' characters from 'start' of the current text with the indicated replacement text. More... | |
bool | set_wtext (const wstring &wtext) |
Accepts a new text string and associated properties structure, and precomputes the wordwrapping layout appropriately. More... | |
Static Public Member Functions | |
static PN_stdfloat | calc_width (wchar_t character, const TextProperties &properties) |
Returns the width of a single character, according to its associated font. More... | |
static PN_stdfloat | calc_width (const TextGraphic *graphic, const TextProperties &properties) |
Returns the width of a single TextGraphic image. More... | |
static bool | has_character (wchar_t character, const TextProperties &properties) |
Returns true if the named character exists in the font or can be synthesized by Panda, false otherwise. More... | |
static bool | has_exact_character (wchar_t character, const TextProperties &properties) |
Returns true if the named character exists in the font exactly as named, false otherwise. More... | |
static bool | is_whitespace (wchar_t 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. More... | |
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.
Definition at line 46 of file textAssembler.h.
|
inline |
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).
Definition at line 194 of file textAssembler.I.
References calc_r_c(), and get_num_characters().
Referenced by calc_r().
int TextAssembler::calc_index | ( | int | r, |
int | c | ||
) | const |
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.
Definition at line 486 of file textAssembler.cxx.
References get_xpos().
Referenced by calc_r_c().
|
inline |
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).
Definition at line 173 of file textAssembler.I.
References calc_c(), and calc_r_c().
Referenced by get_lr().
bool TextAssembler::calc_r_c | ( | int & | r, |
int & | c, | ||
int | n | ||
) | const |
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.
Definition at line 409 of file textAssembler.cxx.
References calc_index().
Referenced by calc_c(), calc_r(), and get_wordwrapped_wtext().
|
static |
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.
Definition at line 680 of file textAssembler.cxx.
References TextProperties::get_font(), TextProperties::get_glyph_scale(), TextFont::get_space_advance(), and TextProperties::get_text_scale().
Referenced by TextNode::calc_width(), get_width(), get_xpos(), and get_ypos().
|
static |
Returns the width of a single TextGraphic image.
Definition at line 719 of file textAssembler.cxx.
References TextGraphic::get_frame(), TextProperties::get_glyph_scale(), TextProperties::get_text_scale(), and has_exact_character().
void TextAssembler::clear | ( | ) |
Reinitializes the contents of the TextAssembler.
Definition at line 155 of file textAssembler.cxx.
References set_wtext().
|
inline |
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.
Definition at line 222 of file textAssembler.I.
References get_graphic().
Referenced by PGEntry::get_character(), get_num_characters(), and get_num_cols().
|
inline |
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.
Definition at line 301 of file textAssembler.I.
References get_graphic().
|
inline |
Returns the dynamic_merge flag.
See TextNode::set_flatten_flags().
Definition at line 88 of file textAssembler.I.
References set_multiline_mode().
Referenced by set_dynamic_merge().
|
inline |
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.
Definition at line 236 of file textAssembler.I.
References get_properties().
Referenced by get_character(), and PGEntry::get_graphic().
|
inline |
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.
Definition at line 316 of file textAssembler.I.
References get_properties().
|
inline |
Returns the lower-right corner of the assembled text, in 2-d text coordinates.
Definition at line 156 of file textAssembler.I.
References calc_r().
Referenced by TextNode::calc_width(), and get_ul().
|
inline |
If max_rows is greater than zero, no more than max_rows will be accepted.
Text beyond that will be truncated.
Definition at line 66 of file textAssembler.I.
References set_dynamic_merge().
Referenced by set_max_rows().
|
inline |
Returns the multline_mode flag.
See TextNode::set_multiline_mode().
Definition at line 110 of file textAssembler.I.
References set_properties().
Referenced by set_multiline_mode().
|
inline |
Returns the number of characters of text, before wordwrapping.
Definition at line 209 of file textAssembler.I.
References get_character().
Referenced by calc_c(), PGEntry::get_num_characters(), and PGEntry::set_wtext().
|
inline |
Returns the number of characters and/or graphic objects in the nth row.
Definition at line 285 of file textAssembler.I.
References get_character().
Referenced by get_num_rows().
|
inline |
Returns the number of rows of text after it has all been wordwrapped and assembled.
Definition at line 274 of file textAssembler.I.
References get_num_cols().
Referenced by TextNode::calc_width(), and get_width().
wstring TextAssembler::get_plain_wtext | ( | ) | const |
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).
Definition at line 252 of file textAssembler.cxx.
References get_wordwrapped_plain_wtext().
Referenced by PGEntry::get_plain_wtext(), and set_wsubstr().
|
inline |
Returns the default TextProperties that are applied to the text in the absence of any nested property change sequences.
Definition at line 134 of file textAssembler.I.
References get_ul().
Referenced by get_graphic(), PGEntry::get_properties(), and set_properties().
|
inline |
Returns the TextProperties in effect for the object at the indicated position in the pre-wordwrapped string.
Definition at line 249 of file textAssembler.I.
References get_width().
|
inline |
Returns the TextProperties in effect for the object at the indicated position in the indicated row.
Definition at line 329 of file textAssembler.I.
References get_width().
|
inline |
Returns the upper-left corner of the assembled text, in 2-d text coordinates.
Definition at line 145 of file textAssembler.I.
References get_lr().
Referenced by TextNode::calc_width(), and get_properties().
|
inline |
Returns the UsageHint that will be applied to generated geometry.
See set_usage_hint().
Definition at line 38 of file textAssembler.I.
References set_max_rows().
Referenced by set_usage_hint().
|
inline |
Returns the width of the character or object at the indicated position in the pre-wordwrapped string.
Definition at line 261 of file textAssembler.I.
References calc_width(), and get_num_rows().
Referenced by get_properties().
|
inline |
Returns the width of the character or object at the indicated position in the indicated row.
Definition at line 342 of file textAssembler.I.
References calc_width(), and get_ypos().
wstring TextAssembler::get_wordwrapped_plain_wtext | ( | ) | const |
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).
Definition at line 284 of file textAssembler.cxx.
References get_wtext().
Referenced by get_plain_wtext().
wstring TextAssembler::get_wordwrapped_wtext | ( | ) | const |
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.
Definition at line 362 of file textAssembler.cxx.
References calc_r_c().
Referenced by TextNode::calc_width(), and get_wtext().
wstring TextAssembler::get_wtext | ( | ) | const |
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.
Definition at line 320 of file textAssembler.cxx.
References get_wordwrapped_wtext().
Referenced by get_wordwrapped_plain_wtext(), and PGEntry::get_wtext().
PN_stdfloat TextAssembler::get_xpos | ( | int | r, |
int | c | ||
) | const |
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.
Definition at line 529 of file textAssembler.cxx.
References calc_width(), TextProperties::get_bin(), TextProperties::get_draw_order(), TextProperties::get_shadow(), TextProperties::has_bin(), LMatrix4f::ident_mat(), and LMatrix4f::translate_mat().
Referenced by calc_index(), and PGEntry::is_wtext().
|
inline |
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.
Definition at line 359 of file textAssembler.I.
References TextProperties::add_properties(), calc_width(), TextEncoder::encode_wtext(), TextPropertiesManager::get_global_ptr(), and TextPropertiesManager::get_properties_ptr().
Referenced by get_width().
|
static |
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".
Definition at line 771 of file textAssembler.cxx.
References is_whitespace().
Referenced by TextNode::has_character(), and has_exact_character().
|
static |
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().
Definition at line 743 of file textAssembler.cxx.
References TextProperties::get_font(), TextFont::get_glyph(), and has_character().
Referenced by calc_width(), and TextNode::has_exact_character().
|
static |
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.
Definition at line 813 of file textAssembler.cxx.
References GeomVertexWriter::add_data3(), GeomVertexWriter::add_data4(), GeomNode::add_geom(), GeomPrimitive::add_vertex(), GeomPrimitive::close_primitive(), Thread::get_current_thread(), GeomVertexReader::get_data3(), TextProperties::get_font(), GeomVertexData::get_format(), TextGraphic::get_frame(), TextPropertiesManager::get_global_ptr(), TextFont::get_glyph(), TextProperties::get_glyph_scale(), TextProperties::get_glyph_shift(), TextPropertiesManager::get_graphic_ptr(), TextGraphic::get_instance_flag(), TextFont::get_line_height(), TextGraphic::get_model(), GeomPrimitive::get_primitive_start(), TextProperties::get_slant(), TextProperties::get_small_caps(), TextProperties::get_small_caps_scale(), TextFont::get_space_advance(), TextProperties::get_tab_width(), TextProperties::get_text_scale(), TextProperties::get_underscore(), TextProperties::get_underscore_height(), LMatrix4f::ident_mat(), TextGlyph::is_whitespace(), UnicodeLatinMap::look_up(), Geom::make_copy(), NodePath::node(), LMatrix4f::rotate_mat_normaxis(), LMatrix4f::scale_mat(), GeomVertexWriter::set_data3(), LMatrix4f::set_rotate_mat_normaxis(), LMatrix4f::set_row(), GeomVertexRewriter::set_row_unsafe(), Geom::transform_vertices(), and LMatrix4f::translate_mat().
Referenced by has_character(), and TextNode::is_whitespace().
|
inline |
Sets the dynamic_merge flag.
See TextNode::set_flatten_flags().
Definition at line 77 of file textAssembler.I.
References get_dynamic_merge().
Referenced by TextNode::calc_width(), and get_max_rows().
|
inline |
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.
Definition at line 54 of file textAssembler.I.
References get_max_rows().
Referenced by TextNode::calc_width(), and get_usage_hint().
|
inline |
Sets the multiline mode flag.
Set the multiline mode to allow text to wrap. It defaults to true.
Definition at line 99 of file textAssembler.I.
References get_multiline_mode().
Referenced by get_dynamic_merge().
|
inline |
Specifies the default TextProperties that are applied to the text in the absence of any nested property change sequences.
Definition at line 122 of file textAssembler.I.
References get_properties().
Referenced by TextNode::calc_width(), and get_multiline_mode().
|
inline |
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.
Definition at line 27 of file textAssembler.I.
References get_usage_hint().
Referenced by TextNode::calc_width().
bool TextAssembler::set_wsubstr | ( | const wstring & | 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()).
Definition at line 217 of file textAssembler.cxx.
References get_plain_wtext().
Referenced by PGEntry::is_wtext(), and set_wtext().
bool TextAssembler::set_wtext | ( | const wstring & | 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()).
Definition at line 177 of file textAssembler.cxx.
References set_wsubstr().
Referenced by TextNode::calc_width(), clear(), and PGEntry::set_wtext().