diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh index 140928406..6a2fedd41 100644 --- a/src/OT/Color/COLR/COLR.hh +++ b/src/OT/Color/COLR/COLR.hh @@ -97,15 +97,13 @@ public: if (color_index != 0xffff) { - if (palette_index != HB_PAINT_PALETTE_INDEX_CUSTOM) + if (!funcs->custom_palette_color (data, color_index, &color)) { unsigned int clen = 1; hb_face_t *face = hb_font_get_face (font); hb_ot_color_palette_get_colors (face, palette_index, color_index, &clen, &color); } - else - color = funcs->custom_palette_color (data, color_index); *is_foreground = false; } diff --git a/src/hb-cairo.cc b/src/hb-cairo.cc index 15f804a73..c760311a5 100644 --- a/src/hb-cairo.cc +++ b/src/hb-cairo.cc @@ -306,10 +306,11 @@ hb_cairo_paint_sweep_gradient (hb_paint_funcs_t *pfuncs HB_UNUSED, _hb_cairo_paint_sweep_gradient (cr, color_line, x0, y0, start_angle, end_angle); } -static hb_color_t +static hb_bool_t hb_cairo_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, + hb_color_t *color, void *user_data HB_UNUSED) { #ifdef CAIRO_COLOR_PALETTE_CUSTOM @@ -324,12 +325,13 @@ hb_cairo_paint_custom_palette_color (hb_paint_funcs_t *funcs, &red, &green, &blue, &alpha)) { cairo_font_options_destroy (options); - return HB_COLOR (255 * blue, 255 * green, 255 * red, 255 * alpha); + *color = HB_COLOR (255 * blue, 255 * green, 255 * red, 255 * alpha); + return true; } cairo_font_options_destroy (options); #endif - return HB_COLOR (0, 0, 0, 0); + return false; } static inline void free_static_cairo_paint_funcs (); diff --git a/src/hb-font.cc b/src/hb-font.cc index ccd93f3d5..f2127c2b1 100644 --- a/src/hb-font.cc +++ b/src/hb-font.cc @@ -1440,8 +1440,7 @@ hb_font_draw_glyph (hb_font_t *font, * * If the font has color palettes (see hb_ot_color_has_palettes()), * then @palette_index selects the palette to use. If the font only - * has one palette, this will be 0. Use %HB_PAINT_PALETTE_INDEX_CUSTOM - * for custom palette. + * has one palette, this will be 0. * * Since: REPLACEME */ diff --git a/src/hb-ft-colr.hh b/src/hb-ft-colr.hh index 73f046385..b3457933c 100644 --- a/src/hb-ft-colr.hh +++ b/src/hb-ft-colr.hh @@ -156,9 +156,9 @@ _hb_ft_color_line_get_color_stops (hb_color_line_t *color_line, (hb_color_get_alpha (c->foreground) * stop.color.alpha) >> 14); else { - if (c->palette_index == HB_PAINT_PALETTE_INDEX_CUSTOM) + hb_color_t color; + if (c->funcs->custom_palette_color (c->data, stop.color.palette_index, &color)) { - hb_color_t color = c->funcs->custom_palette_color (c->data, stop.color.palette_index); color_stops->color = HB_COLOR (hb_color_get_blue (color), hb_color_get_green (color), hb_color_get_red (color), @@ -237,9 +237,8 @@ _hb_ft_paint (hb_ft_paint_context_t *c, (hb_color_get_alpha (c->foreground) * paint.u.solid.color.alpha) >> 14); else { - if (c->palette_index == HB_PAINT_PALETTE_INDEX_CUSTOM) + if (c->funcs->custom_palette_color (c->data, paint.u.solid.color.palette_index, &color)) { - color = c->funcs->custom_palette_color (c->data, paint.u.solid.color.palette_index); color = HB_COLOR (hb_color_get_blue (color), hb_color_get_green (color), hb_color_get_red (color), diff --git a/src/hb-paint.cc b/src/hb-paint.cc index 21229c49e..9fcff5f79 100644 --- a/src/hb-paint.cc +++ b/src/hb-paint.cc @@ -117,10 +117,11 @@ hb_paint_pop_group_nil (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode, void *user_data) {} -static hb_color_t +static hb_bool_t hb_paint_custom_palette_color_nil (hb_paint_funcs_t *funcs, void *paint_data, unsigned int color_index, - void *user_data) { return HB_COLOR(0,0,0,0); } + hb_color_t *color, + void *user_data) { return false; } static bool _hb_paint_funcs_set_preamble (hb_paint_funcs_t *funcs, @@ -690,11 +691,12 @@ hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data, * * Since: REPLACEME */ -hb_color_t +hb_bool_t hb_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data, - unsigned int color_index) + unsigned int color_index, + hb_color_t *color) { - return funcs->custom_palette_color (paint_data, color_index); + return funcs->custom_palette_color (paint_data, color_index, color); } #endif diff --git a/src/hb-paint.h b/src/hb-paint.h index d4d831e57..5f63b0a4b 100644 --- a/src/hb-paint.h +++ b/src/hb-paint.h @@ -34,17 +34,6 @@ HB_BEGIN_DECLS -/** - * HB_PAINT_PALETTE_INDEX_CUSTOM - * - * A palette index signifying that custom colors are in use. - * Such colors are fetched from the client using the - * custom-palette-color callback of the paint functions. - * - * Since: REPLACEME - **/ -#define HB_PAINT_PALETTE_INDEX_CUSTOM 0xFFFFFFFF - /** * hb_paint_funcs_t: * @@ -680,10 +669,11 @@ typedef void (*hb_paint_pop_group_func_t) (hb_paint_funcs_t *funcs, * Return value: the color * Since: REPLACEME */ -typedef hb_color_t (*hb_paint_custom_palette_color_func_t) (hb_paint_funcs_t *funcs, - void *paint_data, - unsigned int color_index, - void *user_data); +typedef hb_bool_t (*hb_paint_custom_palette_color_func_t) (hb_paint_funcs_t *funcs, + void *paint_data, + unsigned int color_index, + hb_color_t *color, + void *user_data); /** @@ -974,9 +964,10 @@ HB_EXTERN void hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data, hb_paint_composite_mode_t mode); -HB_EXTERN hb_color_t +HB_EXTERN hb_bool_t hb_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data, - unsigned int color_index); + unsigned int color_index, + hb_color_t *color); HB_END_DECLS diff --git a/src/hb-paint.hh b/src/hb-paint.hh index b31a0cfc0..c4789cf9b 100644 --- a/src/hb-paint.hh +++ b/src/hb-paint.hh @@ -138,10 +138,12 @@ struct hb_paint_funcs_t { func.pop_group (this, paint_data, mode, !user_data ? nullptr : user_data->pop_group); } - hb_color_t custom_palette_color (void *paint_data, - unsigned int color_index) + bool custom_palette_color (void *paint_data, + unsigned int color_index, + hb_color_t *color) { return func.custom_palette_color (this, paint_data, color_index, + color, !user_data ? nullptr : user_data->custom_palette_color); } diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh index a066d6807..ca7f469c1 100644 --- a/util/helper-cairo.hh +++ b/util/helper-cairo.hh @@ -124,24 +124,22 @@ helper_cairo_create_scaled_font (const font_options_t *font_opts, 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 - unsigned palette_index = view_opts->palette; + cairo_font_options_set_color_palette (font_options, view_opts->palette); +#endif #ifdef CAIRO_COLOR_PALETTE_CUSTOM if (view_opts->custom_palette) { - palette_index = HB_PAINT_PALETTE_INDEX_CUSTOM; char **entries = g_strsplit (view_opts->custom_palette, ",", -1); for (unsigned i = 0; entries[i]; i++) { unsigned fr, fg, fb, fa; fr = fg = fb = fa = 0; - parse_color (entries[i], fr, fg,fb, fa); - cairo_font_options_set_custom_palette_color (font_options, i, fr / 255., fg / 255., fb / 255., fa / 255.); + if (parse_color (entries[i], fr, fg,fb, fa)) + cairo_font_options_set_custom_palette_color (font_options, i, fr / 255., fg / 255., fb / 255., fa / 255.); } g_strfreev (entries); } #endif - cairo_font_options_set_color_palette (font_options, palette_index); -#endif cairo_scaled_font_t *scaled_font = cairo_scaled_font_create (cairo_face, &font_matrix,