diff --git a/util/face-options.hh b/util/face-options.hh index 229c40e97..3ac366404 100644 --- a/util/face-options.hh +++ b/util/face-options.hh @@ -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 diff --git a/util/font-options.hh b/util/font-options.hh index 36bdd85f9..fd63a3ceb 100644 --- a/util/font-options.hh +++ b/util/font-options.hh @@ -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) diff --git a/util/hb-subset.cc b/util/hb-subset.cc index f9ecca173..6664ed48c 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -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, diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh index e219e646b..19651b23b 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -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,