hb-paint.h 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029
  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. #if !defined(HB_H_IN) && !defined(HB_NO_SINGLE_HEADER_ERROR)
  25. #error "Include <hb.h> instead."
  26. #endif
  27. #ifndef HB_PAINT_H
  28. #define HB_PAINT_H
  29. #include "hb-common.h"
  30. HB_BEGIN_DECLS
  31. /**
  32. * hb_paint_funcs_t:
  33. *
  34. * Glyph paint callbacks.
  35. *
  36. * The callbacks assume that the caller maintains a stack
  37. * of current transforms, clips and intermediate surfaces,
  38. * as evidenced by the pairs of push/pop callbacks. The
  39. * push/pop calls will be properly nested, so it is fine
  40. * to store the different kinds of object on a single stack.
  41. *
  42. * Not all callbacks are required for all kinds of glyphs.
  43. * For rendering COLRv0 or non-color outline glyphs, the
  44. * gradient callbacks are not needed, and the composite
  45. * callback only needs to handle simple alpha compositing
  46. * (#HB_PAINT_COMPOSITE_MODE_SRC_OVER).
  47. *
  48. * The paint-image callback is only needed for glyphs
  49. * with image blobs in the CBDT, sbix or SVG tables.
  50. *
  51. * The custom-palette-color callback is only necessary if
  52. * you want to override colors from the font palette with
  53. * custom colors.
  54. *
  55. * Since: 7.0.0
  56. **/
  57. typedef struct hb_paint_funcs_t hb_paint_funcs_t;
  58. HB_EXTERN hb_paint_funcs_t *
  59. hb_paint_funcs_create (void);
  60. HB_EXTERN hb_paint_funcs_t *
  61. hb_paint_funcs_get_empty (void);
  62. HB_EXTERN hb_paint_funcs_t *
  63. hb_paint_funcs_reference (hb_paint_funcs_t *funcs);
  64. HB_EXTERN void
  65. hb_paint_funcs_destroy (hb_paint_funcs_t *funcs);
  66. HB_EXTERN hb_bool_t
  67. hb_paint_funcs_set_user_data (hb_paint_funcs_t *funcs,
  68. hb_user_data_key_t *key,
  69. void * data,
  70. hb_destroy_func_t destroy,
  71. hb_bool_t replace);
  72. HB_EXTERN void *
  73. hb_paint_funcs_get_user_data (const hb_paint_funcs_t *funcs,
  74. hb_user_data_key_t *key);
  75. HB_EXTERN void
  76. hb_paint_funcs_make_immutable (hb_paint_funcs_t *funcs);
  77. HB_EXTERN hb_bool_t
  78. hb_paint_funcs_is_immutable (hb_paint_funcs_t *funcs);
  79. /**
  80. * hb_paint_push_transform_func_t:
  81. * @funcs: paint functions object
  82. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  83. * @xx: xx component of the transform matrix
  84. * @yx: yx component of the transform matrix
  85. * @xy: xy component of the transform matrix
  86. * @yy: yy component of the transform matrix
  87. * @dx: dx component of the transform matrix
  88. * @dy: dy component of the transform matrix
  89. * @user_data: User data pointer passed to hb_paint_funcs_set_push_transform_func()
  90. *
  91. * A virtual method for the #hb_paint_funcs_t to apply
  92. * a transform to subsequent paint calls.
  93. *
  94. * This transform is applied after the current transform,
  95. * and remains in effect until a matching call to
  96. * the #hb_paint_funcs_pop_transform_func_t vfunc.
  97. *
  98. * Since: 7.0.0
  99. */
  100. typedef void (*hb_paint_push_transform_func_t) (hb_paint_funcs_t *funcs,
  101. void *paint_data,
  102. float xx, float yx,
  103. float xy, float yy,
  104. float dx, float dy,
  105. void *user_data);
  106. /**
  107. * hb_paint_pop_transform_func_t:
  108. * @funcs: paint functions object
  109. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  110. * @user_data: User data pointer passed to hb_paint_funcs_set_pop_transform_func()
  111. *
  112. * A virtual method for the #hb_paint_funcs_t to undo
  113. * the effect of a prior call to the #hb_paint_funcs_push_transform_func_t
  114. * vfunc.
  115. *
  116. * Since: 7.0.0
  117. */
  118. typedef void (*hb_paint_pop_transform_func_t) (hb_paint_funcs_t *funcs,
  119. void *paint_data,
  120. void *user_data);
  121. /**
  122. * hb_paint_color_glyph_func_t:
  123. * @funcs: paint functions object
  124. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  125. * @glyph: the glyph ID
  126. * @font: the font
  127. * @user_data: User data pointer passed to hb_paint_funcs_set_color_glyph_func()
  128. *
  129. * A virtual method for the #hb_paint_funcs_t to render a color glyph by glyph index.
  130. *
  131. * Return value: %true if the glyph was painted, %false otherwise.
  132. *
  133. * Since: 8.2.0
  134. */
  135. typedef hb_bool_t (*hb_paint_color_glyph_func_t) (hb_paint_funcs_t *funcs,
  136. void *paint_data,
  137. hb_codepoint_t glyph,
  138. hb_font_t *font,
  139. void *user_data);
  140. /**
  141. * hb_paint_push_clip_glyph_func_t:
  142. * @funcs: paint functions object
  143. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  144. * @glyph: the glyph ID
  145. * @font: the font
  146. * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_glyph_func()
  147. *
  148. * A virtual method for the #hb_paint_funcs_t to clip
  149. * subsequent paint calls to the outline of a glyph.
  150. *
  151. * The coordinates of the glyph outline are interpreted according
  152. * to the current transform.
  153. *
  154. * This clip is applied in addition to the current clip,
  155. * and remains in effect until a matching call to
  156. * the #hb_paint_funcs_pop_clip_func_t vfunc.
  157. *
  158. * Since: 7.0.0
  159. */
  160. typedef void (*hb_paint_push_clip_glyph_func_t) (hb_paint_funcs_t *funcs,
  161. void *paint_data,
  162. hb_codepoint_t glyph,
  163. hb_font_t *font,
  164. void *user_data);
  165. /**
  166. * hb_paint_push_clip_rectangle_func_t:
  167. * @funcs: paint functions object
  168. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  169. * @xmin: min X for the rectangle
  170. * @ymin: min Y for the rectangle
  171. * @xmax: max X for the rectangle
  172. * @ymax: max Y for the rectangle
  173. * @user_data: User data pointer passed to hb_paint_funcs_set_push_clip_rectangle_func()
  174. *
  175. * A virtual method for the #hb_paint_funcs_t to clip
  176. * subsequent paint calls to a rectangle.
  177. *
  178. * The coordinates of the rectangle are interpreted according
  179. * to the current transform.
  180. *
  181. * This clip is applied in addition to the current clip,
  182. * and remains in effect until a matching call to
  183. * the #hb_paint_funcs_pop_clip_func_t vfunc.
  184. *
  185. * Since: 7.0.0
  186. */
  187. typedef void (*hb_paint_push_clip_rectangle_func_t) (hb_paint_funcs_t *funcs,
  188. void *paint_data,
  189. float xmin, float ymin,
  190. float xmax, float ymax,
  191. void *user_data);
  192. /**
  193. * hb_paint_pop_clip_func_t:
  194. * @funcs: paint functions object
  195. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  196. * @user_data: User data pointer passed to hb_paint_funcs_set_pop_clip_func()
  197. *
  198. * A virtual method for the #hb_paint_funcs_t to undo
  199. * the effect of a prior call to the #hb_paint_funcs_push_clip_glyph_func_t
  200. * or #hb_paint_funcs_push_clip_rectangle_func_t vfuncs.
  201. *
  202. * Since: 7.0.0
  203. */
  204. typedef void (*hb_paint_pop_clip_func_t) (hb_paint_funcs_t *funcs,
  205. void *paint_data,
  206. void *user_data);
  207. /**
  208. * hb_paint_color_func_t:
  209. * @funcs: paint functions object
  210. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  211. * @is_foreground: whether the color is the foreground
  212. * @color: The color to use, unpremultiplied
  213. * @user_data: User data pointer passed to hb_paint_funcs_set_color_func()
  214. *
  215. * A virtual method for the #hb_paint_funcs_t to paint a
  216. * color everywhere within the current clip.
  217. *
  218. * Since: 7.0.0
  219. */
  220. typedef void (*hb_paint_color_func_t) (hb_paint_funcs_t *funcs,
  221. void *paint_data,
  222. hb_bool_t is_foreground,
  223. hb_color_t color,
  224. void *user_data);
  225. /**
  226. * HB_PAINT_IMAGE_FORMAT_PNG:
  227. *
  228. * Tag identifying PNG images in #hb_paint_image_func_t callbacks.
  229. *
  230. * Since: 7.0.0
  231. */
  232. #define HB_PAINT_IMAGE_FORMAT_PNG HB_TAG('p','n','g',' ')
  233. /**
  234. * HB_PAINT_IMAGE_FORMAT_SVG:
  235. *
  236. * Tag identifying SVG images in #hb_paint_image_func_t callbacks.
  237. *
  238. * Since: 7.0.0
  239. */
  240. #define HB_PAINT_IMAGE_FORMAT_SVG HB_TAG('s','v','g',' ')
  241. /**
  242. * HB_PAINT_IMAGE_FORMAT_BGRA:
  243. *
  244. * Tag identifying raw pixel-data images in #hb_paint_image_func_t callbacks.
  245. * The data is in BGRA pre-multiplied sRGBA color-space format.
  246. *
  247. * Since: 7.0.0
  248. */
  249. #define HB_PAINT_IMAGE_FORMAT_BGRA HB_TAG('B','G','R','A')
  250. /**
  251. * hb_paint_image_func_t:
  252. * @funcs: paint functions object
  253. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  254. * @image: the image data
  255. * @width: width of the raster image in pixels, or 0
  256. * @height: height of the raster image in pixels, or 0
  257. * @format: the image format as a tag
  258. * @slant: the synthetic slant ratio to be applied to the image during rendering
  259. * @extents: (nullable): glyph extents for desired rendering
  260. * @user_data: User data pointer passed to hb_paint_funcs_set_image_func()
  261. *
  262. * A virtual method for the #hb_paint_funcs_t to paint a glyph image.
  263. *
  264. * This method is called for glyphs with image blobs in the CBDT,
  265. * sbix or SVG tables. The @format identifies the kind of data that
  266. * is contained in @image. Possible values include #HB_PAINT_IMAGE_FORMAT_PNG,
  267. * #HB_PAINT_IMAGE_FORMAT_SVG and #HB_PAINT_IMAGE_FORMAT_BGRA.
  268. *
  269. * The image dimensions and glyph extents are provided if available,
  270. * and should be used to size and position the image.
  271. *
  272. * Return value: Whether the operation was successful.
  273. *
  274. * Since: 7.0.0
  275. */
  276. typedef hb_bool_t (*hb_paint_image_func_t) (hb_paint_funcs_t *funcs,
  277. void *paint_data,
  278. hb_blob_t *image,
  279. unsigned int width,
  280. unsigned int height,
  281. hb_tag_t format,
  282. float slant,
  283. hb_glyph_extents_t *extents,
  284. void *user_data);
  285. /**
  286. * hb_color_stop_t:
  287. * @offset: the offset of the color stop
  288. * @is_foreground: whether the color is the foreground
  289. * @color: the color, unpremultiplied
  290. *
  291. * Information about a color stop on a color line.
  292. *
  293. * Color lines typically have offsets ranging between 0 and 1,
  294. * but that is not required.
  295. *
  296. * Note: despite @color being unpremultiplied here, interpolation in
  297. * gradients shall happen in premultiplied space. See the OpenType spec
  298. * [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
  299. * section for details.
  300. *
  301. * Since: 7.0.0
  302. */
  303. typedef struct {
  304. float offset;
  305. hb_bool_t is_foreground;
  306. hb_color_t color;
  307. } hb_color_stop_t;
  308. /**
  309. * hb_paint_extend_t:
  310. * @HB_PAINT_EXTEND_PAD: Outside the defined interval,
  311. * the color of the closest color stop is used.
  312. * @HB_PAINT_EXTEND_REPEAT: The color line is repeated over
  313. * repeated multiples of the defined interval
  314. * @HB_PAINT_EXTEND_REFLECT: The color line is repeated over
  315. * repeated intervals, as for the repeat mode.
  316. * However, in each repeated interval, the ordering of
  317. * color stops is the reverse of the adjacent interval.
  318. *
  319. * The values of this enumeration determine how color values
  320. * outside the minimum and maximum defined offset on a #hb_color_line_t
  321. * are determined.
  322. *
  323. * See the OpenType spec [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
  324. * section for details.
  325. *
  326. * Since: 7.0.0
  327. */
  328. typedef enum {
  329. HB_PAINT_EXTEND_PAD,
  330. HB_PAINT_EXTEND_REPEAT,
  331. HB_PAINT_EXTEND_REFLECT
  332. } hb_paint_extend_t;
  333. typedef struct hb_color_line_t hb_color_line_t;
  334. /**
  335. * hb_color_line_get_color_stops_func_t:
  336. * @color_line: a #hb_color_line_t object
  337. * @color_line_data: the data accompanying @color_line
  338. * @start: the index of the first color stop to return
  339. * @count: (inout) (optional): Input = the maximum number of feature tags to return;
  340. * Output = the actual number of feature tags returned (may be zero)
  341. * @color_stops: (out) (array length=count) (optional): Array of #hb_color_stop_t to populate
  342. * @user_data: the data accompanying this method
  343. *
  344. * A virtual method for the #hb_color_line_t to fetch color stops.
  345. *
  346. * Return value: the total number of color stops in @color_line
  347. *
  348. * Since: 7.0.0
  349. */
  350. typedef unsigned int (*hb_color_line_get_color_stops_func_t) (hb_color_line_t *color_line,
  351. void *color_line_data,
  352. unsigned int start,
  353. unsigned int *count,
  354. hb_color_stop_t *color_stops,
  355. void *user_data);
  356. /**
  357. * hb_color_line_get_extend_func_t:
  358. * @color_line: a #hb_color_line_t object
  359. * @color_line_data: the data accompanying @color_line
  360. * @user_data: the data accompanying this method
  361. *
  362. * A virtual method for the @hb_color_line_t to fetches the extend mode.
  363. *
  364. * Return value: the extend mode of @color_line
  365. *
  366. * Since: 7.0.0
  367. */
  368. typedef hb_paint_extend_t (*hb_color_line_get_extend_func_t) (hb_color_line_t *color_line,
  369. void *color_line_data,
  370. void *user_data);
  371. /**
  372. * hb_color_line_t:
  373. *
  374. * A struct containing color information for a gradient.
  375. *
  376. * Since: 7.0.0
  377. */
  378. struct hb_color_line_t {
  379. void *data;
  380. hb_color_line_get_color_stops_func_t get_color_stops;
  381. void *get_color_stops_user_data;
  382. hb_color_line_get_extend_func_t get_extend;
  383. void *get_extend_user_data;
  384. void *reserved0;
  385. void *reserved1;
  386. void *reserved2;
  387. void *reserved3;
  388. void *reserved5;
  389. void *reserved6;
  390. void *reserved7;
  391. void *reserved8;
  392. };
  393. HB_EXTERN unsigned int
  394. hb_color_line_get_color_stops (hb_color_line_t *color_line,
  395. unsigned int start,
  396. unsigned int *count,
  397. hb_color_stop_t *color_stops);
  398. HB_EXTERN hb_paint_extend_t
  399. hb_color_line_get_extend (hb_color_line_t *color_line);
  400. /**
  401. * hb_paint_linear_gradient_func_t:
  402. * @funcs: paint functions object
  403. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  404. * @color_line: Color information for the gradient
  405. * @x0: X coordinate of the first point
  406. * @y0: Y coordinate of the first point
  407. * @x1: X coordinate of the second point
  408. * @y1: Y coordinate of the second point
  409. * @x2: X coordinate of the third point
  410. * @y2: Y coordinate of the third point
  411. * @user_data: User data pointer passed to hb_paint_funcs_set_linear_gradient_func()
  412. *
  413. * A virtual method for the #hb_paint_funcs_t to paint a linear
  414. * gradient everywhere within the current clip.
  415. *
  416. * The @color_line object contains information about the colors of the gradients.
  417. * It is only valid for the duration of the callback, you cannot keep it around.
  418. *
  419. * The coordinates of the points are interpreted according
  420. * to the current transform.
  421. *
  422. * See the OpenType spec [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
  423. * section for details on how the points define the direction
  424. * of the gradient, and how to interpret the @color_line.
  425. *
  426. * Since: 7.0.0
  427. */
  428. typedef void (*hb_paint_linear_gradient_func_t) (hb_paint_funcs_t *funcs,
  429. void *paint_data,
  430. hb_color_line_t *color_line,
  431. float x0, float y0,
  432. float x1, float y1,
  433. float x2, float y2,
  434. void *user_data);
  435. /**
  436. * hb_paint_radial_gradient_func_t:
  437. * @funcs: paint functions object
  438. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  439. * @color_line: Color information for the gradient
  440. * @x0: X coordinate of the first circle's center
  441. * @y0: Y coordinate of the first circle's center
  442. * @r0: radius of the first circle
  443. * @x1: X coordinate of the second circle's center
  444. * @y1: Y coordinate of the second circle's center
  445. * @r1: radius of the second circle
  446. * @user_data: User data pointer passed to hb_paint_funcs_set_radial_gradient_func()
  447. *
  448. * A virtual method for the #hb_paint_funcs_t to paint a radial
  449. * gradient everywhere within the current clip.
  450. *
  451. * The @color_line object contains information about the colors of the gradients.
  452. * It is only valid for the duration of the callback, you cannot keep it around.
  453. *
  454. * The coordinates of the points are interpreted according
  455. * to the current transform.
  456. *
  457. * See the OpenType spec [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
  458. * section for details on how the points define the direction
  459. * of the gradient, and how to interpret the @color_line.
  460. *
  461. * Since: 7.0.0
  462. */
  463. typedef void (*hb_paint_radial_gradient_func_t) (hb_paint_funcs_t *funcs,
  464. void *paint_data,
  465. hb_color_line_t *color_line,
  466. float x0, float y0, float r0,
  467. float x1, float y1, float r1,
  468. void *user_data);
  469. /**
  470. * hb_paint_sweep_gradient_func_t:
  471. * @funcs: paint functions object
  472. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  473. * @color_line: Color information for the gradient
  474. * @x0: X coordinate of the circle's center
  475. * @y0: Y coordinate of the circle's center
  476. * @start_angle: the start angle, in radians
  477. * @end_angle: the end angle, in radians
  478. * @user_data: User data pointer passed to hb_paint_funcs_set_sweep_gradient_func()
  479. *
  480. * A virtual method for the #hb_paint_funcs_t to paint a sweep
  481. * gradient everywhere within the current clip.
  482. *
  483. * The @color_line object contains information about the colors of the gradients.
  484. * It is only valid for the duration of the callback, you cannot keep it around.
  485. *
  486. * The coordinates of the points are interpreted according
  487. * to the current transform.
  488. *
  489. * See the OpenType spec [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
  490. * section for details on how the points define the direction
  491. * of the gradient, and how to interpret the @color_line.
  492. *
  493. * Since: 7.0.0
  494. */
  495. typedef void (*hb_paint_sweep_gradient_func_t) (hb_paint_funcs_t *funcs,
  496. void *paint_data,
  497. hb_color_line_t *color_line,
  498. float x0, float y0,
  499. float start_angle,
  500. float end_angle,
  501. void *user_data);
  502. /**
  503. * hb_paint_composite_mode_t:
  504. * @HB_PAINT_COMPOSITE_MODE_CLEAR: clear destination layer (bounded)
  505. * @HB_PAINT_COMPOSITE_MODE_SRC: replace destination layer (bounded)
  506. * @HB_PAINT_COMPOSITE_MODE_SRC_OVER: draw source layer on top of destination layer
  507. * (bounded)
  508. * @HB_PAINT_COMPOSITE_MODE_SRC_IN: draw source where there was destination content
  509. * (unbounded)
  510. * @HB_PAINT_COMPOSITE_MODE_SRC_OUT: draw source where there was no destination
  511. * content (unbounded)
  512. * @HB_PAINT_COMPOSITE_MODE_SRC_ATOP: draw source on top of destination content and
  513. * only there
  514. * @HB_PAINT_COMPOSITE_MODE_DEST: ignore the source
  515. * @HB_PAINT_COMPOSITE_MODE_DEST_OVER: draw destination on top of source
  516. * @HB_PAINT_COMPOSITE_MODE_DEST_IN: leave destination only where there was
  517. * source content (unbounded)
  518. * @HB_PAINT_COMPOSITE_MODE_DEST_OUT: leave destination only where there was no
  519. * source content
  520. * @HB_PAINT_COMPOSITE_MODE_DEST_ATOP: leave destination on top of source content
  521. * and only there (unbounded)
  522. * @HB_PAINT_COMPOSITE_MODE_XOR: source and destination are shown where there is only
  523. * one of them
  524. * @HB_PAINT_COMPOSITE_MODE_PLUS: source and destination layers are accumulated
  525. * @HB_PAINT_COMPOSITE_MODE_MULTIPLY: source and destination layers are multiplied.
  526. * This causes the result to be at least as dark as the darker inputs.
  527. * @HB_PAINT_COMPOSITE_MODE_SCREEN: source and destination are complemented and
  528. * multiplied. This causes the result to be at least as light as the lighter
  529. * inputs.
  530. * @HB_PAINT_COMPOSITE_MODE_OVERLAY: multiplies or screens, depending on the
  531. * lightness of the destination color.
  532. * @HB_PAINT_COMPOSITE_MODE_DARKEN: replaces the destination with the source if it
  533. * is darker, otherwise keeps the source.
  534. * @HB_PAINT_COMPOSITE_MODE_LIGHTEN: replaces the destination with the source if it
  535. * is lighter, otherwise keeps the source.
  536. * @HB_PAINT_COMPOSITE_MODE_COLOR_DODGE: brightens the destination color to reflect
  537. * the source color.
  538. * @HB_PAINT_COMPOSITE_MODE_COLOR_BURN: darkens the destination color to reflect
  539. * the source color.
  540. * @HB_PAINT_COMPOSITE_MODE_HARD_LIGHT: Multiplies or screens, dependent on source
  541. * color.
  542. * @HB_PAINT_COMPOSITE_MODE_SOFT_LIGHT: Darkens or lightens, dependent on source
  543. * color.
  544. * @HB_PAINT_COMPOSITE_MODE_DIFFERENCE: Takes the difference of the source and
  545. * destination color.
  546. * @HB_PAINT_COMPOSITE_MODE_EXCLUSION: Produces an effect similar to difference, but
  547. * with lower contrast.
  548. * @HB_PAINT_COMPOSITE_MODE_HSL_HUE: Creates a color with the hue of the source
  549. * and the saturation and luminosity of the target.
  550. * @HB_PAINT_COMPOSITE_MODE_HSL_SATURATION: Creates a color with the saturation
  551. * of the source and the hue and luminosity of the target. Painting with
  552. * this mode onto a gray area produces no change.
  553. * @HB_PAINT_COMPOSITE_MODE_HSL_COLOR: Creates a color with the hue and saturation
  554. * of the source and the luminosity of the target. This preserves the gray
  555. * levels of the target and is useful for coloring monochrome images or
  556. * tinting color images.
  557. * @HB_PAINT_COMPOSITE_MODE_HSL_LUMINOSITY: Creates a color with the luminosity of
  558. * the source and the hue and saturation of the target. This produces an
  559. * inverse effect to @HB_PAINT_COMPOSITE_MODE_HSL_COLOR.
  560. *
  561. * The values of this enumeration describe the compositing modes
  562. * that can be used when combining temporary redirected drawing
  563. * with the backdrop.
  564. *
  565. * See the OpenType spec [COLR](https://learn.microsoft.com/en-us/typography/opentype/spec/colr)
  566. * section for details.
  567. *
  568. * Since: 7.0.0
  569. */
  570. typedef enum {
  571. HB_PAINT_COMPOSITE_MODE_CLEAR,
  572. HB_PAINT_COMPOSITE_MODE_SRC,
  573. HB_PAINT_COMPOSITE_MODE_DEST,
  574. HB_PAINT_COMPOSITE_MODE_SRC_OVER,
  575. HB_PAINT_COMPOSITE_MODE_DEST_OVER,
  576. HB_PAINT_COMPOSITE_MODE_SRC_IN,
  577. HB_PAINT_COMPOSITE_MODE_DEST_IN,
  578. HB_PAINT_COMPOSITE_MODE_SRC_OUT,
  579. HB_PAINT_COMPOSITE_MODE_DEST_OUT,
  580. HB_PAINT_COMPOSITE_MODE_SRC_ATOP,
  581. HB_PAINT_COMPOSITE_MODE_DEST_ATOP,
  582. HB_PAINT_COMPOSITE_MODE_XOR,
  583. HB_PAINT_COMPOSITE_MODE_PLUS,
  584. HB_PAINT_COMPOSITE_MODE_SCREEN,
  585. HB_PAINT_COMPOSITE_MODE_OVERLAY,
  586. HB_PAINT_COMPOSITE_MODE_DARKEN,
  587. HB_PAINT_COMPOSITE_MODE_LIGHTEN,
  588. HB_PAINT_COMPOSITE_MODE_COLOR_DODGE,
  589. HB_PAINT_COMPOSITE_MODE_COLOR_BURN,
  590. HB_PAINT_COMPOSITE_MODE_HARD_LIGHT,
  591. HB_PAINT_COMPOSITE_MODE_SOFT_LIGHT,
  592. HB_PAINT_COMPOSITE_MODE_DIFFERENCE,
  593. HB_PAINT_COMPOSITE_MODE_EXCLUSION,
  594. HB_PAINT_COMPOSITE_MODE_MULTIPLY,
  595. HB_PAINT_COMPOSITE_MODE_HSL_HUE,
  596. HB_PAINT_COMPOSITE_MODE_HSL_SATURATION,
  597. HB_PAINT_COMPOSITE_MODE_HSL_COLOR,
  598. HB_PAINT_COMPOSITE_MODE_HSL_LUMINOSITY
  599. } hb_paint_composite_mode_t;
  600. /**
  601. * hb_paint_push_group_func_t:
  602. * @funcs: paint functions object
  603. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  604. * @user_data: User data pointer passed to hb_paint_funcs_set_push_group_func()
  605. *
  606. * A virtual method for the #hb_paint_funcs_t to use
  607. * an intermediate surface for subsequent paint calls.
  608. *
  609. * The drawing will be redirected to an intermediate surface
  610. * until a matching call to the #hb_paint_funcs_pop_group_func_t
  611. * vfunc.
  612. *
  613. * Since: 7.0.0
  614. */
  615. typedef void (*hb_paint_push_group_func_t) (hb_paint_funcs_t *funcs,
  616. void *paint_data,
  617. void *user_data);
  618. /**
  619. * hb_paint_pop_group_func_t:
  620. * @funcs: paint functions object
  621. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  622. * @mode: the compositing mode to use
  623. * @user_data: User data pointer passed to hb_paint_funcs_set_pop_group_func()
  624. *
  625. * A virtual method for the #hb_paint_funcs_t to undo
  626. * the effect of a prior call to the #hb_paint_funcs_push_group_func_t
  627. * vfunc.
  628. *
  629. * This call stops the redirection to the intermediate surface,
  630. * and then composites it on the previous surface, using the
  631. * compositing mode passed to this call.
  632. *
  633. * Since: 7.0.0
  634. */
  635. typedef void (*hb_paint_pop_group_func_t) (hb_paint_funcs_t *funcs,
  636. void *paint_data,
  637. hb_paint_composite_mode_t mode,
  638. void *user_data);
  639. /**
  640. * hb_paint_custom_palette_color_func_t:
  641. * @funcs: paint functions object
  642. * @paint_data: The data accompanying the paint functions in hb_font_paint_glyph()
  643. * @color_index: the color index
  644. * @color: (out): fetched color
  645. * @user_data: User data pointer passed to hb_paint_funcs_set_pop_group_func()
  646. *
  647. * A virtual method for the #hb_paint_funcs_t to fetch a color from the custom
  648. * color palette.
  649. *
  650. * Custom palette colors override the colors from the fonts selected color
  651. * palette. It is not necessary to override all palette entries; for entries
  652. * that should be taken from the font palette, return `false`.
  653. *
  654. * This function might get called multiple times, but the custom palette is
  655. * expected to remain unchanged for duration of a hb_font_paint_glyph() call.
  656. *
  657. * Return value: `true` if found, `false` otherwise
  658. *
  659. * Since: 7.0.0
  660. */
  661. typedef hb_bool_t (*hb_paint_custom_palette_color_func_t) (hb_paint_funcs_t *funcs,
  662. void *paint_data,
  663. unsigned int color_index,
  664. hb_color_t *color,
  665. void *user_data);
  666. /**
  667. * hb_paint_funcs_set_push_transform_func:
  668. * @funcs: A paint functions struct
  669. * @func: (closure user_data) (destroy destroy) (scope notified): The push-transform callback
  670. * @user_data: Data to pass to @func
  671. * @destroy: (nullable): Function to call when @user_data is no longer needed
  672. *
  673. * Sets the push-transform callback on the paint functions struct.
  674. *
  675. * Since: 7.0.0
  676. */
  677. HB_EXTERN void
  678. hb_paint_funcs_set_push_transform_func (hb_paint_funcs_t *funcs,
  679. hb_paint_push_transform_func_t func,
  680. void *user_data,
  681. hb_destroy_func_t destroy);
  682. /**
  683. * hb_paint_funcs_set_pop_transform_func:
  684. * @funcs: A paint functions struct
  685. * @func: (closure user_data) (destroy destroy) (scope notified): The pop-transform callback
  686. * @user_data: Data to pass to @func
  687. * @destroy: (nullable): Function to call when @user_data is no longer needed
  688. *
  689. * Sets the pop-transform callback on the paint functions struct.
  690. *
  691. * Since: 7.0.0
  692. */
  693. HB_EXTERN void
  694. hb_paint_funcs_set_pop_transform_func (hb_paint_funcs_t *funcs,
  695. hb_paint_pop_transform_func_t func,
  696. void *user_data,
  697. hb_destroy_func_t destroy);
  698. /**
  699. * hb_paint_funcs_set_color_glyph_func:
  700. * @funcs: A paint functions struct
  701. * @func: (closure user_data) (destroy destroy) (scope notified): The color-glyph callback
  702. * @user_data: Data to pass to @func
  703. * @destroy: (nullable): Function to call when @user_data is no longer needed
  704. *
  705. * Sets the color-glyph callback on the paint functions struct.
  706. *
  707. * Since: 8.2.0
  708. */
  709. HB_EXTERN void
  710. hb_paint_funcs_set_color_glyph_func (hb_paint_funcs_t *funcs,
  711. hb_paint_color_glyph_func_t func,
  712. void *user_data,
  713. hb_destroy_func_t destroy);
  714. /**
  715. * hb_paint_funcs_set_push_clip_glyph_func:
  716. * @funcs: A paint functions struct
  717. * @func: (closure user_data) (destroy destroy) (scope notified): The push-clip-glyph callback
  718. * @user_data: Data to pass to @func
  719. * @destroy: (nullable): Function to call when @user_data is no longer needed
  720. *
  721. * Sets the push-clip-glyph callback on the paint functions struct.
  722. *
  723. * Since: 7.0.0
  724. */
  725. HB_EXTERN void
  726. hb_paint_funcs_set_push_clip_glyph_func (hb_paint_funcs_t *funcs,
  727. hb_paint_push_clip_glyph_func_t func,
  728. void *user_data,
  729. hb_destroy_func_t destroy);
  730. /**
  731. * hb_paint_funcs_set_push_clip_rectangle_func:
  732. * @funcs: A paint functions struct
  733. * @func: (closure user_data) (destroy destroy) (scope notified): The push-clip-rectangle callback
  734. * @user_data: Data to pass to @func
  735. * @destroy: (nullable): Function to call when @user_data is no longer needed
  736. *
  737. * Sets the push-clip-rect callback on the paint functions struct.
  738. *
  739. * Since: 7.0.0
  740. */
  741. HB_EXTERN void
  742. hb_paint_funcs_set_push_clip_rectangle_func (hb_paint_funcs_t *funcs,
  743. hb_paint_push_clip_rectangle_func_t func,
  744. void *user_data,
  745. hb_destroy_func_t destroy);
  746. /**
  747. * hb_paint_funcs_set_pop_clip_func:
  748. * @funcs: A paint functions struct
  749. * @func: (closure user_data) (destroy destroy) (scope notified): The pop-clip callback
  750. * @user_data: Data to pass to @func
  751. * @destroy: (nullable): Function to call when @user_data is no longer needed
  752. *
  753. * Sets the pop-clip callback on the paint functions struct.
  754. *
  755. * Since: 7.0.0
  756. */
  757. HB_EXTERN void
  758. hb_paint_funcs_set_pop_clip_func (hb_paint_funcs_t *funcs,
  759. hb_paint_pop_clip_func_t func,
  760. void *user_data,
  761. hb_destroy_func_t destroy);
  762. /**
  763. * hb_paint_funcs_set_color_func:
  764. * @funcs: A paint functions struct
  765. * @func: (closure user_data) (destroy destroy) (scope notified): The paint-color callback
  766. * @user_data: Data to pass to @func
  767. * @destroy: (nullable): Function to call when @user_data is no longer needed
  768. *
  769. * Sets the paint-color callback on the paint functions struct.
  770. *
  771. * Since: 7.0.0
  772. */
  773. HB_EXTERN void
  774. hb_paint_funcs_set_color_func (hb_paint_funcs_t *funcs,
  775. hb_paint_color_func_t func,
  776. void *user_data,
  777. hb_destroy_func_t destroy);
  778. /**
  779. * hb_paint_funcs_set_image_func:
  780. * @funcs: A paint functions struct
  781. * @func: (closure user_data) (destroy destroy) (scope notified): The paint-image callback
  782. * @user_data: Data to pass to @func
  783. * @destroy: (nullable): Function to call when @user_data is no longer needed
  784. *
  785. * Sets the paint-image callback on the paint functions struct.
  786. *
  787. * Since: 7.0.0
  788. */
  789. HB_EXTERN void
  790. hb_paint_funcs_set_image_func (hb_paint_funcs_t *funcs,
  791. hb_paint_image_func_t func,
  792. void *user_data,
  793. hb_destroy_func_t destroy);
  794. /**
  795. * hb_paint_funcs_set_linear_gradient_func:
  796. * @funcs: A paint functions struct
  797. * @func: (closure user_data) (destroy destroy) (scope notified): The linear-gradient callback
  798. * @user_data: Data to pass to @func
  799. * @destroy: (nullable): Function to call when @user_data is no longer needed
  800. *
  801. * Sets the linear-gradient callback on the paint functions struct.
  802. *
  803. * Since: 7.0.0
  804. */
  805. HB_EXTERN void
  806. hb_paint_funcs_set_linear_gradient_func (hb_paint_funcs_t *funcs,
  807. hb_paint_linear_gradient_func_t func,
  808. void *user_data,
  809. hb_destroy_func_t destroy);
  810. /**
  811. * hb_paint_funcs_set_radial_gradient_func:
  812. * @funcs: A paint functions struct
  813. * @func: (closure user_data) (destroy destroy) (scope notified): The radial-gradient callback
  814. * @user_data: Data to pass to @func
  815. * @destroy: (nullable): Function to call when @user_data is no longer needed
  816. *
  817. * Sets the radial-gradient callback on the paint functions struct.
  818. *
  819. * Since: 7.0.0
  820. */
  821. HB_EXTERN void
  822. hb_paint_funcs_set_radial_gradient_func (hb_paint_funcs_t *funcs,
  823. hb_paint_radial_gradient_func_t func,
  824. void *user_data,
  825. hb_destroy_func_t destroy);
  826. /**
  827. * hb_paint_funcs_set_sweep_gradient_func:
  828. * @funcs: A paint functions struct
  829. * @func: (closure user_data) (destroy destroy) (scope notified): The sweep-gradient callback
  830. * @user_data: Data to pass to @func
  831. * @destroy: (nullable): Function to call when @user_data is no longer needed
  832. *
  833. * Sets the sweep-gradient callback on the paint functions struct.
  834. *
  835. * Since: 7.0.0
  836. */
  837. HB_EXTERN void
  838. hb_paint_funcs_set_sweep_gradient_func (hb_paint_funcs_t *funcs,
  839. hb_paint_sweep_gradient_func_t func,
  840. void *user_data,
  841. hb_destroy_func_t destroy);
  842. /**
  843. * hb_paint_funcs_set_push_group_func:
  844. * @funcs: A paint functions struct
  845. * @func: (closure user_data) (destroy destroy) (scope notified): The push-group callback
  846. * @user_data: Data to pass to @func
  847. * @destroy: (nullable): Function to call when @user_data is no longer needed
  848. *
  849. * Sets the push-group callback on the paint functions struct.
  850. *
  851. * Since: 7.0.0
  852. */
  853. HB_EXTERN void
  854. hb_paint_funcs_set_push_group_func (hb_paint_funcs_t *funcs,
  855. hb_paint_push_group_func_t func,
  856. void *user_data,
  857. hb_destroy_func_t destroy);
  858. /**
  859. * hb_paint_funcs_set_pop_group_func:
  860. * @funcs: A paint functions struct
  861. * @func: (closure user_data) (destroy destroy) (scope notified): The pop-group callback
  862. * @user_data: Data to pass to @func
  863. * @destroy: (nullable): Function to call when @user_data is no longer needed
  864. *
  865. * Sets the pop-group callback on the paint functions struct.
  866. *
  867. * Since: 7.0.0
  868. */
  869. HB_EXTERN void
  870. hb_paint_funcs_set_pop_group_func (hb_paint_funcs_t *funcs,
  871. hb_paint_pop_group_func_t func,
  872. void *user_data,
  873. hb_destroy_func_t destroy);
  874. /**
  875. * hb_paint_funcs_set_custom_palette_color_func:
  876. * @funcs: A paint functions struct
  877. * @func: (closure user_data) (destroy destroy) (scope notified): The custom-palette-color callback
  878. * @user_data: Data to pass to @func
  879. * @destroy: (nullable): Function to call when @user_data is no longer needed
  880. *
  881. * Sets the custom-palette-color callback on the paint functions struct.
  882. *
  883. * Since: 7.0.0
  884. */
  885. HB_EXTERN void
  886. hb_paint_funcs_set_custom_palette_color_func (hb_paint_funcs_t *funcs,
  887. hb_paint_custom_palette_color_func_t func,
  888. void *user_data,
  889. hb_destroy_func_t destroy);
  890. /*
  891. * Manual API
  892. */
  893. HB_EXTERN void
  894. hb_paint_push_transform (hb_paint_funcs_t *funcs, void *paint_data,
  895. float xx, float yx,
  896. float xy, float yy,
  897. float dx, float dy);
  898. HB_EXTERN void
  899. hb_paint_pop_transform (hb_paint_funcs_t *funcs, void *paint_data);
  900. HB_EXTERN hb_bool_t
  901. hb_paint_color_glyph (hb_paint_funcs_t *funcs, void *paint_data,
  902. hb_codepoint_t glyph,
  903. hb_font_t *font);
  904. HB_EXTERN void
  905. hb_paint_push_clip_glyph (hb_paint_funcs_t *funcs, void *paint_data,
  906. hb_codepoint_t glyph,
  907. hb_font_t *font);
  908. HB_EXTERN void
  909. hb_paint_push_clip_rectangle (hb_paint_funcs_t *funcs, void *paint_data,
  910. float xmin, float ymin,
  911. float xmax, float ymax);
  912. HB_EXTERN void
  913. hb_paint_pop_clip (hb_paint_funcs_t *funcs, void *paint_data);
  914. HB_EXTERN void
  915. hb_paint_color (hb_paint_funcs_t *funcs, void *paint_data,
  916. hb_bool_t is_foreground,
  917. hb_color_t color);
  918. HB_EXTERN void
  919. hb_paint_image (hb_paint_funcs_t *funcs, void *paint_data,
  920. hb_blob_t *image,
  921. unsigned int width,
  922. unsigned int height,
  923. hb_tag_t format,
  924. float slant,
  925. hb_glyph_extents_t *extents);
  926. HB_EXTERN void
  927. hb_paint_linear_gradient (hb_paint_funcs_t *funcs, void *paint_data,
  928. hb_color_line_t *color_line,
  929. float x0, float y0,
  930. float x1, float y1,
  931. float x2, float y2);
  932. HB_EXTERN void
  933. hb_paint_radial_gradient (hb_paint_funcs_t *funcs, void *paint_data,
  934. hb_color_line_t *color_line,
  935. float x0, float y0,
  936. float r0,
  937. float x1, float y1,
  938. float r1);
  939. HB_EXTERN void
  940. hb_paint_sweep_gradient (hb_paint_funcs_t *funcs, void *paint_data,
  941. hb_color_line_t *color_line,
  942. float x0, float y0,
  943. float start_angle, float end_angle);
  944. HB_EXTERN void
  945. hb_paint_push_group (hb_paint_funcs_t *funcs, void *paint_data);
  946. HB_EXTERN void
  947. hb_paint_pop_group (hb_paint_funcs_t *funcs, void *paint_data,
  948. hb_paint_composite_mode_t mode);
  949. HB_EXTERN hb_bool_t
  950. hb_paint_custom_palette_color (hb_paint_funcs_t *funcs, void *paint_data,
  951. unsigned int color_index,
  952. hb_color_t *color);
  953. HB_END_DECLS
  954. #endif /* HB_PAINT_H */