From 0f159a38a62bbf1b7fb267694a5d91d8135da625 Mon Sep 17 00:00:00 2001 From: Michiharu Ariza Date: Wed, 12 Sep 2018 16:08:54 -0700 Subject: [PATCH] fixed serialize_fdselect_3_4 --- src/hb-ot-cff-common.hh | 6 ++++ src/hb-ot-cff1-table.hh | 6 ---- src/hb-subset-cff-common.cc | 68 ++++++++++++++++++++++--------------- src/hb-subset-cff-common.hh | 10 +++--- src/hb-subset-cff1.cc | 12 +++---- src/hb-subset-cff2.cc | 12 +++---- 6 files changed, 63 insertions(+), 51 deletions(-) diff --git a/src/hb-ot-cff-common.hh b/src/hb-ot-cff-common.hh index 87ca69d69..3bebf3bfa 100644 --- a/src/hb-ot-cff-common.hh +++ b/src/hb-ot-cff-common.hh @@ -55,6 +55,12 @@ inline unsigned int calcOffSize(unsigned int dataSize) return size; } +struct code_pair +{ + hb_codepoint_t code; + hb_codepoint_t glyph; +}; + /* CFF INDEX */ template struct CFFIndex diff --git a/src/hb-ot-cff1-table.hh b/src/hb-ot-cff1-table.hh index 66e547531..22a447f98 100644 --- a/src/hb-ot-cff1-table.hh +++ b/src/hb-ot-cff1-table.hh @@ -158,12 +158,6 @@ struct CFF1SuppEncData { DEFINE_SIZE_ARRAY (1, supps); }; -struct code_pair -{ - hb_codepoint_t code; - hb_codepoint_t glyph; -}; - struct Encoding { inline bool sanitize (hb_sanitize_context_t *c) const { diff --git a/src/hb-subset-cff-common.cc b/src/hb-subset-cff-common.cc index c62f83a7b..fe18510c9 100644 --- a/src/hb-subset-cff-common.cc +++ b/src/hb-subset-cff-common.cc @@ -43,14 +43,14 @@ hb_plan_subset_cff_fdselect (const hb_vector_t &glyphs, unsigned int fdCount, const FDSelect &src, /* IN */ unsigned int &subset_fd_count /* OUT */, - unsigned int &subst_fdselect_size /* OUT */, - unsigned int &subst_fdselect_format /* OUT */, - hb_vector_t &subst_first_glyphs /* OUT */, + unsigned int &subset_fdselect_size /* OUT */, + unsigned int &subset_fdselect_format /* OUT */, + hb_vector_t &fdselect_ranges /* OUT */, Remap &fdmap /* OUT */) { subset_fd_count = 0; - subst_fdselect_size = 0; - subst_fdselect_format = 0; + subset_fdselect_size = 0; + subset_fdselect_format = 0; unsigned int num_ranges = 0; unsigned int subset_num_glyphs = glyphs.len; @@ -72,7 +72,8 @@ hb_plan_subset_cff_fdselect (const hb_vector_t &glyphs, { num_ranges++; prev_fd = fd; - subst_first_glyphs.push (i); + code_pair pair = { fd, i }; + fdselect_ranges.push (pair); } } @@ -96,14 +97,18 @@ hb_plan_subset_cff_fdselect (const hb_vector_t &glyphs, fdmap.add (fd); assert (fdmap.get_count () == subset_fd_count); hb_set_destroy (set); + + /* update each font dict index stored as "code" in fdselect_ranges */ + for (unsigned int i = 0; i < fdselect_ranges.len; i++) + fdselect_ranges[i].code = fdmap[fdselect_ranges[i].code]; } /* determine which FDSelect format is most compact */ if (subset_fd_count > 0xFF) { assert (src.format == 4); - subst_fdselect_format = 4; - subst_fdselect_size = FDSelect4::min_size + FDSelect4_Range::static_size * num_ranges; + subset_fdselect_format = 4; + subset_fdselect_size = FDSelect4::min_size + FDSelect4_Range::static_size * num_ranges; } else { @@ -112,14 +117,13 @@ hb_plan_subset_cff_fdselect (const hb_vector_t &glyphs, if (format0_size <= format3_size) { - // subst_fdselect_format = 0; - subst_fdselect_size = format0_size; - subst_first_glyphs.fini (); + // subset_fdselect_format = 0; + subset_fdselect_size = format0_size; } else { - subst_fdselect_format = 3; - subst_fdselect_size = format3_size; + subset_fdselect_format = 3; + subset_fdselect_size = format3_size; } } @@ -129,21 +133,20 @@ hb_plan_subset_cff_fdselect (const hb_vector_t &glyphs, template static inline bool serialize_fdselect_3_4 (hb_serialize_context_t *c, - unsigned int num_glyphs, + const unsigned int num_glyphs, const FDSelect &src, unsigned int size, - const hb_vector_t &first_glyphs, + const hb_vector_t &fdselect_ranges, const Remap &fdmap) { TRACE_SERIALIZE (this); FDSELECT3_4 *p = c->allocate_size (size); if (unlikely (p == nullptr)) return_trace (false); - p->nRanges.set (first_glyphs.len); - for (unsigned int i = 0; i < first_glyphs.len; i++) + p->nRanges.set (fdselect_ranges.len); + for (unsigned int i = 0; i < fdselect_ranges.len; i++) { - hb_codepoint_t glyph = first_glyphs[i]; - p->ranges[i].first.set (glyph); - p->ranges[i].fd.set (fdmap[src.get_fd (glyph)]); + p->ranges[i].first.set (fdselect_ranges[i].glyph); + p->ranges[i].fd.set (fdselect_ranges[i].code); } p->sentinel().set (num_glyphs); return_trace (true); @@ -155,12 +158,12 @@ serialize_fdselect_3_4 (hb_serialize_context_t *c, **/ bool hb_serialize_cff_fdselect (hb_serialize_context_t *c, - const hb_vector_t &glyphs, + const unsigned int num_glyphs, const FDSelect &src, unsigned int fd_count, unsigned int fdselect_format, unsigned int size, - const hb_vector_t &first_glyphs, + const hb_vector_t &fdselect_ranges, const Remap &fdmap) { TRACE_SERIALIZE (this); @@ -175,25 +178,34 @@ hb_serialize_cff_fdselect (hb_serialize_context_t *c, { FDSelect0 *p = c->allocate_size (size); if (unlikely (p == nullptr)) return_trace (false); - for (unsigned int i = 0; i < glyphs.len; i++) - p->fds[i].set (fdmap[src.get_fd (glyphs[i])]); + unsigned int range_index = 0; + unsigned int fd = fdselect_ranges[range_index].code; + for (unsigned int i = 0; i < num_glyphs; i++) + { + if ((range_index < fdselect_ranges.len) && + (i >= fdselect_ranges[range_index + 1].glyph)) + { + fd = fdselect_ranges[++range_index].code; + } + p->fds[i].set (fd); + } break; } case 3: return serialize_fdselect_3_4 (c, - glyphs.len, + num_glyphs, src, size, - first_glyphs, + fdselect_ranges, fdmap); case 4: return serialize_fdselect_3_4 (c, - glyphs.len, + num_glyphs, src, size, - first_glyphs, + fdselect_ranges, fdmap); default: diff --git a/src/hb-subset-cff-common.hh b/src/hb-subset-cff-common.hh index 6c2b2a2d3..7d9340010 100644 --- a/src/hb-subset-cff-common.hh +++ b/src/hb-subset-cff-common.hh @@ -291,19 +291,19 @@ hb_plan_subset_cff_fdselect (const hb_vector_t &glyphs, unsigned int fdCount, const CFF::FDSelect &src, /* IN */ unsigned int &subset_fd_count /* OUT */, - unsigned int &subst_fdselect_size /* OUT */, - unsigned int &subst_fdselect_format /* OUT */, - hb_vector_t &subst_first_glyphs /* OUT */, + unsigned int &subset_fdselect_size /* OUT */, + unsigned int &subset_fdselect_format /* OUT */, + hb_vector_t &fdselect_ranges /* OUT */, CFF::Remap &fdmap /* OUT */); HB_INTERNAL bool hb_serialize_cff_fdselect (hb_serialize_context_t *c, - const hb_vector_t &glyphs, + unsigned int num_glyphs, const CFF::FDSelect &src, unsigned int fd_count, unsigned int fdselect_format, unsigned int size, - const hb_vector_t &first_glyphs, + const hb_vector_t &fdselect_ranges, const CFF::Remap &fdmap); #endif /* HB_SUBSET_CFF_COMMON_HH */ diff --git a/src/hb-subset-cff1.cc b/src/hb-subset-cff1.cc index 62f81d8f0..2f3d691ad 100644 --- a/src/hb-subset-cff1.cc +++ b/src/hb-subset-cff1.cc @@ -348,7 +348,7 @@ struct cff_subset_plan { topdict_sizes.init (); topdict_sizes.resize (1); topdict_mod.init (); - subset_fdselect_first_glyphs.init (); + subset_fdselect_ranges.init (); fdmap.init (); subset_charstrings.init (); flat_charstrings.init (); @@ -365,7 +365,7 @@ struct cff_subset_plan { { topdict_sizes.fini (); topdict_mod.fini (); - subset_fdselect_first_glyphs.fini (); + subset_fdselect_ranges.fini (); fdmap.fini (); subset_charstrings.fini (); flat_charstrings.fini (); @@ -566,7 +566,7 @@ struct cff_subset_plan { subset_fdcount, offsets.FDSelectInfo.size, subset_fdselect_format, - subset_fdselect_first_glyphs, + subset_fdselect_ranges, fdmap))) return false; @@ -685,7 +685,7 @@ struct cff_subset_plan { unsigned int subset_fdcount; inline bool is_fds_subsetted (void) const { return subset_fdcount < orig_fdcount; } unsigned int subset_fdselect_format; - hb_vector_t subset_fdselect_first_glyphs; + hb_vector_t subset_fdselect_ranges; /* font dict index remap table from fullset FDArray to subset FDArray. * set to CFF_UNDEF_CODE if excluded from subset */ @@ -823,9 +823,9 @@ static inline bool _write_cff1 (const cff_subset_plan &plan, if (plan.is_fds_subsetted ()) { - if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs, *acc.fdSelect, acc.fdCount, + if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *acc.fdSelect, acc.fdCount, plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size, - plan.subset_fdselect_first_glyphs, + plan.subset_fdselect_ranges, plan.fdmap))) { DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF subset FDSelect"); diff --git a/src/hb-subset-cff2.cc b/src/hb-subset-cff2.cc index 15d2c571f..a58ca6aea 100644 --- a/src/hb-subset-cff2.cc +++ b/src/hb-subset-cff2.cc @@ -176,7 +176,7 @@ struct cff2_subset_plan { subset_fdselect_format (0), drop_hints (false) { - subset_fdselect_first_glyphs.init (); + subset_fdselect_ranges.init (); fdmap.init (); subset_charstrings.init (); flat_charstrings.init (); @@ -185,7 +185,7 @@ struct cff2_subset_plan { inline ~cff2_subset_plan (void) { - subset_fdselect_first_glyphs.fini (); + subset_fdselect_ranges.fini (); fdmap.fini (); subset_charstrings.fini (); flat_charstrings.fini (); @@ -242,7 +242,7 @@ struct cff2_subset_plan { subset_fdcount, offsets.FDSelectInfo.size, subset_fdselect_format, - subset_fdselect_first_glyphs, + subset_fdselect_ranges, fdmap))) return false; @@ -300,7 +300,7 @@ struct cff2_subset_plan { unsigned int subset_fdcount; inline bool is_fds_subsetted (void) const { return subset_fdcount < orig_fdcount; } unsigned int subset_fdselect_format; - hb_vector_t subset_fdselect_first_glyphs; + hb_vector_t subset_fdselect_ranges; Remap fdmap; @@ -368,9 +368,9 @@ static inline bool _write_cff2 (const cff2_subset_plan &plan, if (plan.is_fds_subsetted ()) { - if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs, *(const FDSelect *)acc.fdSelect, acc.fdArray->count, + if (unlikely (!hb_serialize_cff_fdselect (&c, glyphs.len, *(const FDSelect *)acc.fdSelect, acc.fdArray->count, plan.subset_fdselect_format, plan.offsets.FDSelectInfo.size, - plan.subset_fdselect_first_glyphs, + plan.subset_fdselect_ranges, plan.fdmap))) { DEBUG_MSG (SUBSET, nullptr, "failed to serialize CFF2 subset FDSelect");