Browse Source

fix sequential-newlines problem

David Rose 18 years ago
parent
commit
fee45da2c1
3 changed files with 22 additions and 3 deletions
  1. 3 1
      panda/src/text/textAssembler.I
  2. 18 2
      panda/src/text/textAssembler.cxx
  3. 1 0
      panda/src/text/textAssembler.h

+ 3 - 1
panda/src/text/textAssembler.I

@@ -419,7 +419,8 @@ TextRow(const TextAssembler::TextRow &copy) :
   _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 &copy) {
   _got_soft_hyphens = copy._got_soft_hyphens;
   _xpos = copy._xpos;
   _ypos = copy._ypos;
+  _eol_cprops = copy._eol_cprops;
 }
 
 ////////////////////////////////////////////////////////////////////

+ 18 - 2
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());
+  }
 }
   
 

+ 1 - 0
panda/src/text/textAssembler.h

@@ -142,6 +142,7 @@ private:
     bool _got_soft_hyphens;
     float _xpos;
     float _ypos;
+    PT(ComputedProperties) _eol_cprops;
   };
   typedef pvector<TextRow> TextBlock;