From 9f7538c2606d330f64bed5e71d7676195bb74975 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sun, 25 Dec 2022 13:46:37 -0700 Subject: [PATCH] [hb-cairo] Change API --- src/hb-cairo.c | 46 ++++++++++++-------------------------------- src/hb-cairo.h | 9 ++++----- util/helper-cairo.hh | 23 ++++++++++------------ 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/src/hb-cairo.c b/src/hb-cairo.c index 4fb970111..cfd577c34 100644 --- a/src/hb-cairo.c +++ b/src/hb-cairo.c @@ -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); } diff --git a/src/hb-cairo.h b/src/hb-cairo.h index e9002e0d7..53f4b84b7 100644 --- a/src/hb-cairo.h +++ b/src/hb-cairo.h @@ -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 diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh index 4dec3f3d1..16cbf0259 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -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) ||