line_height, ymin, ymax and advance all look right now
This commit is contained in:
parent
3948e01c97
commit
38966674f1
3 changed files with 21 additions and 27 deletions
|
@ -43,13 +43,11 @@ struct glyph_info
|
|||
: glyph_index(0),
|
||||
face(nullptr),
|
||||
char_index(0),
|
||||
x_scale(0.0),
|
||||
y_scale(0.0),
|
||||
unscaled_ymin(0.0),
|
||||
unscaled_ymax(0.0),
|
||||
unscaled_width(0.0),
|
||||
unscaled_height(0.0),
|
||||
unscaled_advance(0.0),
|
||||
unscaled_ascender(0.0),
|
||||
unscaled_descender(0.0),
|
||||
unscaled_line_height(0.0),
|
||||
scale_multiplier(0.0),
|
||||
offset(),
|
||||
|
@ -58,13 +56,11 @@ struct glyph_info
|
|||
face_ptr face;
|
||||
// Position in the string of all characters i.e. before itemizing
|
||||
unsigned char_index;
|
||||
double x_scale;
|
||||
double y_scale;
|
||||
double unscaled_ymin;
|
||||
double unscaled_ymax;
|
||||
double unscaled_width;
|
||||
double unscaled_height;
|
||||
double unscaled_advance;
|
||||
double unscaled_ascender;
|
||||
double unscaled_descender;
|
||||
// Line height returned by freetype, includes normal font
|
||||
// line spacing, but not additional user defined spacing
|
||||
double unscaled_line_height;
|
||||
|
@ -72,14 +68,11 @@ struct glyph_info
|
|||
pixel_position offset;
|
||||
char_properties_ptr format;
|
||||
|
||||
double ymin() const { return unscaled_ymin * scale_multiplier; }
|
||||
double ymax() const { return unscaled_ymax * scale_multiplier; }
|
||||
double width() const { return unscaled_width * scale_multiplier; };
|
||||
double height() const { return unscaled_height * scale_multiplier; };
|
||||
double advance() const { return floor(unscaled_advance * scale_multiplier); };
|
||||
double ascender() const { return unscaled_ascender * scale_multiplier; };
|
||||
double descender() const { return unscaled_descender * scale_multiplier; };
|
||||
double line_height() const { return unscaled_line_height * scale_multiplier; };
|
||||
double ymin() const { return floor(unscaled_ymin * scale_multiplier / y_scale); }
|
||||
double ymax() const { return ceil(unscaled_ymax * scale_multiplier / y_scale); }
|
||||
double height() const { return ymax() - ymin(); };
|
||||
double advance() const { return floor(unscaled_advance * scale_multiplier / x_scale); };
|
||||
double line_height() const { return floor(unscaled_line_height * scale_multiplier / y_scale); };
|
||||
};
|
||||
|
||||
} //ns mapnik
|
||||
|
|
|
@ -108,7 +108,11 @@ static void shape_text(text_line & line,
|
|||
tmp.format = text_item.format;
|
||||
tmp.scale_multiplier = size / face->get_face()->units_per_EM;
|
||||
//Overwrite default advance with better value provided by HarfBuzz
|
||||
tmp.unscaled_advance = positions[i].x_advance;
|
||||
tmp.unscaled_advance = positions[i].x_advance * tmp.x_scale;
|
||||
|
||||
std::cerr << tmp.line_height() << ' ' <<
|
||||
tmp.advance() << '\n';
|
||||
|
||||
tmp.offset.set(positions[i].x_offset * tmp.scale_multiplier, positions[i].y_offset * tmp.scale_multiplier);
|
||||
width_map[glyphs[i].cluster] += tmp.advance();
|
||||
line.add_glyph(tmp, scale_factor);
|
||||
|
|
|
@ -88,19 +88,16 @@ void font_face::glyph_dimensions(glyph_info & glyph) const
|
|||
FT_Glyph image;
|
||||
if (FT_Get_Glyph(face_->glyph, &image)) return;
|
||||
FT_BBox glyph_bbox;
|
||||
FT_Glyph_Get_CBox(image, ft_glyph_bbox_pixels, &glyph_bbox);
|
||||
FT_Glyph_Get_CBox(image, FT_GLYPH_BBOX_TRUNCATE, &glyph_bbox);
|
||||
FT_Done_Glyph(image);
|
||||
|
||||
glyph.unscaled_ymin = glyph_bbox.yMin;
|
||||
glyph.unscaled_ymax = glyph_bbox.yMax;
|
||||
glyph.x_scale = face_->size->metrics.x_scale;
|
||||
glyph.y_scale = face_->size->metrics.y_scale;
|
||||
|
||||
glyph.unscaled_width = glyph_bbox.xMax - glyph_bbox.xMin;
|
||||
glyph.unscaled_height = glyph_bbox.yMax - glyph_bbox.yMin;
|
||||
glyph.unscaled_advance = face_->glyph->advance.x;
|
||||
|
||||
glyph.unscaled_ascender = face_->size->metrics.ascender;
|
||||
glyph.unscaled_descender = face_->size->metrics.descender;
|
||||
glyph.unscaled_line_height = face_->size->metrics.height;
|
||||
glyph.unscaled_ymin = glyph_bbox.yMin * glyph.y_scale;
|
||||
glyph.unscaled_ymax = glyph_bbox.yMax * glyph.y_scale;
|
||||
glyph.unscaled_advance = face_->glyph->metrics.horiAdvance * glyph.x_scale;
|
||||
glyph.unscaled_line_height = face_->size->metrics.height * glyph.y_scale;
|
||||
|
||||
//TODO: dimension_cache_.insert(std::pair<unsigned, char_info>(c, dim));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue