From 16b232be0ed2c8486a9f30523f989e77dd8d13f2 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Fri, 18 Feb 2022 18:05:58 -0600 Subject: [PATCH] [hb-style] Fix the sign of slant ratios We want negative slant angles to yield positive slant ratios. Fix that. Test included. --- src/hb-style.cc | 4 ++-- src/hb-style.h | 4 +++- test/api/test-style.c | 12 ++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/hb-style.cc b/src/hb-style.cc index ee2ffc497..c48e3aa3c 100644 --- a/src/hb-style.cc +++ b/src/hb-style.cc @@ -46,13 +46,13 @@ static inline float _hb_angle_to_ratio (float a) { - return tanf (a * float (M_PI / 180.)); + return - tanf (a * float (M_PI / 180.)); } static inline float _hb_ratio_to_angle (float r) { - return atanf (r) * float (180. / M_PI); + return - atanf (r) * float (180. / M_PI); } /** diff --git a/src/hb-style.h b/src/hb-style.h index 30a6f2b87..d17d2daa5 100644 --- a/src/hb-style.h +++ b/src/hb-style.h @@ -43,8 +43,10 @@ HB_BEGIN_DECLS * @HB_STYLE_TAG_SLANT_ANGLE: Used to vary between upright and slanted text. Values * must be greater than -90 and less than +90. Values can be interpreted as * the angle, in counter-clockwise degrees, of oblique slant from whatever the - * designer considers to be upright for that font design. + * designer considers to be upright for that font design. Typical right-leaning + * Italic fonts have a negative slant angle (typically around -12) * @HB_STYLE_TAG_SLANT_RATIO: same as @HB_STYLE_TAG_SLANT_ANGLE expression as ratio. + * Typical right-leaning Italic fonts have a positive slant ratio (typically around 0.2) * @HB_STYLE_TAG_WIDTH: Used to vary width of text from narrower to wider. * Non-zero. Values can be interpreted as a percentage of whatever the font * designer considers “normal width” for that font design. diff --git a/test/api/test-style.c b/test/api/test-style.c index b4f91ea36..27b135f99 100644 --- a/test/api/test-style.c +++ b/test/api/test-style.c @@ -161,6 +161,18 @@ test_synthetic_slant (void) hb_font_destroy (font); hb_face_destroy (face); + + face = hb_test_open_font_file ("fonts/notosansitalic.ttf"); + font = hb_font_create (face); + + /* We expect a negative angle for a typical italic font, + * which should give us a positive ratio + */ + assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_ANGLE), -12); + assert_cmpfloat (hb_style_get_value (font, HB_STYLE_TAG_SLANT_RATIO), 0.21); + + hb_font_destroy (font); + hb_face_destroy (face); } int