From 0859a006695097c2a66a07284f3cc5b8de8edb05 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 7 Feb 2018 15:59:36 -0800 Subject: [PATCH] sketch a subset and call it for cmap. Add subset to cmap, albeit not working even for the msot basic case just yet --- src/hb-ot-cmap-table.hh | 18 ++++++++++++++++-- src/hb-subset.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index b9d6e248a..570f13408 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -27,8 +27,8 @@ #ifndef HB_OT_CMAP_TABLE_HH #define HB_OT_CMAP_TABLE_HH -#include "hb-open-type-private.hh" - +#include "hb-open-type-private.hh" +#include "hb-subset-plan.hh" namespace OT { @@ -504,6 +504,20 @@ struct cmap encodingRecord.sanitize (c, this)); } + inline bool subset(hb_subset_plan_t *plan, OT::hb_serialize_context_t *out) const + { + // Same version + OT::cmap new_cmap; + new_cmap.version = version; + new_cmap.encodingRecord.len.set(1); // one format 12 subtable + + // TODO we need to actually build the format 12 subtable + + // TODO: this fails + // out->extend_min(new_cmap); + return true; + } + struct accelerator_t { inline void init (hb_face_t *face) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 8c1e43f73..9c1d6d43e 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -26,6 +26,8 @@ */ #include "hb-object-private.hh" +#include "hb-open-type-private.hh" + #include "hb-private.hh" #include "hb-subset-glyf.hh" @@ -33,6 +35,7 @@ #include "hb-subset-plan.hh" #include "hb-open-file-private.hh" +#include "hb-ot-cmap-table.hh" #include "hb-ot-glyf-table.hh" @@ -104,6 +107,26 @@ hb_subset_input_destroy(hb_subset_input_t *subset_input) free (subset_input); } +template +hb_bool_t +subset(hb_subset_plan_t *plan, hb_face_t *face, hb_blob_t **out) +{ + OT::Sanitizer sanitizer; + hb_blob_t *table_blob = sanitizer.sanitize (face->reference_table (TableType::tableTag)); + if (unlikely(!table_blob)) { + return false; + } + const TableType *table = OT::Sanitizer::lock_instance (table_blob); + + // TODO actually manage the context/output memory + size_t dest_sz = 64536; // as much as anyone would ever need + void *dest = malloc(dest_sz); + OT::hb_serialize_context_t context(dest, dest_sz); + hb_bool_t result = table->subset(plan, &context); + // TODO populate out + hb_blob_destroy (table_blob); + return result; +} /* @@ -289,6 +312,13 @@ hb_subset (hb_face_t *source, } hb_blob_destroy (glyf_prime); + hb_blob_t *cmap_prime = nullptr; + if (subset(plan, source, &cmap_prime)) { + DEBUG_MSG(SUBSET, nullptr, "subset cmap success!"); + } else { + DEBUG_MSG(SUBSET, nullptr, "subset cmap FAILED!"); + } + hb_subset_plan_destroy (plan); return face;