libfort/src/properties.c

1016 lines
30 KiB
C
Raw Normal View History

2018-11-10 07:58:21 +01:00
#include "fort_utils.h"
2018-05-06 12:12:28 +02:00
#include <assert.h>
2018-11-03 21:50:30 +01:00
#include "properties.h"
2018-01-17 19:22:57 +01:00
#include "vector.h"
2018-11-10 07:58:21 +01:00
#define FT_RESET_COLOR "\033[0m"
const char *fg_colors[] = {
"",
"\033[30m",
"\033[31m",
"\033[32m",
"\033[33m",
"\033[34m",
"\033[35m",
"\033[36m",
"\033[37m",
"\033[90m",
"\033[91m",
"\033[92m",
"\033[93m",
"\033[94m",
"\033[95m",
"\033[96m",
"\033[97m",
};
const char *reset_fg_colors[] = {
"",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
"\033[39m",
};
const char *bg_colors[] = {
"",
"\033[40m",
"\033[41m",
"\033[42m",
"\033[43m",
"\033[44m",
"\033[45m",
"\033[46m",
"\033[47m",
"\033[100m",
"\033[101m",
"\033[102m",
"\033[103m",
"\033[104m",
"\033[105m",
"\033[106m",
"\033[107m",
};
const char *reset_bg_colors[] = {
"",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
"\033[49m",
};
const char *text_styles[] = {
"",
"\033[1m",
"\033[2m",
2018-11-14 20:50:36 +01:00
"\033[3m",
2018-11-10 07:58:21 +01:00
"\033[4m",
"\033[5m",
"\033[7m",
"\033[8m",
};
const char *reset_text_styles[] = {
"",
"\033[21m",
"\033[22m",
2018-11-14 20:50:36 +01:00
"\033[23m",
2018-11-10 07:58:21 +01:00
"\033[24m",
"\033[25m",
"\033[27m",
"\033[28m",
};
static const size_t n_fg_colors = sizeof(fg_colors) / sizeof(fg_colors[0]);
static const size_t n_bg_colors = sizeof(bg_colors) / sizeof(bg_colors[0]);
static const size_t n_styles = sizeof(text_styles) / sizeof(text_styles[0]);
void get_style_tag_for_cell(const fort_table_properties_t *props,
size_t row, size_t col, char *style_tag, size_t sz)
{
(void)sz;
unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_BG_COLOR);
unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_TEXT_STYLE);
style_tag[0] = '\0';
if (text_style < n_styles) {
strcat(style_tag, text_styles[text_style]);
} else {
goto error;
}
if (bg_color_number < n_bg_colors) {
strcat(style_tag, bg_colors[bg_color_number]);
} else {
goto error;
}
return;
error:
// shouldn't be here
assert(0);
style_tag[0] = '\0';
return;
}
void get_reset_style_tag_for_cell(const fort_table_properties_t *props,
size_t row, size_t col, char *reset_style_tag, size_t sz)
{
(void)sz;
unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_BG_COLOR);
unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CELL_TEXT_STYLE);
reset_style_tag[0] = '\0';
if (text_style < n_styles) {
strcat(reset_style_tag, reset_text_styles[text_style]);
} else {
goto error;
}
if (bg_color_number < n_bg_colors) {
strcat(reset_style_tag, reset_bg_colors[bg_color_number]);
} else {
goto error;
}
return;
error:
// shouldn't be here
assert(0);
reset_style_tag[0] = '\0';
return;
}
void get_style_tag_for_content(const fort_table_properties_t *props,
size_t row, size_t col, char *style_tag, size_t sz)
{
(void)sz;
unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_TEXT_STYLE);
unsigned fg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_FG_COLOR);
unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_BG_COLOR);
style_tag[0] = '\0';
if (text_style < n_styles) {
strcat(style_tag, text_styles[text_style]);
} else {
goto error;
}
if (fg_color_number < n_fg_colors) {
strcat(style_tag, fg_colors[fg_color_number]);
} else {
goto error;
}
if (bg_color_number < n_bg_colors) {
strcat(style_tag, bg_colors[bg_color_number]);
} else {
goto error;
}
return;
error:
// shouldn't be here
assert(0);
style_tag[0] = '\0';
return;
}
void get_reset_style_tag_for_content(const fort_table_properties_t *props,
size_t row, size_t col, char *reset_style_tag, size_t sz)
{
(void)sz;
unsigned text_style = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_TEXT_STYLE);
unsigned fg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_FG_COLOR);
unsigned bg_color_number = get_cell_property_value_hierarcial(props, row, col, FT_CPROP_CONT_BG_COLOR);
reset_style_tag[0] = '\0';
if (text_style < n_styles) {
strcat(reset_style_tag, reset_text_styles[text_style]);
} else {
goto error;
}
if (fg_color_number < n_fg_colors) {
strcat(reset_style_tag, reset_fg_colors[fg_color_number]);
} else {
goto error;
}
if (bg_color_number < n_bg_colors) {
strcat(reset_style_tag, reset_bg_colors[bg_color_number]);
} else {
goto error;
}
return;
error:
// shouldn't be here
assert(0);
reset_style_tag[0] = '\0';
return;
}
2018-01-17 19:22:57 +01:00
/*****************************************************************************
2018-11-03 21:50:30 +01:00
* COLUMN PROPERTIES
2018-01-17 19:22:57 +01:00
* ***************************************************************************/
2018-11-03 21:50:30 +01:00
struct fort_cell_props g_default_cell_properties = {
FT_ANY_ROW, /* cell_row */
FT_ANY_COLUMN, /* cell_col */
2018-11-03 21:50:30 +01:00
/* properties */
FT_CPROP_MIN_WIDTH | FT_CPROP_TEXT_ALIGN | FT_CPROP_TOP_PADDING
| FT_CPROP_BOTTOM_PADDING | FT_CPROP_LEFT_PADDING | FT_CPROP_RIGHT_PADDING
2018-11-10 07:58:21 +01:00
| FT_CPROP_EMPTY_STR_HEIGHT | FT_CPROP_CONT_FG_COLOR | FT_CPROP_CELL_BG_COLOR
| FT_CPROP_CONT_BG_COLOR | FT_CPROP_CELL_TEXT_STYLE | FT_CPROP_CONT_TEXT_STYLE,
0, /* col_min_width */
2018-05-08 19:57:49 +02:00
FT_ALIGNED_LEFT, /* align */
2018-02-27 18:41:57 +01:00
0, /* cell_padding_top */
0, /* cell_padding_bottom */
1, /* cell_padding_left */
1, /* cell_padding_right */
1, /* cell_empty_string_height */
2018-03-05 19:08:14 +01:00
2018-04-01 12:27:02 +02:00
FT_ROW_COMMON, /* row_type */
2018-11-10 07:58:21 +01:00
FT_COLOR_DEFAULT, /* content_fg_color_number */
FT_COLOR_DEFAULT, /* content_bg_color_number */
FT_COLOR_DEFAULT, /* cell_bg_color_number */
FT_TSTYLE_DEFAULT, /* cell_text_style */
FT_TSTYLE_DEFAULT, /* content_text_style */
};
2018-11-03 21:50:30 +01:00
static int get_prop_value_if_exists_otherwise_default(const struct fort_cell_props *cell_opts, uint32_t property)
{
2018-11-03 21:50:30 +01:00
if (cell_opts == NULL || !PROP_IS_SET(cell_opts->properties, property)) {
cell_opts = &g_default_cell_properties;
}
2018-11-03 21:50:30 +01:00
switch (property) {
case FT_CPROP_MIN_WIDTH:
return cell_opts->col_min_width;
2018-11-03 21:50:30 +01:00
case FT_CPROP_TEXT_ALIGN:
return cell_opts->align;
2018-11-03 21:50:30 +01:00
case FT_CPROP_TOP_PADDING:
2018-02-27 18:41:57 +01:00
return cell_opts->cell_padding_top;
2018-11-03 21:50:30 +01:00
case FT_CPROP_BOTTOM_PADDING:
2018-02-27 18:41:57 +01:00
return cell_opts->cell_padding_bottom;
2018-11-03 21:50:30 +01:00
case FT_CPROP_LEFT_PADDING:
2018-02-27 18:41:57 +01:00
return cell_opts->cell_padding_left;
2018-11-03 21:50:30 +01:00
case FT_CPROP_RIGHT_PADDING:
2018-02-27 18:41:57 +01:00
return cell_opts->cell_padding_right;
2018-11-03 21:50:30 +01:00
case FT_CPROP_EMPTY_STR_HEIGHT:
2018-02-27 18:41:57 +01:00
return cell_opts->cell_empty_string_height;
2018-11-03 21:50:30 +01:00
case FT_CPROP_ROW_TYPE:
2018-03-05 19:08:14 +01:00
return cell_opts->row_type;
2018-11-10 07:58:21 +01:00
case FT_CPROP_CONT_FG_COLOR:
return cell_opts->content_fg_color_number;
case FT_CPROP_CONT_BG_COLOR:
return cell_opts->content_bg_color_number;
case FT_CPROP_CELL_BG_COLOR:
return cell_opts->cell_bg_color_number;
case FT_CPROP_CELL_TEXT_STYLE:
return cell_opts->cell_text_style;
case FT_CPROP_CONT_TEXT_STYLE:
return cell_opts->content_text_style;
default:
2018-03-09 10:44:16 +01:00
/* todo: implement later */
exit(333);
}
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_cell_prop_container_t *create_cell_prop_container(void)
2018-02-25 09:39:41 +01:00
{
2018-11-03 21:50:30 +01:00
fort_cell_prop_container_t *ret = create_vector(sizeof(fort_cell_props_t), DEFAULT_VECTOR_CAPACITY);
2018-02-25 09:39:41 +01:00
return ret;
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
void destroy_cell_prop_container(fort_cell_prop_container_t *cont)
2018-02-25 09:39:41 +01:00
{
if (cont)
destroy_vector(cont);
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
const fort_cell_props_t *cget_cell_prop(const fort_cell_prop_container_t *cont, size_t row, size_t col)
2018-02-25 09:39:41 +01:00
{
assert(cont);
size_t sz = vector_size(cont);
2018-03-09 10:44:16 +01:00
size_t i = 0;
for (i = 0; i < sz; ++i) {
2018-11-03 21:50:30 +01:00
const fort_cell_props_t *opt = (const fort_cell_props_t *)vector_at_c(cont, i);
2018-02-25 09:39:41 +01:00
if (opt->cell_row == row && opt->cell_col == col)
return opt;
}
return NULL;
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_cell_props_t *get_cell_prop_and_create_if_not_exists(fort_cell_prop_container_t *cont, size_t row, size_t col)
2018-02-25 09:39:41 +01:00
{
assert(cont);
size_t sz = vector_size(cont);
2018-03-09 10:44:16 +01:00
size_t i = 0;
for (i = 0; i < sz; ++i) {
2018-11-03 21:50:30 +01:00
fort_cell_props_t *opt = (fort_cell_props_t *)vector_at(cont, i);
2018-02-25 09:39:41 +01:00
if (opt->cell_row == row && opt->cell_col == col)
return opt;
}
2018-11-03 21:50:30 +01:00
fort_cell_props_t opt;
if (row == FT_ANY_ROW && col == FT_ANY_COLUMN)
2018-11-03 21:50:30 +01:00
memcpy(&opt, &g_default_cell_properties, sizeof(fort_cell_props_t));
else
2018-11-03 21:50:30 +01:00
memset(&opt, 0, sizeof(fort_cell_props_t));
2018-02-25 17:25:00 +01:00
opt.cell_row = row;
opt.cell_col = col;
2018-05-05 17:38:45 +02:00
if (FT_IS_SUCCESS(vector_push(cont, &opt))) {
2018-11-03 21:50:30 +01:00
return (fort_cell_props_t *)vector_at(cont, sz);
2018-02-25 09:39:41 +01:00
}
return NULL;
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
int get_cell_property_value_hierarcial(const fort_table_properties_t *propertiess, size_t row, size_t column, uint32_t property)
{
2018-11-03 21:50:30 +01:00
assert(propertiess);
2018-11-10 07:58:21 +01:00
size_t row_origin = row;
2018-11-03 21:50:30 +01:00
const fort_cell_props_t *opt = NULL;
if (propertiess->cell_properties != NULL) {
while (1) {
2018-11-03 21:50:30 +01:00
opt = cget_cell_prop(propertiess->cell_properties, row, column);
if (opt != NULL && PROP_IS_SET(opt->properties, property))
break;
2018-11-10 07:58:21 +01:00
if (row != FT_ANY_ROW && column != FT_ANY_COLUMN) {
row = FT_ANY_ROW;
continue;
2018-11-10 07:58:21 +01:00
} else if (row == FT_ANY_ROW && column != FT_ANY_COLUMN) {
row = row_origin;
column = FT_ANY_COLUMN;
continue;
} else if (row != FT_ANY_ROW && column == FT_ANY_COLUMN) {
row = FT_ANY_ROW;
column = FT_ANY_COLUMN;
continue;
}
2018-11-10 07:58:21 +01:00
// if (row != FT_ANY_ROW) {
// row = FT_ANY_ROW;
// continue;
// }
// if (column != FT_ANY_COLUMN) {
// column = FT_ANY_COLUMN;
// continue;
// }
opt = NULL;
break;
}
}
2018-11-03 21:50:30 +01:00
return get_prop_value_if_exists_otherwise_default(opt, property);
}
2018-11-03 21:50:30 +01:00
static fort_status_t set_cell_property_impl(fort_cell_props_t *opt, uint32_t property, int value)
2018-02-27 18:41:57 +01:00
{
assert(opt);
2018-11-03 21:50:30 +01:00
PROP_SET(opt->properties, property);
if (PROP_IS_SET(property, FT_CPROP_MIN_WIDTH)) {
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-02-27 18:41:57 +01:00
opt->col_min_width = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_TEXT_ALIGN)) {
2018-04-01 12:27:02 +02:00
opt->align = (enum ft_text_alignment)value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_TOP_PADDING)) {
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-02-27 18:41:57 +01:00
opt->cell_padding_top = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_BOTTOM_PADDING)) {
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-02-27 18:41:57 +01:00
opt->cell_padding_bottom = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_LEFT_PADDING)) {
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-02-27 18:41:57 +01:00
opt->cell_padding_left = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_RIGHT_PADDING)) {
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-02-27 18:41:57 +01:00
opt->cell_padding_right = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_EMPTY_STR_HEIGHT)) {
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-02-27 18:41:57 +01:00
opt->cell_empty_string_height = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_ROW_TYPE)) {
2018-04-01 12:27:02 +02:00
opt->row_type = (enum ft_row_type)value;
2018-11-10 07:58:21 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_CONT_FG_COLOR)) {
opt->content_fg_color_number = value;
} else if (PROP_IS_SET(property, FT_CPROP_CONT_BG_COLOR)) {
opt->content_bg_color_number = value;
} else if (PROP_IS_SET(property, FT_CPROP_CELL_BG_COLOR)) {
opt->cell_bg_color_number = value;
} else if (PROP_IS_SET(property, FT_CPROP_CELL_TEXT_STYLE)) {
opt->cell_text_style = value;
} else if (PROP_IS_SET(property, FT_CPROP_CONT_TEXT_STYLE)) {
opt->content_text_style = value;
2018-02-27 18:41:57 +01:00
}
2018-03-19 21:07:18 +01:00
return FT_SUCCESS;
2018-04-16 21:33:05 +02:00
fort_fail:
return FT_EINVAL;
2018-02-27 18:41:57 +01:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_status_t set_cell_property(fort_cell_prop_container_t *cont, size_t row, size_t col, uint32_t property, int value)
2018-02-27 18:41:57 +01:00
{
2018-11-03 21:50:30 +01:00
fort_cell_props_t *opt = get_cell_prop_and_create_if_not_exists(cont, row, col);
2018-02-27 18:41:57 +01:00
if (opt == NULL)
2018-03-19 21:07:18 +01:00
return FT_ERROR;
2018-02-27 18:41:57 +01:00
2018-11-03 21:50:30 +01:00
return set_cell_property_impl(opt, property, value);
2018-03-09 10:44:16 +01:00
/*
2018-11-03 21:50:30 +01:00
PROP_SET(opt->propertiess, property);
if (PROP_IS_SET(property, FT_CPROP_MIN_WIDTH)) {
2018-03-09 10:44:16 +01:00
opt->col_min_width = value;
2018-11-03 21:50:30 +01:00
} else if (PROP_IS_SET(property, FT_CPROP_TEXT_ALIGN)) {
2018-03-09 10:44:16 +01:00
opt->align = value;
}
2018-03-19 21:07:18 +01:00
return FT_SUCCESS;
2018-03-09 10:44:16 +01:00
*/
2018-02-27 18:41:57 +01:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_status_t set_default_cell_property(uint32_t property, int value)
2018-02-27 18:41:57 +01:00
{
2018-11-03 21:50:30 +01:00
return set_cell_property_impl(&g_default_cell_properties, property, value);
2018-02-27 18:41:57 +01:00
}
2018-01-17 19:22:57 +01:00
/*****************************************************************************
2018-11-03 21:50:30 +01:00
* PROPERTIESS
2018-01-17 19:22:57 +01:00
* ***************************************************************************/
2018-03-12 21:02:59 +01:00
#define BASIC_STYLE { \
/* border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
"+", "-", "+", "+", \
"|", "|", "|", \
"\0", "\0", "\0", "\0", \
"+", "-", "+", "+", \
"+", "+", "+", "+", \
2018-03-12 21:02:59 +01:00
}, \
/* header_border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
"+", "-", "+", "+", \
"|", "|", "|", \
"+", "-", "+", "+", \
"+", "-", "+", "+", \
"+", "+", "+", "+", \
2018-03-12 21:02:59 +01:00
}, \
/* separator_chars */ \
{ \
2018-05-02 20:16:41 +02:00
"+", "-", "+", "+", \
2018-11-15 21:14:18 +01:00
"+", "+", \
2018-03-12 21:02:59 +01:00
}, \
}
2018-01-17 19:22:57 +01:00
#define BASIC2_STYLE { \
2018-05-07 22:25:45 +02:00
/* border_chars */ \
{ \
"+", "-", "+", "+", \
"|", "|", "|", \
"+", "-", "+", "+", \
"+", "-", "+", "+", \
"+", "+", "+", "+", \
2018-05-07 22:25:45 +02:00
}, \
/* header_border_chars */ \
{ \
"+", "-", "+", "+", \
"|", "|", "|", \
"+", "-", "+", "+", \
"+", "-", "+", "+", \
"+", "+", "+", "+", \
2018-05-07 22:25:45 +02:00
}, \
/* separator_chars */ \
{ \
"+", "-", "+", "+", \
2018-11-15 21:14:18 +01:00
"+", "+", \
2018-05-07 22:25:45 +02:00
}, \
}
2018-03-12 21:02:59 +01:00
#define SIMPLE_STYLE { \
/* border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \
" ", " ", " ", " ", \
2018-03-12 21:02:59 +01:00
}, \
/* header_border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", " ", " ", " ", \
" ", " ", " ", \
" ", "-", " ", " ", \
" ", " ", " ", " ", \
2018-11-02 17:32:35 +01:00
" ", "-", " ", "-", \
2018-03-12 21:02:59 +01:00
}, \
/* separator_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", "-", " ", " ", \
2018-11-15 21:14:18 +01:00
" ", " ", \
2018-03-14 19:30:27 +01:00
}, \
}
#define PLAIN_STYLE { \
/* border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \
" ", " ", " ", " ", \
2018-03-14 19:30:27 +01:00
}, \
/* header_border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", "-", "-", " ", \
" ", " ", " ", \
" ", "-", "-", " ", \
" ", "-", "-", " ", \
2018-11-02 17:32:35 +01:00
" ", "-", " ", "-", \
2018-03-14 19:30:27 +01:00
}, \
/* separator_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", "-", "-", " ", \
2018-11-15 21:14:18 +01:00
"-", "-", \
2018-03-12 21:02:59 +01:00
}, \
}
2018-01-21 18:02:43 +01:00
2018-03-12 21:02:59 +01:00
#define DOT_STYLE { \
/* border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
".", ".", ".", ".", \
":", ":", ":", \
"\0", "\0", "\0", "\0", \
":", ".", ":", ":", \
2018-11-02 17:32:35 +01:00
"+", ":", "+", ":", \
2018-03-12 21:02:59 +01:00
}, \
/* header_border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
".", ".", ".", ".", \
":", ":", ":", \
":", ".", ":", ":", \
":", ".", ":", ":", \
2018-11-02 17:32:35 +01:00
"+", ".", "+", ".", \
2018-03-12 21:02:59 +01:00
}, \
/* separator_chars */ \
{ \
2018-05-02 20:16:41 +02:00
":", ".", ":", ":", \
2018-11-15 21:14:18 +01:00
":", ":", \
2018-03-14 19:30:27 +01:00
}, \
}
2018-03-31 12:33:37 +02:00
#define EMPTY_STYLE { \
2018-03-14 19:30:27 +01:00
/* border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \
" ", " ", " ", " ", \
2018-03-14 19:30:27 +01:00
}, \
/* header_border_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", " ", " ", " ", \
" ", " ", " ", \
"\0", "\0", "\0", "\0", \
" ", " ", " ", " ", \
" ", " ", " ", " ", \
2018-03-14 19:30:27 +01:00
}, \
/* separator_chars */ \
{ \
2018-05-02 20:16:41 +02:00
" ", " ", " ", " ", \
2018-11-15 21:14:18 +01:00
" ", " ", \
2018-03-12 21:02:59 +01:00
}, \
}
2018-01-21 18:02:43 +01:00
2018-05-02 20:16:41 +02:00
#define SOLID_STYLE { \
2018-05-02 20:16:41 +02:00
/* border_chars */ \
{ \
2018-05-04 20:25:29 +02:00
"", "", "", "", \
"", "", "", \
2018-05-02 20:16:41 +02:00
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-02 20:16:41 +02:00
}, \
/* header_border_chars */ \
{ \
2018-05-04 20:25:29 +02:00
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-02 20:16:41 +02:00
}, \
/* separator_chars */ \
{ \
2018-05-04 20:25:29 +02:00
"", "", "", "", \
2018-11-15 21:14:18 +01:00
"", "", \
2018-05-04 20:25:29 +02:00
}, \
}
#define SOLID_ROUND_STYLE { \
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* separator_chars */ \
{ \
"", "", "", "", \
2018-11-15 21:14:18 +01:00
"", "", \
2018-05-02 20:16:41 +02:00
}, \
}
2018-11-16 18:35:56 +01:00
#define NICE_STYLE { \
2018-05-02 20:16:41 +02:00
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-05-02 20:16:41 +02:00
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-02 20:16:41 +02:00
}, \
/* separator_chars */ \
{ \
2018-11-16 18:35:56 +01:00
"", "", "", "", \
"", "", \
2018-05-02 20:16:41 +02:00
}, \
}
2018-11-16 18:35:56 +01:00
#define DOUBLE_STYLE { \
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
"", "", "", "", \
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
"", "", "", "", \
}, \
/* separator_chars */ \
{ \
"", "", "", "", \
"", "", \
}, \
}
2018-05-02 20:16:41 +02:00
#define DOUBLE2_STYLE { \
2018-05-04 20:25:29 +02:00
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* separator_chars */ \
{ \
"", "", "", "", \
2018-11-15 21:14:18 +01:00
"", "", \
2018-05-04 20:25:29 +02:00
}, \
}
#define BOLD_STYLE { \
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* separator_chars */ \
{ \
"", "", "", "", \
2018-11-15 21:14:18 +01:00
"", "", \
2018-05-04 20:25:29 +02:00
}, \
}
#define BOLD2_STYLE { \
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* separator_chars */ \
{ \
"", "", "", "", \
2018-11-15 21:14:18 +01:00
"", "", \
2018-05-04 20:25:29 +02:00
}, \
}
#define FRAME_STYLE { \
/* border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "" \
2018-05-04 20:25:29 +02:00
}, \
/* header_border_chars */ \
{ \
"", "", "", "", \
"", "", "", \
"", "", "", "", \
"", "", "", "", \
2018-11-02 17:32:35 +01:00
"", "", "", "", \
2018-05-04 20:25:29 +02:00
}, \
/* separator_chars */ \
{ \
"", "", "", "", \
2018-11-15 21:14:18 +01:00
"", "", \
2018-05-04 20:25:29 +02:00
}, \
}
2018-03-12 21:02:59 +01:00
struct fort_border_style FORT_BASIC_STYLE = BASIC_STYLE;
2018-05-07 22:25:45 +02:00
struct fort_border_style FORT_BASIC2_STYLE = BASIC2_STYLE;
2018-03-12 21:02:59 +01:00
struct fort_border_style FORT_SIMPLE_STYLE = SIMPLE_STYLE;
2018-03-14 19:30:27 +01:00
struct fort_border_style FORT_PLAIN_STYLE = PLAIN_STYLE;
2018-03-12 21:02:59 +01:00
struct fort_border_style FORT_DOT_STYLE = DOT_STYLE;
2018-03-14 19:30:27 +01:00
struct fort_border_style FORT_EMPTY_STYLE = EMPTY_STYLE;
2018-05-02 20:16:41 +02:00
struct fort_border_style FORT_SOLID_STYLE = SOLID_STYLE;
2018-05-04 20:25:29 +02:00
struct fort_border_style FORT_SOLID_ROUND_STYLE = SOLID_ROUND_STYLE;
2018-11-16 18:35:56 +01:00
struct fort_border_style FORT_NICE_STYLE = NICE_STYLE;
2018-05-02 20:16:41 +02:00
struct fort_border_style FORT_DOUBLE_STYLE = DOUBLE_STYLE;
2018-05-04 20:25:29 +02:00
struct fort_border_style FORT_DOUBLE2_STYLE = DOUBLE2_STYLE;
struct fort_border_style FORT_BOLD_STYLE = BOLD_STYLE;
struct fort_border_style FORT_BOLD2_STYLE = BOLD2_STYLE;
struct fort_border_style FORT_FRAME_STYLE = FRAME_STYLE;
2018-02-04 14:21:04 +01:00
2018-03-12 21:02:59 +01:00
2018-11-03 21:50:30 +01:00
fort_entire_table_properties_t g_entire_table_properties = {
2018-03-25 10:11:08 +02:00
0, /* left_margin */
0, /* top_margin */
0, /* right_margin */
0, /* bottom_margin */
};
2018-11-03 21:50:30 +01:00
static fort_status_t set_entire_table_property_internal(fort_entire_table_properties_t *properties, uint32_t property, int value)
2018-03-25 10:11:08 +02:00
{
2018-11-03 21:50:30 +01:00
assert(properties);
2018-04-16 21:33:05 +02:00
CHECK_NOT_NEGATIVE(value);
2018-11-03 21:50:30 +01:00
if (PROP_IS_SET(property, FT_TPROP_LEFT_MARGIN)) {
properties->left_margin = value;
} else if (PROP_IS_SET(property, FT_TPROP_TOP_MARGIN)) {
properties->top_margin = value;
} else if (PROP_IS_SET(property, FT_TPROP_RIGHT_MARGIN)) {
properties->right_margin = value;
} else if (PROP_IS_SET(property, FT_TPROP_BOTTOM_MARGIN)) {
properties->bottom_margin = value;
2018-03-25 10:11:08 +02:00
} else {
return FT_EINVAL;
}
return FT_SUCCESS;
2018-04-16 21:33:05 +02:00
fort_fail:
return FT_EINVAL;
2018-03-25 10:11:08 +02:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_status_t set_entire_table_property(fort_table_properties_t *table_properties, uint32_t property, int value)
2018-03-25 10:11:08 +02:00
{
2018-11-03 21:50:30 +01:00
assert(table_properties);
return set_entire_table_property_internal(&table_properties->entire_table_properties, property, value);
2018-03-25 10:11:08 +02:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_status_t set_default_entire_table_property(uint32_t property, int value)
2018-03-25 10:11:08 +02:00
{
2018-11-03 21:50:30 +01:00
return set_entire_table_property_internal(&g_entire_table_properties, property, value);
2018-03-25 10:11:08 +02:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
size_t max_border_elem_strlen(struct fort_table_properties *properties)
2018-05-02 20:16:41 +02:00
{
2018-11-03 21:50:30 +01:00
assert(properties);
2018-05-02 20:16:41 +02:00
size_t result = 1;
int i = 0;
for (i = 0; i < BorderItemPosSize; ++i) {
2018-11-03 21:50:30 +01:00
result = MAX(result, strlen(properties->border_style.border_chars[i]));
2018-05-02 20:16:41 +02:00
}
i = 0;
for (i = 0; i < BorderItemPosSize; ++i) {
2018-11-03 21:50:30 +01:00
result = MAX(result, strlen(properties->border_style.header_border_chars[i]));
2018-05-02 20:16:41 +02:00
}
2018-03-25 10:11:08 +02:00
2018-05-02 20:16:41 +02:00
i = 0;
for (i = 0; i < SepratorItemPosSize; ++i) {
2018-11-03 21:50:30 +01:00
result = MAX(result, strlen(properties->border_style.separator_chars[i]));
2018-05-02 20:16:41 +02:00
}
return result;
}
2018-03-25 10:11:08 +02:00
2018-11-03 21:50:30 +01:00
fort_table_properties_t g_table_properties = {
2018-03-12 21:02:59 +01:00
/* border_style */
BASIC_STYLE,
2018-11-03 21:50:30 +01:00
NULL, /* cell_properties */
/* entire_table_properties */
2018-04-16 21:33:05 +02:00
{
0, /* left_margin */
0, /* top_margin */
0, /* right_margin */
0 /* bottom_margin */
}
2018-01-17 19:22:57 +01:00
};
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_table_properties_t *create_table_properties(void)
2018-01-17 19:22:57 +01:00
{
2018-11-03 21:50:30 +01:00
fort_table_properties_t *properties = (fort_table_properties_t *)F_CALLOC(sizeof(fort_table_properties_t), 1);
if (properties == NULL) {
2018-01-17 19:22:57 +01:00
return NULL;
}
2018-11-03 21:50:30 +01:00
memcpy(properties, &g_table_properties, sizeof(fort_table_properties_t));
properties->cell_properties = create_cell_prop_container();
if (properties->cell_properties == NULL) {
destroy_table_properties(properties);
return NULL;
2018-02-25 09:39:41 +01:00
}
2018-11-03 21:50:30 +01:00
memcpy(&properties->entire_table_properties, &g_entire_table_properties, sizeof(fort_entire_table_properties_t));
return properties;
2018-01-17 19:22:57 +01:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
void destroy_table_properties(fort_table_properties_t *properties)
2018-01-21 11:22:46 +01:00
{
2018-11-03 21:50:30 +01:00
if (properties == NULL)
2018-11-02 22:16:20 +01:00
return;
2018-01-21 11:22:46 +01:00
2018-11-03 21:50:30 +01:00
if (properties->cell_properties != NULL) {
destroy_cell_prop_container(properties->cell_properties);
2018-11-02 22:16:20 +01:00
}
2018-11-03 21:50:30 +01:00
F_FREE(properties);
2018-11-02 22:16:20 +01:00
}
2018-01-21 11:22:46 +01:00
2018-11-02 22:16:20 +01:00
static
2018-11-03 21:50:30 +01:00
fort_cell_prop_container_t *copy_cell_properties(fort_cell_prop_container_t *cont)
2018-11-02 22:16:20 +01:00
{
2018-11-03 21:50:30 +01:00
fort_cell_prop_container_t *result = create_cell_prop_container();
2018-11-02 22:16:20 +01:00
if (result == NULL)
return NULL;
2018-02-25 09:39:41 +01:00
2018-11-02 22:16:20 +01:00
size_t sz = vector_size(cont);
for (size_t i = 0; i < sz; ++i) {
2018-11-03 21:50:30 +01:00
fort_cell_props_t *opt = (fort_cell_props_t *)vector_at(cont, i);
2018-11-02 22:16:20 +01:00
if (FT_IS_ERROR(vector_push(result, opt))) {
2018-11-03 21:50:30 +01:00
destroy_cell_prop_container(result);
2018-11-02 22:16:20 +01:00
return NULL;
2018-02-25 09:39:41 +01:00
}
}
2018-11-02 22:16:20 +01:00
return result;
2018-01-21 11:22:46 +01:00
}
2018-09-01 14:45:34 +02:00
FT_INTERNAL
2018-11-03 21:50:30 +01:00
fort_table_properties_t *copy_table_properties(const fort_table_properties_t *properties)
2018-01-17 19:22:57 +01:00
{
2018-11-03 21:50:30 +01:00
fort_table_properties_t *new_opt = create_table_properties();
2018-11-02 22:16:20 +01:00
if (new_opt == NULL)
return NULL;
2018-11-03 21:50:30 +01:00
destroy_vector(new_opt->cell_properties);
new_opt->cell_properties = copy_cell_properties(properties->cell_properties);
2018-11-02 22:16:20 +01:00
if (new_opt == NULL) {
2018-11-03 21:50:30 +01:00
destroy_table_properties(new_opt);
2018-11-02 22:16:20 +01:00
return NULL;
2018-02-25 09:39:41 +01:00
}
2018-11-02 22:16:20 +01:00
2018-11-03 21:50:30 +01:00
memcpy(&new_opt->border_style, &properties->border_style, sizeof(struct fort_border_style));
memcpy(&new_opt->entire_table_properties,
&properties->entire_table_properties, sizeof(fort_entire_table_properties_t));
2018-11-02 22:16:20 +01:00
return new_opt;
2018-01-17 19:22:57 +01:00
}