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.
 
 
 
 
 

809 rivejä
40 KiB

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