Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 1 | /* |
| 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 Esfahbod | 4b0285b | 2022-12-17 11:18:42 -0700 | [diff] [blame] | 29 | #include "hb-face.hh" |
| 30 | #include "hb-font.hh" |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 31 | |
| 32 | #define HB_PAINT_FUNCS_IMPLEMENT_CALLBACKS \ |
| 33 | HB_PAINT_FUNC_IMPLEMENT (push_transform) \ |
| 34 | HB_PAINT_FUNC_IMPLEMENT (pop_transform) \ |
Matthias Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 35 | HB_PAINT_FUNC_IMPLEMENT (push_clip_glyph) \ |
Matthias Clasen | 485ba9b | 2022-12-17 12:25:04 -0500 | [diff] [blame] | 36 | HB_PAINT_FUNC_IMPLEMENT (push_clip_rectangle) \ |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 37 | HB_PAINT_FUNC_IMPLEMENT (pop_clip) \ |
Matthias Clasen | 0d89006 | 2022-12-17 00:07:30 -0500 | [diff] [blame] | 38 | HB_PAINT_FUNC_IMPLEMENT (color) \ |
Matthias Clasen | 82e23f3 | 2022-12-17 00:33:59 -0500 | [diff] [blame] | 39 | HB_PAINT_FUNC_IMPLEMENT (image) \ |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 40 | 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 Clasen | 627c857 | 2022-12-14 22:36:54 -0500 | [diff] [blame] | 44 | HB_PAINT_FUNC_IMPLEMENT (pop_group) \ |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 45 | /* ^--- Add new callbacks here */ |
| 46 | |
| 47 | struct 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 Clasen | 64f1b55 | 2022-12-14 23:58:25 -0500 | [diff] [blame] | 70 | float xx, float yx, |
| 71 | float xy, float yy, |
| 72 | float dx, float dy) |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 73 | { func.push_transform (this, paint_data, |
Matthias Clasen | 64f1b55 | 2022-12-14 23:58:25 -0500 | [diff] [blame] | 74 | xx, yx, xy, yy, dx, dy, |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 75 | !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 Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 79 | 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 Clasen | 485ba9b | 2022-12-17 12:25:04 -0500 | [diff] [blame] | 84 | 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 Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 89 | void pop_clip (void *paint_data) |
| 90 | { func.pop_clip (this, paint_data, |
| 91 | !user_data ? nullptr : user_data->pop_clip); } |
Matthias Clasen | 0d89006 | 2022-12-17 00:07:30 -0500 | [diff] [blame] | 92 | void color (void *paint_data, |
Matthias Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 93 | unsigned int color_index, |
| 94 | float alpha) |
Matthias Clasen | 0d89006 | 2022-12-17 00:07:30 -0500 | [diff] [blame] | 95 | { func.color (this, paint_data, |
Matthias Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 96 | color_index, alpha, |
Matthias Clasen | 0d89006 | 2022-12-17 00:07:30 -0500 | [diff] [blame] | 97 | !user_data ? nullptr : user_data->color); } |
Matthias Clasen | 82e23f3 | 2022-12-17 00:33:59 -0500 | [diff] [blame] | 98 | void image (void *paint_data, |
Matthias Clasen | 37f3f0f | 2022-12-17 11:49:18 -0500 | [diff] [blame] | 99 | hb_blob_t *image, |
Matthias Clasen | 0a2f367 | 2022-12-17 13:51:23 -0500 | [diff] [blame^] | 100 | hb_tag_t format, |
Matthias Clasen | 37f3f0f | 2022-12-17 11:49:18 -0500 | [diff] [blame] | 101 | hb_glyph_extents_t *extents) |
Matthias Clasen | 82e23f3 | 2022-12-17 00:33:59 -0500 | [diff] [blame] | 102 | { func.image (this, paint_data, |
Matthias Clasen | 0a2f367 | 2022-12-17 13:51:23 -0500 | [diff] [blame^] | 103 | image, format, extents, |
Matthias Clasen | 82e23f3 | 2022-12-17 00:33:59 -0500 | [diff] [blame] | 104 | !user_data ? nullptr : user_data->image); } |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 105 | void linear_gradient (void *paint_data, |
| 106 | hb_color_line_t *color_line, |
Matthias Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 107 | float x0, float y0, |
| 108 | float x1, float y1, |
| 109 | float x2, float y2) |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 110 | { 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 Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 115 | float x0, float y0, float r0, |
| 116 | float x1, float y1, float r1) |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 117 | { 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 Clasen | c935083 | 2022-12-14 22:32:40 -0500 | [diff] [blame] | 122 | float x0, float y0, |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 123 | 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 Clasen | 627c857 | 2022-12-14 22:36:54 -0500 | [diff] [blame] | 131 | 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 Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 136 | |
Matthias Clasen | 686e627 | 2022-12-17 12:44:16 -0500 | [diff] [blame] | 137 | void push_root_transform (void *paint_data, |
| 138 | hb_font_t *font) |
| 139 | { |
Behdad Esfahbod | 4b0285b | 2022-12-17 11:18:42 -0700 | [diff] [blame] | 140 | int xscale = font->x_scale, yscale = font->y_scale; |
| 141 | float upem = font->face->get_upem (); |
| 142 | float slant = font->slant_xy; |
| 143 | |
Matthias Clasen | a935e4b | 2022-12-17 12:59:58 -0500 | [diff] [blame] | 144 | func.push_transform (this, paint_data, xscale/upem, 0, slant * yscale/upem, yscale/upem, 0, 0, |
Behdad Esfahbod | 4b0285b | 2022-12-17 11:18:42 -0700 | [diff] [blame] | 145 | !user_data ? nullptr : user_data->push_transform); |
| 146 | } |
Matthias Clasen | 686e627 | 2022-12-17 12:44:16 -0500 | [diff] [blame] | 147 | void pop_root_transform (void *paint_data) |
Behdad Esfahbod | 4b0285b | 2022-12-17 11:18:42 -0700 | [diff] [blame] | 148 | { |
| 149 | func.pop_transform (this, paint_data, |
| 150 | !user_data ? nullptr : user_data->pop_transform); |
| 151 | } |
Matthias Clasen | 83d0a49 | 2022-12-13 21:14:25 -0500 | [diff] [blame] | 152 | }; |
| 153 | DECLARE_NULL_INSTANCE (hb_paint_funcs_t); |
| 154 | |
| 155 | #endif /* HB_PAINT_HH */ |