diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 5d23f88b2..a9e11fc0e 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -27,7 +27,24 @@ #include "hb-subset-plan.hh" #include "hb-subset-private.hh" -// TODO(Q1) map from old:new gid +hb_bool_t +hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan, + hb_codepoint_t old_gid, + hb_codepoint_t *new_gid) { + // TODO(Q1) lookup in map from old:new gid + // TEMPORARY: just loop over ids to retain and count up + hb_codepoint_t current = -1; + hb_codepoint_t count = 0; + while (hb_set_next(plan->glyphs_to_retain, ¤t)) { + if (old_gid == current) { + *new_gid = count; + return true; + } + count++; + } + return false; +} + hb_set_t * glyph_ids_to_retain (hb_subset_face_t *face, hb_set_t *codepoints) @@ -37,13 +54,15 @@ glyph_ids_to_retain (hb_subset_face_t *face, while (hb_set_next(codepoints, &cp)) { hb_codepoint_t gid; if (face->cmap.get_nominal_glyph(cp, &gid)) { - // TODO(Q1) a nice way to turn on/off logs - fprintf(stderr, "gid for U+%04X is %d\n", cp, gid); + DEBUG_MSG(SUBSET, nullptr, "gid for U+%04X is %d\n", cp, gid); hb_set_add(gids, cp); } else { - fprintf(stderr, "Unable to resolve gid for U+%04X\n", cp); + DEBUG_MSG(SUBSET, nullptr, "Unable to resolve gid for U+%04X\n", cp); } } + + // TODO(Q1) expand with glyphs that make up complex glyphs + // TODO expand with glyphs reached by G* return gids; } diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 6e94a76ff..549c87e28 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -44,6 +44,11 @@ hb_subset_plan_create (hb_subset_face_t *face, hb_subset_profile_t *profile, hb_subset_input_t *input); +hb_bool_t +hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan, + hb_codepoint_t old_gid, + hb_codepoint_t *new_gid /* OUT */); + hb_subset_plan_t * hb_subset_plan_get_empty (); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index e8b87ca3f..dc0d49251 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -151,6 +151,15 @@ hb_subset (hb_subset_profile_t *profile, hb_subset_plan_t *plan = hb_subset_plan_create (face, profile, input); + hb_codepoint_t old_gid = -1; + while (hb_set_next(plan->glyphs_to_retain, &old_gid)) { + hb_codepoint_t new_gid; + if (hb_subset_plan_new_gid_for_old_id(plan, old_gid, &new_gid)) { + DEBUG_MSG(SUBSET, nullptr, "Remap %d : %d\n", old_gid, new_gid); + } else { + DEBUG_MSG(SUBSET, nullptr, "Remap %d : DOOM! No new ID\n", old_gid); + } + } // TODO: // - Create initial header + table directory // - Loop through the set of tables to be kept: