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.
 
 
 
 
 

820 lines
40 KiB

  1. #ifndef LIB_TEXT_SUITE_H
  2. #define LIB_TEXT_SUITE_H
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <stdbool.h>
  6. #if __MINGW32__
  7. # define WINAPI __stdcall
  8. #elif __GNUC__
  9. # if defined(__x86_64__)
  10. # define WINAPI
  11. # else
  12. # define WINAPI __attribute__((stdcall))
  13. # endif
  14. #else
  15. # define WINAPI
  16. #endif
  17. #define STATIC_ASSERT(cond, msg) typedef char static_assertion_##msg[(cond)?1:-1]
  18. typedef uint16_t lts_wchar_t;
  19. STATIC_ASSERT(sizeof(float) == 4, size_of_float_should_be_4);
  20. STATIC_ASSERT(sizeof(lts_wchar_t) == 2, size_of_wchar_t_should_be_2);
  21. /**********************************************************************************************************************************/
  22. /* public interface */
  23. /**********************************************************************************************************************************/
  24. /* enumerations *******************************************************************************************************************/
  25. typedef enum
  26. {
  27. ltsErrUnknown = -1,
  28. ltsErrNone = 0,
  29. // misc
  30. ltsErrNotInitialized = 1,
  31. ltsErrInvalidEnum = 2,
  32. ltsErrInvalidValue = 3,
  33. ltsErrInvalidOperation = 4,
  34. ltsErrInvalidType = 5,
  35. // invalid handles
  36. ltsErrInvalidContextHandle = 100,
  37. ltsErrInvalidRendererHandle = 101,
  38. ltsErrInvalidTextBlockHandle = 102,
  39. ltsErrInvalidFontHandle = 103,
  40. ltsErrInvalidFontCreatorHandle = 104,
  41. ltsErrInvalidImageHandle = 105,
  42. ltsErrInvalidPostProcHandle = 106,
  43. // library
  44. ltsErrInvalidLibName = 200,
  45. ltsErrInvalidLibHandle = 201,
  46. ltsErrInvalidMethodName = 202
  47. }
  48. lts_error_code_t;
  49. STATIC_ASSERT(sizeof(lts_error_code_t) == 4, size_of_lts_error_code_t_should_be_4);
  50. typedef enum
  51. {
  52. ltsUTF8,
  53. ltsISO_8859_1,
  54. ltsISO_8859_2,
  55. ltsISO_8859_3,
  56. ltsISO_8859_4,
  57. ltsISO_8859_5,
  58. ltsISO_8859_6,
  59. ltsISO_8859_7,
  60. ltsISO_8859_8,
  61. ltsISO_8859_9,
  62. ltsISO_8859_10,
  63. ltsISO_8859_11,
  64. ltsISO_8859_13,
  65. ltsISO_8859_14,
  66. ltsISO_8859_15,
  67. ltsISO_8859_16,
  68. ltsISO_037,
  69. ltsISO_437,
  70. ltsISO_500,
  71. ltsISO_737,
  72. ltsISO_775,
  73. ltsISO_850,
  74. ltsISO_852,
  75. ltsISO_855,
  76. ltsISO_857,
  77. ltsISO_860,
  78. ltsISO_861,
  79. ltsISO_862,
  80. ltsISO_863,
  81. ltsISO_864,
  82. ltsISO_865,
  83. ltsISO_866,
  84. ltsISO_869,
  85. ltsISO_874,
  86. ltsISO_875,
  87. ltsISO_1026,
  88. ltsISO_1250,
  89. ltsISO_1251,
  90. ltsISO_1252,
  91. ltsISO_1253,
  92. ltsISO_1254,
  93. ltsISO_1255,
  94. ltsISO_1256,
  95. ltsISO_1257,
  96. ltsISO_1258
  97. }
  98. lts_code_page_t;
  99. STATIC_ASSERT(sizeof(lts_code_page_t) == 4, size_of_lts_code_page_t_should_be_4);
  100. typedef enum
  101. {
  102. ltsFormatEmpty,
  103. ltsFormatRGBA8,
  104. ltsFormatLumAlpha8,
  105. ltsFormatAlpha8,
  106. ltsFormatLum8
  107. }
  108. lts_format_t;
  109. STATIC_ASSERT(sizeof(lts_format_t) == 4, size_of_lts_format_t_should_be_4);
  110. typedef enum
  111. {
  112. ltsRendererUnknown,
  113. ltsRendererOpenGL,
  114. ltsRendererOpenGLES
  115. }
  116. lts_renderer_type_t;
  117. STATIC_ASSERT(sizeof(lts_renderer_type_t) == 4, size_of_lts_renderer_type_t_should_be_4);
  118. typedef enum
  119. {
  120. ltsFontCreatorUnknown,
  121. ltsFontCreatorFreeType,
  122. ltsFontCreatorGDI,
  123. ltsFontCreatorCustom
  124. }
  125. lts_font_creator_type_t;
  126. STATIC_ASSERT(sizeof(lts_font_creator_type_t) == 4, size_of_lts_font_creator_type_t_should_be_4);
  127. typedef enum
  128. {
  129. ltsVertAlignTop,
  130. ltsVertAlignCenter,
  131. ltsVertAlignBottom
  132. }
  133. lts_vert_align_t;
  134. STATIC_ASSERT(sizeof(lts_vert_align_t) == 4, size_of_lts_vert_align_t_should_be_4);
  135. typedef enum
  136. {
  137. ltsHorzAlignLeft,
  138. ltsHorzAlignCenter,
  139. ltsHorzAlignRight,
  140. ltsHorzAlignJustify
  141. }
  142. lts_horz_align_t;
  143. STATIC_ASSERT(sizeof(lts_horz_align_t) == 4, size_of_lts_horz_align_t_should_be_4);
  144. typedef enum
  145. {
  146. ltsClipNone,
  147. ltsClipWordBorder,
  148. ltsClipCharBorder,
  149. ltsClipWordComplete,
  150. ltsClipCharComplete
  151. }
  152. lts_clipping_t;
  153. STATIC_ASSERT(sizeof(lts_clipping_t) == 4, size_of_lts_clipping_t_should_be_4);
  154. typedef enum
  155. {
  156. ltsAANone,
  157. ltsAANormal
  158. }
  159. lts_anti_aliasing_t;
  160. STATIC_ASSERT(sizeof(lts_anti_aliasing_t) == 4, size_of_lts_anti_aliasing_t_should_be_4);
  161. typedef enum
  162. {
  163. ltsUsageInclude,
  164. ltsUsageExclude
  165. }
  166. lts_char_range_usage_t;
  167. STATIC_ASSERT(sizeof(lts_char_range_usage_t) == 4, size_of_lts_char_range_usage_t_should_be_4);
  168. typedef enum
  169. {
  170. ltsStreamOriginBegin = 0,
  171. ltsStreamOriginCurrent = 1,
  172. ltsStreamOriginEnd = 2
  173. }
  174. lts_stream_origin_t;
  175. STATIC_ASSERT(sizeof(lts_stream_origin_t) == 4, size_of_lts_stream_origin_t_should_be_4);
  176. typedef enum
  177. {
  178. ltsModeIgnore,
  179. ltsModeReplace,
  180. ltsModeModulate
  181. }
  182. lts_image_mode_t;
  183. STATIC_ASSERT(sizeof(lts_image_mode_t) == 4, size_of_lts_image_mode_t_should_be_4);
  184. /* flags **************************************************************************************************************************/
  185. #define FLAGS_MAKE(enum) (1 << enum)
  186. #define FLAGS_SET(flags, enum) flags |= FLAGS_MAKE(enum)
  187. #define FLAGS_UNSET(flags, enum) flags &= ~FLAGS_MAKE(enum)
  188. #define FLAGS_CLEAR(flags) flags = 0
  189. #define FLAGS_IS_SET(flags, enum) (flags & FLAGS_MAKE(enum))
  190. typedef enum
  191. {
  192. ltsBlockFlagWordWrap
  193. }
  194. lts_block_flag_t;
  195. typedef uint32_t lts_block_flags_t;
  196. STATIC_ASSERT(sizeof(lts_block_flag_t) == 4, size_of_lts_block_flag_t_should_be_4);
  197. typedef enum
  198. {
  199. ltsFontStyleBold,
  200. ltsFontStyleItalic,
  201. ltsFontStyleUnderline,
  202. ltsFontStyleStrikeout,
  203. }
  204. lts_font_style_flag_t;
  205. typedef uint32_t lts_font_style_flags_t;
  206. STATIC_ASSERT(sizeof(lts_font_style_flag_t) == 4, size_of_lts_font_style_flag_t_should_be_4);
  207. typedef enum
  208. {
  209. ltsColorChannelRed,
  210. ltsColorChannelGreen,
  211. ltsColorChannelBlue,
  212. ltsColorChannelAlpha
  213. }
  214. lts_color_channel_flag_t;
  215. typedef uint32_t lts_color_channel_flags_t;
  216. STATIC_ASSERT(sizeof(lts_color_channel_flags_t) == 4, size_of_lts_color_channel_flag_t_should_be_4);
  217. /* structures *********************************************************************************************************************/
  218. typedef struct
  219. {
  220. int32_t x;
  221. int32_t y;
  222. }
  223. lts_position_t;
  224. STATIC_ASSERT(sizeof(lts_position_t) == 8, size_of_lts_position_t_should_be_8);
  225. typedef union
  226. {
  227. struct { lts_position_t top_left, bottom_right; };
  228. struct { int32_t left, top, right, bottom; };
  229. }
  230. lts_rect_t;
  231. STATIC_ASSERT(sizeof(lts_rect_t) == 16, size_of_lts_rect_t_should_be_16);
  232. typedef union
  233. {
  234. struct { float r, g, b, a; };
  235. float arr[4];
  236. }
  237. lts_color4f_t;
  238. STATIC_ASSERT(sizeof(lts_color4f_t) == 16, size_of_lts_color4f_t_should_be_16);
  239. typedef struct
  240. {
  241. lts_position_t glyph_origin;
  242. lts_rect_t glyph_rect;
  243. int32_t advance;
  244. }
  245. lts_glyph_metric_t;
  246. STATIC_ASSERT(sizeof(lts_glyph_metric_t) == 28, size_of_lts_glyph_metric_t_should_be_28);
  247. typedef struct
  248. {
  249. int32_t ascent;
  250. int32_t descent;
  251. int32_t external_leading;
  252. int32_t base_line_offset;
  253. int32_t char_spacing;
  254. int32_t line_height;
  255. int32_t line_spacing;
  256. }
  257. lts_text_metric_t;
  258. STATIC_ASSERT(sizeof(lts_text_metric_t) == 28, size_of_lts_text_metric_t_should_be_28);
  259. typedef struct
  260. {
  261. int32_t size;
  262. lts_font_style_flags_t style;
  263. lts_anti_aliasing_t anti_aliasing;
  264. lts_wchar_t default_char;
  265. uint8_t __reserved[2];
  266. int32_t ascent;
  267. int32_t descent;
  268. int32_t external_leading;
  269. int32_t base_line_offset;
  270. int32_t underline_pos;
  271. int32_t underline_size;
  272. int32_t strikeout_pos;
  273. int32_t strikeout_size;
  274. }
  275. lts_font_metric_t;
  276. STATIC_ASSERT(sizeof(lts_font_metric_t) == 48, size_of_lts_font_metric_t_should_be_48);
  277. typedef float lts_vector4f_t[4];
  278. STATIC_ASSERT(sizeof(lts_vector4f_t) == 16, size_of_lts_vector4f_t_should_be_16);
  279. typedef lts_vector4f_t lts_matrix4f_t[4];
  280. STATIC_ASSERT(sizeof(lts_matrix4f_t) == 64, size_of_lts_matrix4f_t_should_be_64);
  281. typedef void* lts_handle_t;
  282. typedef lts_handle_t lts_context_handle_t;
  283. typedef lts_handle_t lts_renderer_handle_t;
  284. typedef lts_handle_t lts_text_block_handle_t;
  285. typedef lts_handle_t lts_font_creator_handle_t;
  286. typedef lts_handle_t lts_font_handle_t;
  287. typedef lts_handle_t lts_post_processor_handle_t;
  288. typedef lts_handle_t lts_image_handle_t;
  289. typedef lts_handle_t lts_char_handle_t;
  290. typedef lts_image_mode_t lts_image_modes_t[4];
  291. /* stream */
  292. typedef int (WINAPI *lts_stream_func_read_t)(void* args, void* buffer, int count);
  293. typedef int (WINAPI *lts_stream_func_seek_t)(void* args, lts_stream_origin_t origin, int offset);
  294. typedef struct
  295. {
  296. void* args;
  297. lts_stream_func_read_t read;
  298. lts_stream_func_seek_t seek;
  299. }
  300. lts_stream_t;
  301. /* custom post processor */
  302. typedef void (WINAPI *lts_post_processor_execute_func_t)(lts_char_handle_t charHandle, lts_image_handle_t imageHandle);
  303. typedef struct
  304. {
  305. void* args;
  306. lts_post_processor_execute_func_t execute;
  307. }
  308. lts_post_processor_custom_data_t;
  309. /* custom renderer */
  310. typedef void (WINAPI *lts_renderer_custom_begin_render_t) (void* args);
  311. typedef void (WINAPI *lts_renderer_custom_end_render_t) (void* args);
  312. typedef lts_position_t (WINAPI *lts_renderer_custom_get_draw_pos_t) (void* args);
  313. typedef void (WINAPI *lts_renderer_custom_set_draw_pos_t) (lts_position_t value, void* args);
  314. typedef void (WINAPI *lts_renderer_custom_move_draw_pos_t) (lts_position_t value, void* args);
  315. typedef void (WINAPI *lts_renderer_custom_set_color_t) (lts_color4f_t value, void* args);
  316. typedef void (WINAPI *lts_renderer_custom_render) (void* ref, int forcedWidth, void* args);
  317. typedef void* (WINAPI *lts_renderer_custom_create_ref) (lts_char_handle_t charHandle, lts_image_handle_t imageHandle, void* args);
  318. typedef void (WINAPI *lts_renderer_custom_free_ref) (void* ref, void* args);
  319. typedef struct
  320. {
  321. void* args;
  322. lts_renderer_custom_begin_render_t beginRender;
  323. lts_renderer_custom_end_render_t endRender;
  324. lts_renderer_custom_get_draw_pos_t getDrawPos;
  325. lts_renderer_custom_set_draw_pos_t setDrawPos;
  326. lts_renderer_custom_move_draw_pos_t moveDrawPos;
  327. lts_renderer_custom_set_color_t setColor;
  328. lts_renderer_custom_render render;
  329. lts_renderer_custom_create_ref createRef;
  330. lts_renderer_custom_free_ref freeRef;
  331. }
  332. lts_renderer_custom_data_t;
  333. /* image */
  334. typedef void (WINAPI *lts_image_load_callback_t) (lts_image_handle_t handle, int x, int y, lts_color4f_t pixel, void* args);
  335. typedef void (WINAPI *lts_image_blend_callback_t)(lts_image_handle_t handle, lts_color4f_t src, lts_color4f_t dst, lts_color4f_t* result, void* args);
  336. /* callbacks **********************************************************************************************************************/
  337. lts_context_handle_t (WINAPI *lts_context_create) ();
  338. lts_error_code_t (WINAPI *lts_context_get_code_page) (lts_context_handle_t handle, lts_code_page_t* value);
  339. lts_error_code_t (WINAPI *lts_context_get_default_char) (lts_context_handle_t handle, lts_wchar_t* value);
  340. lts_error_code_t (WINAPI *lts_context_set_code_page) (lts_context_handle_t handle, lts_code_page_t value);
  341. lts_error_code_t (WINAPI *lts_context_set_default_char) (lts_context_handle_t handle, lts_wchar_t value);
  342. lts_wchar_t* (WINAPI *lts_context_ansi_to_wide) (lts_context_handle_t handle, const char* text);
  343. lts_error_code_t (WINAPI *lts_context_destroy) (lts_context_handle_t handle);
  344. lts_renderer_handle_t (WINAPI *lts_renderer_create) (lts_context_handle_t handle, lts_renderer_type_t type, lts_format_t format);
  345. lts_renderer_handle_t (WINAPI *lts_renderer_create_custom) (lts_context_handle_t handle, lts_format_t format, const lts_renderer_custom_data_t* data);
  346. lts_text_block_handle_t (WINAPI *lts_renderer_begin_block) (lts_renderer_handle_t handle, int top, int left, int width, int height, lts_block_flags_t flags);
  347. lts_error_code_t (WINAPI *lts_renderer_end_block) (lts_renderer_handle_t handle, lts_text_block_handle_t block);
  348. lts_error_code_t (WINAPI *lts_renderer_abort_block) (lts_renderer_handle_t handle, lts_text_block_handle_t block);
  349. int (WINAPI *lts_renderer_get_text_width_a) (lts_renderer_handle_t handle, lts_font_handle_t font, const char* text);
  350. int (WINAPI *lts_renderer_get_text_width_w) (lts_renderer_handle_t handle, lts_font_handle_t font, const lts_wchar_t* text);
  351. lts_error_code_t (WINAPI *lts_renderer_destroy) (lts_renderer_handle_t handle);
  352. lts_font_creator_handle_t (WINAPI *lts_font_creator_create) (lts_context_handle_t handle, lts_font_creator_type_t type);
  353. lts_font_handle_t (WINAPI *lts_font_creator_get_font_by_name) (lts_font_creator_handle_t handle, const char* fontname, int size, lts_font_style_flags_t style, lts_anti_aliasing_t antialiasing);
  354. lts_font_handle_t (WINAPI *lts_font_creator_get_font_by_file) (lts_font_creator_handle_t handle, const char* filename, int size, lts_font_style_flags_t style, lts_anti_aliasing_t antialiasing);
  355. lts_font_handle_t (WINAPI *lts_font_creator_get_font_by_stream) (lts_font_creator_handle_t handle, lts_stream_t* stream, int size, lts_font_style_flags_t style, lts_anti_aliasing_t antialiasing);
  356. lts_error_code_t (WINAPI *lts_font_creator_destroy) (lts_font_creator_handle_t handle);
  357. lts_post_processor_handle_t (WINAPI *lts_font_get_post_processor) (lts_font_handle_t handle);
  358. lts_error_code_t (WINAPI *lts_font_get_tab_width) (lts_font_handle_t handle, int* value);
  359. lts_error_code_t (WINAPI *lts_font_get_char_spacing) (lts_font_handle_t handle, int* value);
  360. lts_error_code_t (WINAPI *lts_font_get_line_spacing) (lts_font_handle_t handle, float* value);
  361. lts_error_code_t (WINAPI *lts_font_get_metric) (lts_font_handle_t handle, lts_font_metric_t* value);
  362. const char* (WINAPI *lts_font_get_fontname) (lts_font_handle_t handle);
  363. const char* (WINAPI *lts_font_get_facename) (lts_font_handle_t handle);
  364. const char* (WINAPI *lts_font_get_stylename) (lts_font_handle_t handle);
  365. const char* (WINAPI *lts_font_get_fillname) (lts_font_handle_t handle);
  366. const char* (WINAPI *lts_font_get_copyright) (lts_font_handle_t handle);
  367. lts_error_code_t (WINAPI *lts_font_set_post_processor) (lts_font_handle_t handle, lts_post_processor_handle_t pp);
  368. lts_error_code_t (WINAPI *lts_font_set_tab_width) (lts_font_handle_t handle, int value);
  369. lts_error_code_t (WINAPI *lts_font_set_char_spacing) (lts_font_handle_t handle, int value);
  370. lts_error_code_t (WINAPI *lts_font_set_line_spacing) (lts_font_handle_t handle, float value);
  371. lts_error_code_t (WINAPI *lts_font_destroy) (lts_font_handle_t handle);
  372. lts_error_code_t (WINAPI *lts_text_block_get_rect) (lts_text_block_handle_t handle, lts_rect_t* value);
  373. lts_error_code_t (WINAPI *lts_text_block_get_width) (lts_text_block_handle_t handle, int* value);
  374. lts_error_code_t (WINAPI *lts_text_block_get_height) (lts_text_block_handle_t handle, int* value);
  375. lts_error_code_t (WINAPI *lts_text_block_get_flags) (lts_text_block_handle_t handle, lts_block_flags_t* value);
  376. lts_error_code_t (WINAPI *lts_text_block_get_top) (lts_text_block_handle_t handle, int* value);
  377. lts_error_code_t (WINAPI *lts_text_block_get_left) (lts_text_block_handle_t handle, int* value);
  378. lts_error_code_t (WINAPI *lts_text_block_get_vert_align) (lts_text_block_handle_t handle, lts_vert_align_t* value);
  379. lts_error_code_t (WINAPI *lts_text_block_get_horz_align) (lts_text_block_handle_t handle, lts_horz_align_t* value);
  380. lts_error_code_t (WINAPI *lts_text_block_get_clipping) (lts_text_block_handle_t handle, lts_clipping_t* value);
  381. lts_error_code_t (WINAPI *lts_text_block_get_color) (lts_text_block_handle_t handle, lts_color4f_t* value);
  382. lts_error_code_t (WINAPI *lts_text_block_get_font) (lts_text_block_handle_t handle, lts_font_handle_t* value);
  383. lts_error_code_t (WINAPI *lts_text_block_set_top) (lts_text_block_handle_t handle, int value);
  384. lts_error_code_t (WINAPI *lts_text_block_set_left) (lts_text_block_handle_t handle, int value);
  385. lts_error_code_t (WINAPI *lts_text_block_set_vert_align) (lts_text_block_handle_t handle, lts_vert_align_t value);
  386. lts_error_code_t (WINAPI *lts_text_block_set_horz_align) (lts_text_block_handle_t handle, lts_horz_align_t value);
  387. lts_error_code_t (WINAPI *lts_text_block_set_clipping) (lts_text_block_handle_t handle, lts_clipping_t value);
  388. lts_error_code_t (WINAPI *lts_text_block_set_color) (lts_text_block_handle_t handle, lts_color4f_t value);
  389. lts_error_code_t (WINAPI *lts_text_block_set_font) (lts_text_block_handle_t handle, lts_font_handle_t value);
  390. int (WINAPI *lts_text_block_get_actual_height) (lts_text_block_handle_t handle);
  391. int (WINAPI *lts_text_block_get_text_width_a) (lts_text_block_handle_t handle, const char* text);
  392. int (WINAPI *lts_text_block_get_text_width_w) (lts_text_block_handle_t handle, const lts_wchar_t* text);
  393. lts_error_code_t (WINAPI *lts_text_block_text_out_a) (lts_text_block_handle_t handle, const char* text);
  394. lts_error_code_t (WINAPI *lts_text_block_text_out_w) (lts_text_block_handle_t handle, const lts_wchar_t* text);
  395. lts_error_code_t (WINAPI *lts_text_block_destroy) (lts_text_block_handle_t handle);
  396. lts_image_handle_t (WINAPI *lts_image_create) (lts_context_handle_t handle);
  397. lts_error_code_t (WINAPI *lts_image_is_empty) (lts_image_handle_t handle, bool* value);
  398. int (WINAPI *lts_image_get_width) (lts_image_handle_t handle);
  399. int (WINAPI *lts_image_get_height) (lts_image_handle_t handle);
  400. int (WINAPI *lts_image_get_line_size) (lts_image_handle_t handle);
  401. int (WINAPI *lts_image_get_data_size) (lts_image_handle_t handle);
  402. lts_error_code_t (WINAPI *lts_image_get_format) (lts_image_handle_t handle, lts_format_t* value);
  403. void* (WINAPI *lts_image_get_data) (lts_image_handle_t handle);
  404. void* (WINAPI *lts_image_get_scanline) (lts_image_handle_t handle, int index);
  405. lts_error_code_t (WINAPI *lts_image_get_pixel_at) (lts_image_handle_t handle, int x, int y, lts_color4f_t pixel);
  406. lts_error_code_t (WINAPI *lts_image_assign) (lts_image_handle_t handle, lts_image_handle_t source);
  407. lts_error_code_t (WINAPI *lts_image_create_empty) (lts_image_handle_t handle, lts_format_t format, int width, int height);
  408. lts_error_code_t (WINAPI *lts_image_load_from_func) (lts_image_handle_t handle, lts_image_load_callback_t callback, void* args);
  409. lts_error_code_t (WINAPI *lts_image_resize) (lts_image_handle_t handle, int width, int height, int x, int y);
  410. lts_error_code_t (WINAPI *lts_image_fill_color) (lts_image_handle_t handle, lts_color4f_t color, lts_color_channel_flags_t mask, lts_image_modes_t modes);
  411. lts_error_code_t (WINAPI *lts_image_fill_pattern) (lts_image_handle_t handle, lts_image_handle_t pattern, int x, int y, lts_color_channel_flags_t mask, lts_image_modes_t modes);
  412. lts_error_code_t (WINAPI *lts_image_blend) (lts_image_handle_t handle, lts_image_handle_t source, int x, int y, lts_image_blend_callback_t callback, void* args);
  413. lts_error_code_t (WINAPI *lts_image_blur) (lts_image_handle_t handle, float horzRad, float horzStr, float vertRad, float vertStr, lts_color_channel_flags_t mask);
  414. lts_error_code_t (WINAPI *lts_image_destroy) (lts_image_handle_t handle);
  415. lts_error_code_t (WINAPI *lts_post_processor_add_range) (lts_post_processor_handle_t handle, lts_char_range_usage_t usage, lts_wchar_t start, lts_wchar_t stop);
  416. lts_error_code_t (WINAPI *lts_post_processor_add_chars) (lts_post_processor_handle_t handle, lts_char_range_usage_t usage, const lts_wchar_t* chars);
  417. lts_error_code_t (WINAPI *lts_post_processor_clear_ranges) (lts_post_processor_handle_t handle);
  418. lts_error_code_t (WINAPI *lts_post_processor_execute) (lts_post_processor_handle_t handle, lts_char_handle_t charHandle, lts_image_handle_t image);
  419. lts_post_processor_handle_t (WINAPI *lts_post_processor_fill_color_create) (lts_post_processor_handle_t handle, lts_color4f_t color, lts_image_modes_t modes, lts_color_channel_flags_t channels);
  420. lts_post_processor_handle_t (WINAPI *lts_post_processor_fill_pattern_create) (lts_post_processor_handle_t handle, lts_image_handle_t pattern, bool ownsPattern, lts_position_t position, lts_image_modes_t modes, lts_color_channel_flags_t channels);
  421. lts_post_processor_handle_t (WINAPI *lts_post_processor_border_create) (lts_post_processor_handle_t handle, float width, float strength, lts_color4f_t color, bool keepSize);
  422. lts_post_processor_handle_t (WINAPI *lts_post_processor_shadow_create) (lts_post_processor_handle_t handle, float radius, float strength, lts_position_t offset, lts_color4f_t color);
  423. lts_post_processor_handle_t (WINAPI *lts_post_processor_custom_create) (lts_post_processor_handle_t handle, const lts_post_processor_custom_data_t* data);
  424. lts_error_code_t (WINAPI *lts_post_processor_destroy) (lts_post_processor_handle_t handle);
  425. lts_error_code_t (WINAPI *lts_char_get_char_code) (lts_char_handle_t handle, lts_wchar_t* value);
  426. lts_error_code_t (WINAPI *lts_char_get_glyph_metric) (lts_char_handle_t handle, lts_glyph_metric_t* value);
  427. lts_error_code_t (WINAPI *lts_char_set_glyph_metric) (lts_char_handle_t handle, const lts_glyph_metric_t* value);
  428. const char* (WINAPI *lts_get_version) ();
  429. lts_error_code_t (WINAPI *lts_get_last_error_code) ();
  430. const char* (WINAPI *lts_get_last_error_msg) ();
  431. /* constants **********************************************************************************************************************/
  432. lts_image_modes_t LTS_IMAGE_MODES_REPLACE_ALL = {
  433. ltsModeReplace,
  434. ltsModeReplace,
  435. ltsModeReplace,
  436. ltsModeReplace
  437. };
  438. lts_image_modes_t LTS_IMAGE_MODES_MODULATE_ALPHA = {
  439. ltsModeReplace,
  440. ltsModeReplace,
  441. ltsModeReplace,
  442. ltsModeModulate
  443. };
  444. lts_image_modes_t LTS_IMAGE_MODES_MODULATE_ALL = {
  445. ltsModeModulate,
  446. ltsModeModulate,
  447. ltsModeModulate,
  448. ltsModeModulate
  449. };
  450. lts_color_channel_flags_t LTS_COLOR_CHANNELS_RGB =
  451. FLAGS_MAKE(ltsColorChannelRed) |
  452. FLAGS_MAKE(ltsColorChannelGreen) |
  453. FLAGS_MAKE(ltsColorChannelBlue);
  454. lts_color_channel_flags_t LTS_COLOR_CHANNELS_RGBA =
  455. FLAGS_MAKE(ltsColorChannelRed) |
  456. FLAGS_MAKE(ltsColorChannelGreen) |
  457. FLAGS_MAKE(ltsColorChannelBlue) |
  458. FLAGS_MAKE(ltsColorChannelAlpha);
  459. /* helper *************************************************************************************************************************/
  460. static inline lts_color4f_t ltsColor4f(float r, float g, float b, float a)
  461. { lts_color4f_t ret = { r, g, b, a }; return ret; };
  462. static inline lts_position_t ltsPosition(int x, int y)
  463. { lts_position_t ret = { x, y }; return ret; };
  464. static inline lts_rect_t ltsRect(int left, int top, int right, int bottom)
  465. { lts_rect_t ret = { left, top, right, bottom }; return ret; };
  466. static inline lts_rect_t ltsRectFromPos(lts_position_t leftTop, lts_position_t bottomRight)
  467. { lts_rect_t ret = { leftTop.x, leftTop.y, bottomRight.x, bottomRight.y }; return ret; };
  468. /**********************************************************************************************************************************/
  469. /* internal initialization code */
  470. /**********************************************************************************************************************************/
  471. //#define LSF_DEBUG
  472. #ifdef LSF_DEBUG
  473. # include <stdio.h>
  474. #endif
  475. #if WIN32 || WIN64 || _WIN32 || _WIN64
  476. # include <windows.h>
  477. typedef HMODULE lib_handle_t;
  478. lib_handle_t open_lib(const char* name)
  479. { return LoadLibrary(name); };
  480. void* get_addr(lib_handle_t handle, const char* name)
  481. { return GetProcAddress(handle, name); };
  482. int close_lib(lib_handle_t handle)
  483. { return FreeLibrary(handle); };
  484. #elif LINUX || __linux__
  485. # include <dlfcn.h>
  486. typedef void* lib_handle_t;
  487. lib_handle_t open_lib(const char* name)
  488. { return dlopen(name, RTLD_LAZY); };
  489. void* get_addr(lib_handle_t handle, const char* name)
  490. { return dlsym(handle, name); };
  491. int close_lib(lib_handle_t handle)
  492. { return !dlclose(handle); };
  493. #else
  494. # error "unknown operation system"
  495. #endif
  496. #ifndef LSF_DEBUG
  497. # define LoadProc(proc, name) \
  498. proc = get_addr(handle, name); \
  499. if (!proc) \
  500. return ltsErrInvalidMethodName
  501. #else
  502. # define LoadProc(proc, name) \
  503. proc = get_addr(handle, name); \
  504. printf("load method '%s' (addr=0x%016x)\n", name, proc); \
  505. if (!proc) \
  506. return ltsErrInvalidMethodName
  507. #endif
  508. lts_error_code_t (WINAPI *lts_initialize_intern)();
  509. lts_error_code_t (WINAPI *lts_finalize_intern) ();
  510. lib_handle_t handle = NULL;
  511. lts_error_code_t lts_initialize(const char* libname)
  512. {
  513. #ifdef LSF_DEBUG
  514. printf("loading library '%s'\n", libname);
  515. #endif
  516. handle = open_lib(libname);
  517. if (!handle)
  518. return ltsErrInvalidLibName;
  519. #ifdef LSF_DEBUG
  520. printf(" done (handle=0x%016x)\n", handle);
  521. #endif
  522. LoadProc(lts_context_create, "ltsContextCreate");
  523. LoadProc(lts_context_get_code_page, "ltsContextGetCodePage");
  524. LoadProc(lts_context_get_default_char, "ltsContextGetDefaultChar");
  525. LoadProc(lts_context_set_code_page, "ltsContextSetCodePage");
  526. LoadProc(lts_context_set_default_char, "ltsContextSetDefaultChar");
  527. LoadProc(lts_context_ansi_to_wide, "ltsContextAnsiToWide");
  528. LoadProc(lts_context_destroy, "ltsContextDestroy");
  529. LoadProc(lts_renderer_create, "ltsRendererCreate");
  530. LoadProc(lts_renderer_create_custom, "ltsRendererCustomCreate");
  531. LoadProc(lts_renderer_begin_block, "ltsRendererBeginBlock");
  532. LoadProc(lts_renderer_end_block, "ltsRendererEndBlock");
  533. LoadProc(lts_renderer_abort_block, "ltsRendererAbortBlock");
  534. LoadProc(lts_renderer_get_text_width_a, "ltsRendererGetTextWidthA");
  535. LoadProc(lts_renderer_get_text_width_w, "ltsRendererGetTextWidthW");
  536. LoadProc(lts_renderer_destroy, "ltsRendererDestroy");
  537. LoadProc(lts_font_creator_create, "ltsFontCreatorCreate");
  538. LoadProc(lts_font_creator_get_font_by_name, "ltsFontCreatorGetFontByName");
  539. LoadProc(lts_font_creator_get_font_by_file, "ltsFontCreatorGetFontByFile");
  540. LoadProc(lts_font_creator_get_font_by_stream, "ltsFontCreatorGetFontByStream");
  541. LoadProc(lts_font_creator_destroy, "ltsFontCreatorDestroy");
  542. LoadProc(lts_font_get_post_processor, "ltsFontGetPostProcessor");
  543. LoadProc(lts_font_get_tab_width, "ltsFontGetTabWidth");
  544. LoadProc(lts_font_get_char_spacing, "ltsFontGetCharSpacing");
  545. LoadProc(lts_font_get_line_spacing, "ltsFontGetLineSpacing");
  546. LoadProc(lts_font_get_metric, "ltsFontGetMetric");
  547. LoadProc(lts_font_get_fontname, "ltsFontGetFontname");
  548. LoadProc(lts_font_get_facename, "ltsFontGetFacename");
  549. LoadProc(lts_font_get_stylename, "ltsFontGetStylename");
  550. LoadProc(lts_font_get_fillname, "ltsFontGetFullname");
  551. LoadProc(lts_font_get_copyright, "ltsFontGetCopyright");
  552. LoadProc(lts_font_set_post_processor, "ltsFontSetPostProcessor");
  553. LoadProc(lts_font_set_tab_width, "ltsFontSetTabWidth");
  554. LoadProc(lts_font_set_char_spacing, "ltsFontSetCharSpacing");
  555. LoadProc(lts_font_set_line_spacing, "ltsFontSetLineSpacing");
  556. LoadProc(lts_font_destroy, "ltsFontDestroy");
  557. LoadProc(lts_text_block_get_rect, "ltsTextBlockGetRect");
  558. LoadProc(lts_text_block_get_width, "ltsTextBlockGetWidth");
  559. LoadProc(lts_text_block_get_height, "ltsTextBlockGetHeight");
  560. LoadProc(lts_text_block_get_flags, "ltsTextBlockGetFlags");
  561. LoadProc(lts_text_block_get_top, "ltsTextBlockGetTop");
  562. LoadProc(lts_text_block_get_left, "ltsTextBlockGetLeft");
  563. LoadProc(lts_text_block_get_vert_align, "ltsTextBlockGetVertAlign");
  564. LoadProc(lts_text_block_get_horz_align, "ltsTextBlockGetHorzAlign");
  565. LoadProc(lts_text_block_get_clipping, "ltsTextBlockGetClipping");
  566. LoadProc(lts_text_block_get_color, "ltsTextBlockGetColor");
  567. LoadProc(lts_text_block_get_font, "ltsTextBlockGetFont");
  568. LoadProc(lts_text_block_set_top, "ltsTextBlockSetTop");
  569. LoadProc(lts_text_block_set_left, "ltsTextBlockSetLeft");
  570. LoadProc(lts_text_block_set_vert_align, "ltsTextBlockSetVertAlign");
  571. LoadProc(lts_text_block_set_horz_align, "ltsTextBlockSetHorzAlign");
  572. LoadProc(lts_text_block_set_clipping, "ltsTextBlockSetClipping");
  573. LoadProc(lts_text_block_set_color, "ltsTextBlockSetColor");
  574. LoadProc(lts_text_block_set_font, "ltsTextBlockSetFont");
  575. LoadProc(lts_text_block_get_actual_height, "ltsTextBlockGetActualHeight");
  576. LoadProc(lts_text_block_get_text_width_a, "ltsTextBlockGetTextWidthA");
  577. LoadProc(lts_text_block_get_text_width_w, "ltsTextBlockGetTextWidthW");
  578. LoadProc(lts_text_block_text_out_a, "ltsTextBlockTextOutA");
  579. LoadProc(lts_text_block_text_out_w, "ltsTextBlockTextOutW");
  580. LoadProc(lts_text_block_destroy, "ltsTextBlockDestroy");
  581. LoadProc(lts_image_create, "ltsImageCreate");
  582. LoadProc(lts_image_is_empty, "ltsImageIsEmpty");
  583. LoadProc(lts_image_get_width, "ltsImageGetWidth");
  584. LoadProc(lts_image_get_height, "ltsImageGetHeight");
  585. LoadProc(lts_image_get_line_size, "ltsImageGetLineSize");
  586. LoadProc(lts_image_get_data_size, "ltsImageGetDataSize");
  587. LoadProc(lts_image_get_format, "ltsImageGetFormat");
  588. LoadProc(lts_image_get_data, "ltsImageGetData");
  589. LoadProc(lts_image_get_scanline, "ltsImageGetScanline");
  590. LoadProc(lts_image_get_pixel_at, "ltsImageGetPixelAt");
  591. LoadProc(lts_image_assign, "ltsImageAssign");
  592. LoadProc(lts_image_create_empty, "ltsImageCreateEmpty");
  593. LoadProc(lts_image_load_from_func, "ltsImageLoadFromFunc");
  594. LoadProc(lts_image_resize, "ltsImageResize");
  595. LoadProc(lts_image_fill_color, "ltsImageFillColor");
  596. LoadProc(lts_image_fill_pattern, "ltsImageFillPattern");
  597. LoadProc(lts_image_blend, "ltsImageBlend");
  598. LoadProc(lts_image_blur, "ltsImageBlur");
  599. LoadProc(lts_image_destroy, "ltsImageDestroy");
  600. LoadProc(lts_post_processor_add_range, "ltsPostProcessorAddRange");
  601. LoadProc(lts_post_processor_add_chars, "ltsPostProcessorAddChars");
  602. LoadProc(lts_post_processor_clear_ranges, "ltsPostProcessorClearRanges");
  603. LoadProc(lts_post_processor_execute, "ltsPostProcessorExecute");
  604. LoadProc(lts_post_processor_fill_color_create, "ltsPostProcessorFillColorCreate");
  605. LoadProc(lts_post_processor_fill_pattern_create, "ltsPostProcessorFillPatterCreate");
  606. LoadProc(lts_post_processor_border_create, "ltsPostProcessorBorderCreate");
  607. LoadProc(lts_post_processor_shadow_create, "ltsPostProcessorShadowCreate");
  608. LoadProc(lts_post_processor_custom_create, "ltsPostProcessorCustomCreate");
  609. LoadProc(lts_post_processor_destroy, "ltsPostProcessorDestroy");
  610. LoadProc(lts_char_get_char_code, "ltsCharGetCharCode");
  611. LoadProc(lts_char_get_glyph_metric, "ltsCharGetGlyphMetric");
  612. LoadProc(lts_char_set_glyph_metric, "ltsCharSetGlyphMetric");
  613. LoadProc(lts_initialize_intern, "ltsInitialize");
  614. LoadProc(lts_get_version, "ltsGetVersion");
  615. LoadProc(lts_get_last_error_code, "ltsGetLastErrorCode");
  616. LoadProc(lts_get_last_error_msg, "ltsGetLastErrorMsg");
  617. LoadProc(lts_finalize_intern, "ltsFinalize");
  618. return lts_initialize_intern();
  619. }
  620. int lts_finalize(void)
  621. {
  622. lts_error_code_t err = lts_finalize_intern();
  623. lts_context_create = NULL;
  624. lts_context_get_code_page = NULL;
  625. lts_context_get_default_char = NULL;
  626. lts_context_set_code_page = NULL;
  627. lts_context_set_default_char = NULL;
  628. lts_context_ansi_to_wide = NULL;
  629. lts_context_destroy = NULL;
  630. lts_renderer_create = NULL;
  631. lts_renderer_create_custom = NULL;
  632. lts_renderer_begin_block = NULL;
  633. lts_renderer_end_block = NULL;
  634. lts_renderer_abort_block = NULL;
  635. lts_renderer_get_text_width_a = NULL;
  636. lts_renderer_get_text_width_w = NULL;
  637. lts_renderer_destroy = NULL;
  638. lts_font_creator_create = NULL;
  639. lts_font_creator_get_font_by_name = NULL;
  640. lts_font_creator_get_font_by_file = NULL;
  641. lts_font_creator_get_font_by_stream = NULL;
  642. lts_font_creator_destroy = NULL;
  643. lts_font_get_post_processor = NULL;
  644. lts_font_get_tab_width = NULL;
  645. lts_font_get_char_spacing = NULL;
  646. lts_font_get_line_spacing = NULL;
  647. lts_font_get_metric = NULL;
  648. lts_font_get_fontname = NULL;
  649. lts_font_get_facename = NULL;
  650. lts_font_get_stylename = NULL;
  651. lts_font_get_fillname = NULL;
  652. lts_font_get_copyright = NULL;
  653. lts_font_set_post_processor = NULL;
  654. lts_font_set_tab_width = NULL;
  655. lts_font_set_char_spacing = NULL;
  656. lts_font_set_line_spacing = NULL;
  657. lts_font_destroy = NULL;
  658. lts_text_block_get_rect = NULL;
  659. lts_text_block_get_width = NULL;
  660. lts_text_block_get_height = NULL;
  661. lts_text_block_get_flags = NULL;
  662. lts_text_block_get_top = NULL;
  663. lts_text_block_get_left = NULL;
  664. lts_text_block_get_vert_align = NULL;
  665. lts_text_block_get_horz_align = NULL;
  666. lts_text_block_get_clipping = NULL;
  667. lts_text_block_get_color = NULL;
  668. lts_text_block_get_font = NULL;
  669. lts_text_block_set_top = NULL;
  670. lts_text_block_set_left = NULL;
  671. lts_text_block_set_vert_align = NULL;
  672. lts_text_block_set_horz_align = NULL;
  673. lts_text_block_set_clipping = NULL;
  674. lts_text_block_set_color = NULL;
  675. lts_text_block_set_font = NULL;
  676. lts_text_block_get_actual_height = NULL;
  677. lts_text_block_get_text_width_a = NULL;
  678. lts_text_block_get_text_width_w = NULL;
  679. lts_text_block_text_out_a = NULL;
  680. lts_text_block_text_out_w = NULL;
  681. lts_text_block_destroy = NULL;
  682. lts_image_create = NULL;
  683. lts_image_is_empty = NULL;
  684. lts_image_get_width = NULL;
  685. lts_image_get_height = NULL;
  686. lts_image_get_line_size = NULL;
  687. lts_image_get_data_size = NULL;
  688. lts_image_get_format = NULL;
  689. lts_image_get_data = NULL;
  690. lts_image_get_scanline = NULL;
  691. lts_image_get_pixel_at = NULL;
  692. lts_image_assign = NULL;
  693. lts_image_create_empty = NULL;
  694. lts_image_load_from_func = NULL;
  695. lts_image_resize = NULL;
  696. lts_image_fill_color = NULL;
  697. lts_image_fill_pattern = NULL;
  698. lts_image_blend = NULL;
  699. lts_image_blur = NULL;
  700. lts_image_destroy = NULL;
  701. lts_post_processor_add_range = NULL;
  702. lts_post_processor_add_chars = NULL;
  703. lts_post_processor_clear_ranges = NULL;
  704. lts_post_processor_execute = NULL;
  705. lts_post_processor_fill_color_create = NULL;
  706. lts_post_processor_fill_pattern_create = NULL;
  707. lts_post_processor_border_create = NULL;
  708. lts_post_processor_shadow_create = NULL;
  709. lts_post_processor_custom_create = NULL;
  710. lts_post_processor_destroy = NULL;
  711. lts_char_get_char_code = NULL;
  712. lts_char_get_glyph_metric = NULL;
  713. lts_char_set_glyph_metric = NULL;
  714. lts_initialize_intern = NULL;
  715. lts_get_version = NULL;
  716. lts_get_last_error_code = NULL;
  717. lts_get_last_error_msg = NULL;
  718. lts_finalize_intern = NULL;
  719. if (!close_lib(handle))
  720. return ltsErrInvalidLibHandle;
  721. return err;
  722. }
  723. #endif /* LIB_TEXT_SUITE_H */