Use offsets for correct positioning of glyphs.

Refs #1208.
This commit is contained in:
Hermann Kraus 2012-07-17 23:28:20 +02:00
parent e9354f5802
commit 27c5e50dcb
3 changed files with 12 additions and 4 deletions

View file

@ -52,6 +52,9 @@ struct glyph_info
double ymax; double ymax;
double line_height; double line_height;
double offset_x;
double offset_y;
char_properties_ptr format; char_properties_ptr format;
double height() const { return ymax-ymin; } double height() const { return ymax-ymin; }

View file

@ -79,10 +79,13 @@ void text_layout::shape_text()
tmp.char_index = glyphs[i].cluster; tmp.char_index = glyphs[i].cluster;
tmp.glyph_index = glyphs[i].codepoint; tmp.glyph_index = glyphs[i].codepoint;
tmp.width = positions[i].x_advance / 64.0; tmp.width = positions[i].x_advance / 64.0;
tmp.offset_x = positions[i].x_offset / 64.0;
tmp.offset_y = positions[i].y_offset / 64.0;
tmp.face = face; tmp.face = face;
tmp.format = itr->format; tmp.format = itr->format;
face->glyph_dimensions(tmp); face->glyph_dimensions(tmp);
glyphs_.push_back(tmp); glyphs_.push_back(tmp);
std::cout << "glyph:" << glyphs[i].mask << " xa:" << positions[i].x_advance << " ya:" << positions[i].y_advance << " xo:" << positions[i].x_offset << " yo:" << positions[i].y_offset << "\n";
} }
} }
std::cout << "text_length: unicode chars: " << itemizer.get_text().length() << " glyphs: " << glyphs_.size() << "\n"; std::cout << "text_length: unicode chars: " << itemizer.get_text().length() << " glyphs: " << glyphs_.size() << "\n";
@ -104,6 +107,7 @@ void text_layout::clear()
glyphs_.clear(); glyphs_.clear();
} }
#if 0
format_run::format_run(char_properties_ptr properties, double text_height) format_run::format_run(char_properties_ptr properties, double text_height)
: properties_(properties), glyphs_(), width_(0), text_height_(text_height), line_height_(0) : properties_(properties), glyphs_(), width_(0), text_height_(text_height), line_height_(0)
{ {
@ -127,5 +131,6 @@ void text_line::add_run(format_run_ptr run)
max_text_height = std::max(max_text_height, run->text_height()); max_text_height = std::max(max_text_height, run->text_height());
runs_.push_back(run); runs_.push_back(run);
} }
#endif
} //ns mapnik } //ns mapnik

View file

@ -38,13 +38,13 @@ void text_renderer<T>::prepare_glyphs(glyph_positions_ptr pos)
} }
while (pos->next()) while (pos->next())
{ {
pixel_position p = pos->get_position();
pen.x = int(p.x * 64);
pen.y = int(p.y * 64);
glyph_info const& glyph = pos->get_glyph(); glyph_info const& glyph = pos->get_glyph();
glyph.face->set_character_sizes(glyph.format->text_size); //TODO: Optimize this? glyph.face->set_character_sizes(glyph.format->text_size); //TODO: Optimize this?
pixel_position p = pos->get_position();
pen.x = int((p.x +glyph.offset_x) * 64);
pen.y = int((p.y + glyph.offset_y) * 64);
if (!constant_angle) if (!constant_angle)
{ {
double angle = pos->get_angle(); double angle = pos->get_angle();