Fix char spacing for scale_factor != 1.

This commit is contained in:
Hermann Kraus 2013-03-24 12:01:51 +01:00
parent 51832de841
commit 0c4d123602
4 changed files with 8 additions and 7 deletions

View file

@ -51,7 +51,7 @@ public:
typedef std::vector<glyph_info> glyph_vector;
typedef glyph_vector::const_iterator const_iterator;
glyph_vector const& get_glyphs() const { return glyphs_; }
void add_glyph(glyph_info const& glyph);
void add_glyph(glyph_info const& glyph, double scale_factor_);
void reserve(glyph_vector::size_type length);
const_iterator begin() const;

View file

@ -89,7 +89,7 @@ void text_layout::break_line(text_line_ptr line, double wrap_width, unsigned tex
unsigned last_break_position = 0;
for (unsigned i=line->get_first_char(); i<line->get_last_char(); i++)
{
//TODO: Char spacing
//TODO: character_spacing
std::map<unsigned, double>::const_iterator width_itr = width_map_.find(i);
if (width_itr != width_map_.end())
{
@ -192,14 +192,15 @@ text_line::text_line(unsigned first_char, unsigned last_char)
{
}
void text_line::add_glyph(const glyph_info &glyph)
void text_line::add_glyph(const glyph_info &glyph, double scale_factor_)
{
line_height_ = std::max(line_height_, glyph.line_height + glyph.format->line_spacing);
if (glyphs_.empty())
{
width_ = glyph.width;
} else {
width_ += glyph.width + glyphs_.back().format->character_spacing;
} else if (glyph.width) {
//Only add character spacing if the character is not a zero-width part of a cluster.
width_ += glyph.width + glyphs_.back().format->character_spacing * scale_factor_;
}
glyphs_.push_back(glyph);
}

View file

@ -59,7 +59,7 @@ void text_layout::shape_text(text_line_ptr line)
width_map_[i] += tmp.width;
line->add_glyph(tmp);
line->add_glyph(tmp, scale_factor_);
}
line->update_max_char_height(face->get_char_height());
}

View file

@ -73,7 +73,7 @@ void text_layout::shape_text(text_line_ptr line)
width_map_[glyphs[i].cluster] += tmp.width;
line->add_glyph(tmp);
line->add_glyph(tmp, scale_factor_);
}
line->update_max_char_height(face->get_char_height());
break; //When we reach this point the current font had all glyphs.