提交 d5b33f2f 编写于 作者: B Behdad Esfahbod

[subset] hb_subset_input_t changes

上级 28e63a12
......@@ -185,6 +185,7 @@ HB_ICU_headers = hb-icu.h
HB_SUBSET_sources = \
hb-subset.cc \
hb-subset-glyf.cc \
hb-subset-input.cc \
hb-subset-plan.cc \
$(NULL)
......
......@@ -71,7 +71,6 @@ hb_face_set_user_data (hb_face_t *face,
hb_destroy_func_t destroy,
hb_bool_t replace);
HB_EXTERN void *
hb_face_get_user_data (hb_face_t *face,
hb_user_data_key_t *key);
......
......@@ -50,6 +50,13 @@ hb_set_create (void)
return set;
}
static const hb_set_t _hb_set_nil = {
HB_OBJECT_HEADER_STATIC,
true, /* in_error */
{0} /* elts */
};
/**
* hb_set_get_empty:
*
......@@ -60,13 +67,6 @@ hb_set_create (void)
hb_set_t *
hb_set_get_empty (void)
{
static const hb_set_t _hb_set_nil = {
HB_OBJECT_HEADER_STATIC,
true, /* in_error */
{0} /* elts */
};
return const_cast<hb_set_t *> (&_hb_set_nil);
}
......
/*
* Copyright © 2018 Google, Inc.
*
* This is part of HarfBuzz, a text shaping library.
*
* Permission is hereby granted, without written agreement and without
* license or royalty fees, to use, copy, modify, and distribute this
* software and its documentation for any purpose, provided that the
* above copyright notice and the following two paragraphs appear in
* all copies of this software.
*
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod
*/
#include "hb-object-private.hh"
#include "hb-subset-private.hh"
#include "hb-set-private.hh"
/**
* hb_subset_input_create:
*
* Return value: New subset input.
*
* Since: 1.8.0
**/
hb_subset_input_t *
hb_subset_input_create (void)
{
hb_subset_input_t *input = hb_object_create<hb_subset_input_t>();
/* Unlike libharfbuzz, in this lib we return nullptr
* in case of allocation failure. */
if (unlikely (!input))
return nullptr;
input->unicodes = hb_set_create ();
input->glyphs = hb_set_create ();
return input;
}
/**
* hb_subset_input_reference: (skip)
* @subset_input: a subset_input.
*
*
*
* Return value:
*
* Since: 1.8.0
**/
hb_subset_input_t *
hb_subset_input_reference (hb_subset_input_t *subset_input)
{
return hb_object_reference (subset_input);
}
/**
* hb_subset_input_destroy:
* @subset_input: a subset_input.
*
* Since: 1.8.0
**/
void
hb_subset_input_destroy(hb_subset_input_t *subset_input)
{
if (!hb_object_destroy (subset_input)) return;
hb_set_destroy (subset_input->unicodes);
hb_set_destroy (subset_input->glyphs);
free (subset_input);
}
/**
* hb_subset_input_unicode_set:
* @subset_input: a subset_input.
*
* Since: 1.8.0
**/
HB_EXTERN hb_set_t *
hb_subset_input_unicode_set (hb_subset_input_t *subset_input)
{
return subset_input->unicodes;
}
/**
* hb_subset_input_glyph_set:
* @subset_input: a subset_input.
*
* Since: 1.8.0
**/
HB_EXTERN hb_set_t *
hb_subset_input_glyph_set (hb_subset_input_t *subset_input)
{
return subset_input->glyphs;
}
......@@ -140,7 +140,7 @@ hb_subset_plan_create (hb_face_t *face,
plan->gids_to_retain.init();
plan->gids_to_retain_sorted.init();
_populate_codepoints (input->codepoints, plan->codepoints);
_populate_codepoints (input->unicodes, plan->codepoints);
_populate_gids_to_retain (face,
plan->codepoints,
plan->gids_to_retain,
......
......@@ -38,7 +38,16 @@ struct hb_subset_input_t {
hb_object_header_t header;
ASSERT_POD ();
hb_set_t *codepoints;
hb_set_t *unicodes;
hb_set_t *glyphs;
/* TODO
*
* features
* lookups
* nameIDs
* ...
*/
};
#endif /* HB_SUBSET_PRIVATE_HH */
......@@ -21,14 +21,12 @@
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*
* Google Author(s): Garret Rieger, Rod Sheeter
* Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod
*/
#include "hb-object-private.hh"
#include "hb-open-type-private.hh"
#include "hb-private.hh"
#include "hb-subset-glyf.hh"
#include "hb-subset-private.hh"
#include "hb-subset-plan.hh"
......@@ -53,7 +51,7 @@ struct hb_subset_profile_t {
*
* Return value: New profile with default settings.
*
* Since: 1.7.5
* Since: 1.8.0
**/
hb_subset_profile_t *
hb_subset_profile_create ()
......@@ -64,7 +62,7 @@ hb_subset_profile_create ()
/**
* hb_subset_profile_destroy:
*
* Since: 1.7.5
* Since: 1.8.0
**/
void
hb_subset_profile_destroy (hb_subset_profile_t *profile)
......@@ -74,38 +72,6 @@ hb_subset_profile_destroy (hb_subset_profile_t *profile)
free (profile);
}
/**
* hb_subset_input_create:
*
* Return value: New subset input.
*
* Since: 1.7.5
**/
hb_subset_input_t *
hb_subset_input_create (hb_set_t *codepoints)
{
if (unlikely (!codepoints))
codepoints = hb_set_get_empty();
hb_subset_input_t *input = hb_object_create<hb_subset_input_t>();
input->codepoints = hb_set_reference(codepoints);
return input;
}
/**
* hb_subset_input_destroy:
*
* Since: 1.7.5
**/
void
hb_subset_input_destroy(hb_subset_input_t *subset_input)
{
if (!hb_object_destroy (subset_input)) return;
hb_set_destroy (subset_input->codepoints);
free (subset_input);
}
template<typename TableType>
static hb_blob_t *
_subset (hb_subset_plan_t *plan, hb_face_t *source)
......
......@@ -47,17 +47,27 @@ hb_subset_profile_destroy (hb_subset_profile_t *profile);
/*
* hb_subset_input_t
*
* Things that change based on the input. Characters to keep, etc.
*/
typedef struct hb_subset_input_t hb_subset_input_t;
HB_EXTERN hb_subset_input_t *
hb_subset_input_create (hb_set_t *codepoints);
hb_subset_input_create (void);
HB_EXTERN hb_subset_input_t *
hb_subset_input_reference (hb_subset_input_t *subset_input);
HB_EXTERN void
hb_subset_input_destroy (hb_subset_input_t *subset_input);
HB_EXTERN hb_set_t *
hb_subset_input_unicode_set (hb_subset_input_t *subset_input);
HB_EXTERN hb_set_t *
hb_subset_input_glyph_set (hb_subset_input_t *subset_input);
/* hb_subset() */
......
......@@ -94,9 +94,9 @@ test_subset_glyf (void)
hb_face_t *face_abc_subset;
hb_blob_t *glyf_expected_blob;
hb_blob_t *glyf_actual_blob;
hb_set_t *codepoints = hb_set_create();
hb_subset_profile_t *profile = hb_subset_profile_create();
hb_subset_input_t *input = hb_subset_input_create (codepoints);
hb_subset_input_t *input = hb_subset_input_create ();
hb_set_t *codepoints = hb_set_reference (hb_subset_input_unicode_set (input));
g_assert (face_abc);
g_assert (face_ac);
......
......@@ -43,7 +43,7 @@ test_subset (void)
hb_face_t *face = hb_face_create(font_blob, 0);
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_face_t *out_face = hb_subset(face, profile, input);
g_assert(out_face);
......
......@@ -37,13 +37,13 @@
struct subset_consumer_t
{
subset_consumer_t (option_parser_t *parser)
: failed (false), options (parser), font (nullptr), codepoints (nullptr) {}
: failed (false), options (parser), font (nullptr), input (nullptr) {}
void init (hb_buffer_t *buffer_,
const font_options_t *font_opts)
{
font = hb_font_reference (font_opts->get_font ());
codepoints = hb_set_create();
input = hb_subset_input_create ();
}
void consume_line (const char *text,
......@@ -51,14 +51,13 @@ struct subset_consumer_t
const char *text_before,
const char *text_after)
{
// text appears to be a g_string when set by --unicodes
// TODO(Q1) are gunichar and hbcodepoint_t interchangeable?
// TODO(Q1) does this only get called with at least 1 codepoint?
hb_set_t *codepoints = hb_subset_input_unicode_set (input);
gchar *c = (gchar *)text;
do {
gunichar cp = g_utf8_get_char(c);
hb_codepoint_t hb_cp = cp; // TODO(Q1) is this safe?
hb_set_add(codepoints, hb_cp);
hb_codepoint_t hb_cp = cp;
hb_set_add (codepoints, hb_cp);
} while ((c = g_utf8_find_next_char(c, text + text_len)) != nullptr);
}
......@@ -90,12 +89,10 @@ struct subset_consumer_t
void finish (const font_options_t *font_opts)
{
// TODO(Q1) check for errors from creates and such
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_face_t *new_face = hb_subset(face, subset_profile, subset_input);
hb_face_t *new_face = hb_subset(face, subset_profile, input);
hb_blob_t *result = hb_face_reference_blob (new_face);
failed = !hb_blob_get_length (result);
......@@ -103,8 +100,7 @@ struct subset_consumer_t
write_file (options.output_file, result);
hb_subset_profile_destroy (subset_profile);
hb_subset_input_destroy (subset_input);
hb_set_destroy (codepoints);
hb_subset_input_destroy (input);
hb_blob_destroy (result);
hb_face_destroy (new_face);
hb_font_destroy (font);
......@@ -116,7 +112,7 @@ struct subset_consumer_t
private:
output_options_t options;
hb_font_t *font;
hb_set_t *codepoints;
hb_subset_input_t *input;
};
int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册