|
- #ifndef LIB_TEXT_SUITE_H
- #define LIB_TEXT_SUITE_H
-
- #include <stdint.h>
- #include <string.h>
- #include <stdbool.h>
-
- #if __MINGW32__
- # define WINAPI __stdcall
- #elif __GNUC__
- # if defined(__x86_64__)
- # define WINAPI
- # else
- # define WINAPI __attribute__((stdcall))
- # endif
- #else
- # define WINAPI
- #endif
-
- #define STATIC_ASSERT(cond, msg) typedef char static_assertion_##msg[(cond)?1:-1]
-
- typedef uint16_t lts_wchar_t;
-
- STATIC_ASSERT(sizeof(float) == 4, size_of_float_should_be_4);
- STATIC_ASSERT(sizeof(lts_wchar_t) == 2, size_of_wchar_t_should_be_2);
-
- /**********************************************************************************************************************************/
- /* public interface */
- /**********************************************************************************************************************************/
-
- /* enumerations *******************************************************************************************************************/
- typedef enum
- {
- ltsErrUnknown = -1,
- ltsErrNone = 0,
-
- // misc
- ltsErrNotInitialized = 1,
- ltsErrInvalidEnum = 2,
- ltsErrInvalidValue = 3,
- ltsErrInvalidOperation = 4,
- ltsErrInvalidType = 5,
-
- // invalid handles
- ltsErrInvalidContextHandle = 100,
- ltsErrInvalidRendererHandle = 101,
- ltsErrInvalidTextBlockHandle = 102,
- ltsErrInvalidFontHandle = 103,
- ltsErrInvalidFontCreatorHandle = 104,
- ltsErrInvalidImageHandle = 105,
- ltsErrInvalidPostProcHandle = 106,
-
- // library
- ltsErrInvalidLibName = 200,
- ltsErrInvalidLibHandle = 201,
- ltsErrInvalidMethodName = 202
- }
- lts_error_code_t;
- STATIC_ASSERT(sizeof(lts_error_code_t) == 4, size_of_lts_error_code_t_should_be_4);
-
- typedef enum
- {
- ltsUTF8,
- ltsISO_8859_1,
- ltsISO_8859_2,
- ltsISO_8859_3,
- ltsISO_8859_4,
- ltsISO_8859_5,
- ltsISO_8859_6,
- ltsISO_8859_7,
- ltsISO_8859_8,
- ltsISO_8859_9,
- ltsISO_8859_10,
- ltsISO_8859_11,
- ltsISO_8859_13,
- ltsISO_8859_14,
- ltsISO_8859_15,
- ltsISO_8859_16,
- ltsISO_037,
- ltsISO_437,
- ltsISO_500,
- ltsISO_737,
- ltsISO_775,
- ltsISO_850,
- ltsISO_852,
- ltsISO_855,
- ltsISO_857,
- ltsISO_860,
- ltsISO_861,
- ltsISO_862,
- ltsISO_863,
- ltsISO_864,
- ltsISO_865,
- ltsISO_866,
- ltsISO_869,
- ltsISO_874,
- ltsISO_875,
- ltsISO_1026,
- ltsISO_1250,
- ltsISO_1251,
- ltsISO_1252,
- ltsISO_1253,
- ltsISO_1254,
- ltsISO_1255,
- ltsISO_1256,
- ltsISO_1257,
- ltsISO_1258
- }
- lts_code_page_t;
- STATIC_ASSERT(sizeof(lts_code_page_t) == 4, size_of_lts_code_page_t_should_be_4);
-
- typedef enum
- {
- ltsFormatEmpty,
- ltsFormatRGBA8,
- ltsFormatLumAlpha8,
- ltsFormatAlpha8,
- ltsFormatLum8
- }
- lts_format_t;
- STATIC_ASSERT(sizeof(lts_format_t) == 4, size_of_lts_format_t_should_be_4);
-
- typedef enum
- {
- ltsRendererUnknown,
- ltsRendererOpenGL,
- ltsRendererOpenGLES
- }
- lts_renderer_type_t;
- STATIC_ASSERT(sizeof(lts_renderer_type_t) == 4, size_of_lts_renderer_type_t_should_be_4);
-
- typedef enum
- {
- ltsFontCreatorUnknown,
- ltsFontCreatorFreeType,
- ltsFontCreatorGDI,
- ltsFontCreatorCustom
- }
- lts_font_creator_type_t;
- STATIC_ASSERT(sizeof(lts_font_creator_type_t) == 4, size_of_lts_font_creator_type_t_should_be_4);
-
- typedef enum
- {
- ltsVertAlignTop,
- ltsVertAlignCenter,
- ltsVertAlignBottom
- }
- lts_vert_align_t;
- STATIC_ASSERT(sizeof(lts_vert_align_t) == 4, size_of_lts_vert_align_t_should_be_4);
-
- typedef enum
- {
- ltsHorzAlignLeft,
- ltsHorzAlignCenter,
- ltsHorzAlignRight,
- ltsHorzAlignJustify
- }
- lts_horz_align_t;
- STATIC_ASSERT(sizeof(lts_horz_align_t) == 4, size_of_lts_horz_align_t_should_be_4);
-
- typedef enum
- {
- ltsClipNone,
- ltsClipWordBorder,
- ltsClipCharBorder,
- ltsClipWordComplete,
- ltsClipCharComplete
- }
- lts_clipping_t;
- STATIC_ASSERT(sizeof(lts_clipping_t) == 4, size_of_lts_clipping_t_should_be_4);
-
- typedef enum
- {
- ltsAANone,
- ltsAANormal
- }
- lts_anti_aliasing_t;
- STATIC_ASSERT(sizeof(lts_anti_aliasing_t) == 4, size_of_lts_anti_aliasing_t_should_be_4);
-
- typedef enum
- {
- ltsUsageInclude,
- ltsUsageExclude
- }
- lts_char_range_usage_t;
- STATIC_ASSERT(sizeof(lts_char_range_usage_t) == 4, size_of_lts_char_range_usage_t_should_be_4);
-
- typedef enum
- {
- ltsStreamOriginBegin = 0,
- ltsStreamOriginCurrent = 1,
- ltsStreamOriginEnd = 2
- }
- lts_stream_origin_t;
- STATIC_ASSERT(sizeof(lts_stream_origin_t) == 4, size_of_lts_stream_origin_t_should_be_4);
-
- typedef enum
- {
- ltsModeIgnore,
- ltsModeReplace,
- ltsModeModulate
- }
- lts_image_mode_t;
- STATIC_ASSERT(sizeof(lts_image_mode_t) == 4, size_of_lts_image_mode_t_should_be_4);
-
- /* flags **************************************************************************************************************************/
- #define FLAGS_MAKE(enum) (1 << enum)
- #define FLAGS_SET(flags, enum) flags |= FLAGS_MAKE(enum)
- #define FLAGS_UNSET(flags, enum) flags &= ~FLAGS_MAKE(enum)
- #define FLAGS_CLEAR(flags) flags = 0
- #define FLAGS_IS_SET(flags, enum) (flags & FLAGS_MAKE(enum))
-
- typedef enum
- {
- ltsBlockFlagWordWrap
- }
- lts_block_flag_t;
- typedef uint32_t lts_block_flags_t;
- STATIC_ASSERT(sizeof(lts_block_flag_t) == 4, size_of_lts_block_flag_t_should_be_4);
-
- typedef enum
- {
- ltsFontStyleBold,
- ltsFontStyleItalic,
- ltsFontStyleUnderline,
- ltsFontStyleStrikeout,
- }
- lts_font_style_flag_t;
- typedef uint32_t lts_font_style_flags_t;
- STATIC_ASSERT(sizeof(lts_font_style_flag_t) == 4, size_of_lts_font_style_flag_t_should_be_4);
-
- typedef enum
- {
- ltsColorChannelRed,
- ltsColorChannelGreen,
- ltsColorChannelBlue,
- ltsColorChannelAlpha
- }
- lts_color_channel_flag_t;
- typedef uint32_t lts_color_channel_flags_t;
- STATIC_ASSERT(sizeof(lts_color_channel_flags_t) == 4, size_of_lts_color_channel_flag_t_should_be_4);
-
- /* structures *********************************************************************************************************************/
- typedef struct
- {
- int32_t x;
- int32_t y;
- }
- lts_position_t;
- STATIC_ASSERT(sizeof(lts_position_t) == 8, size_of_lts_position_t_should_be_8);
-
- typedef union
- {
- struct { lts_position_t top_left, bottom_right; };
- struct { int32_t left, top, right, bottom; };
- }
- lts_rect_t;
- STATIC_ASSERT(sizeof(lts_rect_t) == 16, size_of_lts_rect_t_should_be_16);
-
- typedef union
- {
- struct { float r, g, b, a; };
- float arr[4];
- }
- lts_color4f_t;
- STATIC_ASSERT(sizeof(lts_color4f_t) == 16, size_of_lts_color4f_t_should_be_16);
-
- typedef struct
- {
- lts_position_t glyph_origin;
- lts_rect_t glyph_rect;
- int32_t advance;
- }
- lts_glyph_metric_t;
- STATIC_ASSERT(sizeof(lts_glyph_metric_t) == 28, size_of_lts_glyph_metric_t_should_be_28);
-
- typedef struct
- {
- int32_t ascent;
- int32_t descent;
- int32_t external_leading;
- int32_t base_line_offset;
- int32_t char_spacing;
- int32_t line_height;
- int32_t line_spacing;
- }
- lts_text_metric_t;
- STATIC_ASSERT(sizeof(lts_text_metric_t) == 28, size_of_lts_text_metric_t_should_be_28);
-
- typedef struct
- {
- int32_t size;
- lts_font_style_flags_t style;
- lts_anti_aliasing_t anti_aliasing;
- lts_wchar_t default_char;
- uint8_t __reserved[2];
-
- int32_t ascent;
- int32_t descent;
- int32_t external_leading;
- int32_t base_line_offset;
-
- int32_t underline_pos;
- int32_t underline_size;
- int32_t strikeout_pos;
- int32_t strikeout_size;
- }
- lts_font_metric_t;
- STATIC_ASSERT(sizeof(lts_font_metric_t) == 48, size_of_lts_font_metric_t_should_be_48);
-
- typedef float lts_vector4f_t[4];
- STATIC_ASSERT(sizeof(lts_vector4f_t) == 16, size_of_lts_vector4f_t_should_be_16);
-
- typedef lts_vector4f_t lts_matrix4f_t[4];
- STATIC_ASSERT(sizeof(lts_matrix4f_t) == 64, size_of_lts_matrix4f_t_should_be_64);
-
- typedef void* lts_handle_t;
- typedef lts_handle_t lts_context_handle_t;
- typedef lts_handle_t lts_renderer_handle_t;
- typedef lts_handle_t lts_text_block_handle_t;
- typedef lts_handle_t lts_font_creator_handle_t;
- typedef lts_handle_t lts_font_handle_t;
- typedef lts_handle_t lts_post_processor_handle_t;
- typedef lts_handle_t lts_image_handle_t;
- typedef lts_handle_t lts_char_handle_t;
- typedef lts_image_mode_t lts_image_modes_t[4];
-
- /* stream */
- typedef int (WINAPI *lts_stream_func_read_t)(void* args, void* buffer, int count);
- typedef int (WINAPI *lts_stream_func_seek_t)(void* args, lts_stream_origin_t origin, int offset);
- typedef struct
- {
- void* args;
- lts_stream_func_read_t read;
- lts_stream_func_seek_t seek;
- }
- lts_stream_t;
-
- /* custom post processor */
- typedef void (WINAPI *lts_post_processor_execute_func_t)(lts_char_handle_t charHandle, lts_image_handle_t imageHandle);
- typedef struct
- {
- void* args;
- lts_post_processor_execute_func_t execute;
- }
- lts_post_processor_custom_data_t;
-
- /* custom renderer */
- typedef void (WINAPI *lts_renderer_custom_begin_render_t) (void* args);
- typedef void (WINAPI *lts_renderer_custom_end_render_t) (void* args);
- typedef lts_position_t (WINAPI *lts_renderer_custom_get_draw_pos_t) (void* args);
- typedef void (WINAPI *lts_renderer_custom_set_draw_pos_t) (lts_position_t value, void* args);
- typedef void (WINAPI *lts_renderer_custom_move_draw_pos_t) (lts_position_t value, void* args);
- typedef void (WINAPI *lts_renderer_custom_set_color_t) (lts_color4f_t value, void* args);
- typedef void (WINAPI *lts_renderer_custom_render) (void* ref, int forcedWidth, void* args);
- typedef void* (WINAPI *lts_renderer_custom_create_ref) (lts_char_handle_t charHandle, lts_image_handle_t imageHandle, void* args);
- typedef void (WINAPI *lts_renderer_custom_free_ref) (void* ref, void* args);
- typedef struct
- {
- void* args;
-
- lts_renderer_custom_begin_render_t beginRender;
- lts_renderer_custom_end_render_t endRender;
- lts_renderer_custom_get_draw_pos_t getDrawPos;
- lts_renderer_custom_set_draw_pos_t setDrawPos;
- lts_renderer_custom_move_draw_pos_t moveDrawPos;
- lts_renderer_custom_set_color_t setColor;
- lts_renderer_custom_render render;
-
- lts_renderer_custom_create_ref createRef;
- lts_renderer_custom_free_ref freeRef;
- }
- lts_renderer_custom_data_t;
-
- /* image */
- typedef void (WINAPI *lts_image_load_callback_t) (lts_image_handle_t handle, int x, int y, lts_color4f_t pixel, void* args);
- 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);
-
- /* callbacks **********************************************************************************************************************/
- lts_context_handle_t (WINAPI *lts_context_create) ();
- lts_error_code_t (WINAPI *lts_context_get_code_page) (lts_context_handle_t handle, lts_code_page_t* value);
- lts_error_code_t (WINAPI *lts_context_get_default_char) (lts_context_handle_t handle, lts_wchar_t* value);
- lts_error_code_t (WINAPI *lts_context_set_code_page) (lts_context_handle_t handle, lts_code_page_t value);
- lts_error_code_t (WINAPI *lts_context_set_default_char) (lts_context_handle_t handle, lts_wchar_t value);
- lts_wchar_t* (WINAPI *lts_context_ansi_to_wide) (lts_context_handle_t handle, const char* text);
- lts_error_code_t (WINAPI *lts_context_destroy) (lts_context_handle_t handle);
-
- lts_renderer_handle_t (WINAPI *lts_renderer_create) (lts_context_handle_t handle, lts_renderer_type_t type, lts_format_t format);
- 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);
- 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);
- lts_error_code_t (WINAPI *lts_renderer_end_block) (lts_renderer_handle_t handle, lts_text_block_handle_t block);
- lts_error_code_t (WINAPI *lts_renderer_abort_block) (lts_renderer_handle_t handle, lts_text_block_handle_t block);
- int (WINAPI *lts_renderer_get_text_width_a) (lts_renderer_handle_t handle, lts_font_handle_t font, const char* text);
- int (WINAPI *lts_renderer_get_text_width_w) (lts_renderer_handle_t handle, lts_font_handle_t font, const lts_wchar_t* text);
- lts_error_code_t (WINAPI *lts_renderer_destroy) (lts_renderer_handle_t handle);
-
- lts_font_creator_handle_t (WINAPI *lts_font_creator_create) (lts_context_handle_t handle, lts_font_creator_type_t type);
- 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);
- 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);
- 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);
- lts_error_code_t (WINAPI *lts_font_creator_destroy) (lts_font_creator_handle_t handle);
-
- lts_post_processor_handle_t (WINAPI *lts_font_get_post_processor) (lts_font_handle_t handle);
- lts_error_code_t (WINAPI *lts_font_get_tab_width) (lts_font_handle_t handle, int* value);
- lts_error_code_t (WINAPI *lts_font_get_char_spacing) (lts_font_handle_t handle, int* value);
- lts_error_code_t (WINAPI *lts_font_get_line_spacing) (lts_font_handle_t handle, float* value);
- lts_error_code_t (WINAPI *lts_font_get_metric) (lts_font_handle_t handle, lts_font_metric_t* value);
- const char* (WINAPI *lts_font_get_fontname) (lts_font_handle_t handle);
- const char* (WINAPI *lts_font_get_facename) (lts_font_handle_t handle);
- const char* (WINAPI *lts_font_get_stylename) (lts_font_handle_t handle);
- const char* (WINAPI *lts_font_get_fillname) (lts_font_handle_t handle);
- const char* (WINAPI *lts_font_get_copyright) (lts_font_handle_t handle);
- lts_error_code_t (WINAPI *lts_font_set_post_processor) (lts_font_handle_t handle, lts_post_processor_handle_t pp);
- lts_error_code_t (WINAPI *lts_font_set_tab_width) (lts_font_handle_t handle, int value);
- lts_error_code_t (WINAPI *lts_font_set_char_spacing) (lts_font_handle_t handle, int value);
- lts_error_code_t (WINAPI *lts_font_set_line_spacing) (lts_font_handle_t handle, float value);
- lts_error_code_t (WINAPI *lts_font_destroy) (lts_font_handle_t handle);
-
- lts_error_code_t (WINAPI *lts_text_block_get_rect) (lts_text_block_handle_t handle, lts_rect_t* value);
- lts_error_code_t (WINAPI *lts_text_block_get_width) (lts_text_block_handle_t handle, int* value);
- lts_error_code_t (WINAPI *lts_text_block_get_height) (lts_text_block_handle_t handle, int* value);
- lts_error_code_t (WINAPI *lts_text_block_get_flags) (lts_text_block_handle_t handle, lts_block_flags_t* value);
- lts_error_code_t (WINAPI *lts_text_block_get_top) (lts_text_block_handle_t handle, int* value);
- lts_error_code_t (WINAPI *lts_text_block_get_left) (lts_text_block_handle_t handle, int* value);
- lts_error_code_t (WINAPI *lts_text_block_get_vert_align) (lts_text_block_handle_t handle, lts_vert_align_t* value);
- lts_error_code_t (WINAPI *lts_text_block_get_horz_align) (lts_text_block_handle_t handle, lts_horz_align_t* value);
- lts_error_code_t (WINAPI *lts_text_block_get_clipping) (lts_text_block_handle_t handle, lts_clipping_t* value);
- lts_error_code_t (WINAPI *lts_text_block_get_color) (lts_text_block_handle_t handle, lts_color4f_t* value);
- lts_error_code_t (WINAPI *lts_text_block_get_font) (lts_text_block_handle_t handle, lts_font_handle_t* value);
- lts_error_code_t (WINAPI *lts_text_block_set_top) (lts_text_block_handle_t handle, int value);
- lts_error_code_t (WINAPI *lts_text_block_set_left) (lts_text_block_handle_t handle, int value);
- lts_error_code_t (WINAPI *lts_text_block_set_vert_align) (lts_text_block_handle_t handle, lts_vert_align_t value);
- lts_error_code_t (WINAPI *lts_text_block_set_horz_align) (lts_text_block_handle_t handle, lts_horz_align_t value);
- lts_error_code_t (WINAPI *lts_text_block_set_clipping) (lts_text_block_handle_t handle, lts_clipping_t value);
- lts_error_code_t (WINAPI *lts_text_block_set_color) (lts_text_block_handle_t handle, lts_color4f_t value);
- lts_error_code_t (WINAPI *lts_text_block_set_font) (lts_text_block_handle_t handle, lts_font_handle_t value);
- int (WINAPI *lts_text_block_get_actual_height) (lts_text_block_handle_t handle);
- int (WINAPI *lts_text_block_get_text_width_a) (lts_text_block_handle_t handle, const char* text);
- int (WINAPI *lts_text_block_get_text_width_w) (lts_text_block_handle_t handle, const lts_wchar_t* text);
- lts_error_code_t (WINAPI *lts_text_block_text_out_a) (lts_text_block_handle_t handle, const char* text);
- lts_error_code_t (WINAPI *lts_text_block_text_out_w) (lts_text_block_handle_t handle, const lts_wchar_t* text);
- lts_error_code_t (WINAPI *lts_text_block_destroy) (lts_text_block_handle_t handle);
-
- lts_image_handle_t (WINAPI *lts_image_create) (lts_context_handle_t handle);
- lts_error_code_t (WINAPI *lts_image_is_empty) (lts_image_handle_t handle, bool* value);
- int (WINAPI *lts_image_get_width) (lts_image_handle_t handle);
- int (WINAPI *lts_image_get_height) (lts_image_handle_t handle);
- int (WINAPI *lts_image_get_line_size) (lts_image_handle_t handle);
- int (WINAPI *lts_image_get_data_size) (lts_image_handle_t handle);
- lts_error_code_t (WINAPI *lts_image_get_format) (lts_image_handle_t handle, lts_format_t* value);
- void* (WINAPI *lts_image_get_data) (lts_image_handle_t handle);
- void* (WINAPI *lts_image_get_scanline) (lts_image_handle_t handle, int index);
- lts_error_code_t (WINAPI *lts_image_get_pixel_at) (lts_image_handle_t handle, int x, int y, lts_color4f_t pixel);
- lts_error_code_t (WINAPI *lts_image_assign) (lts_image_handle_t handle, lts_image_handle_t source);
- lts_error_code_t (WINAPI *lts_image_create_empty) (lts_image_handle_t handle, lts_format_t format, int width, int height);
- lts_error_code_t (WINAPI *lts_image_load_from_func) (lts_image_handle_t handle, lts_image_load_callback_t callback, void* args);
- lts_error_code_t (WINAPI *lts_image_resize) (lts_image_handle_t handle, int width, int height, int x, int y);
- 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);
- 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);
- 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);
- 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);
- lts_error_code_t (WINAPI *lts_image_destroy) (lts_image_handle_t handle);
-
- 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);
- 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);
- lts_error_code_t (WINAPI *lts_post_processor_clear_ranges) (lts_post_processor_handle_t handle);
- 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);
- 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);
- 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);
- 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);
- 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);
- 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);
- lts_error_code_t (WINAPI *lts_post_processor_destroy) (lts_post_processor_handle_t handle);
-
- lts_error_code_t (WINAPI *lts_char_get_char_code) (lts_char_handle_t handle, lts_wchar_t* value);
- lts_error_code_t (WINAPI *lts_char_get_glyph_metric) (lts_char_handle_t handle, lts_glyph_metric_t* value);
- lts_error_code_t (WINAPI *lts_char_set_glyph_metric) (lts_char_handle_t handle, const lts_glyph_metric_t* value);
-
- const char* (WINAPI *lts_get_version) ();
- lts_error_code_t (WINAPI *lts_get_last_error_code) ();
- const char* (WINAPI *lts_get_last_error_msg) ();
-
- /* constants **********************************************************************************************************************/
- lts_image_modes_t LTS_IMAGE_MODES_REPLACE_ALL = {
- ltsModeReplace,
- ltsModeReplace,
- ltsModeReplace,
- ltsModeReplace
- };
- lts_image_modes_t LTS_IMAGE_MODES_MODULATE_ALPHA = {
- ltsModeReplace,
- ltsModeReplace,
- ltsModeReplace,
- ltsModeModulate
- };
- lts_image_modes_t LTS_IMAGE_MODES_MODULATE_ALL = {
- ltsModeModulate,
- ltsModeModulate,
- ltsModeModulate,
- ltsModeModulate
- };
-
- lts_color_channel_flags_t LTS_COLOR_CHANNELS_RGB =
- FLAGS_MAKE(ltsColorChannelRed) |
- FLAGS_MAKE(ltsColorChannelGreen) |
- FLAGS_MAKE(ltsColorChannelBlue);
- lts_color_channel_flags_t LTS_COLOR_CHANNELS_RGBA =
- FLAGS_MAKE(ltsColorChannelRed) |
- FLAGS_MAKE(ltsColorChannelGreen) |
- FLAGS_MAKE(ltsColorChannelBlue) |
- FLAGS_MAKE(ltsColorChannelAlpha);
-
- /* helper *************************************************************************************************************************/
- static inline lts_color4f_t ltsColor4f(float r, float g, float b, float a)
- { lts_color4f_t ret = { r, g, b, a }; return ret; };
-
- static inline lts_position_t ltsPosition(int x, int y)
- { lts_position_t ret = { x, y }; return ret; };
-
- static inline lts_rect_t ltsRect(int left, int top, int right, int bottom)
- { lts_rect_t ret = { left, top, right, bottom }; return ret; };
-
- static inline lts_rect_t ltsRectFromPos(lts_position_t leftTop, lts_position_t bottomRight)
- { lts_rect_t ret = { leftTop.x, leftTop.y, bottomRight.x, bottomRight.y }; return ret; };
-
- /**********************************************************************************************************************************/
- /* internal initialization code */
- /**********************************************************************************************************************************/
- //#define LSF_DEBUG
- #ifdef LSF_DEBUG
- # include <stdio.h>
- #endif
-
- #if WIN32 || WIN64 || _WIN32 || _WIN64
- # include <windows.h>
-
- typedef HMODULE lib_handle_t;
-
- lib_handle_t open_lib(const char* name)
- { return LoadLibrary(name); };
-
- void* get_addr(lib_handle_t handle, const char* name)
- { return GetProcAddress(handle, name); };
-
- int close_lib(lib_handle_t handle)
- { return FreeLibrary(handle); };
-
- #elif LINUX || __linux__
- # include <dlfcn.h>
-
- typedef void* lib_handle_t;
-
- lib_handle_t open_lib(const char* name)
- { return dlopen(name, RTLD_LAZY); };
-
- void* get_addr(lib_handle_t handle, const char* name)
- { return dlsym(handle, name); };
-
- int close_lib(lib_handle_t handle)
- { return !dlclose(handle); };
-
- #else
- # error "unknown operation system"
- #endif
-
- #ifndef LSF_DEBUG
- # define LoadProc(proc, name) \
- proc = get_addr(handle, name); \
- if (!proc) \
- return ltsErrInvalidMethodName
- #else
- # define LoadProc(proc, name) \
- proc = get_addr(handle, name); \
- printf("load method '%s' (addr=0x%016x)\n", name, proc); \
- if (!proc) \
- return ltsErrInvalidMethodName
- #endif
-
- lts_error_code_t (WINAPI *lts_initialize_intern)();
- lts_error_code_t (WINAPI *lts_finalize_intern) ();
-
- lib_handle_t handle = NULL;
-
- lts_error_code_t lts_initialize(const char* libname)
- {
- #ifdef LSF_DEBUG
- printf("loading library '%s'\n", libname);
- #endif
-
- handle = open_lib(libname);
- if (!handle)
- return ltsErrInvalidLibName;
-
- #ifdef LSF_DEBUG
- printf(" done (handle=0x%016x)\n", handle);
- #endif
-
- LoadProc(lts_context_create, "ltsContextCreate");
- LoadProc(lts_context_get_code_page, "ltsContextGetCodePage");
- LoadProc(lts_context_get_default_char, "ltsContextGetDefaultChar");
- LoadProc(lts_context_set_code_page, "ltsContextSetCodePage");
- LoadProc(lts_context_set_default_char, "ltsContextSetDefaultChar");
- LoadProc(lts_context_ansi_to_wide, "ltsContextAnsiToWide");
- LoadProc(lts_context_destroy, "ltsContextDestroy");
-
- LoadProc(lts_renderer_create, "ltsRendererCreate");
- LoadProc(lts_renderer_create_custom, "ltsRendererCustomCreate");
- LoadProc(lts_renderer_begin_block, "ltsRendererBeginBlock");
- LoadProc(lts_renderer_end_block, "ltsRendererEndBlock");
- LoadProc(lts_renderer_abort_block, "ltsRendererAbortBlock");
- LoadProc(lts_renderer_get_text_width_a, "ltsRendererGetTextWidthA");
- LoadProc(lts_renderer_get_text_width_w, "ltsRendererGetTextWidthW");
- LoadProc(lts_renderer_destroy, "ltsRendererDestroy");
-
- LoadProc(lts_font_creator_create, "ltsFontCreatorCreate");
- LoadProc(lts_font_creator_get_font_by_name, "ltsFontCreatorGetFontByName");
- LoadProc(lts_font_creator_get_font_by_file, "ltsFontCreatorGetFontByFile");
- LoadProc(lts_font_creator_get_font_by_stream, "ltsFontCreatorGetFontByStream");
- LoadProc(lts_font_creator_destroy, "ltsFontCreatorDestroy");
-
- LoadProc(lts_font_get_post_processor, "ltsFontGetPostProcessor");
- LoadProc(lts_font_get_tab_width, "ltsFontGetTabWidth");
- LoadProc(lts_font_get_char_spacing, "ltsFontGetCharSpacing");
- LoadProc(lts_font_get_line_spacing, "ltsFontGetLineSpacing");
- LoadProc(lts_font_get_metric, "ltsFontGetMetric");
- LoadProc(lts_font_get_fontname, "ltsFontGetFontname");
- LoadProc(lts_font_get_facename, "ltsFontGetFacename");
- LoadProc(lts_font_get_stylename, "ltsFontGetStylename");
- LoadProc(lts_font_get_fillname, "ltsFontGetFullname");
- LoadProc(lts_font_get_copyright, "ltsFontGetCopyright");
- LoadProc(lts_font_set_post_processor, "ltsFontSetPostProcessor");
- LoadProc(lts_font_set_tab_width, "ltsFontSetTabWidth");
- LoadProc(lts_font_set_char_spacing, "ltsFontSetCharSpacing");
- LoadProc(lts_font_set_line_spacing, "ltsFontSetLineSpacing");
- LoadProc(lts_font_destroy, "ltsFontDestroy");
-
- LoadProc(lts_text_block_get_rect, "ltsTextBlockGetRect");
- LoadProc(lts_text_block_get_width, "ltsTextBlockGetWidth");
- LoadProc(lts_text_block_get_height, "ltsTextBlockGetHeight");
- LoadProc(lts_text_block_get_flags, "ltsTextBlockGetFlags");
- LoadProc(lts_text_block_get_top, "ltsTextBlockGetTop");
- LoadProc(lts_text_block_get_left, "ltsTextBlockGetLeft");
- LoadProc(lts_text_block_get_vert_align, "ltsTextBlockGetVertAlign");
- LoadProc(lts_text_block_get_horz_align, "ltsTextBlockGetHorzAlign");
- LoadProc(lts_text_block_get_clipping, "ltsTextBlockGetClipping");
- LoadProc(lts_text_block_get_color, "ltsTextBlockGetColor");
- LoadProc(lts_text_block_get_font, "ltsTextBlockGetFont");
- LoadProc(lts_text_block_set_top, "ltsTextBlockSetTop");
- LoadProc(lts_text_block_set_left, "ltsTextBlockSetLeft");
- LoadProc(lts_text_block_set_vert_align, "ltsTextBlockSetVertAlign");
- LoadProc(lts_text_block_set_horz_align, "ltsTextBlockSetHorzAlign");
- LoadProc(lts_text_block_set_clipping, "ltsTextBlockSetClipping");
- LoadProc(lts_text_block_set_color, "ltsTextBlockSetColor");
- LoadProc(lts_text_block_set_font, "ltsTextBlockSetFont");
- LoadProc(lts_text_block_get_actual_height, "ltsTextBlockGetActualHeight");
- LoadProc(lts_text_block_get_text_width_a, "ltsTextBlockGetTextWidthA");
- LoadProc(lts_text_block_get_text_width_w, "ltsTextBlockGetTextWidthW");
- LoadProc(lts_text_block_text_out_a, "ltsTextBlockTextOutA");
- LoadProc(lts_text_block_text_out_w, "ltsTextBlockTextOutW");
- LoadProc(lts_text_block_destroy, "ltsTextBlockDestroy");
-
- LoadProc(lts_image_create, "ltsImageCreate");
- LoadProc(lts_image_is_empty, "ltsImageIsEmpty");
- LoadProc(lts_image_get_width, "ltsImageGetWidth");
- LoadProc(lts_image_get_height, "ltsImageGetHeight");
- LoadProc(lts_image_get_line_size, "ltsImageGetLineSize");
- LoadProc(lts_image_get_data_size, "ltsImageGetDataSize");
- LoadProc(lts_image_get_format, "ltsImageGetFormat");
- LoadProc(lts_image_get_data, "ltsImageGetData");
- LoadProc(lts_image_get_scanline, "ltsImageGetScanline");
- LoadProc(lts_image_get_pixel_at, "ltsImageGetPixelAt");
- LoadProc(lts_image_assign, "ltsImageAssign");
- LoadProc(lts_image_create_empty, "ltsImageCreateEmpty");
- LoadProc(lts_image_load_from_func, "ltsImageLoadFromFunc");
- LoadProc(lts_image_resize, "ltsImageResize");
- LoadProc(lts_image_fill_color, "ltsImageFillColor");
- LoadProc(lts_image_fill_pattern, "ltsImageFillPattern");
- LoadProc(lts_image_blend, "ltsImageBlend");
- LoadProc(lts_image_blur, "ltsImageBlur");
- LoadProc(lts_image_destroy, "ltsImageDestroy");
-
- LoadProc(lts_post_processor_add_range, "ltsPostProcessorAddRange");
- LoadProc(lts_post_processor_add_chars, "ltsPostProcessorAddChars");
- LoadProc(lts_post_processor_clear_ranges, "ltsPostProcessorClearRanges");
- LoadProc(lts_post_processor_execute, "ltsPostProcessorExecute");
- LoadProc(lts_post_processor_fill_color_create, "ltsPostProcessorFillColorCreate");
- LoadProc(lts_post_processor_fill_pattern_create, "ltsPostProcessorFillPatterCreate");
- LoadProc(lts_post_processor_border_create, "ltsPostProcessorBorderCreate");
- LoadProc(lts_post_processor_shadow_create, "ltsPostProcessorShadowCreate");
- LoadProc(lts_post_processor_custom_create, "ltsPostProcessorCustomCreate");
- LoadProc(lts_post_processor_destroy, "ltsPostProcessorDestroy");
-
- LoadProc(lts_char_get_char_code, "ltsCharGetCharCode");
- LoadProc(lts_char_get_glyph_metric, "ltsCharGetGlyphMetric");
- LoadProc(lts_char_set_glyph_metric, "ltsCharSetGlyphMetric");
-
- LoadProc(lts_initialize_intern, "ltsInitialize");
- LoadProc(lts_get_version, "ltsGetVersion");
- LoadProc(lts_get_last_error_code, "ltsGetLastErrorCode");
- LoadProc(lts_get_last_error_msg, "ltsGetLastErrorMsg");
- LoadProc(lts_finalize_intern, "ltsFinalize");
-
- return lts_initialize_intern();
- }
-
- int lts_finalize(void)
- {
- lts_error_code_t err = lts_finalize_intern();
-
- lts_context_create = NULL;
- lts_context_get_code_page = NULL;
- lts_context_get_default_char = NULL;
- lts_context_set_code_page = NULL;
- lts_context_set_default_char = NULL;
- lts_context_ansi_to_wide = NULL;
- lts_context_destroy = NULL;
-
- lts_renderer_create = NULL;
- lts_renderer_create_custom = NULL;
- lts_renderer_begin_block = NULL;
- lts_renderer_end_block = NULL;
- lts_renderer_abort_block = NULL;
- lts_renderer_get_text_width_a = NULL;
- lts_renderer_get_text_width_w = NULL;
- lts_renderer_destroy = NULL;
-
- lts_font_creator_create = NULL;
- lts_font_creator_get_font_by_name = NULL;
- lts_font_creator_get_font_by_file = NULL;
- lts_font_creator_get_font_by_stream = NULL;
- lts_font_creator_destroy = NULL;
-
- lts_font_get_post_processor = NULL;
- lts_font_get_tab_width = NULL;
- lts_font_get_char_spacing = NULL;
- lts_font_get_line_spacing = NULL;
- lts_font_get_metric = NULL;
- lts_font_get_fontname = NULL;
- lts_font_get_facename = NULL;
- lts_font_get_stylename = NULL;
- lts_font_get_fillname = NULL;
- lts_font_get_copyright = NULL;
- lts_font_set_post_processor = NULL;
- lts_font_set_tab_width = NULL;
- lts_font_set_char_spacing = NULL;
- lts_font_set_line_spacing = NULL;
- lts_font_destroy = NULL;
-
- lts_text_block_get_rect = NULL;
- lts_text_block_get_width = NULL;
- lts_text_block_get_height = NULL;
- lts_text_block_get_flags = NULL;
- lts_text_block_get_top = NULL;
- lts_text_block_get_left = NULL;
- lts_text_block_get_vert_align = NULL;
- lts_text_block_get_horz_align = NULL;
- lts_text_block_get_clipping = NULL;
- lts_text_block_get_color = NULL;
- lts_text_block_get_font = NULL;
- lts_text_block_set_top = NULL;
- lts_text_block_set_left = NULL;
- lts_text_block_set_vert_align = NULL;
- lts_text_block_set_horz_align = NULL;
- lts_text_block_set_clipping = NULL;
- lts_text_block_set_color = NULL;
- lts_text_block_set_font = NULL;
- lts_text_block_get_actual_height = NULL;
- lts_text_block_get_text_width_a = NULL;
- lts_text_block_get_text_width_w = NULL;
- lts_text_block_text_out_a = NULL;
- lts_text_block_text_out_w = NULL;
- lts_text_block_destroy = NULL;
-
- lts_image_create = NULL;
- lts_image_is_empty = NULL;
- lts_image_get_width = NULL;
- lts_image_get_height = NULL;
- lts_image_get_line_size = NULL;
- lts_image_get_data_size = NULL;
- lts_image_get_format = NULL;
- lts_image_get_data = NULL;
- lts_image_get_scanline = NULL;
- lts_image_get_pixel_at = NULL;
- lts_image_assign = NULL;
- lts_image_create_empty = NULL;
- lts_image_load_from_func = NULL;
- lts_image_resize = NULL;
- lts_image_fill_color = NULL;
- lts_image_fill_pattern = NULL;
- lts_image_blend = NULL;
- lts_image_blur = NULL;
- lts_image_destroy = NULL;
-
- lts_post_processor_add_range = NULL;
- lts_post_processor_add_chars = NULL;
- lts_post_processor_clear_ranges = NULL;
- lts_post_processor_execute = NULL;
- lts_post_processor_fill_color_create = NULL;
- lts_post_processor_fill_pattern_create = NULL;
- lts_post_processor_border_create = NULL;
- lts_post_processor_shadow_create = NULL;
- lts_post_processor_custom_create = NULL;
- lts_post_processor_destroy = NULL;
-
- lts_char_get_char_code = NULL;
- lts_char_get_glyph_metric = NULL;
- lts_char_set_glyph_metric = NULL;
-
- lts_initialize_intern = NULL;
- lts_get_version = NULL;
- lts_get_last_error_code = NULL;
- lts_get_last_error_msg = NULL;
- lts_finalize_intern = NULL;
-
- if (!close_lib(handle))
- return ltsErrInvalidLibHandle;
- return err;
- }
-
- #endif /* LIB_TEXT_SUITE_H */
|