/work/workdir/UnpackedTarball/harfbuzz/src/hb-paint-bounded.cc
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright © 2022 Behdad Esfahbod |
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 | | #include "hb.hh" |
26 | | |
27 | | #ifndef HB_NO_PAINT |
28 | | |
29 | | #include "hb-paint-bounded.hh" |
30 | | |
31 | | #include "hb-machinery.hh" |
32 | | |
33 | | |
34 | | /* |
35 | | * This file implements boundedness computation of COLRv1 fonts as described in: |
36 | | * |
37 | | * https://learn.microsoft.com/en-us/typography/opentype/spec/colr#glyph-metrics-and-boundedness |
38 | | */ |
39 | | |
40 | | static void |
41 | | hb_paint_bounded_push_clip_glyph (hb_paint_funcs_t *funcs HB_UNUSED, |
42 | | void *paint_data, |
43 | | hb_codepoint_t glyph, |
44 | | hb_font_t *font, |
45 | | void *user_data HB_UNUSED) |
46 | 0 | { |
47 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
48 | |
|
49 | 0 | c->push_clip (); |
50 | 0 | } |
51 | | |
52 | | static void |
53 | | hb_paint_bounded_push_clip_rectangle (hb_paint_funcs_t *funcs HB_UNUSED, |
54 | | void *paint_data, |
55 | | float xmin, float ymin, float xmax, float ymax, |
56 | | void *user_data) |
57 | 0 | { |
58 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
59 | |
|
60 | 0 | c->push_clip (); |
61 | 0 | } |
62 | | |
63 | | static void |
64 | | hb_paint_bounded_pop_clip (hb_paint_funcs_t *funcs HB_UNUSED, |
65 | | void *paint_data, |
66 | | void *user_data HB_UNUSED) |
67 | 0 | { |
68 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
69 | |
|
70 | 0 | c->pop_clip (); |
71 | 0 | } |
72 | | |
73 | | static void |
74 | | hb_paint_bounded_push_group (hb_paint_funcs_t *funcs HB_UNUSED, |
75 | | void *paint_data, |
76 | | void *user_data HB_UNUSED) |
77 | 0 | { |
78 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
79 | |
|
80 | 0 | c->push_group (); |
81 | 0 | } |
82 | | |
83 | | static void |
84 | | hb_paint_bounded_pop_group (hb_paint_funcs_t *funcs HB_UNUSED, |
85 | | void *paint_data, |
86 | | hb_paint_composite_mode_t mode, |
87 | | void *user_data HB_UNUSED) |
88 | 0 | { |
89 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
90 | |
|
91 | 0 | c->pop_group (mode); |
92 | 0 | } |
93 | | |
94 | | static hb_bool_t |
95 | | hb_paint_bounded_paint_image (hb_paint_funcs_t *funcs HB_UNUSED, |
96 | | void *paint_data, |
97 | | hb_blob_t *blob HB_UNUSED, |
98 | | unsigned int width HB_UNUSED, |
99 | | unsigned int height HB_UNUSED, |
100 | | hb_tag_t format HB_UNUSED, |
101 | | float slant HB_UNUSED, |
102 | | hb_glyph_extents_t *glyph_extents, |
103 | | void *user_data HB_UNUSED) |
104 | 0 | { |
105 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
106 | |
|
107 | 0 | c->push_clip (); |
108 | 0 | c->paint (); |
109 | 0 | c->pop_clip (); |
110 | |
|
111 | 0 | return true; |
112 | 0 | } |
113 | | |
114 | | static void |
115 | | hb_paint_bounded_paint_color (hb_paint_funcs_t *funcs HB_UNUSED, |
116 | | void *paint_data, |
117 | | hb_bool_t use_foreground HB_UNUSED, |
118 | | hb_color_t color HB_UNUSED, |
119 | | void *user_data HB_UNUSED) |
120 | 0 | { |
121 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
122 | |
|
123 | 0 | c->paint (); |
124 | 0 | } |
125 | | |
126 | | static void |
127 | | hb_paint_bounded_paint_linear_gradient (hb_paint_funcs_t *funcs HB_UNUSED, |
128 | | void *paint_data, |
129 | | hb_color_line_t *color_line HB_UNUSED, |
130 | | float x0 HB_UNUSED, float y0 HB_UNUSED, |
131 | | float x1 HB_UNUSED, float y1 HB_UNUSED, |
132 | | float x2 HB_UNUSED, float y2 HB_UNUSED, |
133 | | void *user_data HB_UNUSED) |
134 | 0 | { |
135 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
136 | |
|
137 | 0 | c->paint (); |
138 | 0 | } |
139 | | |
140 | | static void |
141 | | hb_paint_bounded_paint_radial_gradient (hb_paint_funcs_t *funcs HB_UNUSED, |
142 | | void *paint_data, |
143 | | hb_color_line_t *color_line HB_UNUSED, |
144 | | float x0 HB_UNUSED, float y0 HB_UNUSED, float r0 HB_UNUSED, |
145 | | float x1 HB_UNUSED, float y1 HB_UNUSED, float r1 HB_UNUSED, |
146 | | void *user_data HB_UNUSED) |
147 | 0 | { |
148 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
149 | |
|
150 | 0 | c->paint (); |
151 | 0 | } |
152 | | |
153 | | static void |
154 | | hb_paint_bounded_paint_sweep_gradient (hb_paint_funcs_t *funcs HB_UNUSED, |
155 | | void *paint_data, |
156 | | hb_color_line_t *color_line HB_UNUSED, |
157 | | float cx HB_UNUSED, float cy HB_UNUSED, |
158 | | float start_angle HB_UNUSED, |
159 | | float end_angle HB_UNUSED, |
160 | | void *user_data HB_UNUSED) |
161 | 0 | { |
162 | 0 | hb_paint_bounded_context_t *c = (hb_paint_bounded_context_t *) paint_data; |
163 | |
|
164 | 0 | c->paint (); |
165 | 0 | } |
166 | | |
167 | | static inline void free_static_paint_bounded_funcs (); |
168 | | |
169 | | static struct hb_paint_bounded_funcs_lazy_loader_t : hb_paint_funcs_lazy_loader_t<hb_paint_bounded_funcs_lazy_loader_t> |
170 | | { |
171 | | static hb_paint_funcs_t *create () |
172 | 0 | { |
173 | 0 | hb_paint_funcs_t *funcs = hb_paint_funcs_create (); |
174 | |
|
175 | 0 | hb_paint_funcs_set_push_clip_glyph_func (funcs, hb_paint_bounded_push_clip_glyph, nullptr, nullptr); |
176 | 0 | hb_paint_funcs_set_push_clip_rectangle_func (funcs, hb_paint_bounded_push_clip_rectangle, nullptr, nullptr); |
177 | 0 | hb_paint_funcs_set_pop_clip_func (funcs, hb_paint_bounded_pop_clip, nullptr, nullptr); |
178 | 0 | hb_paint_funcs_set_push_group_func (funcs, hb_paint_bounded_push_group, nullptr, nullptr); |
179 | 0 | hb_paint_funcs_set_pop_group_func (funcs, hb_paint_bounded_pop_group, nullptr, nullptr); |
180 | 0 | hb_paint_funcs_set_color_func (funcs, hb_paint_bounded_paint_color, nullptr, nullptr); |
181 | 0 | hb_paint_funcs_set_image_func (funcs, hb_paint_bounded_paint_image, nullptr, nullptr); |
182 | 0 | hb_paint_funcs_set_linear_gradient_func (funcs, hb_paint_bounded_paint_linear_gradient, nullptr, nullptr); |
183 | 0 | hb_paint_funcs_set_radial_gradient_func (funcs, hb_paint_bounded_paint_radial_gradient, nullptr, nullptr); |
184 | 0 | hb_paint_funcs_set_sweep_gradient_func (funcs, hb_paint_bounded_paint_sweep_gradient, nullptr, nullptr); |
185 | |
|
186 | 0 | hb_paint_funcs_make_immutable (funcs); |
187 | |
|
188 | 0 | hb_atexit (free_static_paint_bounded_funcs); |
189 | |
|
190 | 0 | return funcs; |
191 | 0 | } |
192 | | } static_paint_bounded_funcs; |
193 | | |
194 | | static inline |
195 | | void free_static_paint_bounded_funcs () |
196 | 0 | { |
197 | 0 | static_paint_bounded_funcs.free_instance (); |
198 | 0 | } |
199 | | |
200 | | hb_paint_funcs_t * |
201 | | hb_paint_bounded_get_funcs () |
202 | 0 | { |
203 | 0 | return static_paint_bounded_funcs.get_unconst (); |
204 | 0 | } |
205 | | |
206 | | |
207 | | #endif |