2 * Copyright © 2019-2020 Ebrahim Byagowi
4 * This is part of HarfBuzz, a text shaping library.
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.
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
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.
28 #ifdef HB_EXPERIMENTAL_API
32 #include "hb-ot-glyf-table.hh"
33 #include "hb-ot-cff1-table.hh"
34 #include "hb-ot-cff2-table.hh"
37 * hb_draw_funcs_set_move_to_func:
38 * @funcs: draw functions object
39 * @move_to: move-to callback
41 * Sets move-to callback to the draw functions object.
46 hb_draw_funcs_set_move_to_func (hb_draw_funcs_t *funcs,
47 hb_draw_move_to_func_t move_to)
49 if (unlikely (hb_object_is_immutable (funcs))) return;
50 funcs->move_to = move_to;
54 * hb_draw_funcs_set_line_to_func:
55 * @funcs: draw functions object
56 * @line_to: line-to callback
58 * Sets line-to callback to the draw functions object.
63 hb_draw_funcs_set_line_to_func (hb_draw_funcs_t *funcs,
64 hb_draw_line_to_func_t line_to)
66 if (unlikely (hb_object_is_immutable (funcs))) return;
67 funcs->line_to = line_to;
71 * hb_draw_funcs_set_quadratic_to_func:
72 * @funcs: draw functions object
73 * @move_to: quadratic-to callback
75 * Sets quadratic-to callback to the draw functions object.
80 hb_draw_funcs_set_quadratic_to_func (hb_draw_funcs_t *funcs,
81 hb_draw_quadratic_to_func_t quadratic_to)
83 if (unlikely (hb_object_is_immutable (funcs))) return;
84 funcs->quadratic_to = quadratic_to;
85 funcs->is_quadratic_to_set = true;
89 * hb_draw_funcs_set_cubic_to_func:
90 * @funcs: draw functions
91 * @cubic_to: cubic-to callback
93 * Sets cubic-to callback to the draw functions object.
98 hb_draw_funcs_set_cubic_to_func (hb_draw_funcs_t *funcs,
99 hb_draw_cubic_to_func_t cubic_to)
101 if (unlikely (hb_object_is_immutable (funcs))) return;
102 funcs->cubic_to = cubic_to;
106 * hb_draw_funcs_set_close_path_func:
107 * @funcs: draw functions object
108 * @close_path: close-path callback
110 * Sets close-path callback to the draw functions object.
112 * Since: EXPERIMENTAL
115 hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *funcs,
116 hb_draw_close_path_func_t close_path)
118 if (unlikely (hb_object_is_immutable (funcs))) return;
119 funcs->close_path = close_path;
123 _move_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}
126 _line_to_nil (hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED, void *user_data HB_UNUSED) {}
129 _quadratic_to_nil (hb_position_t control_x HB_UNUSED, hb_position_t control_y HB_UNUSED,
130 hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED,
131 void *user_data HB_UNUSED) {}
134 _cubic_to_nil (hb_position_t control1_x HB_UNUSED, hb_position_t control1_y HB_UNUSED,
135 hb_position_t control2_x HB_UNUSED, hb_position_t control2_y HB_UNUSED,
136 hb_position_t to_x HB_UNUSED, hb_position_t to_y HB_UNUSED,
137 void *user_data HB_UNUSED) {}
140 _close_path_nil (void *user_data HB_UNUSED) {}
143 * hb_draw_funcs_create:
145 * Creates a new draw callbacks object.
147 * Since: EXPERIMENTAL
150 hb_draw_funcs_create ()
152 hb_draw_funcs_t *funcs;
153 if (unlikely (!(funcs = hb_object_create<hb_draw_funcs_t> ())))
154 return const_cast<hb_draw_funcs_t *> (&Null (hb_draw_funcs_t));
156 funcs->move_to = (hb_draw_move_to_func_t) _move_to_nil;
157 funcs->line_to = (hb_draw_line_to_func_t) _line_to_nil;
158 funcs->quadratic_to = (hb_draw_quadratic_to_func_t) _quadratic_to_nil;
159 funcs->is_quadratic_to_set = false;
160 funcs->cubic_to = (hb_draw_cubic_to_func_t) _cubic_to_nil;
161 funcs->close_path = (hb_draw_close_path_func_t) _close_path_nil;
166 * hb_draw_funcs_reference:
167 * @funcs: draw functions
169 * Add to callbacks object refcount.
171 * Returns: The same object.
172 * Since: EXPERIMENTAL
175 hb_draw_funcs_reference (hb_draw_funcs_t *funcs)
177 return hb_object_reference (funcs);
181 * hb_draw_funcs_destroy:
182 * @funcs: draw functions
184 * Decreases refcount of callbacks object and deletes the object if it reaches
187 * Since: EXPERIMENTAL
190 hb_draw_funcs_destroy (hb_draw_funcs_t *funcs)
192 if (!hb_object_destroy (funcs)) return;
198 * hb_draw_funcs_make_immutable:
199 * @funcs: draw functions
201 * Makes funcs object immutable.
203 * Since: EXPERIMENTAL
206 hb_draw_funcs_make_immutable (hb_draw_funcs_t *funcs)
208 if (hb_object_is_immutable (funcs))
211 hb_object_make_immutable (funcs);
215 * hb_draw_funcs_is_immutable:
216 * @funcs: draw functions
218 * Checks whether funcs is immutable.
220 * Returns: If is immutable.
221 * Since: EXPERIMENTAL
224 hb_draw_funcs_is_immutable (hb_draw_funcs_t *funcs)
226 return hb_object_is_immutable (funcs);
230 * hb_font_draw_glyph:
231 * @font: a font object
233 * @funcs: draw callbacks object
234 * @user_data: parameter you like be passed to the callbacks when are called
238 * Returns: Whether the font had the glyph and the operation completed successfully.
239 * Since: EXPERIMENTAL
242 hb_font_draw_glyph (hb_font_t *font, hb_codepoint_t glyph,
243 const hb_draw_funcs_t *funcs,
246 if (unlikely (funcs == &Null (hb_draw_funcs_t) ||
247 glyph >= font->face->get_num_glyphs ()))
250 draw_helper_t draw_helper (funcs, user_data);
251 if (font->face->table.glyf->get_path (font, glyph, draw_helper)) return true;
253 if (font->face->table.cff1->get_path (font, glyph, draw_helper)) return true;
254 if (font->face->table.cff2->get_path (font, glyph, draw_helper)) return true;