hb-font.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. /*
  2. * Copyright © 2009 Red Hat, Inc.
  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. * Red Hat Author(s): Behdad Esfahbod
  25. */
  26. #ifndef HB_H_IN
  27. #error "Include <hb.h> instead."
  28. #endif
  29. #ifndef HB_FONT_H
  30. #define HB_FONT_H
  31. #include "hb-common.h"
  32. #include "hb-face.h"
  33. HB_BEGIN_DECLS
  34. typedef struct hb_font_t hb_font_t;
  35. /*
  36. * hb_font_funcs_t
  37. */
  38. typedef struct hb_font_funcs_t hb_font_funcs_t;
  39. hb_font_funcs_t *
  40. hb_font_funcs_create (void);
  41. hb_font_funcs_t *
  42. hb_font_funcs_get_empty (void);
  43. hb_font_funcs_t *
  44. hb_font_funcs_reference (hb_font_funcs_t *ffuncs);
  45. void
  46. hb_font_funcs_destroy (hb_font_funcs_t *ffuncs);
  47. hb_bool_t
  48. hb_font_funcs_set_user_data (hb_font_funcs_t *ffuncs,
  49. hb_user_data_key_t *key,
  50. void * data,
  51. hb_destroy_func_t destroy,
  52. hb_bool_t replace);
  53. void *
  54. hb_font_funcs_get_user_data (hb_font_funcs_t *ffuncs,
  55. hb_user_data_key_t *key);
  56. void
  57. hb_font_funcs_make_immutable (hb_font_funcs_t *ffuncs);
  58. hb_bool_t
  59. hb_font_funcs_is_immutable (hb_font_funcs_t *ffuncs);
  60. /* glyph extents */
  61. typedef struct hb_glyph_extents_t
  62. {
  63. hb_position_t x_bearing;
  64. hb_position_t y_bearing;
  65. hb_position_t width;
  66. hb_position_t height;
  67. } hb_glyph_extents_t;
  68. /* func types */
  69. typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
  70. hb_codepoint_t unicode, hb_codepoint_t variation_selector,
  71. hb_codepoint_t *glyph,
  72. void *user_data);
  73. typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
  74. hb_codepoint_t glyph,
  75. void *user_data);
  76. typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
  77. typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
  78. typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *font_data,
  79. hb_codepoint_t glyph,
  80. hb_position_t *x, hb_position_t *y,
  81. void *user_data);
  82. typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
  83. typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
  84. typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data,
  85. hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
  86. void *user_data);
  87. typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t;
  88. typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t;
  89. typedef hb_bool_t (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, void *font_data,
  90. hb_codepoint_t glyph,
  91. hb_glyph_extents_t *extents,
  92. void *user_data);
  93. typedef hb_bool_t (*hb_font_get_glyph_contour_point_func_t) (hb_font_t *font, void *font_data,
  94. hb_codepoint_t glyph, unsigned int point_index,
  95. hb_position_t *x, hb_position_t *y,
  96. void *user_data);
  97. typedef hb_bool_t (*hb_font_get_glyph_name_func_t) (hb_font_t *font, void *font_data,
  98. hb_codepoint_t glyph,
  99. char *name, unsigned int size,
  100. void *user_data);
  101. typedef hb_bool_t (*hb_font_get_glyph_from_name_func_t) (hb_font_t *font, void *font_data,
  102. const char *name, int len, /* -1 means nul-terminated */
  103. hb_codepoint_t *glyph,
  104. void *user_data);
  105. /* func setters */
  106. /**
  107. * hb_font_funcs_set_glyph_func:
  108. * @ffuncs: font functions.
  109. * @func: (closure user_data) (destroy destroy) (scope notified):
  110. * @user_data:
  111. * @destroy:
  112. *
  113. *
  114. *
  115. * Since: 1.0
  116. **/
  117. void
  118. hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
  119. hb_font_get_glyph_func_t func,
  120. void *user_data, hb_destroy_func_t destroy);
  121. /**
  122. * hb_font_funcs_set_glyph_h_advance_func:
  123. * @ffuncs: font functions.
  124. * @func: (closure user_data) (destroy destroy) (scope notified):
  125. * @user_data:
  126. * @destroy:
  127. *
  128. *
  129. *
  130. * Since: 1.0
  131. **/
  132. void
  133. hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
  134. hb_font_get_glyph_h_advance_func_t func,
  135. void *user_data, hb_destroy_func_t destroy);
  136. /**
  137. * hb_font_funcs_set_glyph_v_advance_func:
  138. * @ffuncs: font functions.
  139. * @func: (closure user_data) (destroy destroy) (scope notified):
  140. * @user_data:
  141. * @destroy:
  142. *
  143. *
  144. *
  145. * Since: 1.0
  146. **/
  147. void
  148. hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
  149. hb_font_get_glyph_v_advance_func_t func,
  150. void *user_data, hb_destroy_func_t destroy);
  151. /**
  152. * hb_font_funcs_set_glyph_h_origin_func:
  153. * @ffuncs: font functions.
  154. * @func: (closure user_data) (destroy destroy) (scope notified):
  155. * @user_data:
  156. * @destroy:
  157. *
  158. *
  159. *
  160. * Since: 1.0
  161. **/
  162. void
  163. hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs,
  164. hb_font_get_glyph_h_origin_func_t func,
  165. void *user_data, hb_destroy_func_t destroy);
  166. /**
  167. * hb_font_funcs_set_glyph_v_origin_func:
  168. * @ffuncs: font functions.
  169. * @func: (closure user_data) (destroy destroy) (scope notified):
  170. * @user_data:
  171. * @destroy:
  172. *
  173. *
  174. *
  175. * Since: 1.0
  176. **/
  177. void
  178. hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs,
  179. hb_font_get_glyph_v_origin_func_t func,
  180. void *user_data, hb_destroy_func_t destroy);
  181. /**
  182. * hb_font_funcs_set_glyph_h_kerning_func:
  183. * @ffuncs: font functions.
  184. * @func: (closure user_data) (destroy destroy) (scope notified):
  185. * @user_data:
  186. * @destroy:
  187. *
  188. *
  189. *
  190. * Since: 1.0
  191. **/
  192. void
  193. hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs,
  194. hb_font_get_glyph_h_kerning_func_t func,
  195. void *user_data, hb_destroy_func_t destroy);
  196. /**
  197. * hb_font_funcs_set_glyph_v_kerning_func:
  198. * @ffuncs: font functions.
  199. * @func: (closure user_data) (destroy destroy) (scope notified):
  200. * @user_data:
  201. * @destroy:
  202. *
  203. *
  204. *
  205. * Since: 1.0
  206. **/
  207. void
  208. hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs,
  209. hb_font_get_glyph_v_kerning_func_t func,
  210. void *user_data, hb_destroy_func_t destroy);
  211. /**
  212. * hb_font_funcs_set_glyph_extents_func:
  213. * @ffuncs: font functions.
  214. * @func: (closure user_data) (destroy destroy) (scope notified):
  215. * @user_data:
  216. * @destroy:
  217. *
  218. *
  219. *
  220. * Since: 1.0
  221. **/
  222. void
  223. hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
  224. hb_font_get_glyph_extents_func_t func,
  225. void *user_data, hb_destroy_func_t destroy);
  226. /**
  227. * hb_font_funcs_set_glyph_contour_point_func:
  228. * @ffuncs: font functions.
  229. * @func: (closure user_data) (destroy destroy) (scope notified):
  230. * @user_data:
  231. * @destroy:
  232. *
  233. *
  234. *
  235. * Since: 1.0
  236. **/
  237. void
  238. hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs,
  239. hb_font_get_glyph_contour_point_func_t func,
  240. void *user_data, hb_destroy_func_t destroy);
  241. /**
  242. * hb_font_funcs_set_glyph_name_func:
  243. * @ffuncs: font functions.
  244. * @func: (closure user_data) (destroy destroy) (scope notified):
  245. * @user_data:
  246. * @destroy:
  247. *
  248. *
  249. *
  250. * Since: 1.0
  251. **/
  252. void
  253. hb_font_funcs_set_glyph_name_func (hb_font_funcs_t *ffuncs,
  254. hb_font_get_glyph_name_func_t func,
  255. void *user_data, hb_destroy_func_t destroy);
  256. /**
  257. * hb_font_funcs_set_glyph_from_name_func:
  258. * @ffuncs: font functions.
  259. * @func: (closure user_data) (destroy destroy) (scope notified):
  260. * @user_data:
  261. * @destroy:
  262. *
  263. *
  264. *
  265. * Since: 1.0
  266. **/
  267. void
  268. hb_font_funcs_set_glyph_from_name_func (hb_font_funcs_t *ffuncs,
  269. hb_font_get_glyph_from_name_func_t func,
  270. void *user_data, hb_destroy_func_t destroy);
  271. /* func dispatch */
  272. hb_bool_t
  273. hb_font_get_glyph (hb_font_t *font,
  274. hb_codepoint_t unicode, hb_codepoint_t variation_selector,
  275. hb_codepoint_t *glyph);
  276. hb_position_t
  277. hb_font_get_glyph_h_advance (hb_font_t *font,
  278. hb_codepoint_t glyph);
  279. hb_position_t
  280. hb_font_get_glyph_v_advance (hb_font_t *font,
  281. hb_codepoint_t glyph);
  282. hb_bool_t
  283. hb_font_get_glyph_h_origin (hb_font_t *font,
  284. hb_codepoint_t glyph,
  285. hb_position_t *x, hb_position_t *y);
  286. hb_bool_t
  287. hb_font_get_glyph_v_origin (hb_font_t *font,
  288. hb_codepoint_t glyph,
  289. hb_position_t *x, hb_position_t *y);
  290. hb_position_t
  291. hb_font_get_glyph_h_kerning (hb_font_t *font,
  292. hb_codepoint_t left_glyph, hb_codepoint_t right_glyph);
  293. hb_position_t
  294. hb_font_get_glyph_v_kerning (hb_font_t *font,
  295. hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph);
  296. hb_bool_t
  297. hb_font_get_glyph_extents (hb_font_t *font,
  298. hb_codepoint_t glyph,
  299. hb_glyph_extents_t *extents);
  300. hb_bool_t
  301. hb_font_get_glyph_contour_point (hb_font_t *font,
  302. hb_codepoint_t glyph, unsigned int point_index,
  303. hb_position_t *x, hb_position_t *y);
  304. hb_bool_t
  305. hb_font_get_glyph_name (hb_font_t *font,
  306. hb_codepoint_t glyph,
  307. char *name, unsigned int size);
  308. hb_bool_t
  309. hb_font_get_glyph_from_name (hb_font_t *font,
  310. const char *name, int len, /* -1 means nul-terminated */
  311. hb_codepoint_t *glyph);
  312. /* high-level funcs, with fallback */
  313. void
  314. hb_font_get_glyph_advance_for_direction (hb_font_t *font,
  315. hb_codepoint_t glyph,
  316. hb_direction_t direction,
  317. hb_position_t *x, hb_position_t *y);
  318. void
  319. hb_font_get_glyph_origin_for_direction (hb_font_t *font,
  320. hb_codepoint_t glyph,
  321. hb_direction_t direction,
  322. hb_position_t *x, hb_position_t *y);
  323. void
  324. hb_font_add_glyph_origin_for_direction (hb_font_t *font,
  325. hb_codepoint_t glyph,
  326. hb_direction_t direction,
  327. hb_position_t *x, hb_position_t *y);
  328. void
  329. hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
  330. hb_codepoint_t glyph,
  331. hb_direction_t direction,
  332. hb_position_t *x, hb_position_t *y);
  333. void
  334. hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
  335. hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
  336. hb_direction_t direction,
  337. hb_position_t *x, hb_position_t *y);
  338. hb_bool_t
  339. hb_font_get_glyph_extents_for_origin (hb_font_t *font,
  340. hb_codepoint_t glyph,
  341. hb_direction_t direction,
  342. hb_glyph_extents_t *extents);
  343. hb_bool_t
  344. hb_font_get_glyph_contour_point_for_origin (hb_font_t *font,
  345. hb_codepoint_t glyph, unsigned int point_index,
  346. hb_direction_t direction,
  347. hb_position_t *x, hb_position_t *y);
  348. /* Generates gidDDD if glyph has no name. */
  349. void
  350. hb_font_glyph_to_string (hb_font_t *font,
  351. hb_codepoint_t glyph,
  352. char *s, unsigned int size);
  353. /* Parses gidDDD and uniUUUU strings automatically. */
  354. hb_bool_t
  355. hb_font_glyph_from_string (hb_font_t *font,
  356. const char *s, int len, /* -1 means nul-terminated */
  357. hb_codepoint_t *glyph);
  358. /*
  359. * hb_font_t
  360. */
  361. /* Fonts are very light-weight objects */
  362. hb_font_t *
  363. hb_font_create (hb_face_t *face);
  364. hb_font_t *
  365. hb_font_create_sub_font (hb_font_t *parent);
  366. hb_font_t *
  367. hb_font_get_empty (void);
  368. hb_font_t *
  369. hb_font_reference (hb_font_t *font);
  370. void
  371. hb_font_destroy (hb_font_t *font);
  372. hb_bool_t
  373. hb_font_set_user_data (hb_font_t *font,
  374. hb_user_data_key_t *key,
  375. void * data,
  376. hb_destroy_func_t destroy,
  377. hb_bool_t replace);
  378. void *
  379. hb_font_get_user_data (hb_font_t *font,
  380. hb_user_data_key_t *key);
  381. void
  382. hb_font_make_immutable (hb_font_t *font);
  383. hb_bool_t
  384. hb_font_is_immutable (hb_font_t *font);
  385. hb_font_t *
  386. hb_font_get_parent (hb_font_t *font);
  387. hb_face_t *
  388. hb_font_get_face (hb_font_t *font);
  389. void
  390. hb_font_set_funcs (hb_font_t *font,
  391. hb_font_funcs_t *klass,
  392. void *font_data,
  393. hb_destroy_func_t destroy);
  394. /* Be *very* careful with this function! */
  395. void
  396. hb_font_set_funcs_data (hb_font_t *font,
  397. void *font_data,
  398. hb_destroy_func_t destroy);
  399. void
  400. hb_font_set_scale (hb_font_t *font,
  401. int x_scale,
  402. int y_scale);
  403. void
  404. hb_font_get_scale (hb_font_t *font,
  405. int *x_scale,
  406. int *y_scale);
  407. /*
  408. * A zero value means "no hinting in that direction"
  409. */
  410. void
  411. hb_font_set_ppem (hb_font_t *font,
  412. unsigned int x_ppem,
  413. unsigned int y_ppem);
  414. void
  415. hb_font_get_ppem (hb_font_t *font,
  416. unsigned int *x_ppem,
  417. unsigned int *y_ppem);
  418. HB_END_DECLS
  419. #endif /* HB_FONT_H */