[subset] Change hb_subset API to remove hb_subset_face_t
This commit is contained in:
parent
2da0d87e76
commit
af02812fc5
|
@ -27,6 +27,8 @@
|
||||||
#include "hb-subset-plan.hh"
|
#include "hb-subset-plan.hh"
|
||||||
#include "hb-subset-private.hh"
|
#include "hb-subset-private.hh"
|
||||||
|
|
||||||
|
#include "hb-ot-cmap-table.hh"
|
||||||
|
|
||||||
hb_bool_t
|
hb_bool_t
|
||||||
hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan,
|
hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan,
|
||||||
hb_codepoint_t old_gid,
|
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 *
|
hb_set_t *
|
||||||
glyph_ids_to_retain (hb_subset_face_t *face,
|
glyph_ids_to_retain (hb_face_t *face,
|
||||||
hb_set_t *codepoints)
|
hb_set_t *codepoints)
|
||||||
{
|
{
|
||||||
|
OT::cmap::accelerator_t cmap;
|
||||||
|
cmap.init (face);
|
||||||
hb_codepoint_t cp = -1;
|
hb_codepoint_t cp = -1;
|
||||||
hb_set_t *gids = hb_set_create();
|
hb_set_t *gids = hb_set_create();
|
||||||
while (hb_set_next(codepoints, &cp)) {
|
while (hb_set_next(codepoints, &cp)) {
|
||||||
hb_codepoint_t gid;
|
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);
|
DEBUG_MSG(SUBSET, nullptr, "gid for U+%04X is %d", cp, gid);
|
||||||
hb_set_add(gids, gid);
|
hb_set_add(gids, gid);
|
||||||
} else {
|
} 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(Q1) expand with glyphs that make up complex glyphs
|
||||||
// TODO expand with glyphs reached by G*
|
// TODO expand with glyphs reached by G*
|
||||||
|
//
|
||||||
|
cmap.fini ();
|
||||||
return gids;
|
return gids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +83,7 @@ glyph_ids_to_retain (hb_subset_face_t *face,
|
||||||
* Since: 1.7.5
|
* Since: 1.7.5
|
||||||
**/
|
**/
|
||||||
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_profile_t *profile,
|
||||||
hb_subset_input_t *input)
|
hb_subset_input_t *input)
|
||||||
{
|
{
|
||||||
|
|
|
@ -40,7 +40,7 @@ struct hb_subset_plan_t {
|
||||||
typedef struct hb_subset_plan_t hb_subset_plan_t;
|
typedef struct hb_subset_plan_t 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_profile_t *profile,
|
||||||
hb_subset_input_t *input);
|
hb_subset_input_t *input);
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,6 @@
|
||||||
|
|
||||||
#include "hb-font-private.hh"
|
#include "hb-font-private.hh"
|
||||||
|
|
||||||
#include "hb-ot-cmap-table.hh"
|
|
||||||
|
|
||||||
struct hb_subset_input_t {
|
struct hb_subset_input_t {
|
||||||
hb_object_header_t header;
|
hb_object_header_t header;
|
||||||
ASSERT_POD ();
|
ASSERT_POD ();
|
||||||
|
@ -43,12 +41,4 @@ struct hb_subset_input_t {
|
||||||
hb_set_t *codepoints;
|
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 */
|
#endif /* HB_SUBSET_PRIVATE_HH */
|
||||||
|
|
|
@ -101,40 +101,6 @@ hb_subset_input_destroy(hb_subset_input_t *subset_input)
|
||||||
free (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:
|
* 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.
|
* Subsets a font according to provided profile and input.
|
||||||
**/
|
**/
|
||||||
hb_bool_t
|
hb_face_t *
|
||||||
hb_subset (hb_subset_profile_t *profile,
|
hb_subset (hb_face_t *source,
|
||||||
hb_subset_input_t *input,
|
hb_subset_profile_t *profile,
|
||||||
hb_subset_face_t *face,
|
hb_subset_input_t *input)
|
||||||
hb_blob_t **result /* OUT */)
|
|
||||||
{
|
{
|
||||||
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;
|
hb_codepoint_t old_gid = -1;
|
||||||
while (hb_set_next(plan->glyphs_to_retain, &old_gid)) {
|
while (hb_set_next(plan->glyphs_to_retain, &old_gid)) {
|
||||||
|
@ -174,14 +139,13 @@ hb_subset (hb_subset_profile_t *profile,
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
hb_blob_t *glyf_prime = nullptr;
|
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.
|
// TODO: write new glyf to new face.
|
||||||
} else {
|
} else {
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
hb_blob_destroy (glyf_prime);
|
hb_blob_destroy (glyf_prime);
|
||||||
|
|
||||||
*result = hb_face_reference_blob(face->face);
|
|
||||||
hb_subset_plan_destroy (plan);
|
hb_subset_plan_destroy (plan);
|
||||||
return success;
|
return success ? hb_face_reference (source) : nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ HB_BEGIN_DECLS
|
||||||
typedef struct hb_subset_profile_t hb_subset_profile_t;
|
typedef struct hb_subset_profile_t hb_subset_profile_t;
|
||||||
|
|
||||||
HB_EXTERN hb_subset_profile_t *
|
HB_EXTERN hb_subset_profile_t *
|
||||||
hb_subset_profile_create ();
|
hb_subset_profile_create (void);
|
||||||
|
|
||||||
HB_EXTERN void
|
HB_EXTERN void
|
||||||
hb_subset_profile_destroy (hb_subset_profile_t *profile);
|
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_EXTERN void
|
||||||
hb_subset_input_destroy (hb_subset_input_t *subset_input);
|
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_subset() */
|
||||||
|
|
||||||
HB_EXTERN hb_subset_face_t *
|
HB_EXTERN hb_face_t *
|
||||||
hb_subset_face_create (hb_face_t *face);
|
hb_subset (hb_face_t *source,
|
||||||
|
hb_subset_profile_t *profile,
|
||||||
HB_EXTERN void
|
hb_subset_input_t *input);
|
||||||
hb_subset_face_destroy (hb_subset_face_t *face);
|
|
||||||
|
|
||||||
|
|
||||||
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_END_DECLS
|
HB_END_DECLS
|
||||||
|
|
||||||
|
|
|
@ -43,19 +43,20 @@ test_subset (void)
|
||||||
|
|
||||||
hb_subset_profile_t *profile = hb_subset_profile_create();
|
hb_subset_profile_t *profile = hb_subset_profile_create();
|
||||||
hb_subset_input_t *input = hb_subset_input_create (hb_set_get_empty ());
|
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;
|
hb_face_t *out_face = hb_subset(face, profile, input);
|
||||||
g_assert(hb_subset(profile, input, subset_face, &output));
|
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;
|
unsigned int output_length;
|
||||||
const char *output_data = hb_blob_get_data(output, &output_length);
|
const char *output_data = hb_blob_get_data(output, &output_length);
|
||||||
g_assert_cmpmem(test_data, 4, output_data, output_length);
|
g_assert_cmpmem(test_data, 4, output_data, output_length);
|
||||||
|
|
||||||
hb_blob_destroy(output);
|
hb_blob_destroy(output);
|
||||||
hb_subset_face_destroy(subset_face);
|
|
||||||
hb_subset_input_destroy(input);
|
hb_subset_input_destroy(input);
|
||||||
hb_subset_profile_destroy(profile);
|
hb_subset_profile_destroy(profile);
|
||||||
|
hb_face_destroy(out_face);
|
||||||
hb_face_destroy(face);
|
hb_face_destroy(face);
|
||||||
hb_blob_destroy(font_blob);
|
hb_blob_destroy(font_blob);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,19 +93,21 @@ struct subset_consumer_t
|
||||||
hb_subset_profile_t *subset_profile = hb_subset_profile_create();
|
hb_subset_profile_t *subset_profile = hb_subset_profile_create();
|
||||||
hb_subset_input_t *subset_input = hb_subset_input_create (codepoints);
|
hb_subset_input_t *subset_input = hb_subset_input_create (codepoints);
|
||||||
hb_face_t *face = hb_font_get_face (font);
|
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;
|
hb_face_t *new_face = hb_subset(face, subset_profile, subset_input);
|
||||||
failed = !(hb_subset(subset_profile, subset_input, subset_face, &result)
|
hb_blob_t *result = hb_face_reference_blob (new_face);
|
||||||
&& write_file(options.output_file, result));
|
|
||||||
|
failed = !hb_blob_get_length (result);
|
||||||
|
if (!failed)
|
||||||
|
write_file (options.output_file, result);
|
||||||
|
|
||||||
hb_subset_profile_destroy (subset_profile);
|
hb_subset_profile_destroy (subset_profile);
|
||||||
hb_subset_input_destroy (subset_input);
|
hb_subset_input_destroy (subset_input);
|
||||||
hb_set_destroy (codepoints);
|
hb_set_destroy (codepoints);
|
||||||
hb_subset_face_destroy (subset_face);
|
|
||||||
hb_blob_destroy (result);
|
hb_blob_destroy (result);
|
||||||
|
hb_face_destroy (new_face);
|
||||||
hb_font_destroy (font);
|
hb_font_destroy (font);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue