From 06f9495ae2371929f9ffdf962c491ec27486bdbc Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 16 Jul 2019 15:08:02 +0200 Subject: render: implement strikeout --- main.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'main.c') diff --git a/main.c b/main.c index 992b1650..1f057812 100644 --- a/main.c +++ b/main.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -376,11 +377,16 @@ main(int argc, char *const *argv) FT_Face ft_face = cairo_ft_scaled_font_lock_face(f->font); double x_scale = ft_face->size->metrics.x_scale / 65526.; + double height = ft_face->size->metrics.height / 64; + double descent = ft_face->size->metrics.descender / 64; + + LOG_DBG("ft: x-scale: %f, height: %f, descent: %f", + x_scale, height, descent); + f->underline.position = ft_face->underline_position * x_scale / 64.; f->underline.thickness = ft_face->underline_thickness * x_scale / 64.; if (f->underline.position == 0.) { - double descent = ft_face->size->metrics.descender / 64; f->underline.position = descent / 2.; f->underline.thickness = fabs(round(descent / 5.)); } @@ -388,7 +394,24 @@ main(int argc, char *const *argv) LOG_DBG("underline: pos=%f, thick=%f", f->underline.position, f->underline.thickness); + TT_OS2 *os2 = FT_Get_Sfnt_Table(ft_face, ft_sfnt_os2); + if (os2 != NULL) { + f->strikeout.position = os2->yStrikeoutPosition * x_scale / 64.; + f->strikeout.thickness = os2->yStrikeoutSize * x_scale / 64.; + } + + if (f->strikeout.position == 0.) { + assert(false); + /* TODO: fixme */ + f->strikeout.position = height / 2. + descent; + f->strikeout.thickness = f->underline.thickness; + } + + LOG_DBG("strikeout: pos=%f, thick=%f", + f->strikeout.position, f->strikeout.thickness); + cairo_ft_scaled_font_unlock_face(f->font); + } cairo_scaled_font_extents(term.fonts[0].font, &term.fextents); -- cgit v1.3