From d0ce3c66e2af2785203f7bbb1d4abca5c226045d Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Tue, 6 Feb 2018 16:58:35 -0800 Subject: [PATCH] Resolve codepoints:glyph ids. Does not compile; undefined reference to OT::_hb_NullPool --- src/hb-subset-plan.cc | 25 +++++++++++++++++++------ src/hb-subset-plan.hh | 2 +- src/hb-subset-private.hh | 17 +++++++++++++++-- src/hb-subset.cc | 13 ++++--------- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 8111d519b..5d23f88b2 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -21,17 +21,30 @@ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * - * Google Author(s): Garret Rieger + * Google Author(s): Garret Rieger, Roderick Sheeter */ #include "hb-subset-plan.hh" #include "hb-subset-private.hh" +// TODO(Q1) map from old:new gid hb_set_t * -get_glyph_ids_from_cmap (hb_face_t *face, - hb_set_t *codepoints) +glyph_ids_to_retain (hb_subset_face_t *face, + hb_set_t *codepoints) { - return hb_set_get_empty (); + hb_codepoint_t cp = -1; + hb_set_t *gids = hb_set_create(); + 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); + hb_set_add(gids, cp); + } else { + fprintf(stderr, "Unable to resolve gid for U+%04X\n", cp); + } + } + return gids; } /** @@ -45,12 +58,12 @@ get_glyph_ids_from_cmap (hb_face_t *face, * Since: 1.7.5 **/ hb_subset_plan_t * -hb_subset_plan_create (hb_face_t *face, +hb_subset_plan_create (hb_subset_face_t *face, hb_subset_profile_t *profile, hb_subset_input_t *input) { hb_subset_plan_t *plan = hb_object_create (); - plan->glyphs_to_retain = get_glyph_ids_from_cmap (face, input->codepoints); + plan->glyphs_to_retain = glyph_ids_to_retain (face, input->codepoints); return plan; } diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 54b1e651d..6e94a76ff 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -40,7 +40,7 @@ struct hb_subset_plan_t { typedef struct hb_subset_plan_t hb_subset_plan_t; hb_subset_plan_t * -hb_subset_plan_create (hb_face_t *face, +hb_subset_plan_create (hb_subset_face_t *face, hb_subset_profile_t *profile, hb_subset_input_t *input); diff --git a/src/hb-subset-private.hh b/src/hb-subset-private.hh index b38ab0b26..eb4147dce 100644 --- a/src/hb-subset-private.hh +++ b/src/hb-subset-private.hh @@ -21,15 +21,21 @@ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * - * Google Author(s): Garret Rieger + * Google Author(s): Garret Rieger, Roderick Sheeter */ #ifndef HB_SUBSET_PRIVATE_HH #define HB_SUBSET_PRIVATE_HH -#include "hb-object-private.hh" + #include "hb-private.hh" +#include "hb-ot.h" + +#include "hb-font-private.hh" + +#include "hb-ot-cmap-table.hh" + struct hb_subset_input_t { hb_object_header_t header; ASSERT_POD (); @@ -37,4 +43,11 @@ struct hb_subset_input_t { hb_set_t *codepoints; }; +struct hb_subset_face_t { + hb_object_header_t header; + + hb_face_t *face; + OT::cmap::accelerator_t cmap; +}; + #endif /* HB_SUBSET_PRIVATE_HH */ diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 7b44d5168..7108eb871 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -27,6 +27,7 @@ #include "hb-object-private.hh" #include "hb-private.hh" + #include "hb-subset-glyf.hh" #include "hb-subset-private.hh" #include "hb-subset-plan.hh" @@ -38,14 +39,6 @@ struct hb_subset_profile_t { ASSERT_POD (); }; -struct hb_subset_face_t { - hb_object_header_t header; - ASSERT_POD (); - - hb_face_t *face; -}; - - /** * hb_subset_profile_create: * @@ -119,6 +112,7 @@ hb_subset_face_create (hb_face_t *face) hb_subset_face_t *subset_face = hb_object_create (); subset_face->face = hb_face_reference (face); + subset_face->cmap.init(face); return subset_face; } @@ -133,6 +127,7 @@ hb_subset_face_destroy (hb_subset_face_t *subset_face) { if (!hb_object_destroy (subset_face)) return; + subset_face->cmap.fini(); hb_face_destroy(subset_face->face); free (subset_face); } @@ -154,7 +149,7 @@ hb_subset (hb_subset_profile_t *profile, { if (!profile || !input || !face) return false; - hb_subset_plan_t *plan = hb_subset_plan_create (face->face, profile, input); + hb_subset_plan_t *plan = hb_subset_plan_create (face, profile, input); // TODO: // - Create initial header + table directory