[util] Use post_parse in font_options_t

This commit is contained in:
Behdad Esfahbod 2021-08-11 18:47:06 -06:00
parent e0d7060f80
commit 24a9d8c78d
6 changed files with 10 additions and 15 deletions

View File

@ -51,7 +51,7 @@ struct font_options_t : face_options_t
void add_options (option_parser_t *parser); void add_options (option_parser_t *parser);
hb_font_t *get_font () const; void post_parse (GError **error);
hb_variation_t *variations = nullptr; hb_variation_t *variations = nullptr;
unsigned int num_variations = 0; unsigned int num_variations = 0;
@ -64,8 +64,7 @@ struct font_options_t : face_options_t
char *font_funcs = nullptr; char *font_funcs = nullptr;
int ft_load_flags = 2; int ft_load_flags = 2;
private: hb_font_t *font = nullptr;
mutable hb_font_t *font = nullptr;
}; };
@ -80,12 +79,10 @@ static struct supported_font_funcs_t {
{"ot", hb_ot_font_set_funcs}, {"ot", hb_ot_font_set_funcs},
}; };
hb_font_t *
font_options_t::get_font () const
{
if (font)
return font;
void
font_options_t::post_parse (GError **error)
{
font = hb_font_create (face); font = hb_font_create (face);
if (font_size_x == FONT_SIZE_UPEM) if (font_size_x == FONT_SIZE_UPEM)
@ -137,8 +134,6 @@ font_options_t::get_font () const
#ifdef HAVE_FREETYPE #ifdef HAVE_FREETYPE
hb_ft_font_set_load_flags (font, ft_load_flags); hb_ft_font_set_load_flags (font, ft_load_flags);
#endif #endif
return font;
} }

View File

@ -57,7 +57,7 @@ struct shape_closure_consumer_t
void init (const font_options_t *font_opts) void init (const font_options_t *font_opts)
{ {
glyphs = hb_set_create (); glyphs = hb_set_create ();
font = hb_font_reference (font_opts->get_font ()); font = hb_font_reference (font_opts->font);
failed = false; failed = false;
buffer = hb_buffer_create (); buffer = hb_buffer_create ();
} }

View File

@ -49,7 +49,7 @@ struct output_buffer_t : output_options_t
get_file_handle (); get_file_handle ();
gs = g_string_new (nullptr); gs = g_string_new (nullptr);
line_no = 0; line_no = 0;
font = hb_font_reference (font_opts->get_font ()); font = hb_font_reference (font_opts->font);
if (!output_format) if (!output_format)
serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT;

View File

@ -79,7 +79,7 @@ void free_ft_library ()
static inline cairo_scaled_font_t * static inline cairo_scaled_font_t *
helper_cairo_create_scaled_font (const font_options_t *font_opts) helper_cairo_create_scaled_font (const font_options_t *font_opts)
{ {
hb_font_t *font = hb_font_reference (font_opts->get_font ()); hb_font_t *font = hb_font_reference (font_opts->font);
cairo_font_face_t *cairo_face; cairo_font_face_t *cairo_face;
/* We cannot use the FT_Face from hb_font_t, as doing so will confuse hb_font_t because /* We cannot use the FT_Face from hb_font_t, as doing so will confuse hb_font_t because

View File

@ -42,7 +42,7 @@ struct shape_consumer_t : shape_options_t
void init (const font_options_t *font_opts) void init (const font_options_t *font_opts)
{ {
font = hb_font_reference (font_opts->get_font ()); font = hb_font_reference (font_opts->font);
failed = false; failed = false;
buffer = hb_buffer_create (); buffer = hb_buffer_create ();

View File

@ -100,7 +100,7 @@ view_cairo_t::render (const font_options_t *font_opts)
int x_sign = font_opts->font_size_x < 0 ? -1 : +1; int x_sign = font_opts->font_size_x < 0 ? -1 : +1;
int y_sign = font_opts->font_size_y < 0 ? -1 : +1; int y_sign = font_opts->font_size_y < 0 ? -1 : +1;
hb_font_t *font = font_opts->get_font(); hb_font_t *font = font_opts->font;
if (!have_font_extents) if (!have_font_extents)
{ {