From c13ef9cc64a447e74abfed75f4f418bf644be88d Mon Sep 17 00:00:00 2001 From: Ebrahim Byagowi Date: Sat, 20 Jul 2019 15:01:37 +0430 Subject: [PATCH] Bring back asc/desc abs logic used to be in hmtx table --- src/hb-ot-metrics.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hb-ot-metrics.cc b/src/hb-ot-metrics.cc index 249f0594c..8b98511ee 100644 --- a/src/hb-ot-metrics.cc +++ b/src/hb-ot-metrics.cc @@ -32,6 +32,19 @@ #include "hb-ot-metrics.hh" #include "hb-ot-face.hh" + +static float +_fix_ascender_descender (float value, hb_ot_metrics_t metrics_tag) +{ + if (metrics_tag == HB_OT_METRICS_HORIZONTAL_ASCENDER || + metrics_tag == HB_OT_METRICS_VERTICAL_ASCENDER) + return fabs ((double) value); + if (metrics_tag == HB_OT_METRICS_HORIZONTAL_DESCENDER || + metrics_tag == HB_OT_METRICS_VERTICAL_DESCENDER) + return -fabs ((double) value); + return value; +} + /* Common part of _get_position logic needed on hb-ot-font so we can have a slim builds using HB_NO_METRICS */ bool @@ -45,14 +58,16 @@ hb_ot_metrics_get_position_common (hb_font_t *font, #ifndef HB_NO_VAR #define GET_VAR hb_ot_metrics_get_variation (face, metrics_tag) #else -#define GET_VAR 0 +#define GET_VAR .0f #endif #define GET_METRIC_X(TABLE, ATTR) \ (face->table.TABLE->has_data () && \ - (position && (*position = font->em_scalef_x (face->table.TABLE->ATTR + GET_VAR)), true)) + (position && (*position = font->em_scalef_x (_fix_ascender_descender ( \ + face->table.TABLE->ATTR + GET_VAR, metrics_tag))), true)) #define GET_METRIC_Y(TABLE, ATTR) \ (face->table.TABLE->has_data () && \ - (position && (*position = font->em_scalef_y (face->table.TABLE->ATTR + GET_VAR)), true)) + (position && (*position = font->em_scalef_y (_fix_ascender_descender ( \ + face->table.TABLE->ATTR + GET_VAR, metrics_tag))), true)) case HB_OT_METRICS_HORIZONTAL_ASCENDER: return (!face->table.OS2->use_typo_metrics () && GET_METRIC_Y (hhea, ascender)) || GET_METRIC_Y (OS2, sTypoAscender);