From e998fb9fbfbd79b476d758238af60f6a4ddff20c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 28 Oct 2018 22:45:53 -0700 Subject: [PATCH] [color] Round extents when scaling --- src/hb-ot-color-cbdt-table.hh | 12 +++++++----- src/hb-ot-color-sbix-table.hh | 12 ++++++------ 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/hb-ot-color-cbdt-table.hh b/src/hb-ot-color-cbdt-table.hh index cacabd075..dab07a206 100644 --- a/src/hb-ot-color-cbdt-table.hh +++ b/src/hb-ot-color-cbdt-table.hh @@ -443,11 +443,13 @@ struct CBDT } } - /* Convert to the font units. */ - extents->x_bearing *= upem / (float) x_ppem; - extents->y_bearing *= upem / (float) y_ppem; - extents->width *= upem / (float) x_ppem; - extents->height *= upem / (float) y_ppem; + /* Convert to font units. */ + double x_scale = upem / (double) x_ppem; + double y_scale = upem / (double) y_ppem; + extents->x_bearing = round (extents->x_bearing * x_scale); + extents->y_bearing = round (extents->y_bearing * y_scale); + extents->width = round (extents->width * x_scale); + extents->height = round (extents->height * y_scale); return true; } diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index fbe48ec02..7bde38a6a 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -252,14 +252,14 @@ struct sbix extents->width = png.IHDR.width; extents->height = png.IHDR.height; - /* Convert to the font units. */ + /* Convert to font units. */ if (strike_ppem) { - unsigned int upem = font->face->upem; - extents->x_bearing *= upem / (float) strike_ppem; - extents->y_bearing *= upem / (float) strike_ppem; - extents->width *= upem / (float) strike_ppem; - extents->height *= upem / (float) strike_ppem; + double scale = font->face->upem / (double) strike_ppem; + extents->x_bearing = round (extents->x_bearing * scale); + extents->y_bearing = round (extents->y_bearing * scale); + extents->width = round (extents->width * scale); + extents->height = round (extents->height * scale); } hb_blob_destroy (blob);