[HarfBuzz] harfbuzz: Branch 'master'
Behdad Esfahbod
behdad at kemper.freedesktop.org
Wed Feb 7 18:08:10 UTC 2018
src/hb-subset-plan.cc | 12 ++++++++--
src/hb-subset-plan.hh | 2 -
src/hb-subset-private.hh | 10 ---------
src/hb-subset.cc | 52 +++++++----------------------------------------
src/hb-subset.h | 25 +++++-----------------
test/api/test-subset.c | 9 ++++----
util/hb-subset.cc | 12 ++++++----
7 files changed, 36 insertions(+), 86 deletions(-)
New commits:
commit af02812fc51812a7e2265a1100bbca1a5bf8af45
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Feb 7 13:07:46 2018 -0500
[subset] Change hb_subset API to remove hb_subset_face_t
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index 470fa03e..20185e1d 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -27,6 +27,8 @@
#include "hb-subset-plan.hh"
#include "hb-subset-private.hh"
+#include "hb-ot-cmap-table.hh"
+
hb_bool_t
hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan,
hb_codepoint_t old_gid,
@@ -46,14 +48,16 @@ hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan,
}
hb_set_t *
-glyph_ids_to_retain (hb_subset_face_t *face,
+glyph_ids_to_retain (hb_face_t *face,
hb_set_t *codepoints)
{
+ OT::cmap::accelerator_t cmap;
+ cmap.init (face);
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)) {
+ if (cmap.get_nominal_glyph(cp, &gid)) {
DEBUG_MSG(SUBSET, nullptr, "gid for U+%04X is %d", cp, gid);
hb_set_add(gids, gid);
} else {
@@ -63,6 +67,8 @@ glyph_ids_to_retain (hb_subset_face_t *face,
// TODO(Q1) expand with glyphs that make up complex glyphs
// TODO expand with glyphs reached by G*
+ //
+ cmap.fini ();
return gids;
}
@@ -77,7 +83,7 @@ glyph_ids_to_retain (hb_subset_face_t *face,
* Since: 1.7.5
**/
hb_subset_plan_t *
-hb_subset_plan_create (hb_subset_face_t *face,
+hb_subset_plan_create (hb_face_t *face,
hb_subset_profile_t *profile,
hb_subset_input_t *input)
{
diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh
index 549c87e2..b1ed1add 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_subset_face_t *face,
+hb_subset_plan_create (hb_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 31fceb47..9689da80 100644
--- a/src/hb-subset-private.hh
+++ b/src/hb-subset-private.hh
@@ -34,8 +34,6 @@
#include "hb-font-private.hh"
-#include "hb-ot-cmap-table.hh"
-
struct hb_subset_input_t {
hb_object_header_t header;
ASSERT_POD ();
@@ -43,12 +41,4 @@ struct hb_subset_input_t {
hb_set_t *codepoints;
};
-struct hb_subset_face_t {
- hb_object_header_t header;
- ASSERT_POD ();
-
- 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 7215b60b..28cfd300 100644
--- a/src/hb-subset.cc
+++ b/src/hb-subset.cc
@@ -101,40 +101,6 @@ hb_subset_input_destroy(hb_subset_input_t *subset_input)
free (subset_input);
}
-/**
- * hb_subset_face_create:
- *
- * Return value: New subset face.
- *
- * Since: 1.7.5
- **/
-hb_subset_face_t *
-hb_subset_face_create (hb_face_t *face)
-{
- if (unlikely (!face))
- face = hb_face_get_empty();
-
- hb_subset_face_t *subset_face = hb_object_create<hb_subset_face_t> ();
- subset_face->face = hb_face_reference (face);
- subset_face->cmap.init(face);
-
- return subset_face;
-}
-
-/**
- * hb_subset_face_destroy:
- *
- * Since: 1.7.5
- **/
-void
-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);
-}
/**
* hb_subset:
@@ -145,15 +111,14 @@ hb_subset_face_destroy (hb_subset_face_t *subset_face)
*
* Subsets a font according to provided profile and input.
**/
-hb_bool_t
-hb_subset (hb_subset_profile_t *profile,
- hb_subset_input_t *input,
- hb_subset_face_t *face,
- hb_blob_t **result /* OUT */)
+hb_face_t *
+hb_subset (hb_face_t *source,
+ hb_subset_profile_t *profile,
+ hb_subset_input_t *input)
{
- if (!profile || !input || !face) return false;
+ if (unlikely (!profile || !input || !source)) return nullptr;
- hb_subset_plan_t *plan = hb_subset_plan_create (face, profile, input);
+ hb_subset_plan_t *plan = hb_subset_plan_create (source, profile, input);
hb_codepoint_t old_gid = -1;
while (hb_set_next(plan->glyphs_to_retain, &old_gid)) {
@@ -174,14 +139,13 @@ hb_subset (hb_subset_profile_t *profile,
bool success = true;
hb_blob_t *glyf_prime = nullptr;
- if (hb_subset_glyf (plan, face->face, &glyf_prime)) {
+ if (hb_subset_glyf (plan, source, &glyf_prime)) {
// TODO: write new glyf to new face.
} else {
success = false;
}
hb_blob_destroy (glyf_prime);
- *result = hb_face_reference_blob(face->face);
hb_subset_plan_destroy (plan);
- return success;
+ return success ? hb_face_reference (source) : nullptr;
}
diff --git a/src/hb-subset.h b/src/hb-subset.h
index 47127e03..2b8d55a2 100644
--- a/src/hb-subset.h
+++ b/src/hb-subset.h
@@ -40,7 +40,7 @@ HB_BEGIN_DECLS
typedef struct hb_subset_profile_t hb_subset_profile_t;
HB_EXTERN hb_subset_profile_t *
-hb_subset_profile_create ();
+hb_subset_profile_create (void);
HB_EXTERN void
hb_subset_profile_destroy (hb_subset_profile_t *profile);
@@ -58,26 +58,13 @@ hb_subset_input_create (hb_set_t *codepoints);
HB_EXTERN void
hb_subset_input_destroy (hb_subset_input_t *subset_input);
-/*
- * hb_subset_face_t
- * Reusable subset-ready plan for a given face. Threadsafe for multiple
- * concurrent subset operations.
- */
-
-typedef struct hb_subset_face_t hb_subset_face_t;
-
-HB_EXTERN hb_subset_face_t *
-hb_subset_face_create (hb_face_t *face);
-
-HB_EXTERN void
-hb_subset_face_destroy (hb_subset_face_t *face);
+/* hb_subset() */
-HB_EXTERN hb_bool_t
-hb_subset (hb_subset_profile_t *profile,
- hb_subset_input_t *input,
- hb_subset_face_t *face,
- hb_blob_t **result /* OUT */);
+HB_EXTERN hb_face_t *
+hb_subset (hb_face_t *source,
+ hb_subset_profile_t *profile,
+ hb_subset_input_t *input);
HB_END_DECLS
diff --git a/test/api/test-subset.c b/test/api/test-subset.c
index 4841af62..db4bbe92 100644
--- a/test/api/test-subset.c
+++ b/test/api/test-subset.c
@@ -43,19 +43,20 @@ test_subset (void)
hb_subset_profile_t *profile = hb_subset_profile_create();
hb_subset_input_t *input = hb_subset_input_create (hb_set_get_empty ());
- hb_subset_face_t *subset_face = hb_subset_face_create(face);
- hb_blob_t *output;
- g_assert(hb_subset(profile, input, subset_face, &output));
+ hb_face_t *out_face = hb_subset(face, profile, input);
+ g_assert(out_face);
+ g_assert(out_face != hb_face_get_empty ());
+ hb_blob_t *output = hb_face_reference_blob (out_face);
unsigned int output_length;
const char *output_data = hb_blob_get_data(output, &output_length);
g_assert_cmpmem(test_data, 4, output_data, output_length);
hb_blob_destroy(output);
- hb_subset_face_destroy(subset_face);
hb_subset_input_destroy(input);
hb_subset_profile_destroy(profile);
+ hb_face_destroy(out_face);
hb_face_destroy(face);
hb_blob_destroy(font_blob);
}
diff --git a/util/hb-subset.cc b/util/hb-subset.cc
index 67cfed19..fb6d3635 100644
--- a/util/hb-subset.cc
+++ b/util/hb-subset.cc
@@ -93,19 +93,21 @@ struct subset_consumer_t
hb_subset_profile_t *subset_profile = hb_subset_profile_create();
hb_subset_input_t *subset_input = hb_subset_input_create (codepoints);
hb_face_t *face = hb_font_get_face (font);
- hb_subset_face_t *subset_face = hb_subset_face_create(face);
- hb_blob_t *result = nullptr;
- failed = !(hb_subset(subset_profile, subset_input, subset_face, &result)
- && write_file(options.output_file, result));
+ hb_face_t *new_face = hb_subset(face, subset_profile, subset_input);
+ hb_blob_t *result = hb_face_reference_blob (new_face);
+
+ failed = !hb_blob_get_length (result);
+ if (!failed)
+ write_file (options.output_file, result);
hb_subset_profile_destroy (subset_profile);
hb_subset_input_destroy (subset_input);
hb_set_destroy (codepoints);
- hb_subset_face_destroy (subset_face);
hb_blob_destroy (result);
+ hb_face_destroy (new_face);
hb_font_destroy (font);
}
More information about the HarfBuzz
mailing list