Changeset 718 for trunk

Show
Ignore:
Timestamp:
07/27/08 07:12:32 (4 months ago)
Author:
tom
Message:

Improve alignment of wrapped text.

Patch from Jon Burgess <jburgess777@…>.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/placement_finder.cpp

    r717 r718  
    233233      std::vector<int> line_breaks; 
    234234      std::vector<double> line_widths; 
     235      std::vector<double> line_heights; 
    235236      if (wrap_at < string_width && p.info.num_characters() > 0) 
    236237      { 
     
    261262            if (line_width > 0 && line_width > wrap_at) 
    262263            { 
     264               // Remove width of breaking space character since it is not rendered 
     265               line_width -= ci.width; 
    263266               string_width = string_width > line_width ? string_width : line_width; 
    264267               string_height += line_height; 
    265268               line_breaks.push_back(last_space); 
    266269               line_widths.push_back(line_width); 
     270               line_heights.push_back(line_height); 
    267271               ii = last_space; 
    268272               line_width = 0; 
     
    278282         line_breaks.push_back(p.info.num_characters() + 1); 
    279283         line_widths.push_back(line_width); 
     284         line_heights.push_back(line_height); 
    280285      } 
    281286      if (line_breaks.size() == 0) 
     
    283288         line_breaks.push_back(p.info.num_characters() + 1); 
    284289         line_widths.push_back(string_width); 
     290         line_heights.push_back(string_height); 
    285291      } 
    286292         
     
    294300      current_placement->starting_y += boost::tuples::get<1>(p.displacement_);  
    295301       
    296       double line_height = 0; 
    297302      unsigned int line_number = 0; 
    298303      unsigned int index_to_wrap_at = line_breaks[line_number]; 
    299304      double line_width = line_widths[line_number]; 
     305      double line_height = line_heights[line_number]; 
    300306     
    301       x = -line_width/2.0 - 1.0; 
    302       y = -string_height/2.0 + 1.0; 
     307      x = -line_width/2.0; 
     308      y = -line_height/2.0; 
    303309     
    304310      for (unsigned i = 0; i < p.info.num_characters(); i++) 
     
    312318            index_to_wrap_at = line_breaks[++line_number]; 
    313319            line_width = line_widths[line_number]; 
     320            line_height = line_heights[line_number]; 
    314321            y -= line_height; 
    315322            x = -line_width/2.0; 
    316             line_height = 0; 
    317323            continue; 
    318324         } 
     
    348354         } 
    349355         x += ci.width; 
    350          line_height = line_height > ci.height ? line_height : ci.height; 
    351356      } 
    352357      p.placements.push_back(current_placement.release());