[ot-metrics] Don't use mixed scaled and not scaled for generating extents
diff --git a/src/hb-ot-cff1-table.cc b/src/hb-ot-cff1-table.cc
index 54bfe5d..d1e4625 100644
--- a/src/hb-ot-cff1-table.cc
+++ b/src/hb-ot-cff1-table.cc
@@ -326,7 +326,7 @@
   else
   {
     extents->x_bearing = font->em_scalef_x (bounds.min.x.to_real ());
-    extents->width = font->em_scalef_x (bounds.max.x.to_real () - extents->x_bearing);
+    extents->width = font->em_scalef_x (bounds.max.x.to_real () - bounds.min.x.to_real ());
   }
   if (bounds.min.y >= bounds.max.y)
   {
@@ -336,7 +336,7 @@
   else
   {
     extents->y_bearing = font->em_scalef_y (bounds.max.y.to_real ());
-    extents->height = font->em_scalef_x (bounds.min.y.to_real () - extents->y_bearing);
+    extents->height = font->em_scalef_x (bounds.min.y.to_real () - bounds.max.y.to_real ());
   }
 
   return true;
diff --git a/src/hb-ot-cff2-table.cc b/src/hb-ot-cff2-table.cc
index e69070e..a2242b7 100644
--- a/src/hb-ot-cff2-table.cc
+++ b/src/hb-ot-cff2-table.cc
@@ -126,7 +126,7 @@
   else
   {
     extents->x_bearing = font->em_scalef_x (param.min_x.to_real ());
-    extents->width = font->em_scalef_x (param.max_x.to_real () - extents->x_bearing);
+    extents->width = font->em_scalef_x (param.max_x.to_real () - param.min_x.to_real ());
   }
   if (param.min_y >= param.max_y)
   {
@@ -136,7 +136,7 @@
   else
   {
     extents->y_bearing = font->em_scalef_y (param.max_y.to_real ());
-    extents->height = font->em_scalef_y (param.min_y.to_real () - extents->y_bearing);
+    extents->height = font->em_scalef_y (param.min_y.to_real () - param.max_y.to_real ());
   }
 
   return true;
diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh
index 6008e7e..35d3fd5 100644
--- a/src/hb-ot-color-sbix-table.hh
+++ b/src/hb-ot-color-sbix-table.hh
@@ -248,6 +248,13 @@
 	extents->width = font->em_scalef_x (extents->width * scale);
 	extents->height = font->em_scalef_y (extents->height * scale);
       }
+      else
+      {
+	extents->x_bearing = font->em_scale_x (extents->x_bearing);
+	extents->y_bearing = font->em_scale_y (extents->y_bearing);
+	extents->width = font->em_scale_x (extents->width);
+	extents->height = font->em_scale_y (extents->height);
+      }
 
       hb_blob_destroy (blob);
 
diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh
index 9cb1a26..cd350f5 100644
--- a/src/hb-ot-glyf-table.hh
+++ b/src/hb-ot-glyf-table.hh
@@ -888,7 +888,7 @@
 	else
 	{
 	  extents->x_bearing = font->em_scalef_x (bounds.min.x);
-	  extents->width = font->em_scalef_x (bounds.max.x) - extents->x_bearing;
+	  extents->width = font->em_scalef_x (bounds.max.x - bounds.min.x);
 	}
 	if (bounds.min.y > bounds.max.y)
 	{
@@ -898,7 +898,7 @@
 	else
 	{
 	  extents->y_bearing = font->em_scalef_y (bounds.max.y);
-	  extents->height = font->em_scalef_y (bounds.min.y) - extents->y_bearing;
+	  extents->height = font->em_scalef_y (bounds.min.y - bounds.max.y);
 	}
       }
       if (phantoms)
@@ -970,7 +970,7 @@
       extents->x_bearing = font->em_scale_x (face->table.hmtx->get_side_bearing (glyph));
       extents->y_bearing = font->em_scale_y (hb_max (glyph_header.yMin, glyph_header.yMax));
       extents->width     = font->em_scale_x (hb_max (glyph_header.xMin, glyph_header.xMax) - hb_min (glyph_header.xMin, glyph_header.xMax));
-      extents->height    = font->em_scale_y (hb_min (glyph_header.yMin, glyph_header.yMax) - extents->y_bearing);
+      extents->height    = font->em_scale_y (hb_min (glyph_header.yMin, glyph_header.yMax) - hb_max (glyph_header.yMin, glyph_header.yMax));
 
       return true;
     }
diff --git a/test/api/test-ot-extents-cff.c b/test/api/test-ot-extents-cff.c
index e6aeb0d..7109e30 100644
--- a/test/api/test-ot-extents-cff.c
+++ b/test/api/test-ot-extents-cff.c
@@ -170,7 +170,7 @@
 
   g_assert_cmpint (extents.x_bearing, ==, 12);
   g_assert_cmpint (extents.y_bearing, ==, 655);
-  g_assert_cmpint (extents.width, ==, 651);
+  g_assert_cmpint (extents.width, ==, 652);
   g_assert_cmpint (extents.height, ==, -655);
 
   result = hb_font_get_glyph_extents (font, 2, &extents);
@@ -178,7 +178,7 @@
 
   g_assert_cmpint (extents.x_bearing, ==, 8);
   g_assert_cmpint (extents.y_bearing, ==, 669);
-  g_assert_cmpint (extents.width, ==, 648);
+  g_assert_cmpint (extents.width, ==, 649);
   g_assert_cmpint (extents.height, ==, -669);
 
   hb_font_destroy (font);
@@ -201,7 +201,7 @@
 
   g_assert_cmpint (extents.x_bearing, ==, 13);
   g_assert_cmpint (extents.y_bearing, ==, 652);
-  g_assert_cmpint (extents.width, ==, 652);
+  g_assert_cmpint (extents.width, ==, 653);
   g_assert_cmpint (extents.height, ==, -652);
 
   result = hb_font_get_glyph_extents (font, 2, &extents);