[subset] zero glyf and loca memory before writing so pads are clean. Test just the part of maxp we care about

This commit is contained in:
Rod Sheeter 2018-02-23 17:43:00 -08:00
parent 9bd6d25254
commit 0ac8c0c1e6
3 changed files with 21 additions and 8 deletions

View File

@ -286,7 +286,7 @@ struct glyf
static const int FLAG_Y_SAME = 0x20; static const int FLAG_Y_SAME = 0x20;
if (*end_offset - start_offset < GlyphHeader::static_size) if (*end_offset - start_offset < GlyphHeader::static_size)
return false; return true;
const char *glyph = ((const char *) glyf_table) + start_offset; const char *glyph = ((const char *) glyf_table) + start_offset;
const char * const glyph_end = glyph + (*end_offset - start_offset); const char * const glyph_end = glyph + (*end_offset - start_offset);
@ -313,7 +313,7 @@ struct glyf
while (glyph < glyph_end) while (glyph < glyph_end)
{ {
uint8_t flag = (uint8_t) *glyph; uint8_t flag = (uint8_t) *glyph;
glyph++; i++; glyph++;
unsigned int repeat = 1; unsigned int repeat = 1;
if (flag & FLAG_REPEAT) if (flag & FLAG_REPEAT)
@ -324,7 +324,7 @@ struct glyf
return false; return false;
} }
repeat = ((uint8_t) *glyph) + 1; repeat = ((uint8_t) *glyph) + 1;
glyph++; i++; glyph++;
} }
unsigned int xBytes, yBytes; unsigned int xBytes, yBytes;

View File

@ -230,8 +230,8 @@ _hb_subset_glyf_and_loca (const OT::glyf::accelerator_t &glyf,
return false; return false;
} }
char *glyf_prime_data = (char *) malloc (glyf_prime_size); char *glyf_prime_data = (char *) calloc (1, glyf_prime_size);
char *loca_prime_data = (char *) malloc (loca_prime_size); char *loca_prime_data = (char *) calloc (1, loca_prime_size);
if (unlikely (!_write_glyf_and_loca_prime (plan, glyf, glyf_data, if (unlikely (!_write_glyf_and_loca_prime (plan, glyf, glyf_data,
*use_short_loca, *use_short_loca,
instruction_ranges, instruction_ranges,

View File

@ -31,6 +31,18 @@
/* Unit tests for hb-subset-glyf.h */ /* Unit tests for hb-subset-glyf.h */
static void check_maxp_num_glyphs (hb_face_t *face, uint16_t expected_num_glyphs)
{
hb_blob_t *maxp_blob = hb_face_reference_table (face, HB_TAG ('m','a','x', 'p'));
unsigned int maxp_len;
uint8_t *raw_maxp = (uint8_t *) hb_blob_get_data(maxp_blob, &maxp_len);
uint16_t num_glyphs = (raw_maxp[4] << 8) + raw_maxp[5];
g_assert_cmpuint(expected_num_glyphs, ==, num_glyphs);
hb_blob_destroy (maxp_blob);
}
static void static void
test_subset_glyf (void) test_subset_glyf (void)
{ {
@ -45,7 +57,7 @@ test_subset_glyf (void)
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f')); hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f'));
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a')); hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a'));
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('m','a','x', 'p')); check_maxp_num_glyphs(face_abc_subset, 3);
hb_face_destroy (face_abc_subset); hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc); hb_face_destroy (face_abc);
@ -65,7 +77,7 @@ test_subset_glyf_with_components (void)
hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('g','l','y','f')); hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('g','l','y','f'));
hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('l','o','c', 'a')); hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('l','o','c', 'a'));
hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('m','a','x', 'p')); check_maxp_num_glyphs(face_generated_subset, 4);
hb_face_destroy (face_generated_subset); hb_face_destroy (face_generated_subset);
hb_face_destroy (face_subset); hb_face_destroy (face_subset);
@ -86,6 +98,7 @@ test_subset_glyf_noop (void)
hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('g','l','y','f')); hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('g','l','y','f'));
hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('l','o','c', 'a')); hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('l','o','c', 'a'));
check_maxp_num_glyphs(face_abc_subset, 4);
hb_face_destroy (face_abc_subset); hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc); hb_face_destroy (face_abc);
@ -107,7 +120,7 @@ test_subset_glyf_strip_hints (void)
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a')); hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a'));
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f')); hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f'));
hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('m','a','x', 'p')); check_maxp_num_glyphs(face_abc_subset, 3);
hb_face_destroy (face_abc_subset); hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc); hb_face_destroy (face_abc);