Simplify font_units_to_pixels

Make use of the precalculated scaling value in the FT Face metrics
object
This commit is contained in:
Kovid Goyal 2017-11-10 17:23:28 +05:30
parent 579933ac27
commit c6fa0503af
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -227,7 +227,7 @@ calc_cell_width(Face *self) {
static inline int
font_units_to_pixels(Face *self, int x) {
return (int)ceilf(((float)x * (((float)self->size_in_pts * (float)self->ydpi) / (72.f * (float)self->units_per_EM))));
return ceil((double)FT_MulFix(x, self->face->size->metrics.y_scale) / 64.0);
}
void
@ -236,7 +236,7 @@ cell_metrics(PyObject *s, unsigned int* cell_width, unsigned int* cell_height, u
*cell_width = calc_cell_width(self);
*cell_height = font_units_to_pixels(self, self->height);
*baseline = font_units_to_pixels(self, self->ascender);
*underline_position = MIN(*cell_height - 1, *baseline - font_units_to_pixels(self, self->underline_position));
*underline_position = MIN(*cell_height - 1, (unsigned int)font_units_to_pixels(self, MAX(0, self->ascender - self->underline_position)));
*underline_thickness = font_units_to_pixels(self, self->underline_thickness);
}