blob: 9e7927ac0ab7db781d6f10094d49e3f43a7f8e74 [file] [log] [blame]
Matthias Clasen83d0a492022-12-13 21:14:25 -05001/*
2 * Copyright © 2022 Matthias Clasen
3 *
4 * This is part of HarfBuzz, a text shaping library.
5 *
6 * Permission is hereby granted, without written agreement and without
7 * license or royalty fees, to use, copy, modify, and distribute this
8 * software and its documentation for any purpose, provided that the
9 * above copyright notice and the following two paragraphs appear in
10 * all copies of this software.
11 *
12 * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15 * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16 * DAMAGE.
17 *
18 * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21 * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 */
24
25#ifndef HB_PAINT_HH
26#define HB_PAINT_HH
27
28#include "hb.hh"
Behdad Esfahbod4b0285b2022-12-17 11:18:42 -070029#include "hb-face.hh"
30#include "hb-font.hh"
Matthias Clasen83d0a492022-12-13 21:14:25 -050031
32#define HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS \
33 HB_PAINT_FUNC_IMPLEMENT (push_transform) \
34 HB_PAINT_FUNC_IMPLEMENT (pop_transform) \
Matthias Clasenc9350832022-12-14 22:32:40 -050035 HB_PAINT_FUNC_IMPLEMENT (push_clip_glyph) \
Matthias Clasen485ba9b2022-12-17 12:25:04 -050036 HB_PAINT_FUNC_IMPLEMENT (push_clip_rectangle) \
Matthias Clasen83d0a492022-12-13 21:14:25 -050037 HB_PAINT_FUNC_IMPLEMENT (pop_clip) \
Matthias Clasen0d890062022-12-17 00:07:30 -050038 HB_PAINT_FUNC_IMPLEMENT (color) \
Matthias Clasen82e23f32022-12-17 00:33:59 -050039 HB_PAINT_FUNC_IMPLEMENT (image) \
Matthias Clasen83d0a492022-12-13 21:14:25 -050040 HB_PAINT_FUNC_IMPLEMENT (linear_gradient) \
41 HB_PAINT_FUNC_IMPLEMENT (radial_gradient) \
42 HB_PAINT_FUNC_IMPLEMENT (sweep_gradient) \
43 HB_PAINT_FUNC_IMPLEMENT (push_group) \
Matthias Clasen627c8572022-12-14 22:36:54 -050044 HB_PAINT_FUNC_IMPLEMENT (pop_group) \
Matthias Clasen83d0a492022-12-13 21:14:25 -050045 /* ^--- Add new callbacks here */
46
47struct hb_paint_funcs_t
48{
49 hb_object_header_t header;
50
51 struct {
52#define HB_PAINT_FUNC_IMPLEMENT(name) hb_paint_##name##_func_t name;
53 HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS
54#undef HB_PAINT_FUNC_IMPLEMENT
55 } func;
56
57 struct {
58#define HB_PAINT_FUNC_IMPLEMENT(name) void *name;
59 HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS
60#undef HB_PAINT_FUNC_IMPLEMENT
61 } *user_data;
62
63 struct {
64#define HB_PAINT_FUNC_IMPLEMENT(name) hb_destroy_func_t name;
65 HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS
66#undef HB_PAINT_FUNC_IMPLEMENT
67 } *destroy;
68
69 void push_transform (void *paint_data,
Matthias Clasen64f1b552022-12-14 23:58:25 -050070 float xx, float yx,
71 float xy, float yy,
72 float dx, float dy)
Matthias Clasen83d0a492022-12-13 21:14:25 -050073 { func.push_transform (this, paint_data,
Matthias Clasen64f1b552022-12-14 23:58:25 -050074 xx, yx, xy, yy, dx, dy,
Matthias Clasen83d0a492022-12-13 21:14:25 -050075 !user_data ? nullptr : user_data->push_transform); }
76 void pop_transform (void *paint_data)
77 { func.pop_transform (this, paint_data,
78 !user_data ? nullptr : user_data->pop_transform); }
Matthias Clasenc9350832022-12-14 22:32:40 -050079 void push_clip_glyph (void *paint_data,
80 hb_codepoint_t glyph)
81 { func.push_clip_glyph (this, paint_data,
82 glyph,
83 !user_data ? nullptr : user_data->push_clip_glyph); }
Matthias Clasen485ba9b2022-12-17 12:25:04 -050084 void push_clip_rectangle (void *paint_data,
85 float xmin, float ymin, float xmax, float ymax)
86 { func.push_clip_rectangle (this, paint_data,
87 xmin, ymin, xmax, ymax,
88 !user_data ? nullptr : user_data->push_clip_rectangle); }
Matthias Clasen83d0a492022-12-13 21:14:25 -050089 void pop_clip (void *paint_data)
90 { func.pop_clip (this, paint_data,
91 !user_data ? nullptr : user_data->pop_clip); }
Matthias Clasen0d890062022-12-17 00:07:30 -050092 void color (void *paint_data,
Matthias Clasenc9350832022-12-14 22:32:40 -050093 unsigned int color_index,
94 float alpha)
Matthias Clasen0d890062022-12-17 00:07:30 -050095 { func.color (this, paint_data,
Matthias Clasenc9350832022-12-14 22:32:40 -050096 color_index, alpha,
Matthias Clasen0d890062022-12-17 00:07:30 -050097 !user_data ? nullptr : user_data->color); }
Matthias Clasen82e23f32022-12-17 00:33:59 -050098 void image (void *paint_data,
Matthias Clasen37f3f0f2022-12-17 11:49:18 -050099 hb_blob_t *image,
Matthias Clasen0a2f3672022-12-17 13:51:23 -0500100 hb_tag_t format,
Matthias Clasen37f3f0f2022-12-17 11:49:18 -0500101 hb_glyph_extents_t *extents)
Matthias Clasen82e23f32022-12-17 00:33:59 -0500102 { func.image (this, paint_data,
Matthias Clasen0a2f3672022-12-17 13:51:23 -0500103 image, format, extents,
Matthias Clasen82e23f32022-12-17 00:33:59 -0500104 !user_data ? nullptr : user_data->image); }
Matthias Clasen83d0a492022-12-13 21:14:25 -0500105 void linear_gradient (void *paint_data,
106 hb_color_line_t *color_line,
Matthias Clasenc9350832022-12-14 22:32:40 -0500107 float x0, float y0,
108 float x1, float y1,
109 float x2, float y2)
Matthias Clasen83d0a492022-12-13 21:14:25 -0500110 { func.linear_gradient (this, paint_data,
111 color_line, x0, y0, x1, y1, x2, y2,
112 !user_data ? nullptr : user_data->linear_gradient); }
113 void radial_gradient (void *paint_data,
114 hb_color_line_t *color_line,
Matthias Clasenc9350832022-12-14 22:32:40 -0500115 float x0, float y0, float r0,
116 float x1, float y1, float r1)
Matthias Clasen83d0a492022-12-13 21:14:25 -0500117 { func.radial_gradient (this, paint_data,
118 color_line, x0, y0, r0, x1, y1, r1,
119 !user_data ? nullptr : user_data->radial_gradient); }
120 void sweep_gradient (void *paint_data,
121 hb_color_line_t *color_line,
Matthias Clasenc9350832022-12-14 22:32:40 -0500122 float x0, float y0,
Matthias Clasen83d0a492022-12-13 21:14:25 -0500123 float start_angle,
124 float end_angle)
125 { func.sweep_gradient (this, paint_data,
126 color_line, x0, y0, start_angle, end_angle,
127 !user_data ? nullptr : user_data->sweep_gradient); }
128 void push_group (void *paint_data)
129 { func.push_group (this, paint_data,
130 !user_data ? nullptr : user_data->push_group); }
Matthias Clasen627c8572022-12-14 22:36:54 -0500131 void pop_group (void *paint_data,
132 hb_paint_composite_mode_t mode)
133 { func.pop_group (this, paint_data,
134 mode,
135 !user_data ? nullptr : user_data->pop_group); }
Matthias Clasen83d0a492022-12-13 21:14:25 -0500136
Matthias Clasen686e6272022-12-17 12:44:16 -0500137 void push_root_transform (void *paint_data,
138 hb_font_t *font)
139 {
Behdad Esfahbod4b0285b2022-12-17 11:18:42 -0700140 int xscale = font->x_scale, yscale = font->y_scale;
141 float upem = font->face->get_upem ();
142 float slant = font->slant_xy;
143
Matthias Clasena935e4b2022-12-17 12:59:58 -0500144 func.push_transform (this, paint_data, xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0,
Behdad Esfahbod4b0285b2022-12-17 11:18:42 -0700145 !user_data ? nullptr : user_data->push_transform);
146 }
Matthias Clasen686e6272022-12-17 12:44:16 -0500147 void pop_root_transform (void *paint_data)
Behdad Esfahbod4b0285b2022-12-17 11:18:42 -0700148 {
149 func.pop_transform (this, paint_data,
150 !user_data ? nullptr : user_data->pop_transform);
151 }
Matthias Clasen83d0a492022-12-13 21:14:25 -0500152};
153DECLARE_NULL_INSTANCE (hb_paint_funcs_t);
154
155#endif /* HB_PAINT_HH */