Browse Source

revert astelix: changed behavior of centering unacceptably

David Rose 17 years ago
parent
commit
db4b14aaf7

+ 14 - 28
panda/src/text/textAssembler.cxx

@@ -636,7 +636,7 @@ calc_width(wchar_t character, const TextProperties &properties) {
     // A space is a special case.
     // A space is a special case.
     TextFont *font = properties.get_font();
     TextFont *font = properties.get_font();
     nassertr(font != (TextFont *)NULL, 0.0f);
     nassertr(font != (TextFont *)NULL, 0.0f);
-    return font->get_space_advance() * properties.get_glyph_scale() * properties.get_text_scale();
+    return font->get_space_advance();
   }
   }
 
 
   bool got_glyph;
   bool got_glyph;
@@ -659,7 +659,7 @@ calc_width(wchar_t character, const TextProperties &properties) {
     advance += second_glyph->get_advance();
     advance += second_glyph->get_advance();
   }
   }
 
 
-  glyph_scale *= properties.get_glyph_scale() * properties.get_text_scale();
+  glyph_scale *= properties.get_glyph_scale();
 
 
   return advance * glyph_scale;
   return advance * glyph_scale;
 }
 }
@@ -672,7 +672,7 @@ calc_width(wchar_t character, const TextProperties &properties) {
 float TextAssembler::
 float TextAssembler::
 calc_width(const TextGraphic *graphic, const TextProperties &properties) {
 calc_width(const TextGraphic *graphic, const TextProperties &properties) {
   LVecBase4f frame = graphic->get_frame();
   LVecBase4f frame = graphic->get_frame();
-  return (frame[1] - frame[0]) * properties.get_glyph_scale() * properties.get_text_scale();
+  return (frame[1] - frame[0]) * properties.get_glyph_scale();
 }
 }
 
 
 #ifndef CPPPARSER  // interrogate has a bit of trouble with wstring.
 #ifndef CPPPARSER  // interrogate has a bit of trouble with wstring.
@@ -1079,10 +1079,11 @@ assemble_paragraph(TextAssembler::PlacedGlyphs &placed_glyphs) {
 
 
     // First, assemble all the glyphs of this row.
     // First, assemble all the glyphs of this row.
     PlacedGlyphs row_placed_glyphs;
     PlacedGlyphs row_placed_glyphs;
-    float row_width, line_height, wordwrap;
+    float row_width, line_height;
     TextProperties::Alignment align;
     TextProperties::Alignment align;
     assemble_row(row, row_placed_glyphs,
     assemble_row(row, row_placed_glyphs,
-                 row_width, line_height, align, wordwrap);
+                 row_width, line_height, align);
+
     // Now move the row to its appropriate position.  This might
     // Now move the row to its appropriate position.  This might
     // involve a horizontal as well as a vertical translation.
     // involve a horizontal as well as a vertical translation.
     LMatrix4f mat = LMatrix4f::ident_mat();
     LMatrix4f mat = LMatrix4f::ident_mat();
@@ -1099,23 +1100,20 @@ assemble_paragraph(TextAssembler::PlacedGlyphs &placed_glyphs) {
     _lr[1] = ypos - 0.2f * line_height;
     _lr[1] = ypos - 0.2f * line_height;
 
 
     // Apply the requested horizontal alignment to the row.
     // Apply the requested horizontal alignment to the row.
-    //[fabius] now we put wordwrap into the calculations
     float xpos;
     float xpos;
     switch (align) {
     switch (align) {
     case TextProperties::A_left:
     case TextProperties::A_left:
       xpos = 0.0f;
       xpos = 0.0f;
-      _lr[0] = max(_lr[0], max(row_width, wordwrap));
+      _lr[0] = max(_lr[0], row_width);
       break;
       break;
 
 
     case TextProperties::A_right:
     case TextProperties::A_right:
       xpos = -row_width;
       xpos = -row_width;
-      if (wordwrap > row_width) xpos += wordwrap;
       _ul[0] = min(_ul[0], xpos);
       _ul[0] = min(_ul[0], xpos);
       break;
       break;
 
 
     case TextProperties::A_center:
     case TextProperties::A_center:
       xpos = -0.5f * row_width;
       xpos = -0.5f * row_width;
-      if (wordwrap > row_width) xpos += (wordwrap * 0.5f);
       _ul[0] = min(_ul[0], xpos);
       _ul[0] = min(_ul[0], xpos);
       _lr[0] = max(_lr[0], -xpos);
       _lr[0] = max(_lr[0], -xpos);
       break;
       break;
@@ -1155,7 +1153,7 @@ void TextAssembler::
 assemble_row(TextAssembler::TextRow &row,
 assemble_row(TextAssembler::TextRow &row,
              TextAssembler::PlacedGlyphs &row_placed_glyphs,
              TextAssembler::PlacedGlyphs &row_placed_glyphs,
              float &row_width, float &line_height, 
              float &row_width, float &line_height, 
-             TextProperties::Alignment &align, float &wordwrap) {
+             TextProperties::Alignment &align) {
   Thread *current_thread = Thread::get_current_thread();
   Thread *current_thread = Thread::get_current_thread();
 
 
   line_height = 0.0f;
   line_height = 0.0f;
@@ -1191,11 +1189,6 @@ assemble_row(TextAssembler::TextRow &row,
 
 
     // We get the row's alignment property from that of the last
     // We get the row's alignment property from that of the last
     // character to be placed in the row (or the newline character).
     // character to be placed in the row (or the newline character).
-    //[fabius] differently as stated above this is not a sure way to get it so we'll set it as soon as we found it
-    if (
-      (align == TextProperties::A_left) &&
-      (properties->get_align() != TextProperties::A_left)
-      )
     align = properties->get_align();
     align = properties->get_align();
 
 
     // And the height of the row is the maximum of all the fonts used
     // And the height of the row is the maximum of all the fonts used
@@ -1204,8 +1197,7 @@ assemble_row(TextAssembler::TextRow &row,
       LVecBase4f frame = graphic->get_frame();
       LVecBase4f frame = graphic->get_frame();
       line_height = max(line_height, frame[3] - frame[2]);
       line_height = max(line_height, frame[3] - frame[2]);
     } else {
     } else {
-      //[fabius] this is not the right place to calc line height (see below)
-//       line_height = max(line_height, font->get_line_height());
+      line_height = max(line_height, font->get_line_height());
     }
     }
 
 
     if (character == ' ') {
     if (character == ' ') {
@@ -1228,7 +1220,7 @@ assemble_row(TextAssembler::TextRow &row,
       placement->_graphic_model = graphic->get_model().node();
       placement->_graphic_model = graphic->get_model().node();
 
 
       LVecBase4f frame = graphic->get_frame();
       LVecBase4f frame = graphic->get_frame();
-      float glyph_scale = properties->get_glyph_scale() * properties->get_text_scale();
+      float glyph_scale = properties->get_glyph_scale();
 
 
       float advance = (frame[1] - frame[0]);
       float advance = (frame[1] - frame[0]);
 
 
@@ -1302,11 +1294,8 @@ assemble_row(TextAssembler::TextRow &row,
         advance += second_glyph->get_advance();
         advance += second_glyph->get_advance();
       }
       }
 
 
-      glyph_scale *= properties->get_glyph_scale() * properties->get_text_scale();
-      //[fabius] a good place to take wordwrap size
-      if (properties->get_wordwrap() > 0.0f) {
-        wordwrap = properties->get_wordwrap();
-      }
+      glyph_scale *= properties->get_glyph_scale();
+
       // Now compute the matrix that will transform the glyph (or
       // Now compute the matrix that will transform the glyph (or
       // glyphs) into position.
       // glyphs) into position.
       LMatrix4f glyph_xform = LMatrix4f::scale_mat(glyph_scale);
       LMatrix4f glyph_xform = LMatrix4f::scale_mat(glyph_scale);
@@ -1361,8 +1350,6 @@ assemble_row(TextAssembler::TextRow &row,
       placement->_properties = properties;
       placement->_properties = properties;
 
 
       xpos += advance * glyph_scale;
       xpos += advance * glyph_scale;
-      //[fabius] the line height is calculated char by char here
-      line_height = max(line_height, font->get_line_height()*glyph_scale);
     }
     }
   }
   }
 
 
@@ -1382,9 +1369,8 @@ assemble_row(TextAssembler::TextRow &row,
     TextFont *font = properties->get_font();
     TextFont *font = properties->get_font();
     nassertv(font != (TextFont *)NULL);
     nassertv(font != (TextFont *)NULL);
 
 
-    //[fabius] not here but above
-/*     align = properties->get_align();
-    line_height = max(line_height, font->get_line_height());*/
+    align = properties->get_align();
+    line_height = max(line_height, font->get_line_height());
   }
   }
 }
 }
   
   

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

@@ -195,7 +195,7 @@ private:
   void assemble_row(TextRow &row,
   void assemble_row(TextRow &row,
                     PlacedGlyphs &row_placed_glyphs,
                     PlacedGlyphs &row_placed_glyphs,
                     float &row_width, float &line_height, 
                     float &row_width, float &line_height, 
-                    TextProperties::Alignment &align, float &wordwrap);
+                    TextProperties::Alignment &align);
 
 
   // These interfaces are for implementing cheesy accent marks and
   // These interfaces are for implementing cheesy accent marks and
   // ligatures when the font doesn't support them.
   // ligatures when the font doesn't support them.

+ 3 - 61
panda/src/text/textProperties.I

@@ -850,18 +850,9 @@ get_tab_width() const {
 //     Function: TextProperties::set_glyph_scale
 //     Function: TextProperties::set_glyph_scale
 //       Access: Published
 //       Access: Published
 //  Description: Specifies the factor by which to scale each letter of
 //  Description: Specifies the factor by which to scale each letter of
-//               the text as it is placed, in addition to any scales
-//               inherited from the node or from set_text_scale().
-//               This can be used (possibly in conjunction with
-//               set_glyph_shift()) to implement superscripting or
-//               subscripting.
-//
-//               The glyph scale is cumulative when applied to nested
-//               TextProperties.  It is intended primarily for
-//               implementing superscripts, not for scaling the text
-//               in general.  See also set_text_scale(), which is
-//               intended primarily for scaling the text in general,
-//               and is not cumulative.
+//               the text as it is placed.  This can be used (possibly
+//               in conjunction with set_glyph_shift()) to implement
+//               superscripting or subscripting.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 INLINE void TextProperties::
 INLINE void TextProperties::
 set_glyph_scale(float glyph_scale) {
 set_glyph_scale(float glyph_scale) {
@@ -946,52 +937,3 @@ INLINE float TextProperties::
 get_glyph_shift() const {
 get_glyph_shift() const {
   return _glyph_shift;
   return _glyph_shift;
 }
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: TextProperties::set_text_scale
-//       Access: Published
-//  Description: Specifies the factor by which to scale the text, in
-//               addition to any scalings imposed by the node, as well
-//               as in addition to the glyph scale.
-//
-//               The text scale is not cumulative when applied to
-//               nested TextProperties.  See also set_glyph_scale(),
-//               which is cumulative.
-////////////////////////////////////////////////////////////////////
-INLINE void TextProperties::
-set_text_scale(float text_scale) {
-  _text_scale = text_scale;
-  _specified |= F_has_text_scale;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: TextProperties::clear_text_scale
-//       Access: Published
-//  Description: 
-////////////////////////////////////////////////////////////////////
-INLINE void TextProperties::
-clear_text_scale() {
-  _specified &= ~F_has_text_scale;
-  _text_scale = 0.0f;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: TextProperties::has_text_scale
-//       Access: Published
-//  Description:
-////////////////////////////////////////////////////////////////////
-INLINE bool TextProperties::
-has_text_scale() const {
-  return (_specified & F_has_text_scale) != 0;
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: TextProperties::get_text_scale
-//       Access: Published
-//  Description: Returns the scale factor of the text as specified
-//               by set_text_scale().
-////////////////////////////////////////////////////////////////////
-INLINE float TextProperties::
-get_text_scale() const {
-  return _text_scale;
-}

+ 2 - 16
panda/src/text/textProperties.cxx

@@ -50,7 +50,6 @@ TextProperties() {
   _tab_width = text_tab_width;
   _tab_width = text_tab_width;
   _glyph_scale = 1.0f;
   _glyph_scale = 1.0f;
   _glyph_shift = 0.0f;
   _glyph_shift = 0.0f;
-  _text_scale = 1.0f;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -90,7 +89,6 @@ operator = (const TextProperties &copy) {
   _tab_width = copy._tab_width;
   _tab_width = copy._tab_width;
   _glyph_scale = copy._glyph_scale;
   _glyph_scale = copy._glyph_scale;
   _glyph_shift = copy._glyph_shift;
   _glyph_shift = copy._glyph_shift;
-  _text_scale = copy._text_scale;
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -161,9 +159,6 @@ operator == (const TextProperties &other) const {
   if ((_specified & F_has_glyph_shift) && _glyph_shift != other._glyph_shift) {
   if ((_specified & F_has_glyph_shift) && _glyph_shift != other._glyph_shift) {
     return false;
     return false;
   }
   }
-  if ((_specified & F_has_text_scale) && _text_scale != other._text_scale) {
-    return false;
-  }
   return true;
   return true;
 }
 }
 
 
@@ -232,19 +227,15 @@ add_properties(const TextProperties &other) {
     set_tab_width(other.get_tab_width());
     set_tab_width(other.get_tab_width());
   }
   }
 
 
+
   // The glyph scale and shift are a special case: rather than
   // The glyph scale and shift are a special case: rather than
-  // replacing the previous value, they modify it, so that they apply
-  // cumulatively to nested TextProperties.
+  // replacing the previous value, they modify it.
   if (other.has_glyph_shift()) {
   if (other.has_glyph_shift()) {
     set_glyph_shift(other.get_glyph_shift() * get_glyph_scale() + get_glyph_shift());
     set_glyph_shift(other.get_glyph_shift() * get_glyph_scale() + get_glyph_shift());
   }
   }
   if (other.has_glyph_scale()) {
   if (other.has_glyph_scale()) {
     set_glyph_scale(other.get_glyph_scale() * get_glyph_scale());
     set_glyph_scale(other.get_glyph_scale() * get_glyph_scale());
   }
   }
-
-  if (other.has_text_scale()) {
-    set_text_scale(other.get_text_scale());
-  }
 }
 }
 
 
 
 
@@ -353,11 +344,6 @@ write(ostream &out, int indent_level) const {
     indent(out, indent_level)
     indent(out, indent_level)
       << "glyph shift is " << get_glyph_shift() << "\n";
       << "glyph shift is " << get_glyph_shift() << "\n";
   }
   }
-
-  if (has_text_scale()) {
-    indent(out, indent_level)
-      << "text scale is " << get_text_scale() << "\n";
-  }
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 0 - 7
panda/src/text/textProperties.h

@@ -157,11 +157,6 @@ PUBLISHED:
   INLINE bool has_glyph_shift() const;
   INLINE bool has_glyph_shift() const;
   INLINE float get_glyph_shift() const;
   INLINE float get_glyph_shift() const;
 
 
-  INLINE void set_text_scale(float text_scale);
-  INLINE void clear_text_scale();
-  INLINE bool has_text_scale() const;
-  INLINE float get_text_scale() const;
-
   void add_properties(const TextProperties &other);
   void add_properties(const TextProperties &other);
 
 
   void write(ostream &out, int indent_level = 0) const;
   void write(ostream &out, int indent_level = 0) const;
@@ -188,7 +183,6 @@ private:
     F_has_glyph_shift                  = 0x00008000,
     F_has_glyph_shift                  = 0x00008000,
     F_has_underscore                   = 0x00010000,
     F_has_underscore                   = 0x00010000,
     F_has_underscore_height            = 0x00020000,
     F_has_underscore_height            = 0x00020000,
-    F_has_text_scale                   = 0x00040000,
   };
   };
 
 
   int _specified;
   int _specified;
@@ -211,7 +205,6 @@ private:
   float _tab_width;
   float _tab_width;
   float _glyph_scale;
   float _glyph_scale;
   float _glyph_shift;
   float _glyph_shift;
-  float _text_scale;
 
 
   static PT(TextFont) _default_font;
   static PT(TextFont) _default_font;
   static bool _loaded_default_font;
   static bool _loaded_default_font;