From 903771b6c7689b9eee9a11bac128c42f39833b2e Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 26 Feb 2018 19:50:06 -0800 Subject: [PATCH] [subset] clearer name for trim() and better comment about composite handling, per review feedback --- src/hb-ot-glyf-table.hh | 8 +++++--- src/hb-subset-glyf.cc | 17 ++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh index 3d0309777..441d4b9ec 100644 --- a/src/hb-ot-glyf-table.hh +++ b/src/hb-ot-glyf-table.hh @@ -276,8 +276,8 @@ struct glyf } /* based on FontTools _g_l_y_f.py::trim */ - inline bool trim(unsigned int start_offset, - unsigned int *end_offset) const + inline bool remove_padding(unsigned int start_offset, + unsigned int *end_offset) const { static const int FLAG_X_SHORT = 0x02; static const int FLAG_Y_SHORT = 0x04; @@ -294,7 +294,9 @@ struct glyf int16_t num_contours = (int16_t) glyph_header.numberOfContours; if (num_contours < 0) - return true; /* no trimming for composites just yet */ + /* Trimming for composites not implemented. + * If removing hints it falls out of that. */ + return true; else if (num_contours > 0) { unsigned int glyph_len = *end_offset - start_offset; diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc index a97e1b76a..696a74de1 100644 --- a/src/hb-subset-glyf.cc +++ b/src/hb-subset-glyf.cc @@ -43,12 +43,14 @@ _calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf, for (unsigned int i = 0; i < glyph_ids.len; i++) { hb_codepoint_t next_glyph = glyph_ids[i]; - *(instruction_ranges->push()) = 0; - *(instruction_ranges->push()) = 0; + unsigned int *instruction_start = instruction_ranges->push(); + unsigned int *instruction_end = instruction_ranges->push(); + *instruction_start = 0; + *instruction_end = 0; unsigned int start_offset, end_offset; if (unlikely (!(glyf.get_offsets(next_glyph, &start_offset, &end_offset) - && glyf.trim(start_offset, &end_offset)))) + && glyf.remove_padding(start_offset, &end_offset)))) { DEBUG_MSG(SUBSET, nullptr, "Invalid gid %d", next_glyph); continue; @@ -56,20 +58,17 @@ _calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf, if (end_offset - start_offset < OT::glyf::GlyphHeader::static_size) continue; /* 0-length glyph */ - unsigned int instruction_start = 0, instruction_end = 0; if (drop_hints) { if (unlikely (!glyf.get_instruction_offsets(start_offset, end_offset, - &instruction_start, &instruction_end))) + instruction_start, instruction_end))) { DEBUG_MSG(SUBSET, nullptr, "Unable to get instruction offsets for %d", next_glyph); return false; } - instruction_ranges->array[i * 2] = instruction_start; - instruction_ranges->array[i * 2 + 1] = instruction_end; } - total += end_offset - start_offset - (instruction_end - instruction_start); + total += end_offset - start_offset - (*instruction_end - *instruction_start); /* round2 so short loca will work */ total += total % 2; } @@ -156,7 +155,7 @@ _write_glyf_and_loca_prime (hb_subset_plan_t *plan, { unsigned int start_offset, end_offset; if (unlikely (!(glyf.get_offsets (glyph_ids[i], &start_offset, &end_offset) - && glyf.trim(start_offset, &end_offset)))) + && glyf.remove_padding(start_offset, &end_offset)))) end_offset = start_offset = 0; unsigned int instruction_start = instruction_ranges[i * 2]; unsigned int instruction_end = instruction_ranges[i * 2 + 1];