font: sync underline_strikeout_metrics() with more recent version of font

Sigh, I really need to break out font.c/font.h to a separate
library...
This commit is contained in:
Daniel Eklöf 2019-11-30 15:40:21 +01:00
parent 2d343755ce
commit c85e52c3c3
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 26 additions and 26 deletions

44
font.c
View file

@ -110,36 +110,36 @@ static void
underline_strikeout_metrics(struct font *font) underline_strikeout_metrics(struct font *font)
{ {
FT_Face ft_face = font->face; FT_Face ft_face = font->face;
double x_scale = ft_face->size->metrics.x_scale / 65526.; double y_scale = ft_face->size->metrics.y_scale / 65526.;
double height = ft_face->size->metrics.height / 64; double height = ft_face->size->metrics.height / 64.;
double descent = ft_face->size->metrics.descender / 64; double descent = ft_face->size->metrics.descender / 64.;
LOG_DBG("ft: x-scale: %f, height: %f, descent: %f", LOG_DBG("ft: y-scale: %f, height: %f, descent: %f",
x_scale, height, descent); y_scale, height, descent);
font->underline.position = round(ft_face->underline_position * x_scale / 64.); font->underline.position = ft_face->underline_position * y_scale / 64.;
font->underline.thickness = ceil(ft_face->underline_thickness * x_scale / 64.); font->underline.thickness = ft_face->underline_thickness * y_scale / 64.;
if (font->underline.position == 0.) { if (font->underline.position == 0.) {
font->underline.position = round(descent / 2.); font->underline.position = descent / 2.;
font->underline.thickness = fabs(round(descent / 5.)); font->underline.thickness = descent / 5.;
} }
LOG_DBG("underline: pos=%d, thick=%d", LOG_DBG("underline: pos=%f, thick=%f",
font->underline.position, font->underline.thickness); font->underline.position, font->underline.thickness);
TT_OS2 *os2 = FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); TT_OS2 *os2 = FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2);
if (os2 != NULL) { if (os2 != NULL) {
font->strikeout.position = round(os2->yStrikeoutPosition * x_scale / 64.); font->strikeout.position = os2->yStrikeoutPosition * y_scale / 64.;
font->strikeout.thickness = ceil(os2->yStrikeoutSize * x_scale / 64.); font->strikeout.thickness = os2->yStrikeoutSize * y_scale / 64.;
} }
if (font->strikeout.position == 0.) { if (font->strikeout.position == 0.) {
font->strikeout.position = round(height / 2. + descent); font->strikeout.position = height / 2. + descent;
font->strikeout.thickness = font->underline.thickness; font->strikeout.thickness = font->underline.thickness;
} }
LOG_DBG("strikeout: pos=%d, thick=%d", LOG_DBG("strikeout: pos=%f, thick=%f",
font->strikeout.position, font->strikeout.thickness); font->strikeout.position, font->strikeout.thickness);
} }
#endif #endif
@ -203,17 +203,17 @@ from_font_set(FcPattern *pattern, FcFontSet *fonts, int start_idx,
* requested-pixel-size / actual-pixels-size * requested-pixel-size / actual-pixels-size
*/ */
if (scalable && !outline) { if (scalable && !outline) {
double original_pixel_size; double requested_pixel_size;
if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &original_pixel_size) != FcResultMatch) { if (FcPatternGetDouble(pattern, FC_PIXEL_SIZE, 0, &requested_pixel_size) != FcResultMatch) {
double original_size; double requested_size;
if (FcPatternGetDouble(pattern, FC_SIZE, 0, &original_size) != FcResultMatch) if (FcPatternGetDouble(pattern, FC_SIZE, 0, &requested_size) != FcResultMatch)
original_size = size; requested_size = size;
original_pixel_size = original_size * dpi / 72; requested_pixel_size = requested_size * dpi / 72;
} }
pixel_fixup = original_pixel_size / pixel_size; pixel_fixup = requested_pixel_size / pixel_size;
LOG_DBG("estimated fixup factor to %f (requested pixel size: %f, actual: %f)", LOG_DBG("estimated fixup factor to %f (requested pixel size: %f, actual: %f)",
pixel_fixup, original_pixel_size, pixel_size); pixel_fixup, requested_pixel_size, pixel_size);
} else } else
pixel_fixup = 1.; pixel_fixup = 1.;
} }

8
font.h
View file

@ -47,13 +47,13 @@ struct font {
int max_x_advance; int max_x_advance;
struct { struct {
int position; double position;
int thickness; double thickness;
} underline; } underline;
struct { struct {
int position; double position;
int thickness; double thickness;
} strikeout; } strikeout;
hash_entry_t **cache; hash_entry_t **cache;