From fee45da2c1a266b0063d3d09a907f495687ebcfb Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 8 Aug 2007 23:52:12 +0000 Subject: [PATCH] fix sequential-newlines problem --- panda/src/text/textAssembler.I | 4 +++- panda/src/text/textAssembler.cxx | 20 ++++++++++++++++++-- panda/src/text/textAssembler.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/panda/src/text/textAssembler.I b/panda/src/text/textAssembler.I index 3a08a12d39..ea99ef4928 100644 --- a/panda/src/text/textAssembler.I +++ b/panda/src/text/textAssembler.I @@ -419,7 +419,8 @@ TextRow(const TextAssembler::TextRow ©) : _row_start(copy._row_start), _got_soft_hyphens(copy._got_soft_hyphens), _xpos(copy._xpos), - _ypos(copy._ypos) + _ypos(copy._ypos), + _eol_cprops(copy._eol_cprops) { } @@ -435,6 +436,7 @@ operator = (const TextAssembler::TextRow ©) { _got_soft_hyphens = copy._got_soft_hyphens; _xpos = copy._xpos; _ypos = copy._ypos; + _eol_cprops = copy._eol_cprops; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/text/textAssembler.cxx b/panda/src/text/textAssembler.cxx index 3b0481f560..ef80493655 100644 --- a/panda/src/text/textAssembler.cxx +++ b/panda/src/text/textAssembler.cxx @@ -629,8 +629,8 @@ calc_width(wchar_t character, const TextProperties &properties) { } bool got_glyph; - const TextGlyph *first_glyph; - const TextGlyph *second_glyph; + const TextGlyph *first_glyph = NULL; + const TextGlyph *second_glyph = NULL; UnicodeLatinMap::AccentType accent_type; int additional_flags; float glyph_scale; @@ -808,6 +808,7 @@ wordwrap_text() { // Truncate. return false; } + _text_block.back()._eol_cprops = _text_string[p]._cprops; _text_block.push_back(TextRow(p + 1)); } else { initial_width += calc_width(_text_string[p]); @@ -993,6 +994,7 @@ wordwrap_text() { // Truncate. return false; } + _text_block.back()._eol_cprops = _text_string[next_start]._cprops; next_start++; _text_block.push_back(TextRow(next_start)); needs_newline = false; @@ -1008,6 +1010,7 @@ wordwrap_text() { // Truncate. return false; } + _text_block.back()._eol_cprops = _text_string[p]._cprops; _text_block.push_back(TextRow(p + 1)); } else { initial_width += calc_width(_text_string[p]); @@ -1323,6 +1326,19 @@ assemble_row(TextAssembler::TextRow &row, } row_width = xpos; + + if (row._eol_cprops != (ComputedProperties *)NULL) { + // If there's an _eol_cprops, it represents the cprops of the + // newline character that ended the line, which should define the + // line_height and the alignment. + + const TextProperties *properties = &(row._eol_cprops->_properties); + TextFont *font = properties->get_font(); + nassertv(font != (TextFont *)NULL); + + align = properties->get_align(); + line_height = max(line_height, font->get_line_height()); + } } diff --git a/panda/src/text/textAssembler.h b/panda/src/text/textAssembler.h index 33064d856c..20d5713aa1 100644 --- a/panda/src/text/textAssembler.h +++ b/panda/src/text/textAssembler.h @@ -142,6 +142,7 @@ private: bool _got_soft_hyphens; float _xpos; float _ypos; + PT(ComputedProperties) _eol_cprops; }; typedef pvector TextBlock;