提交 00894437 编写于 作者: G Garret Rieger

Keep a second set of glyph ids in subset plan which is sorted by glyph id and always has gid 0

上级 3bc81558
...@@ -157,7 +157,7 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan, ...@@ -157,7 +157,7 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan,
OT::glyf::accelerator_t glyf; OT::glyf::accelerator_t glyf;
glyf.init(face); glyf.init(face);
bool result = _hb_subset_glyf_and_loca (glyf, glyf_data, plan->gids_to_retain, glyf_prime, loca_prime); bool result = _hb_subset_glyf_and_loca (glyf, glyf_data, plan->gids_to_retain_sorted, glyf_prime, loca_prime);
glyf.fini(); glyf.fini();
*use_short_loca = false; *use_short_loca = false;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "hb-ot-cmap-table.hh" #include "hb-ot-cmap-table.hh"
int int
hb_codepoint_t_cmp (const void *l, const void *r) { _hb_codepoint_t_cmp (const void *l, const void *r) {
return *((hb_codepoint_t *) l) - *((hb_codepoint_t *) r); return *((hb_codepoint_t *) l) - *((hb_codepoint_t *) r);
} }
...@@ -40,8 +40,8 @@ hb_subset_plan_new_gid_for_old_id (hb_subset_plan_t *plan, ...@@ -40,8 +40,8 @@ hb_subset_plan_new_gid_for_old_id (hb_subset_plan_t *plan,
hb_codepoint_t *new_gid) hb_codepoint_t *new_gid)
{ {
// the index in old_gids is the new gid; only up to codepoints.len are valid // the index in old_gids is the new gid; only up to codepoints.len are valid
for (unsigned int i = 0; i < plan->codepoints.len; i++) { for (unsigned int i = 0; i < plan->gids_to_retain_sorted.len; i++) {
if (plan->gids_to_retain[i] == old_gid) { if (plan->gids_to_retain_sorted[i] == old_gid) {
*new_gid = i; *new_gid = i;
return true; return true;
} }
...@@ -59,13 +59,14 @@ _populate_codepoints (hb_set_t *input_codepoints, ...@@ -59,13 +59,14 @@ _populate_codepoints (hb_set_t *input_codepoints,
hb_codepoint_t *wr = plan_codepoints.push(); hb_codepoint_t *wr = plan_codepoints.push();
*wr = cp; *wr = cp;
} }
plan_codepoints.qsort (hb_codepoint_t_cmp); plan_codepoints.qsort (_hb_codepoint_t_cmp);
} }
void void
_populate_gids_to_retain (hb_face_t *face, _populate_gids_to_retain (hb_face_t *face,
hb_auto_array_t<hb_codepoint_t>& codepoints, hb_auto_array_t<hb_codepoint_t>& codepoints,
hb_auto_array_t<hb_codepoint_t>& old_gids) hb_auto_array_t<hb_codepoint_t>& old_gids,
hb_auto_array_t<hb_codepoint_t>& old_gids_sorted)
{ {
OT::cmap::accelerator_t cmap; OT::cmap::accelerator_t cmap;
cmap.init (face); cmap.init (face);
...@@ -73,12 +74,16 @@ _populate_gids_to_retain (hb_face_t *face, ...@@ -73,12 +74,16 @@ _populate_gids_to_retain (hb_face_t *face,
hb_auto_array_t<unsigned int> bad_indices; hb_auto_array_t<unsigned int> bad_indices;
old_gids.alloc (codepoints.len); old_gids.alloc (codepoints.len);
bool has_zero = false;
for (unsigned int i = 0; i < codepoints.len; i++) { for (unsigned int i = 0; i < codepoints.len; i++) {
hb_codepoint_t gid; hb_codepoint_t gid;
if (!cmap.get_nominal_glyph (codepoints[i], &gid)) { if (!cmap.get_nominal_glyph (codepoints[i], &gid)) {
gid = -1; gid = -1;
*(bad_indices.push ()) = i; *(bad_indices.push ()) = i;
} }
if (gid == 0) {
has_zero = true;
}
*(old_gids.push ()) = gid; *(old_gids.push ()) = gid;
} }
...@@ -90,13 +95,20 @@ _populate_gids_to_retain (hb_face_t *face, ...@@ -90,13 +95,20 @@ _populate_gids_to_retain (hb_face_t *face,
old_gids.remove (i); old_gids.remove (i);
} }
// Populate a second glyph id array that is sorted by glyph id
// and is gauranteed to contain 0.
old_gids_sorted.alloc (old_gids.len + (has_zero ? 0 : 1));
for (unsigned int i = 0; i < old_gids.len; i++) {
*(old_gids_sorted.push ()) = old_gids[i];
}
if (!has_zero)
*(old_gids_sorted.push ()) = 0;
old_gids_sorted.qsort (_hb_codepoint_t_cmp);
for (unsigned int i = 0; i < codepoints.len; i++) { for (unsigned int i = 0; i < codepoints.len; i++) {
DEBUG_MSG(SUBSET, nullptr, " U+%04X, old_gid %d, new_gid %d", codepoints[i], old_gids[i], i); DEBUG_MSG(SUBSET, nullptr, " U+%04X, old_gid %d, new_gid %d", codepoints[i], old_gids[i], i);
} }
// TODO always keep .notdef
// TODO(Q1) expand with glyphs that make up complex glyphs // TODO(Q1) expand with glyphs that make up complex glyphs
// TODO expand with glyphs reached by G* // TODO expand with glyphs reached by G*
// //
...@@ -120,7 +132,10 @@ hb_subset_plan_create (hb_face_t *face, ...@@ -120,7 +132,10 @@ hb_subset_plan_create (hb_face_t *face,
{ {
hb_subset_plan_t *plan = hb_object_create<hb_subset_plan_t> (); hb_subset_plan_t *plan = hb_object_create<hb_subset_plan_t> ();
_populate_codepoints (input->codepoints, plan->codepoints); _populate_codepoints (input->codepoints, plan->codepoints);
_populate_gids_to_retain (face, plan->codepoints, plan->gids_to_retain); _populate_gids_to_retain (face,
plan->codepoints,
plan->gids_to_retain,
plan->gids_to_retain_sorted);
return plan; return plan;
} }
...@@ -143,5 +158,6 @@ hb_subset_plan_destroy (hb_subset_plan_t *plan) ...@@ -143,5 +158,6 @@ hb_subset_plan_destroy (hb_subset_plan_t *plan)
plan->codepoints.finish (); plan->codepoints.finish ();
plan->gids_to_retain.finish (); plan->gids_to_retain.finish ();
plan->gids_to_retain_sorted.finish ();
free (plan); free (plan);
} }
...@@ -40,6 +40,7 @@ struct hb_subset_plan_t { ...@@ -40,6 +40,7 @@ struct hb_subset_plan_t {
// codepoints is sorted and aligned with gids_to_retain. // codepoints is sorted and aligned with gids_to_retain.
hb_auto_array_t<hb_codepoint_t> codepoints; hb_auto_array_t<hb_codepoint_t> codepoints;
hb_auto_array_t<hb_codepoint_t> gids_to_retain; hb_auto_array_t<hb_codepoint_t> gids_to_retain;
hb_auto_array_t<hb_codepoint_t> gids_to_retain_sorted;
}; };
typedef struct hb_subset_plan_t hb_subset_plan_t; typedef struct hb_subset_plan_t hb_subset_plan_t;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册