[subset] collect name_ids from CPAL table

This commit is contained in:
Qunxin Liu 2023-03-13 13:36:00 -07:00
parent 7b77cd198c
commit de6533d885
2 changed files with 56 additions and 16 deletions

View File

@ -73,6 +73,30 @@ struct CPALV1Tail
} }
public: public:
void collect_name_ids (const void *base,
unsigned palette_count,
unsigned color_count,
const hb_map_t *color_index_map,
hb_set_t *nameids_to_retain /* OUT */) const
{
if (paletteLabelsZ)
{
+ (base+paletteLabelsZ).as_array (palette_count)
| hb_sink (nameids_to_retain)
;
}
if (colorLabelsZ)
{
const hb_array_t<const NameID> colorLabels = (base+colorLabelsZ).as_array (color_count);
for (unsigned i = 0; i < color_count; i++)
{
if (!color_index_map->has (i)) continue;
nameids_to_retain->add (colorLabels[i]);
}
}
}
bool serialize (hb_serialize_context_t *c, bool serialize (hb_serialize_context_t *c,
unsigned palette_count, unsigned palette_count,
unsigned color_count, unsigned color_count,
@ -186,6 +210,13 @@ struct CPAL
return numColors; return numColors;
} }
void collect_name_ids (const hb_map_t *color_index_map,
hb_set_t *nameids_to_retain /* OUT */) const
{
if (version == 1)
v1 ().collect_name_ids (this, numPalettes, numColors, color_index_map, nameids_to_retain);
}
private: private:
const CPALV1Tail& v1 () const const CPALV1Tail& v1 () const
{ {

View File

@ -38,6 +38,7 @@
#include "hb-ot-cff1-table.hh" #include "hb-ot-cff1-table.hh"
#include "OT/Color/COLR/COLR.hh" #include "OT/Color/COLR/COLR.hh"
#include "OT/Color/COLR/colrv1-closure.hh" #include "OT/Color/COLR/colrv1-closure.hh"
#include "OT/Color/CPAL/CPAL.hh"
#include "hb-ot-var-fvar-table.hh" #include "hb-ot-var-fvar-table.hh"
#include "hb-ot-var-avar-table.hh" #include "hb-ot-var-avar-table.hh"
#include "hb-ot-stat-table.hh" #include "hb-ot-stat-table.hh"
@ -620,6 +621,26 @@ _glyf_add_gid_and_children (const OT::glyf_accelerator_t &glyf,
return operation_count; return operation_count;
} }
static void
_nameid_closure (hb_face_t *face,
hb_set_t *nameids,
bool all_axes_pinned,
hb_hashmap_t<hb_tag_t, float> *user_axes_location,
bool collect_cpal_name_ids,
const hb_map_t *color_index_map)
{
#ifndef HB_NO_STYLE
face->table.STAT->collect_name_ids (user_axes_location, nameids);
#endif
#ifndef HB_NO_VAR
if (!all_axes_pinned)
face->table.fvar->collect_name_ids (user_axes_location, nameids);
#endif
if (collect_cpal_name_ids)
face->table.CPAL->collect_name_ids (color_index_map, nameids);
}
static void static void
_populate_gids_to_retain (hb_subset_plan_t* plan, _populate_gids_to_retain (hb_subset_plan_t* plan,
hb_set_t* drop_tables) hb_set_t* drop_tables)
@ -673,6 +694,10 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
plan->_glyphset_colred = cur_glyphset; plan->_glyphset_colred = cur_glyphset;
_nameid_closure (plan->source, &(plan->name_ids),
plan->all_axes_pinned, &(plan->user_axes_location),
!drop_tables->has (HB_OT_TAG_CPAL),
&(plan->colr_palettes));
/* Populate a full set of glyphs to retain by adding all referenced /* Populate a full set of glyphs to retain by adding all referenced
* composite glyphs. */ * composite glyphs. */
if (glyf.has_data ()) if (glyf.has_data ())
@ -756,21 +781,6 @@ _create_old_gid_to_new_gid_map (const hb_face_t *face,
; ;
} }
static void
_nameid_closure (hb_face_t *face,
hb_set_t *nameids,
bool all_axes_pinned,
hb_hashmap_t<hb_tag_t, float> *user_axes_location)
{
#ifndef HB_NO_STYLE
face->table.STAT->collect_name_ids (user_axes_location, nameids);
#endif
#ifndef HB_NO_VAR
if (!all_axes_pinned)
face->table.fvar->collect_name_ids (user_axes_location, nameids);
#endif
}
#ifndef HB_NO_VAR #ifndef HB_NO_VAR
static void static void
_normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan) _normalize_axes_location (hb_face_t *face, hb_subset_plan_t *plan)
@ -905,7 +915,6 @@ hb_subset_plan_t::hb_subset_plan_t (hb_face_t *face,
glyph_map->get(unicode_to_new_gid_list.arrayZ[i].second); glyph_map->get(unicode_to_new_gid_list.arrayZ[i].second);
} }
_nameid_closure (face, &name_ids, all_axes_pinned, &user_axes_location);
if (unlikely (in_error ())) if (unlikely (in_error ()))
return; return;