hb-draw.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. #if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)
  25. #error "Include <hb.h> instead."
  26. #endif
  27. #ifndef HB_DRAW_H
  28. #define HB_DRAW_H
  29. #include "hb.h"
  30. HB_BEGIN_DECLS
  31. /**
  32. * hb_draw_state_t
  33. * @path_open: Whether there is an open path
  34. * @path_start_x: X component of the start of current path
  35. * @path_start_y: Y component of the start of current path
  36. * @current_x: X component of current point
  37. * @current_y: Y component of current point
  38. *
  39. * Current drawing state.
  40. *
  41. * Since: 4.0.0
  42. **/
  43. typedef struct hb_draw_state_t {
  44. hb_bool_t path_open;
  45. float path_start_x;
  46. float path_start_y;
  47. float current_x;
  48. float current_y;
  49. /*< private >*/
  50. hb_var_num_t reserved1;
  51. hb_var_num_t reserved2;
  52. hb_var_num_t reserved3;
  53. hb_var_num_t reserved4;
  54. hb_var_num_t reserved5;
  55. hb_var_num_t reserved6;
  56. hb_var_num_t reserved7;
  57. } hb_draw_state_t;
  58. /**
  59. * HB_DRAW_STATE_DEFAULT:
  60. *
  61. * The default #hb_draw_state_t at the start of glyph drawing.
  62. */
  63. #define HB_DRAW_STATE_DEFAULT {0, 0.f, 0.f, 0.f, 0.f, {0.}, {0.}, {0.}}
  64. /**
  65. * hb_draw_funcs_t:
  66. *
  67. * Glyph draw callbacks.
  68. *
  69. * #hb_draw_move_to_func_t, #hb_draw_line_to_func_t and
  70. * #hb_draw_cubic_to_func_t calls are necessary to be defined but we translate
  71. * #hb_draw_quadratic_to_func_t calls to #hb_draw_cubic_to_func_t if the
  72. * callback isn't defined.
  73. *
  74. * Since: 4.0.0
  75. **/
  76. typedef struct hb_draw_funcs_t hb_draw_funcs_t;
  77. /**
  78. * hb_draw_move_to_func_t:
  79. * @dfuncs: draw functions object
  80. * @draw_data: The data accompanying the draw functions
  81. * @st: current draw state
  82. * @to_x: X component of target point
  83. * @to_y: Y component of target point
  84. * @user_data: User data pointer passed by the caller
  85. *
  86. * A virtual method for the #hb_draw_funcs_t to perform a "move-to" draw
  87. * operation.
  88. *
  89. * Since: 4.0.0
  90. *
  91. **/
  92. typedef void (*hb_draw_move_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
  93. hb_draw_state_t *st,
  94. float to_x, float to_y,
  95. void *user_data);
  96. /**
  97. * hb_draw_line_to_func_t:
  98. * @dfuncs: draw functions object
  99. * @draw_data: The data accompanying the draw functions
  100. * @st: current draw state
  101. * @to_x: X component of target point
  102. * @to_y: Y component of target point
  103. * @user_data: User data pointer passed by the caller
  104. *
  105. * A virtual method for the #hb_draw_funcs_t to perform a "line-to" draw
  106. * operation.
  107. *
  108. * Since: 4.0.0
  109. *
  110. **/
  111. typedef void (*hb_draw_line_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
  112. hb_draw_state_t *st,
  113. float to_x, float to_y,
  114. void *user_data);
  115. /**
  116. * hb_draw_quadratic_to_func_t:
  117. * @dfuncs: draw functions object
  118. * @draw_data: The data accompanying the draw functions
  119. * @st: current draw state
  120. * @control_x: X component of control point
  121. * @control_y: Y component of control point
  122. * @to_x: X component of target point
  123. * @to_y: Y component of target point
  124. * @user_data: User data pointer passed by the caller
  125. *
  126. * A virtual method for the #hb_draw_funcs_t to perform a "quadratic-to" draw
  127. * operation.
  128. *
  129. * Since: 4.0.0
  130. *
  131. **/
  132. typedef void (*hb_draw_quadratic_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
  133. hb_draw_state_t *st,
  134. float control_x, float control_y,
  135. float to_x, float to_y,
  136. void *user_data);
  137. /**
  138. * hb_draw_cubic_to_func_t:
  139. * @dfuncs: draw functions object
  140. * @draw_data: The data accompanying the draw functions
  141. * @st: current draw state
  142. * @control1_x: X component of first control point
  143. * @control1_y: Y component of first control point
  144. * @control2_x: X component of second control point
  145. * @control2_y: Y component of second control point
  146. * @to_x: X component of target point
  147. * @to_y: Y component of target point
  148. * @user_data: User data pointer passed by the caller
  149. *
  150. * A virtual method for the #hb_draw_funcs_t to perform a "cubic-to" draw
  151. * operation.
  152. *
  153. * Since: 4.0.0
  154. *
  155. **/
  156. typedef void (*hb_draw_cubic_to_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
  157. hb_draw_state_t *st,
  158. float control1_x, float control1_y,
  159. float control2_x, float control2_y,
  160. float to_x, float to_y,
  161. void *user_data);
  162. /**
  163. * hb_draw_close_path_func_t:
  164. * @dfuncs: draw functions object
  165. * @draw_data: The data accompanying the draw functions
  166. * @st: current draw state
  167. * @user_data: User data pointer passed by the caller
  168. *
  169. * A virtual method for the #hb_draw_funcs_t to perform a "close-path" draw
  170. * operation.
  171. *
  172. * Since: 4.0.0
  173. *
  174. **/
  175. typedef void (*hb_draw_close_path_func_t) (hb_draw_funcs_t *dfuncs, void *draw_data,
  176. hb_draw_state_t *st,
  177. void *user_data);
  178. /**
  179. * hb_draw_funcs_set_move_to_func:
  180. * @dfuncs: draw functions object
  181. * @func: (closure user_data) (destroy destroy) (scope notified): move-to callback
  182. * @user_data: Data to pass to @func
  183. * @destroy: (nullable): The function to call when @user_data is not needed anymore
  184. *
  185. * Sets move-to callback to the draw functions object.
  186. *
  187. * Since: 4.0.0
  188. **/
  189. HB_EXTERN void
  190. hb_draw_funcs_set_move_to_func (hb_draw_funcs_t *dfuncs,
  191. hb_draw_move_to_func_t func,
  192. void *user_data, hb_destroy_func_t destroy);
  193. /**
  194. * hb_draw_funcs_set_line_to_func:
  195. * @dfuncs: draw functions object
  196. * @func: (closure user_data) (destroy destroy) (scope notified): line-to callback
  197. * @user_data: Data to pass to @func
  198. * @destroy: (nullable): The function to call when @user_data is not needed anymore
  199. *
  200. * Sets line-to callback to the draw functions object.
  201. *
  202. * Since: 4.0.0
  203. **/
  204. HB_EXTERN void
  205. hb_draw_funcs_set_line_to_func (hb_draw_funcs_t *dfuncs,
  206. hb_draw_line_to_func_t func,
  207. void *user_data, hb_destroy_func_t destroy);
  208. /**
  209. * hb_draw_funcs_set_quadratic_to_func:
  210. * @dfuncs: draw functions object
  211. * @func: (closure user_data) (destroy destroy) (scope notified): quadratic-to callback
  212. * @user_data: Data to pass to @func
  213. * @destroy: (nullable): The function to call when @user_data is not needed anymore
  214. *
  215. * Sets quadratic-to callback to the draw functions object.
  216. *
  217. * Since: 4.0.0
  218. **/
  219. HB_EXTERN void
  220. hb_draw_funcs_set_quadratic_to_func (hb_draw_funcs_t *dfuncs,
  221. hb_draw_quadratic_to_func_t func,
  222. void *user_data, hb_destroy_func_t destroy);
  223. /**
  224. * hb_draw_funcs_set_cubic_to_func:
  225. * @dfuncs: draw functions
  226. * @func: (closure user_data) (destroy destroy) (scope notified): cubic-to callback
  227. * @user_data: Data to pass to @func
  228. * @destroy: (nullable): The function to call when @user_data is not needed anymore
  229. *
  230. * Sets cubic-to callback to the draw functions object.
  231. *
  232. * Since: 4.0.0
  233. **/
  234. HB_EXTERN void
  235. hb_draw_funcs_set_cubic_to_func (hb_draw_funcs_t *dfuncs,
  236. hb_draw_cubic_to_func_t func,
  237. void *user_data, hb_destroy_func_t destroy);
  238. /**
  239. * hb_draw_funcs_set_close_path_func:
  240. * @dfuncs: draw functions object
  241. * @func: (closure user_data) (destroy destroy) (scope notified): close-path callback
  242. * @user_data: Data to pass to @func
  243. * @destroy: (nullable): The function to call when @user_data is not needed anymore
  244. *
  245. * Sets close-path callback to the draw functions object.
  246. *
  247. * Since: 4.0.0
  248. **/
  249. HB_EXTERN void
  250. hb_draw_funcs_set_close_path_func (hb_draw_funcs_t *dfuncs,
  251. hb_draw_close_path_func_t func,
  252. void *user_data, hb_destroy_func_t destroy);
  253. HB_EXTERN hb_draw_funcs_t *
  254. hb_draw_funcs_create (void);
  255. HB_EXTERN hb_draw_funcs_t *
  256. hb_draw_funcs_reference (hb_draw_funcs_t *dfuncs);
  257. HB_EXTERN void
  258. hb_draw_funcs_destroy (hb_draw_funcs_t *dfuncs);
  259. HB_EXTERN void
  260. hb_draw_funcs_make_immutable (hb_draw_funcs_t *dfuncs);
  261. HB_EXTERN hb_bool_t
  262. hb_draw_funcs_is_immutable (hb_draw_funcs_t *dfuncs);
  263. HB_EXTERN void
  264. hb_draw_move_to (hb_draw_funcs_t *dfuncs, void *draw_data,
  265. hb_draw_state_t *st,
  266. float to_x, float to_y);
  267. HB_EXTERN void
  268. hb_draw_line_to (hb_draw_funcs_t *dfuncs, void *draw_data,
  269. hb_draw_state_t *st,
  270. float to_x, float to_y);
  271. HB_EXTERN void
  272. hb_draw_quadratic_to (hb_draw_funcs_t *dfuncs, void *draw_data,
  273. hb_draw_state_t *st,
  274. float control_x, float control_y,
  275. float to_x, float to_y);
  276. HB_EXTERN void
  277. hb_draw_cubic_to (hb_draw_funcs_t *dfuncs, void *draw_data,
  278. hb_draw_state_t *st,
  279. float control1_x, float control1_y,
  280. float control2_x, float control2_y,
  281. float to_x, float to_y);
  282. HB_EXTERN void
  283. hb_draw_close_path (hb_draw_funcs_t *dfuncs, void *draw_data,
  284. hb_draw_state_t *st);
  285. HB_END_DECLS
  286. #endif /* HB_DRAW_H */