diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index 901e23400..d1a4ee3e3 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -2421,9 +2421,11 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, &embox_bottom); if (baseline_tag == HB_OT_LAYOUT_BASELINE_TAG_IDEO_FACE_TOP_OR_RIGHT) - *coord = embox_top + (embox_bottom - embox_top) / 10; + *coord = hb_saturate_add (embox_top, + hb_clamp_to (((int64_t) embox_bottom - embox_top) / 10)); else - *coord = embox_bottom + (embox_top - embox_bottom) / 10; + *coord = hb_saturate_add (embox_bottom, + hb_clamp_to (((int64_t) embox_top - embox_bottom) / 10)); } break; @@ -2434,7 +2436,8 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, script_tag, language_tag, coord)) - *coord += HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale; + *coord = hb_saturate_add (*coord, + HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale); else { hb_font_extents_t font_extents; @@ -2450,7 +2453,8 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, script_tag, language_tag, coord)) - *coord -= HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale; + *coord = hb_saturate_sub (*coord, + HB_DIRECTION_IS_HORIZONTAL (direction) ? font->y_scale : font->x_scale); else { hb_font_extents_t font_extents; @@ -2510,10 +2514,10 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, hb_font_get_glyph_extents (font, glyph, &extents)) *coord = extents.y_bearing; else - *coord = font->y_scale * 6 / 10; // FIXME makes assumptions about origin + *coord = hb_clamp_to ((int64_t) font->y_scale * 6 / 10); // FIXME makes assumptions about origin } else - *coord = font->x_scale * 6 / 10; // FIXME makes assumptions about origin + *coord = hb_clamp_to ((int64_t) font->x_scale * 6 / 10); // FIXME makes assumptions about origin break; case HB_OT_LAYOUT_BASELINE_TAG_IDEO_EMBOX_CENTRAL: @@ -2531,7 +2535,7 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, script_tag, language_tag, &bottom); - *coord = (top + bottom) / 2; + *coord = hb_clamp_to (((int64_t) top + bottom) / 2); } break; @@ -2551,7 +2555,7 @@ hb_ot_layout_get_baseline_with_fallback (hb_font_t *font, script_tag, language_tag, &bottom); - *coord = (top + bottom) / 2; + *coord = hb_clamp_to (((int64_t) top + bottom) / 2); } break;