You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

382 lines
17 KiB

  1. /*
  2. * libcucul Canvas for ultrafast compositing of Unicode letters
  3. * Copyright (c) 2002-2006 Sam Hocevar <sam@zoy.org>
  4. * All Rights Reserved
  5. *
  6. * $Id$
  7. *
  8. * This library is free software. It comes without any warranty, to
  9. * the extent permitted by applicable law. You can redistribute it
  10. * and/or modify it under the terms of the Do What The Fuck You Want
  11. * To Public License, Version 2, as published by Sam Hocevar. See
  12. * http://sam.zoy.org/wtfpl/COPYING for more details.
  13. */
  14. /** \file cucul.h
  15. * \version \$Id$
  16. * \author Sam Hocevar <sam@zoy.org>
  17. * \brief The \e libcucul public header.
  18. *
  19. * This header contains the public types and functions that applications
  20. * using \e libcucul may use.
  21. */
  22. #ifndef __CUCUL_H__
  23. #define __CUCUL_H__
  24. #include <cucul_types.h>
  25. #undef __extern
  26. #if defined(_DOXYGEN_SKIP_ME)
  27. #elif defined(_WIN32) && defined(__LIBCUCUL__)
  28. # define __extern extern __declspec(dllexport)
  29. #else
  30. # define __extern extern
  31. #endif
  32. /** libcucul API version */
  33. #define CUCUL_API_VERSION_1
  34. #ifdef __cplusplus
  35. extern "C"
  36. {
  37. #endif
  38. /** \e libcucul canvas */
  39. typedef struct cucul_canvas cucul_canvas_t;
  40. /** dither structure */
  41. typedef struct cucul_dither cucul_dither_t;
  42. /** font structure */
  43. typedef struct cucul_font cucul_font_t;
  44. /** file handle structure */
  45. typedef struct cucul_file cucul_file_t;
  46. /** \defgroup cucul_attr libcucul attribute definitions
  47. *
  48. * Colours and styles that can be used with cucul_set_attr().
  49. *
  50. * @{ */
  51. #define CUCUL_BLACK 0x00 /**< The colour index for black. */
  52. #define CUCUL_BLUE 0x01 /**< The colour index for blue. */
  53. #define CUCUL_GREEN 0x02 /**< The colour index for green. */
  54. #define CUCUL_CYAN 0x03 /**< The colour index for cyan. */
  55. #define CUCUL_RED 0x04 /**< The colour index for red. */
  56. #define CUCUL_MAGENTA 0x05 /**< The colour index for magenta. */
  57. #define CUCUL_BROWN 0x06 /**< The colour index for brown. */
  58. #define CUCUL_LIGHTGRAY 0x07 /**< The colour index for light gray. */
  59. #define CUCUL_DARKGRAY 0x08 /**< The colour index for dark gray. */
  60. #define CUCUL_LIGHTBLUE 0x09 /**< The colour index for blue. */
  61. #define CUCUL_LIGHTGREEN 0x0a /**< The colour index for light green. */
  62. #define CUCUL_LIGHTCYAN 0x0b /**< The colour index for light cyan. */
  63. #define CUCUL_LIGHTRED 0x0c /**< The colour index for light red. */
  64. #define CUCUL_LIGHTMAGENTA 0x0d /**< The colour index for light magenta. */
  65. #define CUCUL_YELLOW 0x0e /**< The colour index for yellow. */
  66. #define CUCUL_WHITE 0x0f /**< The colour index for white. */
  67. #define CUCUL_DEFAULT 0x10 /**< The output driver's default colour. */
  68. #define CUCUL_TRANSPARENT 0x20 /**< The transparent colour. */
  69. #define CUCUL_BOLD 0x01 /**< The style mask for bold. */
  70. #define CUCUL_ITALICS 0x02 /**< The style mask for italics. */
  71. #define CUCUL_UNDERLINE 0x04 /**< The style mask for underline. */
  72. #define CUCUL_BLINK 0x08 /**< The style mask for blink. */
  73. /* @} */
  74. /** \defgroup libcucul libcucul basic functions
  75. *
  76. * These functions provide the basic \e libcaca routines for library
  77. * initialisation, system information retrieval and configuration.
  78. *
  79. * @{ */
  80. __extern cucul_canvas_t * cucul_create_canvas(int, int);
  81. __extern int cucul_manage_canvas(cucul_canvas_t *, int (*)(void *), void *);
  82. __extern int cucul_unmanage_canvas(cucul_canvas_t *, int (*)(void *), void *);
  83. __extern int cucul_set_canvas_size(cucul_canvas_t *, int, int);
  84. __extern int cucul_get_canvas_width(cucul_canvas_t const *);
  85. __extern int cucul_get_canvas_height(cucul_canvas_t const *);
  86. __extern uint8_t const * cucul_get_canvas_chars(cucul_canvas_t const *);
  87. __extern uint8_t const * cucul_get_canvas_attrs(cucul_canvas_t const *);
  88. __extern int cucul_free_canvas(cucul_canvas_t *);
  89. __extern int cucul_rand(int, int);
  90. __extern char const * cucul_get_version(void);
  91. /* @} */
  92. /** \defgroup cucul_canvas libcucul canvas drawing
  93. *
  94. * These functions provide low-level character printing routines and
  95. * higher level graphics functions.
  96. *
  97. * @{ */
  98. #define CUCUL_MAGIC_FULLWIDTH 0x000ffffe /**< Used to indicate that the previous character was a fullwidth glyph. */
  99. __extern int cucul_gotoxy(cucul_canvas_t *, int, int);
  100. __extern int cucul_get_cursor_x(cucul_canvas_t const *);
  101. __extern int cucul_get_cursor_y(cucul_canvas_t const *);
  102. __extern int cucul_put_char(cucul_canvas_t *, int, int, uint32_t);
  103. __extern uint32_t cucul_get_char(cucul_canvas_t const *, int, int);
  104. __extern int cucul_put_str(cucul_canvas_t *, int, int, char const *);
  105. __extern uint32_t cucul_get_attr(cucul_canvas_t const *, int, int);
  106. __extern int cucul_set_attr(cucul_canvas_t *, uint32_t);
  107. __extern int cucul_put_attr(cucul_canvas_t *, int, int, uint32_t);
  108. __extern int cucul_set_color_ansi(cucul_canvas_t *, uint8_t, uint8_t);
  109. __extern int cucul_set_color_argb(cucul_canvas_t *, uint16_t, uint16_t);
  110. __extern int cucul_printf(cucul_canvas_t *, int, int, char const *, ...);
  111. __extern int cucul_clear_canvas(cucul_canvas_t *);
  112. __extern int cucul_set_canvas_handle(cucul_canvas_t *, int, int);
  113. __extern int cucul_get_canvas_handle_x(cucul_canvas_t const *);
  114. __extern int cucul_get_canvas_handle_y(cucul_canvas_t const *);
  115. __extern int cucul_blit(cucul_canvas_t *, int, int, cucul_canvas_t const *,
  116. cucul_canvas_t const *);
  117. __extern int cucul_set_canvas_boundaries(cucul_canvas_t *, int, int, int, int);
  118. /* @} */
  119. /** \defgroup cucul_transform libcucul canvas transformation
  120. *
  121. * These functions perform horizontal and vertical canvas flipping.
  122. *
  123. * @{ */
  124. __extern int cucul_invert(cucul_canvas_t *);
  125. __extern int cucul_flip(cucul_canvas_t *);
  126. __extern int cucul_flop(cucul_canvas_t *);
  127. __extern int cucul_rotate_180(cucul_canvas_t *);
  128. __extern int cucul_rotate_left(cucul_canvas_t *);
  129. __extern int cucul_rotate_right(cucul_canvas_t *);
  130. __extern int cucul_stretch_left(cucul_canvas_t *);
  131. __extern int cucul_stretch_right(cucul_canvas_t *);
  132. /* @} */
  133. /** \defgroup cucul_attributes libcucul attribute conversions
  134. *
  135. * These functions perform conversions between attribute values.
  136. *
  137. * @{ */
  138. __extern uint8_t cucul_attr_to_ansi(uint32_t);
  139. __extern uint8_t cucul_attr_to_ansi_fg(uint32_t);
  140. __extern uint8_t cucul_attr_to_ansi_bg(uint32_t);
  141. __extern uint16_t cucul_attr_to_rgb12_fg(uint32_t);
  142. __extern uint16_t cucul_attr_to_rgb12_bg(uint32_t);
  143. __extern void cucul_attr_to_argb64(uint32_t, uint8_t[8]);
  144. /* @} */
  145. /** \defgroup cucul_charset libcucul character set conversions
  146. *
  147. * These functions perform conversions between usual character sets.
  148. *
  149. * @{ */
  150. __extern uint32_t cucul_utf8_to_utf32(char const *, size_t *);
  151. __extern size_t cucul_utf32_to_utf8(char *, uint32_t);
  152. __extern uint8_t cucul_utf32_to_cp437(uint32_t);
  153. __extern uint32_t cucul_cp437_to_utf32(uint8_t);
  154. __extern char cucul_utf32_to_ascii(uint32_t);
  155. __extern int cucul_utf32_is_fullwidth(uint32_t);
  156. /* @} */
  157. /** \defgroup cucul_primitives libcucul primitives drawing
  158. *
  159. * These functions provide routines for primitive drawing, such as lines,
  160. * boxes, triangles and ellipses.
  161. *
  162. * @{ */
  163. __extern int cucul_draw_line(cucul_canvas_t *, int, int, int, int, uint32_t);
  164. __extern int cucul_draw_polyline(cucul_canvas_t *, int const x[],
  165. int const y[], int, uint32_t);
  166. __extern int cucul_draw_thin_line(cucul_canvas_t *, int, int, int, int);
  167. __extern int cucul_draw_thin_polyline(cucul_canvas_t *, int const x[],
  168. int const y[], int);
  169. __extern int cucul_draw_circle(cucul_canvas_t *, int, int, int, uint32_t);
  170. __extern int cucul_draw_ellipse(cucul_canvas_t *, int, int, int, int, uint32_t);
  171. __extern int cucul_draw_thin_ellipse(cucul_canvas_t *, int, int, int, int);
  172. __extern int cucul_fill_ellipse(cucul_canvas_t *, int, int, int, int, uint32_t);
  173. __extern int cucul_draw_box(cucul_canvas_t *, int, int, int, int, uint32_t);
  174. __extern int cucul_draw_thin_box(cucul_canvas_t *, int, int, int, int);
  175. __extern int cucul_draw_cp437_box(cucul_canvas_t *, int, int, int, int);
  176. __extern int cucul_fill_box(cucul_canvas_t *, int, int, int, int, uint32_t);
  177. __extern int cucul_draw_triangle(cucul_canvas_t *, int, int, int, int, int,
  178. int, uint32_t);
  179. __extern int cucul_draw_thin_triangle(cucul_canvas_t *, int, int, int, int,
  180. int, int);
  181. __extern int cucul_fill_triangle(cucul_canvas_t *, int, int, int, int, int,
  182. int, uint32_t);
  183. /* @} */
  184. /** \defgroup cucul_frame libcucul canvas frame handling
  185. *
  186. * These functions provide high level routines for canvas frame insertion,
  187. * removal, copying etc.
  188. *
  189. * @{ */
  190. __extern int cucul_get_frame_count(cucul_canvas_t const *);
  191. __extern int cucul_set_frame(cucul_canvas_t *, int);
  192. __extern char const *cucul_get_frame_name(cucul_canvas_t const *);
  193. __extern int cucul_set_frame_name(cucul_canvas_t *, char const *);
  194. __extern int cucul_create_frame(cucul_canvas_t *, int);
  195. __extern int cucul_free_frame(cucul_canvas_t *, int);
  196. /* @} */
  197. /** \defgroup cucul_dither libcucul bitmap dithering
  198. *
  199. * These functions provide high level routines for dither allocation and
  200. * rendering.
  201. *
  202. * @{ */
  203. __extern cucul_dither_t *cucul_create_dither(int, int, int, int,
  204. uint32_t, uint32_t,
  205. uint32_t, uint32_t);
  206. __extern int cucul_set_dither_palette(cucul_dither_t *,
  207. uint32_t r[], uint32_t g[],
  208. uint32_t b[], uint32_t a[]);
  209. __extern int cucul_set_dither_brightness(cucul_dither_t *, float);
  210. __extern float cucul_get_dither_brightness(cucul_dither_t const *);
  211. __extern int cucul_set_dither_gamma(cucul_dither_t *, float);
  212. __extern float cucul_get_dither_gamma(cucul_dither_t const *);
  213. __extern int cucul_set_dither_contrast(cucul_dither_t *, float);
  214. __extern float cucul_get_dither_contrast(cucul_dither_t const *);
  215. __extern int cucul_set_dither_antialias(cucul_dither_t *, char const *);
  216. __extern char const * const * cucul_get_dither_antialias_list(cucul_dither_t
  217. const *);
  218. __extern char const * cucul_get_dither_antialias(cucul_dither_t const *);
  219. __extern int cucul_set_dither_color(cucul_dither_t *, char const *);
  220. __extern char const * const * cucul_get_dither_color_list(cucul_dither_t
  221. const *);
  222. __extern char const * cucul_get_dither_color(cucul_dither_t const *);
  223. __extern int cucul_set_dither_charset(cucul_dither_t *, char const *);
  224. __extern char const * const * cucul_get_dither_charset_list(cucul_dither_t
  225. const *);
  226. __extern char const * cucul_get_dither_charset(cucul_dither_t const *);
  227. __extern int cucul_set_dither_algorithm(cucul_dither_t *, char const *);
  228. __extern char const * const * cucul_get_dither_algorithm_list(cucul_dither_t
  229. const *);
  230. __extern char const * cucul_get_dither_algorithm(cucul_dither_t const *);
  231. __extern int cucul_dither_bitmap(cucul_canvas_t *, int, int, int, int,
  232. cucul_dither_t const *, void *);
  233. __extern int cucul_free_dither(cucul_dither_t *);
  234. /* @} */
  235. /** \defgroup cucul_font libcucul font handling
  236. *
  237. * These functions provide font handling routines and high quality
  238. * canvas to bitmap rendering.
  239. *
  240. * @{ */
  241. __extern cucul_font_t *cucul_load_font(void const *, size_t);
  242. __extern char const * const * cucul_get_font_list(void);
  243. __extern int cucul_get_font_width(cucul_font_t const *);
  244. __extern int cucul_get_font_height(cucul_font_t const *);
  245. __extern uint32_t const *cucul_get_font_blocks(cucul_font_t const *);
  246. __extern int cucul_render_canvas(cucul_canvas_t const *, cucul_font_t const *,
  247. void *, int, int, int);
  248. __extern int cucul_free_font(cucul_font_t *);
  249. /* @} */
  250. /** \defgroup cucul_figfont libcucul FIGfont handling
  251. *
  252. * These functions provide FIGlet and TOIlet font handling routines.
  253. *
  254. * @{ */
  255. __extern int cucul_canvas_set_figfont(cucul_canvas_t *, char const *);
  256. __extern int cucul_put_figchar(cucul_canvas_t *, uint32_t);
  257. /* @} */
  258. /** \defgroup cucul_file libcucul file IO
  259. *
  260. * These functions allow to read and write files in a platform-independent
  261. * way.
  262. * @{ */
  263. __extern cucul_file_t *cucul_file_open(char const *, const char *);
  264. __extern int cucul_file_close(cucul_file_t *);
  265. __extern size_t cucul_file_read(cucul_file_t *, void *, size_t);
  266. __extern size_t cucul_file_write(cucul_file_t *, const void *, size_t);
  267. __extern char * cucul_file_gets(cucul_file_t *, char *, int);
  268. __extern int cucul_file_eof(cucul_file_t *);
  269. /* @} */
  270. /** \defgroup cucul_importexport libcucul importers/exporters from/to various
  271. * formats
  272. *
  273. * These functions import various file formats into a new canvas, or export
  274. * the current canvas to various text formats.
  275. *
  276. * @{ */
  277. __extern ssize_t cucul_import_memory(cucul_canvas_t *, void const *,
  278. size_t, char const *);
  279. __extern ssize_t cucul_import_file(cucul_canvas_t *, char const *,
  280. char const *);
  281. __extern char const * const * cucul_get_import_list(void);
  282. __extern void *cucul_export_memory(cucul_canvas_t const *, char const *,
  283. size_t *);
  284. __extern char const * const * cucul_get_export_list(void);
  285. /* @} */
  286. #if !defined(_DOXYGEN_SKIP_ME)
  287. /* Legacy stuff from beta versions, will probably disappear in 1.0 */
  288. typedef struct cucul_buffer cucul_buffer_t;
  289. # if defined __GNUC__ && __GNUC__ >= 3
  290. # define CUCUL_DEPRECATED __attribute__ ((__deprecated__))
  291. # else
  292. # define CUCUL_DEPRECATED
  293. # endif
  294. __extern int cucul_putchar(cucul_canvas_t *, int, int,
  295. unsigned long int) CUCUL_DEPRECATED;
  296. __extern unsigned long int cucul_getchar(cucul_canvas_t *,
  297. int, int) CUCUL_DEPRECATED;
  298. __extern int cucul_putstr(cucul_canvas_t *, int, int,
  299. char const *) CUCUL_DEPRECATED;
  300. __extern int cucul_set_color(cucul_canvas_t *, unsigned char,
  301. unsigned char) CUCUL_DEPRECATED;
  302. __extern int cucul_set_truecolor(cucul_canvas_t *, unsigned int,
  303. unsigned int) CUCUL_DEPRECATED;
  304. __extern unsigned int cucul_get_canvas_frame_count(cucul_canvas_t *)
  305. CUCUL_DEPRECATED;
  306. __extern int cucul_set_canvas_frame(cucul_canvas_t *,
  307. unsigned int) CUCUL_DEPRECATED;
  308. __extern int cucul_create_canvas_frame(cucul_canvas_t *,
  309. unsigned int) CUCUL_DEPRECATED;
  310. __extern int cucul_free_canvas_frame(cucul_canvas_t *,
  311. unsigned int) CUCUL_DEPRECATED;
  312. __extern cucul_buffer_t *cucul_load_memory(void *,
  313. unsigned long int) CUCUL_DEPRECATED;
  314. __extern cucul_buffer_t *cucul_load_file(char const *) CUCUL_DEPRECATED;
  315. __extern unsigned long int cucul_get_buffer_size(cucul_buffer_t *)
  316. CUCUL_DEPRECATED;
  317. __extern void * cucul_get_buffer_data(cucul_buffer_t *) CUCUL_DEPRECATED;
  318. __extern int cucul_free_buffer(cucul_buffer_t *) CUCUL_DEPRECATED;
  319. __extern cucul_buffer_t * cucul_export_canvas(cucul_canvas_t *,
  320. char const *) CUCUL_DEPRECATED;
  321. __extern cucul_canvas_t * cucul_import_canvas(cucul_buffer_t *,
  322. char const *) CUCUL_DEPRECATED;
  323. __extern int cucul_rotate(cucul_canvas_t *) CUCUL_DEPRECATED;
  324. __extern int cucul_set_dither_invert(cucul_dither_t *, int) CUCUL_DEPRECATED;
  325. __extern int cucul_set_dither_mode(cucul_dither_t *,
  326. char const *) CUCUL_DEPRECATED;
  327. __extern char const * const * cucul_get_dither_mode_list(cucul_dither_t
  328. const *)
  329. CUCUL_DEPRECATED;
  330. # define CUCUL_COLOR_BLACK CUCUL_BLACK
  331. # define CUCUL_COLOR_BLUE CUCUL_BLUE
  332. # define CUCUL_COLOR_GREEN CUCUL_GREEN
  333. # define CUCUL_COLOR_CYAN CUCUL_CYAN
  334. # define CUCUL_COLOR_RED CUCUL_RED
  335. # define CUCUL_COLOR_MAGENTA CUCUL_MAGENTA
  336. # define CUCUL_COLOR_BROWN CUCUL_BROWN
  337. # define CUCUL_COLOR_LIGHTGRAY CUCUL_LIGHTGRAY
  338. # define CUCUL_COLOR_DARKGRAY CUCUL_DARKGRAY
  339. # define CUCUL_COLOR_LIGHTBLUE CUCUL_LIGHTBLUE
  340. # define CUCUL_COLOR_LIGHTGREEN CUCUL_LIGHTGREEN
  341. # define CUCUL_COLOR_LIGHTCYAN CUCUL_LIGHTCYAN
  342. # define CUCUL_COLOR_LIGHTRED CUCUL_LIGHTRED
  343. # define CUCUL_COLOR_LIGHTMAGENTA CUCUL_LIGHTMAGENTA
  344. # define CUCUL_COLOR_YELLOW CUCUL_YELLOW
  345. # define CUCUL_COLOR_WHITE CUCUL_YELLOW
  346. # define CUCUL_COLOR_DEFAULT CUCUL_DEFAULT
  347. # define CUCUL_COLOR_TRANSPARENT CUCUL_TRANSPARENT
  348. #endif
  349. #ifdef __cplusplus
  350. }
  351. #endif
  352. #undef __extern
  353. #endif /* __CUCUL_H__ */