[COLR] Enable COLRv0 support in get_extents()

paint_glyph() supports COLRv0 but this code is never reached because of
the early return if version is not 1. This early return seems to be from
before COLRv0 extents were supported.
pull/4893/head
Khaled Hosny 4 months ago committed by Behdad Esfahbod
parent 4587e08a46
commit 4d1f6e049c
  1. 26
      src/OT/Color/COLR/COLR.hh
  2. BIN
      test/api/fonts/COLRv0.extents.ttf
  3. 33
      test/api/test-extents.c

@ -2058,7 +2058,7 @@ struct delta_set_index_map_subset_plan_t
unsigned outer = (*var_idx) >> 16;
unsigned bit_count = (outer == 0) ? 1 : hb_bit_storage (outer);
outer_bit_count = hb_max (bit_count, outer_bit_count);
unsigned inner = (*var_idx) & 0xFFFF;
bit_count = (inner == 0) ? 1 : hb_bit_storage (inner);
inner_bit_count = hb_max (bit_count, inner_bit_count);
@ -2505,17 +2505,17 @@ struct COLR
bool
get_extents (hb_font_t *font, hb_codepoint_t glyph, hb_glyph_extents_t *extents) const
{
if (version != 1)
return false;
ItemVarStoreInstancer instancer (&(this+varStore),
&(this+varIdxMap),
hb_array (font->coords, font->num_coords));
if (get_clip (glyph, extents, instancer))
if (version == 1)
{
font->scale_glyph_extents (extents);
return true;
ItemVarStoreInstancer instancer (&(this+varStore),
&(this+varIdxMap),
hb_array (font->coords, font->num_coords));
if (get_clip (glyph, extents, instancer))
{
font->scale_glyph_extents (extents);
return true;
}
}
auto *extents_funcs = hb_paint_extents_get_funcs ();
@ -2570,8 +2570,8 @@ struct COLR
bool
paint_glyph (hb_font_t *font, hb_codepoint_t glyph, hb_paint_funcs_t *funcs, void *data, unsigned int palette_index, hb_color_t foreground, bool clip = true) const
{
ItemVarStoreInstancer instancer (&(this+varStore),
&(this+varIdxMap),
ItemVarStoreInstancer instancer (varStore ? &(this+varStore): nullptr,
varIdxMap ? &(this+varIdxMap): nullptr,
hb_array (font->coords, font->num_coords));
hb_paint_context_t c (this, funcs, data, font, palette_index, foreground, instancer);
c.current_glyphs.add (glyph);

Binary file not shown.

@ -28,7 +28,7 @@
static void
test_glyph_extents (void)
test_glyph_extents_color_v1 (void)
{
hb_face_t *face;
hb_font_t *font;
@ -93,12 +93,41 @@ test_glyph_extents (void)
hb_face_destroy (face);
}
static void
test_glyph_extents_color_v0 (void)
{
hb_face_t *face;
hb_font_t *font;
hb_glyph_extents_t extents;
hb_bool_t ret;
/*
* This font contains a COLRv0 glyph with an empty default glyph
* to make sure we are getting extents from the COLRv0 layers.
*/
face = hb_test_open_font_file ("fonts/COLRv0.extents.ttf");
font = hb_font_create (face);
ret = hb_font_get_glyph_extents (font, 13, &extents);
g_assert_true (ret);
g_assert_true (extents.x_bearing == 192 &&
extents.y_bearing == 573 &&
extents.width == 731 &&
extents.height == -758);
hb_font_destroy (font);
hb_face_destroy (face);
}
int
main (int argc, char **argv)
{
hb_test_init (&argc, &argv);
hb_test_add (test_glyph_extents);
hb_test_add (test_glyph_extents_color_v1);
hb_test_add (test_glyph_extents_color_v0);
return hb_test_run();
}

Loading…
Cancel
Save