2022-12-14 03:14:25 +01:00
|
|
|
/*
|
|
|
|
* Copyright © 2022 Matthias Clasen
|
|
|
|
*
|
|
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, without written agreement and without
|
|
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
|
|
* software and its documentation for any purpose, provided that the
|
|
|
|
* above copyright notice and the following two paragraphs appear in
|
|
|
|
* all copies of this software.
|
|
|
|
*
|
|
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
|
|
* DAMAGE.
|
|
|
|
*
|
|
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HB_PAINT_HH
|
|
|
|
#define HB_PAINT_HH
|
|
|
|
|
|
|
|
#include "hb.hh"
|
2022-12-17 19:18:42 +01:00
|
|
|
#include "hb-face.hh"
|
|
|
|
#include "hb-font.hh"
|
2022-12-14 03:14:25 +01:00
|
|
|
|
|
|
|
#define HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS \
|
|
|
|
HB_PAINT_FUNC_IMPLEMENT (push_transform) \
|
|
|
|
HB_PAINT_FUNC_IMPLEMENT (pop_transform) \
|
2022-12-15 04:32:40 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (push_clip_glyph) \
|
2022-12-17 18:25:04 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (push_clip_rectangle) \
|
2022-12-14 03:14:25 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (pop_clip) \
|
2022-12-17 06:07:30 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (color) \
|
2022-12-17 06:33:59 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (image) \
|
2022-12-14 03:14:25 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (linear_gradient) \
|
|
|
|
HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \
|
|
|
|
HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \
|
|
|
|
HB_PAINT_FUNC_IMPLEMENT (push_group) \
|
2022-12-15 04:36:54 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (pop_group) \
|
2023-01-19 04:37:21 +01:00
|
|
|
HB_PAINT_FUNC_IMPLEMENT (custom_palette_color) \
|
2022-12-14 03:14:25 +01:00
|
|
|
/* ^--- Add new callbacks here */
|
|
|
|
|
|
|
|
struct hb_paint_funcs_t
|
|
|
|
{
|
|
|
|
hb_object_header_t header;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
#define HB_PAINT_FUNC_IMPLEMENT(name) hb_paint_##name##_func_t name;
|
|
|
|
HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS
|
|
|
|
#undef HB_PAINT_FUNC_IMPLEMENT
|
|
|
|
} func;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
#define HB_PAINT_FUNC_IMPLEMENT(name) void *name;
|
|
|
|
HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS
|
|
|
|
#undef HB_PAINT_FUNC_IMPLEMENT
|
|
|
|
} *user_data;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
#define HB_PAINT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
|
|
|
|
HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS
|
|
|
|
#undef HB_PAINT_FUNC_IMPLEMENT
|
|
|
|
} *destroy;
|
|
|
|
|
|
|
|
void push_transform (void *paint_data,
|
2022-12-15 05:58:25 +01:00
|
|
|
float xx, float yx,
|
|
|
|
float xy, float yy,
|
2022-12-21 22:43:19 +01:00
|
|
|
float dx, float dy)
|
2022-12-14 03:14:25 +01:00
|
|
|
{ func.push_transform (this, paint_data,
|
2022-12-15 05:58:25 +01:00
|
|
|
xx, yx, xy, yy, dx, dy,
|
2022-12-14 03:14:25 +01:00
|
|
|
!user_data ? nullptr : user_data->push_transform); }
|
2022-12-21 22:43:19 +01:00
|
|
|
void pop_transform (void *paint_data)
|
|
|
|
{ func.pop_transform (this, paint_data,
|
2022-12-14 03:14:25 +01:00
|
|
|
!user_data ? nullptr : user_data->pop_transform); }
|
2022-12-15 04:32:40 +01:00
|
|
|
void push_clip_glyph (void *paint_data,
|
2022-12-21 08:11:36 +01:00
|
|
|
hb_codepoint_t glyph,
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_font_t *font)
|
2022-12-15 04:32:40 +01:00
|
|
|
{ func.push_clip_glyph (this, paint_data,
|
|
|
|
glyph,
|
2022-12-21 22:43:19 +01:00
|
|
|
font,
|
2022-12-15 04:32:40 +01:00
|
|
|
!user_data ? nullptr : user_data->push_clip_glyph); }
|
2022-12-17 18:25:04 +01:00
|
|
|
void push_clip_rectangle (void *paint_data,
|
2022-12-21 22:43:19 +01:00
|
|
|
float xmin, float ymin, float xmax, float ymax)
|
2022-12-17 18:25:04 +01:00
|
|
|
{ func.push_clip_rectangle (this, paint_data,
|
|
|
|
xmin, ymin, xmax, ymax,
|
|
|
|
!user_data ? nullptr : user_data->push_clip_rectangle); }
|
2022-12-21 22:43:19 +01:00
|
|
|
void pop_clip (void *paint_data)
|
|
|
|
{ func.pop_clip (this, paint_data,
|
2022-12-14 03:14:25 +01:00
|
|
|
!user_data ? nullptr : user_data->pop_clip); }
|
2022-12-17 06:07:30 +01:00
|
|
|
void color (void *paint_data,
|
2022-12-22 00:39:27 +01:00
|
|
|
hb_bool_t is_foreground,
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_color_t color)
|
2022-12-17 06:07:30 +01:00
|
|
|
{ func.color (this, paint_data,
|
2022-12-22 00:39:27 +01:00
|
|
|
is_foreground, color,
|
2022-12-17 06:07:30 +01:00
|
|
|
!user_data ? nullptr : user_data->color); }
|
2022-12-24 18:56:06 +01:00
|
|
|
bool image (void *paint_data,
|
2022-12-17 17:49:18 +01:00
|
|
|
hb_blob_t *image,
|
2022-12-22 20:16:55 +01:00
|
|
|
unsigned width, unsigned height,
|
2022-12-17 19:51:23 +01:00
|
|
|
hb_tag_t format,
|
2022-12-22 16:12:47 +01:00
|
|
|
float slant,
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_glyph_extents_t *extents)
|
2022-12-24 18:56:06 +01:00
|
|
|
{ return func.image (this, paint_data,
|
|
|
|
image, width, height, format, slant, extents,
|
|
|
|
!user_data ? nullptr : user_data->image); }
|
2022-12-14 03:14:25 +01:00
|
|
|
void linear_gradient (void *paint_data,
|
|
|
|
hb_color_line_t *color_line,
|
2022-12-15 04:32:40 +01:00
|
|
|
float x0, float y0,
|
|
|
|
float x1, float y1,
|
2022-12-21 22:43:19 +01:00
|
|
|
float x2, float y2)
|
2022-12-14 03:14:25 +01:00
|
|
|
{ func.linear_gradient (this, paint_data,
|
|
|
|
color_line, x0, y0, x1, y1, x2, y2,
|
|
|
|
!user_data ? nullptr : user_data->linear_gradient); }
|
|
|
|
void radial_gradient (void *paint_data,
|
|
|
|
hb_color_line_t *color_line,
|
2022-12-15 04:32:40 +01:00
|
|
|
float x0, float y0, float r0,
|
2022-12-21 22:43:19 +01:00
|
|
|
float x1, float y1, float r1)
|
2022-12-14 03:14:25 +01:00
|
|
|
{ func.radial_gradient (this, paint_data,
|
|
|
|
color_line, x0, y0, r0, x1, y1, r1,
|
|
|
|
!user_data ? nullptr : user_data->radial_gradient); }
|
|
|
|
void sweep_gradient (void *paint_data,
|
|
|
|
hb_color_line_t *color_line,
|
2022-12-15 04:32:40 +01:00
|
|
|
float x0, float y0,
|
2022-12-14 03:14:25 +01:00
|
|
|
float start_angle,
|
2022-12-21 22:43:19 +01:00
|
|
|
float end_angle)
|
2022-12-14 03:14:25 +01:00
|
|
|
{ func.sweep_gradient (this, paint_data,
|
|
|
|
color_line, x0, y0, start_angle, end_angle,
|
|
|
|
!user_data ? nullptr : user_data->sweep_gradient); }
|
2022-12-21 22:43:19 +01:00
|
|
|
void push_group (void *paint_data)
|
|
|
|
{ func.push_group (this, paint_data,
|
2022-12-14 03:14:25 +01:00
|
|
|
!user_data ? nullptr : user_data->push_group); }
|
2022-12-15 04:36:54 +01:00
|
|
|
void pop_group (void *paint_data,
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_paint_composite_mode_t mode)
|
2022-12-15 04:36:54 +01:00
|
|
|
{ func.pop_group (this, paint_data,
|
|
|
|
mode,
|
|
|
|
!user_data ? nullptr : user_data->pop_group); }
|
2023-01-20 21:01:22 +01:00
|
|
|
bool custom_palette_color (void *paint_data,
|
|
|
|
unsigned int color_index,
|
|
|
|
hb_color_t *color)
|
2023-01-19 04:37:21 +01:00
|
|
|
{ return func.custom_palette_color (this, paint_data,
|
|
|
|
color_index,
|
2023-01-20 21:01:22 +01:00
|
|
|
color,
|
2023-01-19 04:37:21 +01:00
|
|
|
!user_data ? nullptr : user_data->custom_palette_color); }
|
2022-12-14 03:14:25 +01:00
|
|
|
|
2022-12-31 19:12:02 +01:00
|
|
|
|
|
|
|
/* Internal specializations. */
|
|
|
|
|
2022-12-17 18:44:16 +01:00
|
|
|
void push_root_transform (void *paint_data,
|
2022-12-21 22:43:19 +01:00
|
|
|
const hb_font_t *font)
|
2022-12-17 18:44:16 +01:00
|
|
|
{
|
2022-12-17 19:18:42 +01:00
|
|
|
float upem = font->face->get_upem ();
|
2022-12-31 19:04:40 +01:00
|
|
|
int xscale = font->x_scale, yscale = font->y_scale;
|
2022-12-17 19:18:42 +01:00
|
|
|
float slant = font->slant_xy;
|
|
|
|
|
2022-12-31 19:12:02 +01:00
|
|
|
push_transform (paint_data,
|
|
|
|
xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0);
|
2022-12-21 08:11:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void push_inverse_root_transform (void *paint_data,
|
2022-12-21 22:43:19 +01:00
|
|
|
hb_font_t *font)
|
2022-12-21 08:11:36 +01:00
|
|
|
{
|
|
|
|
float upem = font->face->get_upem ();
|
2022-12-31 19:04:40 +01:00
|
|
|
int xscale = font->x_scale ? font->x_scale : upem;
|
|
|
|
int yscale = font->y_scale ? font->y_scale : upem;
|
2022-12-21 08:11:36 +01:00
|
|
|
float slant = font->slant_xy;
|
|
|
|
|
2022-12-31 19:12:02 +01:00
|
|
|
push_transform (paint_data,
|
|
|
|
upem/xscale, 0, -slant * upem/xscale, upem/yscale, 0, 0);
|
2022-12-17 19:18:42 +01:00
|
|
|
}
|
2022-12-31 19:24:42 +01:00
|
|
|
|
2022-12-31 22:49:41 +01:00
|
|
|
HB_NODISCARD
|
|
|
|
bool push_translate (void *paint_data,
|
2022-12-31 19:24:42 +01:00
|
|
|
float dx, float dy)
|
|
|
|
{
|
2022-12-31 22:49:41 +01:00
|
|
|
if (!dx && !dy)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
push_transform (paint_data,
|
|
|
|
1.f, 0.f, 0.f, 1.f, dx, dy);
|
|
|
|
return true;
|
2022-12-31 19:24:42 +01:00
|
|
|
}
|
2022-12-31 19:32:15 +01:00
|
|
|
|
2022-12-31 22:49:41 +01:00
|
|
|
HB_NODISCARD
|
|
|
|
bool push_scale (void *paint_data,
|
2022-12-31 19:32:15 +01:00
|
|
|
float sx, float sy)
|
|
|
|
{
|
2022-12-31 22:49:41 +01:00
|
|
|
if (sx == 1.f && sy == 1.f)
|
|
|
|
return false;
|
2022-12-31 19:35:39 +01:00
|
|
|
|
2022-12-31 22:49:41 +01:00
|
|
|
push_transform (paint_data,
|
|
|
|
sx, 0.f, 0.f, sy, 0.f, 0.f);
|
|
|
|
return true;
|
2022-12-31 19:35:39 +01:00
|
|
|
}
|
2022-12-31 22:49:41 +01:00
|
|
|
|
|
|
|
HB_NODISCARD
|
|
|
|
bool push_rotate (void *paint_data,
|
2022-12-31 19:35:39 +01:00
|
|
|
float a)
|
|
|
|
{
|
2022-12-31 22:49:41 +01:00
|
|
|
if (!a)
|
|
|
|
return false;
|
2022-12-31 19:40:12 +01:00
|
|
|
|
2023-03-14 19:41:46 +01:00
|
|
|
float cc = cosf (a * HB_PI);
|
|
|
|
float ss = sinf (a * HB_PI);
|
2022-12-31 22:49:41 +01:00
|
|
|
push_transform (paint_data, cc, ss, -ss, cc, 0.f, 0.f);
|
|
|
|
return true;
|
2022-12-31 19:40:12 +01:00
|
|
|
}
|
2022-12-31 22:49:41 +01:00
|
|
|
|
|
|
|
HB_NODISCARD
|
|
|
|
bool push_skew (void *paint_data,
|
2022-12-31 19:40:12 +01:00
|
|
|
float sx, float sy)
|
|
|
|
{
|
2022-12-31 22:49:41 +01:00
|
|
|
if (!sx && !sy)
|
|
|
|
return false;
|
|
|
|
|
2023-03-14 19:41:46 +01:00
|
|
|
float x = tanf (-sx * HB_PI);
|
|
|
|
float y = tanf (+sy * HB_PI);
|
2022-12-31 22:49:41 +01:00
|
|
|
push_transform (paint_data, 1.f, y, x, 1.f, 0.f, 0.f);
|
|
|
|
return true;
|
2022-12-31 19:40:12 +01:00
|
|
|
}
|
2022-12-14 03:14:25 +01:00
|
|
|
};
|
|
|
|
DECLARE_NULL_INSTANCE (hb_paint_funcs_t);
|
|
|
|
|
2022-12-21 22:18:46 +01:00
|
|
|
|
2022-12-14 03:14:25 +01:00
|
|
|
#endif /* HB_PAINT_HH */
|