give glyph_info better ctor

This commit is contained in:
Dane Springmeyer 2014-10-11 17:52:54 -07:00
parent eabdf46118
commit b455cc9098
2 changed files with 19 additions and 20 deletions

View file

@ -35,14 +35,12 @@ namespace mapnik
class font_face; class font_face;
using face_ptr = std::shared_ptr<font_face>; using face_ptr = std::shared_ptr<font_face>;
using glyph_index_t = unsigned;
struct glyph_info struct glyph_info
{ {
glyph_info() glyph_info(unsigned g_index, unsigned c_index)
: glyph_index(0), : glyph_index(g_index),
char_index(c_index),
face(nullptr), face(nullptr),
char_index(0),
unscaled_ymin(0.0), unscaled_ymin(0.0),
unscaled_ymax(0.0), unscaled_ymax(0.0),
unscaled_advance(0.0), unscaled_advance(0.0),
@ -50,10 +48,10 @@ struct glyph_info
scale_multiplier(1.0), scale_multiplier(1.0),
offset(), offset(),
format() {} format() {}
glyph_index_t glyph_index; unsigned glyph_index;
face_ptr face;
// Position in the string of all characters i.e. before itemizing // Position in the string of all characters i.e. before itemizing
unsigned char_index; unsigned char_index;
face_ptr face;
double unscaled_ymin; double unscaled_ymin;
double unscaled_ymax; double unscaled_ymax;
double unscaled_advance; double unscaled_advance;

View file

@ -120,21 +120,22 @@ static void shape_text(text_line & line,
double max_glyph_height = 0; double max_glyph_height = 0;
for (unsigned i=0; i<num_glyphs; ++i) for (unsigned i=0; i<num_glyphs; ++i)
{ {
glyph_info tmp; auto const& pos = positions[i];
tmp.glyph_index = glyphs[i].codepoint; auto const& glyph = glyphs[i];
if (face->glyph_dimensions(tmp)) unsigned char_index = glyph.cluster;
glyph_info g(glyph.codepoint,char_index);
if (face->glyph_dimensions(g))
{ {
tmp.char_index = glyphs[i].cluster; g.face = face;
tmp.face = face; g.format = text_item.format;
tmp.format = text_item.format; g.scale_multiplier = size / face->get_face()->units_per_EM;
tmp.scale_multiplier = size / face->get_face()->units_per_EM;
double tmp_height = tmp.height();
if (tmp_height > max_glyph_height) max_glyph_height = tmp_height;
//Overwrite default advance with better value provided by HarfBuzz //Overwrite default advance with better value provided by HarfBuzz
tmp.unscaled_advance = positions[i].x_advance; g.unscaled_advance = pos.x_advance;
tmp.offset.set(positions[i].x_offset * tmp.scale_multiplier, positions[i].y_offset * tmp.scale_multiplier); g.offset.set(pos.x_offset * g.scale_multiplier, pos.y_offset * g.scale_multiplier);
width_map[glyphs[i].cluster] += tmp.advance(); double tmp_height = g.height();
line.add_glyph(tmp, scale_factor); if (tmp_height > max_glyph_height) max_glyph_height = tmp_height;
width_map[char_index] += g.advance();
line.add_glyph(g, scale_factor);
} }
} }
line.update_max_char_height(max_glyph_height); line.update_max_char_height(max_glyph_height);