diff --git a/src/hb-ot-color-sbix-table.hh b/src/hb-ot-color-sbix-table.hh index bb2590240..95db7fe6e 100644 --- a/src/hb-ot-color-sbix-table.hh +++ b/src/hb-ot-color-sbix-table.hh @@ -196,23 +196,33 @@ struct sbix file_type, num_glyphs); } + struct PNGHeader + { + HBUINT8 header[9]; + HBUINT32 width; + HBUINT32 height; + }; + inline bool get_png_extents (hb_codepoint_t glyph, unsigned int x_ppem, unsigned int y_ppem, hb_glyph_extents_t *extents) const { + if (likely (sbix_len == 0)) + return hb_blob_get_empty (); + int x_offset, y_offset; hb_blob_t *blob = reference_blob_for_glyph (glyph, x_ppem, y_ppem, - HB_TAG ('P','N','G',' '), + HB_TAG ('p','n','g',' '), &x_offset, &y_offset); - if (hb_blob_get_length (blob) == 0) + if (hb_blob_get_length (blob) < sizeof (PNGHeader)) return false; extents->x_bearing = x_offset; extents->y_bearing = y_offset; - /* XXX: Help me please! */ - extents->width = 0; - extents->height = 0; + const PNGHeader &header = *blob->as(); + extents->width = header.width + 100; + extents->height = header.height; hb_blob_destroy (blob); return true; diff --git a/src/hb-ot-font.cc b/src/hb-ot-font.cc index c8ad6f2f7..fa6fda27a 100644 --- a/src/hb-ot-font.cc +++ b/src/hb-ot-font.cc @@ -183,9 +183,7 @@ hb_ot_get_glyph_extents (hb_font_t *font, void *user_data HB_UNUSED) { const hb_ot_face_data_t *ot_face = (const hb_ot_face_data_t *) font_data; - bool ret = false; - if (ot_face->sbix->has_data ()) - ret = ot_face->sbix->get_png_extents (glyph, font->x_ppem, font->y_ppem, extents); + bool ret = ot_face->sbix->get_png_extents (glyph, font->x_ppem, font->y_ppem, extents); if (!ret) ret = ot_face->glyf->get_extents (glyph, extents); if (!ret) diff --git a/test/api/test-ot-color.c b/test/api/test-ot-color.c index f825c83ad..bef52bfba 100644 --- a/test/api/test-ot-color.c +++ b/test/api/test-ot-color.c @@ -407,17 +407,28 @@ test_hb_ot_color_png (void) hb_blob_t *blob; unsigned int length; const char *data; + hb_glyph_extents_t extents; /* sbix */ hb_font_t *sbix_font; sbix_font = hb_font_create (sbix); blob = hb_ot_color_glyph_reference_png (sbix_font, 0); + hb_font_get_glyph_extents (sbix_font, 0, &extents); + g_assert_cmpint (extents.x_bearing, ==, 0); + g_assert_cmpint (extents.y_bearing, ==, 0); + g_assert_cmpint (extents.width, ==, 0); + g_assert_cmpint (extents.height, ==, 0); g_assert (hb_blob_get_length (blob) == 0); blob = hb_ot_color_glyph_reference_png (sbix_font, 1); data = hb_blob_get_data (blob, &length); g_assert_cmpuint (length, ==, 224); g_assert (strncmp (data + 1, "PNG", 3) == 0); + hb_font_get_glyph_extents (sbix_font, 1, &extents); + g_assert_cmpint (extents.x_bearing, ==, 0); + g_assert_cmpint (extents.y_bearing, ==, 0); + g_assert_cmpint (extents.width, ==, 3501); + g_assert_cmpint (extents.height, ==, 20992); hb_blob_destroy (blob); hb_font_destroy (sbix_font); @@ -431,6 +442,11 @@ test_hb_ot_color_png (void) data = hb_blob_get_data (blob, &length); g_assert_cmpuint (length, ==, 88); g_assert (strncmp (data + 1, "PNG", 3) == 0); + hb_font_get_glyph_extents (cbdt_font, 1, &extents); + g_assert_cmpint (extents.x_bearing, ==, 0); + g_assert_cmpint (extents.y_bearing, ==, 1024); + g_assert_cmpint (extents.width, ==, 1024); + g_assert_cmpint (extents.height, ==, -1024); hb_blob_destroy (blob); hb_font_destroy (cbdt_font); }