[ot-color] Implement PNGHeader and test it, it doesn't work however

This commit is contained in:
Ebrahim Byagowi 2018-10-28 23:43:50 +03:30 committed by Behdad Esfahbod
parent 38706a0746
commit 632e9af862
3 changed files with 32 additions and 8 deletions

View File

@ -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<PNGHeader>();
extents->width = header.width + 100;
extents->height = header.height;
hb_blob_destroy (blob);
return true;

View File

@ -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)

View File

@ -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);
}