[paint] Overlay custom-palette on top of chosen palette
Got to agree this is more ergonomic.
diff --git a/src/OT/Color/COLR/COLR.hh b/src/OT/Color/COLR/COLR.hh
index 1409284..6a2fedd 100644
--- a/src/OT/Color/COLR/COLR.hh
+++ b/src/OT/Color/COLR/COLR.hh
@@ -97,15 +97,13 @@
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 15f804a..c760311 100644
--- a/src/hb-cairo.cc
+++ b/src/hb-cairo.cc
@@ -306,10 +306,11 @@
_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 @@
&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 ccd93f3..f2127c2 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -1440,8 +1440,7 @@
*
* 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 73f0463..b345793 100644
--- a/src/hb-ft-colr.hh
+++ b/src/hb-ft-colr.hh
@@ -156,9 +156,9 @@
(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_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 21229c4..9fcff5f 100644
--- a/src/hb-paint.cc
+++ b/src/hb-paint.cc
@@ -117,10 +117,11 @@
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 @@
*
* 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 d4d831e..5f63b0a 100644
--- a/src/hb-paint.h
+++ b/src/hb-paint.h
@@ -35,17 +35,6 @@
/**
- * 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:
*
* Glyph paint callbacks.
@@ -680,10 +669,11 @@
* 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_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 b31a0cf..c4789cf 100644
--- a/src/hb-paint.hh
+++ b/src/hb-paint.hh
@@ -138,10 +138,12 @@
{ 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 a066d68..ca7f469 100644
--- a/util/helper-cairo.hh
+++ b/util/helper-cairo.hh
@@ -124,24 +124,22 @@
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,