[hb-cairo] Change API

This commit is contained in:
Behdad Esfahbod 2022-12-25 13:46:37 -07:00
parent 0d6ee4621e
commit 9f7538c260
3 changed files with 26 additions and 52 deletions

View File

@ -386,47 +386,25 @@ user_font_face_create (hb_font_t *font)
return cairo_face;
}
cairo_scaled_font_t *
hb_cairo_scaled_font_create (hb_font_t *font,
unsigned int palette)
cairo_font_face_t *
hb_cairo_font_face_create (hb_face_t *face)
{
cairo_font_face_t *cairo_face;
cairo_matrix_t ctm, font_matrix;
int x_scale, y_scale;
cairo_font_options_t *font_options;
cairo_scaled_font_t *scaled_font;
hb_font_t *font = hb_font_create (face);
cairo_face = user_font_face_create (font);
hb_font_get_scale (font, &x_scale, &y_scale);
cairo_matrix_init_identity (&ctm);
cairo_matrix_init_scale (&font_matrix, x_scale, y_scale);
hb_font_destroy (font);
font_options = cairo_font_options_create ();
cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE);
cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF);
#ifdef CAIRO_COLOR_PALETTE_DEFAULT
cairo_font_options_set_color_palette (font_options, palette);
#endif
scaled_font = cairo_scaled_font_create (cairo_face,
&font_matrix,
&ctm,
font_options);
cairo_font_options_destroy (font_options);
cairo_font_face_destroy (cairo_face);
return scaled_font;
return cairo_face;
}
hb_font_t *
hb_cairo_scaled_font_get_font (cairo_scaled_font_t *scaled_font)
hb_face_t *
hb_cairo_font_face_get_face (cairo_font_face_t *font_face)
{
cairo_font_face_t *font_face;
font_face = cairo_scaled_font_get_font_face (scaled_font);
return (hb_font_t *) cairo_font_face_get_user_data (font_face, &hb_cairo_font_user_data_key);
hb_font_t *font = cairo_font_face_get_user_data (font_face, &hb_cairo_font_user_data_key);
if (!font)
return NULL;
return hb_font_get_face (font);
}

View File

@ -32,12 +32,11 @@
HB_BEGIN_DECLS
HB_EXTERN cairo_scaled_font_t *
hb_cairo_scaled_font_create (hb_font_t *font,
unsigned int palette);
HB_EXTERN cairo_font_face_t *
hb_cairo_font_face_create (hb_face_t *face);
HB_EXTERN hb_font_t *
hb_cairo_scaled_font_get_font (cairo_scaled_font_t *scaled_font);
HB_EXTERN hb_face_t *
hb_cairo_font_face_get_face (cairo_font_face_t *font_face);
HB_END_DECLS

View File

@ -97,16 +97,14 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
use_hb_draw = helper_cairo_use_hb_draw (font_opts);
#endif
if (use_hb_draw)
{
hb_font_set_scale (font, font_opts->font_size_x, font_opts->font_size_y);
hb_font_set_synthetic_slant (font, font_opts->slant);
return hb_cairo_scaled_font_create (font, font_opts->palette);
}
#ifdef HAVE_CAIRO_FT
cairo_font_face_t *cairo_face;
cairo_face = helper_cairo_create_ft_font_face (font_opts);
if (use_hb_draw)
cairo_face = hb_cairo_font_face_create (hb_font_get_face (font));
#ifdef HAVE_CAIRO_FT
else
cairo_face = helper_cairo_create_ft_font_face (font_opts);
#endif
cairo_matrix_t ctm, font_matrix;
cairo_font_options_t *font_options;
@ -135,23 +133,22 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts)
static cairo_user_data_key_t key;
if (cairo_scaled_font_set_user_data (scaled_font,
&key,
(void *) font,
(void *) hb_font_reference (font),
(cairo_destroy_func_t) hb_font_destroy))
hb_font_destroy (font);
return scaled_font;
#endif
}
static inline bool
helper_cairo_scaled_font_has_color (cairo_scaled_font_t *scaled_font)
{
hb_face_t *face = hb_cairo_font_face_get_face (cairo_scaled_font_get_font_face (scaled_font));
#ifdef HAVE_CAIRO_FT
if (!hb_cairo_scaled_font_get_font (scaled_font))
if (!face)
return helper_cairo_ft_scaled_font_has_color (scaled_font);
#endif
hb_font_t *font = hb_cairo_scaled_font_get_font (scaled_font);
hb_face_t *face = hb_font_get_face (font);
return hb_ot_color_has_png (face) ||
hb_ot_color_has_layers (face) ||