Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/java.desktop/share/native/libharfbuzz/hb-draw.cc
66644 views
1
/*
2
* Copyright © 2019-2020 Ebrahim Byagowi
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_DRAW
28
29
#include "hb-draw.hh"
30
31
/**
32
* SECTION:hb-draw
33
* @title: hb-draw
34
* @short_description: Glyph drawing
35
* @include: hb.h
36
*
37
* Functions for drawing (extracting) glyph shapes.
38
**/
39
40
static void
41
hb_draw_move_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
42
hb_draw_state_t *st HB_UNUSED,
43
float to_x HB_UNUSED, float to_y HB_UNUSED,
44
void *user_data HB_UNUSED) {}
45
46
static void
47
hb_draw_line_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
48
hb_draw_state_t *st HB_UNUSED,
49
float to_x HB_UNUSED, float to_y HB_UNUSED,
50
void *user_data HB_UNUSED) {}
51
52
static void
53
hb_draw_quadratic_to_nil (hb_draw_funcs_t *dfuncs, void *draw_data,
54
hb_draw_state_t *st,
55
float control_x, float control_y,
56
float to_x, float to_y,
57
void *user_data HB_UNUSED)
58
{
59
#define HB_ONE_THIRD 0.33333333f
60
dfuncs->emit_cubic_to (draw_data, *st,
61
(st->current_x + 2.f * control_x) * HB_ONE_THIRD,
62
(st->current_y + 2.f * control_y) * HB_ONE_THIRD,
63
(to_x + 2.f * control_x) * HB_ONE_THIRD,
64
(to_y + 2.f * control_y) * HB_ONE_THIRD,
65
to_x, to_y);
66
#undef HB_ONE_THIRD
67
}
68
69
static void
70
hb_draw_cubic_to_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
71
hb_draw_state_t *st HB_UNUSED,
72
float control1_x HB_UNUSED, float control1_y HB_UNUSED,
73
float control2_x HB_UNUSED, float control2_y HB_UNUSED,
74
float to_x HB_UNUSED, float to_y HB_UNUSED,
75
void *user_data HB_UNUSED) {}
76
77
static void
78
hb_draw_close_path_nil (hb_draw_funcs_t *dfuncs HB_UNUSED, void *draw_data HB_UNUSED,
79
hb_draw_state_t *st HB_UNUSED,
80
void *user_data HB_UNUSED) {}
81
82
83
#define HB_DRAW_FUNC_IMPLEMENT(name) \
84
\
85
void \
86
hb_draw_funcs_set_##name##_func (hb_draw_funcs_t *dfuncs, \
87
hb_draw_##name##_func_t func, \
88
void *user_data, \
89
hb_destroy_func_t destroy) \
90
{ \
91
if (hb_object_is_immutable (dfuncs)) \
92
return; \
93
\
94
if (dfuncs->destroy && dfuncs->destroy->name) \
95
dfuncs->destroy->name (!dfuncs->user_data ? nullptr : dfuncs->user_data->name); \
96
\
97
if (user_data && !dfuncs->user_data) \
98
{ \
99
dfuncs->user_data = (decltype (dfuncs->user_data)) hb_calloc (1, sizeof (*dfuncs->user_data)); \
100
if (unlikely (!dfuncs->user_data)) \
101
goto fail; \
102
} \
103
if (destroy && !dfuncs->destroy) \
104
{ \
105
dfuncs->destroy = (decltype (dfuncs->destroy)) hb_calloc (1, sizeof (*dfuncs->destroy)); \
106
if (unlikely (!dfuncs->destroy)) \
107
goto fail; \
108
} \
109
\
110
if (func) { \
111
dfuncs->func.name = func; \
112
if (dfuncs->user_data) \
113
dfuncs->user_data->name = user_data; \
114
if (dfuncs->destroy) \
115
dfuncs->destroy->name = destroy; \
116
} else { \
117
dfuncs->func.name = hb_draw_##name##_nil; \
118
if (dfuncs->user_data) \
119
dfuncs->user_data->name = nullptr; \
120
if (dfuncs->destroy) \
121
dfuncs->destroy->name = nullptr; \
122
} \
123
\
124
fail: \
125
if (destroy) \
126
destroy (user_data); \
127
}
128
129
HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS
130
#undef HB_DRAW_FUNC_IMPLEMENT
131
132
/**
133
* hb_draw_funcs_create:
134
*
135
* Creates a new draw callbacks object.
136
*
137
* Return value: (transfer full):
138
* A newly allocated #hb_draw_funcs_t with a reference count of 1. The initial
139
* reference count should be released with hb_draw_funcs_destroy when you are
140
* done using the #hb_draw_funcs_t. This function never returns %NULL. If
141
* memory cannot be allocated, a special singleton #hb_draw_funcs_t object will
142
* be returned.
143
*
144
* Since: 4.0.0
145
**/
146
hb_draw_funcs_t *
147
hb_draw_funcs_create ()
148
{
149
hb_draw_funcs_t *dfuncs;
150
if (unlikely (!(dfuncs = hb_object_create<hb_draw_funcs_t> ())))
151
return const_cast<hb_draw_funcs_t *> (&Null (hb_draw_funcs_t));
152
153
dfuncs->func = Null (hb_draw_funcs_t).func;
154
155
return dfuncs;
156
}
157
158
DEFINE_NULL_INSTANCE (hb_draw_funcs_t) =
159
{
160
HB_OBJECT_HEADER_STATIC,
161
162
{
163
#define HB_DRAW_FUNC_IMPLEMENT(name) hb_draw_##name##_nil,
164
HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS
165
#undef HB_DRAW_FUNC_IMPLEMENT
166
}
167
};
168
169
170
/**
171
* hb_draw_funcs_reference: (skip)
172
* @dfuncs: draw functions
173
*
174
* Increases the reference count on @dfuncs by one. This prevents @buffer from
175
* being destroyed until a matching call to hb_draw_funcs_destroy() is made.
176
*
177
* Return value: (transfer full):
178
* The referenced #hb_draw_funcs_t.
179
*
180
* Since: 4.0.0
181
**/
182
hb_draw_funcs_t *
183
hb_draw_funcs_reference (hb_draw_funcs_t *dfuncs)
184
{
185
return hb_object_reference (dfuncs);
186
}
187
188
/**
189
* hb_draw_funcs_destroy: (skip)
190
* @dfuncs: draw functions
191
*
192
* Deallocate the @dfuncs.
193
* Decreases the reference count on @dfuncs by one. If the result is zero, then
194
* @dfuncs and all associated resources are freed. See hb_draw_funcs_reference().
195
*
196
* Since: 4.0.0
197
**/
198
void
199
hb_draw_funcs_destroy (hb_draw_funcs_t *dfuncs)
200
{
201
if (!hb_object_destroy (dfuncs)) return;
202
203
if (dfuncs->destroy)
204
{
205
#define HB_DRAW_FUNC_IMPLEMENT(name) \
206
if (dfuncs->destroy->name) dfuncs->destroy->name (!dfuncs->user_data ? nullptr : dfuncs->user_data->name);
207
HB_DRAW_FUNCS_IMPLEMENT_CALLBACKS
208
#undef HB_DRAW_FUNC_IMPLEMENT
209
}
210
211
hb_free (dfuncs);
212
}
213
214
/**
215
* hb_draw_funcs_make_immutable:
216
* @dfuncs: draw functions
217
*
218
* Makes @dfuncs object immutable.
219
*
220
* Since: 4.0.0
221
**/
222
void
223
hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs)
224
{
225
if (hb_object_is_immutable (dfuncs))
226
return;
227
228
hb_object_make_immutable (dfuncs);
229
}
230
231
/**
232
* hb_draw_funcs_is_immutable:
233
* @dfuncs: draw functions
234
*
235
* Checks whether @dfuncs is immutable.
236
*
237
* Return value: %true if @dfuncs is immutable, %false otherwise
238
*
239
* Since: 4.0.0
240
**/
241
hb_bool_t
242
hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs)
243
{
244
return hb_object_is_immutable (dfuncs);
245
}
246
247
248
/**
249
* hb_draw_move_to:
250
* @dfuncs: draw functions
251
* @draw_data: associated draw data passed by the caller
252
* @st: current draw state
253
* @to_x: X component of target point
254
* @to_y: Y component of target point
255
*
256
* Perform a "move-to" draw operation.
257
*
258
* Since: 4.0.0
259
**/
260
void
261
hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data,
262
hb_draw_state_t *st,
263
float to_x, float to_y)
264
{
265
dfuncs->move_to (draw_data, *st,
266
to_x, to_y);
267
}
268
269
/**
270
* hb_draw_line_to:
271
* @dfuncs: draw functions
272
* @draw_data: associated draw data passed by the caller
273
* @st: current draw state
274
* @to_x: X component of target point
275
* @to_y: Y component of target point
276
*
277
* Perform a "line-to" draw operation.
278
*
279
* Since: 4.0.0
280
**/
281
void
282
hb_draw_line_to (hb_draw_funcs_t *dfuncs, void *draw_data,
283
hb_draw_state_t *st,
284
float to_x, float to_y)
285
{
286
dfuncs->line_to (draw_data, *st,
287
to_x, to_y);
288
}
289
290
/**
291
* hb_draw_quadratic_to:
292
* @dfuncs: draw functions
293
* @draw_data: associated draw data passed by the caller
294
* @st: current draw state
295
* @control_x: X component of control point
296
* @control_y: Y component of control point
297
* @to_x: X component of target point
298
* @to_y: Y component of target point
299
*
300
* Perform a "quadratic-to" draw operation.
301
*
302
* Since: 4.0.0
303
**/
304
void
305
hb_draw_quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data,
306
hb_draw_state_t *st,
307
float control_x, float control_y,
308
float to_x, float to_y)
309
{
310
dfuncs->quadratic_to (draw_data, *st,
311
control_x, control_y,
312
to_x, to_y);
313
}
314
315
/**
316
* hb_draw_cubic_to:
317
* @dfuncs: draw functions
318
* @draw_data: associated draw data passed by the caller
319
* @st: current draw state
320
* @control1_x: X component of first control point
321
* @control1_y: Y component of first control point
322
* @control2_x: X component of second control point
323
* @control2_y: Y component of second control point
324
* @to_x: X component of target point
325
* @to_y: Y component of target point
326
*
327
* Perform a "cubic-to" draw operation.
328
*
329
* Since: 4.0.0
330
**/
331
void
332
hb_draw_cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data,
333
hb_draw_state_t *st,
334
float control1_x, float control1_y,
335
float control2_x, float control2_y,
336
float to_x, float to_y)
337
{
338
dfuncs->cubic_to (draw_data, *st,
339
control1_x, control1_y,
340
control2_x, control2_y,
341
to_x, to_y);
342
}
343
344
/**
345
* hb_draw_close_path:
346
* @dfuncs: draw functions
347
* @draw_data: associated draw data passed by the caller
348
* @st: current draw state
349
*
350
* Perform a "close-path" draw operation.
351
*
352
* Since: 4.0.0
353
**/
354
void
355
hb_draw_close_path (hb_draw_funcs_t *dfuncs, void *draw_data,
356
hb_draw_state_t *st)
357
{
358
dfuncs->close_path (draw_data, *st);
359
}
360
361
362
#endif
363
364