[subset] when dropping hints, clear hint related fields in maxp.

This commit is contained in:
Garret Rieger 2018-02-27 13:49:00 -08:00
parent d7633d0a40
commit f14d1b64c2
2 changed files with 63 additions and 10 deletions

View File

@ -57,7 +57,7 @@ struct maxp
{
TRACE_SANITIZE (this);
return_trace (c->check_struct (this) &&
likely (version.major == 1 ||
likely ((version.major == 1 && c->check_range (this, sizeof (maxp))) ||
(version.major == 0 && version.minor == 0x5000u)));
}
@ -73,19 +73,56 @@ struct maxp
OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data (maxp_prime_blob, nullptr);
maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len);
if (plan->drop_hints)
drop_hint_fields (plan, maxp_prime);
bool result = hb_subset_plan_add_table(plan, HB_OT_TAG_maxp, maxp_prime_blob);
hb_blob_destroy (maxp_prime_blob);
return result;
}
/* We only implement version 0.5 as none of the extra fields in version 1.0 are useful. */
static inline void drop_hint_fields (hb_subset_plan_t *plan, OT::maxp *maxp_prime)
{
if (maxp_prime->version.major == 1)
{
maxp_prime->version_1_data.maxZones.set (1);
maxp_prime->version_1_data.maxTwilightPoints.set (0);
maxp_prime->version_1_data.maxStorage.set (0);
maxp_prime->version_1_data.maxFunctionDefs.set (0);
maxp_prime->version_1_data.maxInstructionDefs.set (0);
maxp_prime->version_1_data.maxStackElements.set (0);
maxp_prime->version_1_data.maxSizeOfInstructions.set (0);
}
}
protected:
FixedVersion<>version; /* Version of the maxp table (0.5 or 1.0),
* 0x00005000u or 0x00010000u. */
HBUINT16 numGlyphs; /* The number of glyphs in the font. */
struct
{
HBUINT16 maxPoints; /* Maximum points in a non-composite glyph. */
HBUINT16 maxContours; /* Maximum contours in a non-composite glyph. */
HBUINT16 maxCompositePoints; /* Maximum points in a composite glyph. */
HBUINT16 maxCompositeContours; /* Maximum contours in a composite glyph. */
HBUINT16 maxZones; /* 1 if instructions do not use the twilight zone (Z0),
or 2 if instructions do use Z0; should be set to 2 in
most cases. */
HBUINT16 maxTwilightPoints; /* Maximum points used in Z0. */
HBUINT16 maxStorage; /* Number of Storage Area locations. */
HBUINT16 maxFunctionDefs; /* Number of FDEFs, equal to the highest function number + 1. */
HBUINT16 maxInstructionDefs; /* Number of IDEFs. */
HBUINT16 maxStackElements; /* Maximum stack depth. (This includes Font and CVT
Programs, as well as the instructions for each glyph.) */
HBUINT16 maxSizeOfInstructions; /* Maximum byte count for glyph instructions. */
HBUINT16 maxComponentElements; /* Maximum number of components referenced at
"top level" for any composite glyph. */
HBUINT16 maxComponentDepth; /* Maximum levels of recursion; 1 for simple components. */
} version_1_data;
public:
DEFINE_SIZE_STATIC (6);
DEFINE_SIZE_MIN (6);
};

View File

@ -31,14 +31,30 @@
/* Unit tests for hb-subset-glyf.h */
static void check_maxp_num_glyphs (hb_face_t *face, uint16_t expected_num_glyphs)
static void check_maxp_field (uint8_t *raw_maxp, unsigned int offset, uint16_t expected_value)
{
uint16_t actual_value = (raw_maxp[offset] << 8) + raw_maxp[offset + 1];
g_assert_cmpuint(expected_value, ==, actual_value);
}
static void check_maxp_num_glyphs (hb_face_t *face, uint16_t expected_num_glyphs, bool hints)
{
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);
check_maxp_field (raw_maxp, 4, expected_num_glyphs); // numGlyphs
if (!hints)
{
check_maxp_field (raw_maxp, 14, 1); // maxZones
check_maxp_field (raw_maxp, 16, 0); // maxTwilightPoints
check_maxp_field (raw_maxp, 18, 0); // maxStorage
check_maxp_field (raw_maxp, 20, 0); // maxFunctionDefs
check_maxp_field (raw_maxp, 22, 0); // maxInstructionDefs
check_maxp_field (raw_maxp, 24, 0); // maxStackElements
check_maxp_field (raw_maxp, 26, 0); // maxSizeOfInstructions
}
hb_blob_destroy (maxp_blob);
}
@ -57,7 +73,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 ('l','o','c', 'a'));
check_maxp_num_glyphs(face_abc_subset, 3);
check_maxp_num_glyphs(face_abc_subset, 3, true);
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);
@ -77,7 +93,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 ('l','o','c', 'a'));
check_maxp_num_glyphs(face_generated_subset, 4);
check_maxp_num_glyphs(face_generated_subset, 4, true);
hb_face_destroy (face_generated_subset);
hb_face_destroy (face_subset);
@ -98,7 +114,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 ('l','o','c', 'a'));
check_maxp_num_glyphs(face_abc_subset, 4);
check_maxp_num_glyphs(face_abc_subset, 4, true);
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);
@ -120,7 +136,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 ('g','l','y','f'));
check_maxp_num_glyphs(face_abc_subset, 3);
check_maxp_num_glyphs(face_abc_subset, 3, false);
hb_face_destroy (face_abc_subset);
hb_face_destroy (face_abc);