43class EXPCL_PANDA_TEXT TextAssembler {
46 TextAssembler(
const TextAssembler ©);
47 void operator = (
const TextAssembler ©);
67 bool set_wtext(
const std::wstring &wtext);
68 bool set_wsubstr(
const std::wstring &wtext,
int start,
int count);
75 bool calc_r_c(
int &r,
int &c,
int n)
const;
76 INLINE
int calc_r(
int n)
const;
77 INLINE
int calc_c(
int n)
const;
84 INLINE PN_stdfloat
get_width(
int n)
const;
91 INLINE PN_stdfloat
get_width(
int r,
int c)
const;
92 PN_stdfloat
get_xpos(
int r,
int c)
const;
93 INLINE PN_stdfloat
get_ypos(
int r,
int c)
const;
97 INLINE
const LVector2 &
get_ul()
const;
98 INLINE
const LVector2 &
get_lr()
const;
119 INLINE ComputedProperties(ComputedProperties *based_on,
121 void append_delta(std::wstring &wtext, ComputedProperties *other);
123 PT(ComputedProperties) _based_on;
133 class TextCharacter {
135 INLINE TextCharacter(
wchar_t character, ComputedProperties *cprops);
136 INLINE TextCharacter(
char32_t character, ComputedProperties *cprops);
138 const std::wstring &graphic_wname,
139 ComputedProperties *cprops);
140 INLINE TextCharacter(
const TextCharacter ©);
141 INLINE
void operator = (
const TextCharacter ©);
145 std::wstring _graphic_wname;
146 PT(ComputedProperties) _cprops;
148 typedef pvector<TextCharacter> TextString;
152 INLINE TextRow(
int row_start);
153 INLINE TextRow(
const TextRow ©);
154 INLINE
void operator = (
const TextRow ©);
158 bool _got_soft_hyphens;
161 PT(ComputedProperties) _eol_cprops;
163 typedef pvector<TextRow> TextBlock;
165 PT(ComputedProperties) _initial_cprops;
168 TextString _text_string;
171 TextBlock _text_block;
173 void scan_wtext(TextString &output_string,
174 std::wstring::const_iterator &si,
175 const std::wstring::const_iterator &send,
176 ComputedProperties *current_cprops);
178 bool wordwrap_text();
180 INLINE
static PN_stdfloat calc_width(
const TextCharacter &tch);
181 static PN_stdfloat calc_hyphen_width(
const TextCharacter &tch);
186 class GeomCollectorKey {
188 INLINE GeomCollectorKey(
const RenderState *state,
const GeomVertexFormat *format);
189 INLINE
bool operator < (
const GeomCollectorKey &other)
const;
191 CPT(RenderState) _state;
192 CPT(GeomVertexFormat) _format;
195 typedef pmap<int, int> VertexIndexMap;
197 class GeomCollector {
199 GeomCollector(
const GeomVertexFormat *format);
200 GeomCollector(
const GeomCollector ©);
202 INLINE
void count_geom(
const Geom *geom);
203 GeomPrimitive *get_primitive(TypeHandle prim_type);
204 int append_vertex(
const GeomVertexData *orig_vdata,
int orig_row,
205 const LMatrix4 &xform);
206 void append_geom(GeomNode *geom_node,
const RenderState *state);
209 PT(GeomVertexData) _vdata;
210 PT(GeomTextGlyph) _geom;
211 PT(GeomTriangles) _triangles;
212 PT(GeomLines) _lines;
213 PT(GeomPoints) _points;
215 typedef pmap<GeomCollectorKey, GeomCollector> GeomCollectorMap;
218 LVecBase4 _dimensions;
220 PN_stdfloat _slantl, _slanth;
221 CPT(TextGlyph) _glyph;
223 typedef epvector<QuadDef> QuadDefs;
224 typedef pmap<CPT(RenderState), QuadDefs> QuadMap;
226 void generate_quads(GeomNode *geom_node,
const QuadMap &quad_map);
228 class GlyphPlacement {
230 void assign_to(GeomNode *geom_node,
const RenderState *state,
231 const LVector2 &offset = LVector2::zero())
const;
233 void assign_append_to(GeomCollectorMap &geom_collector_map,
const RenderState *state,
234 const LVector2 &offset = LVector2::zero())
const;
235 void assign_quad_to(QuadMap &quad_map,
const RenderState *state,
236 const LVector2 &offset = LVector2::zero())
const;
237 void copy_graphic_to(PandaNode *node,
const RenderState *state)
const;
239 CPT(TextGlyph) _glyph;
240 PT(PandaNode) _graphic_model;
241 PN_stdfloat _xpos, _ypos;
242 PN_stdfloat _scale, _slant;
243 const TextProperties *_properties;
245 typedef pvector<GlyphPlacement> PlacedGlyphs;
247 void assemble_paragraph(PlacedGlyphs &placed_glyphs);
248 void assemble_row(TextRow &row,
249 PlacedGlyphs &row_placed_glyphs,
250 PN_stdfloat &row_width, PN_stdfloat &line_height,
251 TextProperties::Alignment &align, PN_stdfloat &wordwrap);
253 void shape_buffer(hb_buffer_t *buf, PlacedGlyphs &glyphs, PN_stdfloat &xpos,
254 const TextProperties &properties);
258 enum CheesyPosition {
265 enum CheesyTransform {
274 CT_squash_mirror_diag,
276 CT_small_squash_mirror_y,
277 CT_small_squash_mirror_diag,
286 draw_underscore(TextAssembler::PlacedGlyphs &row_placed_glyphs,
287 PN_stdfloat underscore_start, PN_stdfloat underscore_end,
288 const TextProperties *underscore_properties);
291 get_character_glyphs(
int character,
const TextProperties *properties,
292 bool &got_glyph, CPT(TextGlyph) &glyph,
293 CPT(TextGlyph) &second_glyph,
294 UnicodeLatinMap::AccentType &accent_type,
295 int &additional_flags,
296 PN_stdfloat &glyph_scale, PN_stdfloat &advance_scale);
299 tack_on_accent(UnicodeLatinMap::AccentType accent_type,
300 const LPoint3 &min_vert,
const LPoint3 &max_vert,
301 const LPoint3 ¢roid,
302 const TextProperties *properties, GlyphPlacement &placement)
const;
304 tack_on_accent(
wchar_t accent_mark, CheesyPosition position,
305 CheesyTransform transform,
306 const LPoint3 &min_vert,
const LPoint3 &max_vert,
307 const LPoint3 ¢roid,
308 const TextProperties *properties, GlyphPlacement &placement)
const;
313 PN_stdfloat _next_row_ypos;
315 TextEncoder *_encoder;
316 Geom::UsageHint _usage_hint;
319 bool _multiline_mode;
This class is not normally used directly by user code, but is used by the TextNode to lay out a block...
set_usage_hint
Specifies the UsageHint that will be applied to generated geometry.
bool set_wtext(const std::wstring &wtext)
Accepts a new text string and associated properties structure, and precomputes the wordwrapping layou...
const LVector2 & get_ul() const
Returns the upper-left corner of the assembled text, in 2-d text coordinates.
int get_num_rows() const
Returns the number of rows of text after it has all been wordwrapped and assembled.
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.
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 visib...
std::wstring get_wordwrapped_wtext() const
Returns a wstring that represents the contents of the text, with newlines inserted according to the w...
set_max_rows
If max_rows is greater than zero, no more than max_rows will be accepted.
std::wstring get_wtext() const
Returns a wstring that represents the contents of the text.
int calc_c(int n) const
Computes the column index of the nth character or graphic object in the text and returns it.
int get_num_cols(int r) const
Returns the number of characters and/or graphic objects in the nth row.
std::wstring get_wordwrapped_plain_wtext() const
Returns a wstring that represents the contents of the text, with newlines inserted according to the w...
get_properties
Returns the default TextProperties that are applied to the text in the absence of any nested property...
int get_num_characters() const
Returns the number of characters of text, before wordwrapping.
get_usage_hint
Returns the UsageHint that will be applied to generated geometry.
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 ...
get_max_rows
If max_rows is greater than zero, no more than max_rows will be accepted.
int calc_index(int r, int c) const
Computes the character index of the character at the rth row and cth column position.
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...
static PN_stdfloat calc_width(wchar_t character, const TextProperties &properties)
Returns the width of a single character, according to its associated font.
const TextGraphic * get_graphic(int n) const
Returns the graphic object at the indicated position in the pre-wordwrapped string.
int calc_r(int n) const
Computes the row index of the nth character or graphic object in the text and returns it.
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.
PN_stdfloat get_width(int n) const
Returns the width of the character or object at the indicated position in the pre-wordwrapped string.
const LVector2 & get_lr() const
Returns the lower-right corner of the assembled text, in 2-d text coordinates.
char32_t get_character(int n) const
Returns the character at the indicated position in the pre-wordwrapped string.
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,...
std::wstring get_plain_wtext() const
Returns a wstring that represents the contents of the text, without any embedded properties character...
bool set_wsubstr(const std::wstring &wtext, int start, int count)
Replaces the 'count' characters from 'start' of the current text with the indicated replacement text.
set_properties
Specifies the default TextProperties that are applied to the text in the absence of any nested proper...
This class can be used to convert text between multiple representations, e.g.
This defines a special model that has been constructed for the purposes of embedding an arbitrary gra...
This defines the set of visual properties that may be assigned to the individual characters of the te...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.