[paint] Overlay custom-palette on top of chosen palette
Got to agree this is more ergonomic.
This commit is contained in:
parent
03e2e58642
commit
638e0ed4fd
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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); }
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue