[util] Use post_parse in face_options_t

This commit is contained in:
Behdad Esfahbod 2021-08-11 18:35:11 -06:00
parent c0ea4e2d33
commit e4b33d9d36
4 changed files with 14 additions and 29 deletions

View File

@ -38,15 +38,7 @@ struct face_options_t
void add_options (option_parser_t *parser);
void post_parse (GError **error)
{
if (!this->font_file)
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
"No font file set");
}
hb_blob_t *get_blob () const;
hb_face_t *get_face () const;
void post_parse (GError **error);
static struct cache_t
{
@ -65,25 +57,20 @@ struct face_options_t
char *font_file = nullptr;
unsigned face_index = 0;
private:
mutable hb_face_t *face = nullptr;
hb_blob_t *blob = nullptr;
hb_face_t *face = nullptr;
};
face_options_t::cache_t face_options_t::cache {};
hb_blob_t *
face_options_t::get_blob () const
void
face_options_t::post_parse (GError **error)
{
// XXX This does the job for now; will move to post_parse.
return cache.blob;
}
hb_face_t *
face_options_t::get_face () const
{
if (face)
return face;
if (!font_file)
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
"No font file set");
assert (font_file);
@ -108,7 +95,8 @@ face_options_t::get_face () const
cache.font_path = g_strdup (font_path);
if (!cache.blob)
fail (false, "%s: Failed reading file", font_path);
g_set_error (error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED,
"%s: Failed reading file", font_path);
hb_face_destroy (cache.face);
cache.face = nullptr;
@ -122,9 +110,8 @@ face_options_t::get_face () const
cache.face_index = face_index;
}
blob = cache.blob;
face = cache.face;
return face;
}
void

View File

@ -86,8 +86,6 @@ font_options_t::get_font () const
if (font)
return font;
auto *face = get_face ();
font = hb_font_create (face);
if (font_size_x == FONT_SIZE_UPEM)

View File

@ -49,7 +49,7 @@ struct subset_consumer_t : subset_options_t, output_options_t
void init (const face_options_t *face_opts)
{
face = hb_face_reference (face_opts->get_face ());
face = hb_face_reference (face_opts->face);
}
void consume_line (const char *text,

View File

@ -97,7 +97,7 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
}
unsigned int blob_length;
const char *blob_data = hb_blob_get_data (font_opts->get_blob (), &blob_length);
const char *blob_data = hb_blob_get_data (font_opts->blob, &blob_length);
if (FT_New_Memory_Face (ft_library,
(const FT_Byte *) blob_data,