2018-05-06 12:12:28 +02:00
|
|
|
#include <assert.h>
|
2018-01-17 19:22:57 +01:00
|
|
|
#include "options.h"
|
2018-05-06 15:36:53 +02:00
|
|
|
#include "fort_utils.h"
|
2018-01-17 19:22:57 +01:00
|
|
|
#include "vector.h"
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* COLUMN OPTIONS
|
|
|
|
* ***************************************************************************/
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
struct fort_cell_options g_default_cell_option = {
|
2018-02-26 18:25:11 +01:00
|
|
|
FT_ANY_ROW, /* cell_row */
|
|
|
|
FT_ANY_COLUMN, /* cell_col */
|
|
|
|
|
|
|
|
/* options */
|
2018-03-25 10:11:08 +02:00
|
|
|
FT_COPT_MIN_WIDTH | FT_COPT_TEXT_ALIGN | FT_COPT_TOP_PADDING
|
|
|
|
| FT_COPT_BOTTOM_PADDING | FT_COPT_LEFT_PADDING | FT_COPT_RIGHT_PADDING
|
2018-03-31 12:33:37 +02:00
|
|
|
| FT_COPT_EMPTY_STR_HEIGHT,
|
2018-02-26 18:25:11 +01:00
|
|
|
|
|
|
|
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-02-26 18:25:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static int get_option_value_if_exists_otherwise_default(const struct fort_cell_options *cell_opts, uint32_t option)
|
|
|
|
{
|
|
|
|
if (cell_opts == NULL || !OPTION_IS_SET(cell_opts->options, option)) {
|
|
|
|
cell_opts = &g_default_cell_option;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (option) {
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_MIN_WIDTH:
|
2018-02-26 18:25:11 +01:00
|
|
|
return cell_opts->col_min_width;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_TEXT_ALIGN:
|
2018-02-26 18:25:11 +01:00
|
|
|
return cell_opts->align;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_TOP_PADDING:
|
2018-02-27 18:41:57 +01:00
|
|
|
return cell_opts->cell_padding_top;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_BOTTOM_PADDING:
|
2018-02-27 18:41:57 +01:00
|
|
|
return cell_opts->cell_padding_bottom;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_LEFT_PADDING:
|
2018-02-27 18:41:57 +01:00
|
|
|
return cell_opts->cell_padding_left;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_RIGHT_PADDING:
|
2018-02-27 18:41:57 +01:00
|
|
|
return cell_opts->cell_padding_right;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_EMPTY_STR_HEIGHT:
|
2018-02-27 18:41:57 +01:00
|
|
|
return cell_opts->cell_empty_string_height;
|
2018-03-25 10:11:08 +02:00
|
|
|
case FT_COPT_ROW_TYPE:
|
2018-03-05 19:08:14 +01:00
|
|
|
return cell_opts->row_type;
|
2018-02-26 18:25:11 +01:00
|
|
|
default:
|
2018-03-09 10:44:16 +01:00
|
|
|
/* todo: implement later */
|
2018-02-26 18:25:11 +01:00
|
|
|
exit(333);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
fort_column_options_t g_column_options = {
|
2018-01-17 19:22:57 +01:00
|
|
|
0, /* col_min_width*/
|
2018-04-01 12:27:02 +02:00
|
|
|
FT_ALIGNED_RIGHT, /* align */
|
2018-01-17 19:22:57 +01:00
|
|
|
};
|
|
|
|
|
2018-03-17 19:53:38 +01:00
|
|
|
fort_column_options_t create_column_options(void)
|
2018-01-17 19:22:57 +01:00
|
|
|
{
|
|
|
|
fort_column_options_t result;
|
|
|
|
memset(&result, '\0', sizeof(result));
|
|
|
|
memcpy(&result, &g_column_options, sizeof(result));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-02-25 09:39:41 +01:00
|
|
|
|
2018-03-17 19:53:38 +01:00
|
|
|
//#define DEFAULT_CELL_OPTION {FT_ROW_UNSPEC, FT_COLUMN_UNSPEC, 0, 0, 0}
|
2018-02-25 09:39:41 +01:00
|
|
|
|
2018-03-17 19:53:38 +01:00
|
|
|
fort_cell_opt_container_t *create_cell_opt_container(void)
|
2018-02-25 09:39:41 +01:00
|
|
|
{
|
|
|
|
fort_cell_opt_container_t *ret = create_vector(sizeof(fort_cell_options_t), DEFAULT_VECTOR_CAPACITY);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void destroy_cell_opt_container(fort_cell_opt_container_t *cont)
|
|
|
|
{
|
|
|
|
if (cont)
|
|
|
|
destroy_vector(cont);
|
|
|
|
}
|
|
|
|
|
2018-04-17 19:14:50 +02:00
|
|
|
const fort_cell_options_t *cget_cell_opt(const fort_cell_opt_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-03-31 12:33:37 +02:00
|
|
|
const fort_cell_options_t *opt = (const fort_cell_options_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-04-17 19:14:50 +02:00
|
|
|
fort_cell_options_t *get_cell_opt_and_create_if_not_exists(fort_cell_opt_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-03-31 12:33:37 +02:00
|
|
|
fort_cell_options_t *opt = (fort_cell_options_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-03-17 19:53:38 +01:00
|
|
|
fort_cell_options_t opt = g_default_cell_option;// DEFAULT_CELL_OPTION;
|
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-03-31 12:33:37 +02:00
|
|
|
return (fort_cell_options_t *)vector_at(cont, sz);
|
2018-02-25 09:39:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-26 18:25:11 +01:00
|
|
|
int get_cell_opt_value_hierarcial(const fort_table_options_t *options, size_t row, size_t column, uint32_t option)
|
|
|
|
{
|
|
|
|
assert(options);
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
const fort_cell_options_t *opt = NULL;
|
2018-02-26 18:25:11 +01:00
|
|
|
if (options->cell_options != NULL) {
|
|
|
|
while (1) {
|
|
|
|
opt = cget_cell_opt(options->cell_options, row, column);
|
|
|
|
if (opt != NULL)
|
|
|
|
break;
|
|
|
|
if (row != FT_ANY_ROW) {
|
|
|
|
row = FT_ANY_ROW;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (column != FT_ANY_COLUMN) {
|
|
|
|
column = FT_ANY_COLUMN;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return get_option_value_if_exists_otherwise_default(opt, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-27 18:41:57 +01:00
|
|
|
static fort_status_t set_cell_option_impl(fort_cell_options_t *opt, uint32_t option, int value)
|
|
|
|
{
|
|
|
|
assert(opt);
|
|
|
|
|
|
|
|
OPTION_SET(opt->options, option);
|
2018-03-25 10:11:08 +02:00
|
|
|
if (OPTION_IS_SET(option, FT_COPT_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-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_TEXT_ALIGN)) {
|
2018-04-01 12:27:02 +02:00
|
|
|
opt->align = (enum ft_text_alignment)value;
|
2018-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_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-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_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-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_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-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_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-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_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-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_ROW_TYPE)) {
|
2018-04-01 12:27:02 +02:00
|
|
|
opt->row_type = (enum ft_row_type)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-04-17 19:14:50 +02:00
|
|
|
fort_status_t set_cell_option(fort_cell_opt_container_t *cont, size_t row, size_t col, uint32_t option, int value)
|
2018-02-27 18:41:57 +01:00
|
|
|
{
|
2018-03-31 12:33:37 +02:00
|
|
|
fort_cell_options_t *opt = get_cell_opt_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
|
|
|
|
|
|
|
return set_cell_option_impl(opt, option, value);
|
2018-03-09 10:44:16 +01:00
|
|
|
/*
|
|
|
|
OPTION_SET(opt->options, option);
|
2018-03-25 10:11:08 +02:00
|
|
|
if (OPTION_IS_SET(option, FT_COPT_MIN_WIDTH)) {
|
2018-03-09 10:44:16 +01:00
|
|
|
opt->col_min_width = value;
|
2018-03-25 10:11:08 +02:00
|
|
|
} else if (OPTION_IS_SET(option, FT_COPT_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
|
|
|
}
|
|
|
|
|
|
|
|
fort_status_t set_default_cell_option(uint32_t option, int value)
|
|
|
|
{
|
|
|
|
return set_cell_option_impl(&g_default_cell_option, option, value);
|
|
|
|
}
|
|
|
|
|
2018-01-17 19:22:57 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* OPTIONS
|
|
|
|
* ***************************************************************************/
|
|
|
|
|
|
|
|
|
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-03-12 21:02:59 +01:00
|
|
|
}, \
|
|
|
|
}
|
2018-01-17 19:22:57 +01:00
|
|
|
|
2018-05-07 22:25:45 +02:00
|
|
|
#define BASIC2_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"+", "-", "+", "+", \
|
|
|
|
"|", "|", "|", \
|
|
|
|
"+", "-", "+", "+", \
|
|
|
|
"+", "-", "+", "+" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"+", "-", "+", "+", \
|
|
|
|
"|", "|", "|", \
|
|
|
|
"+", "-", "+", "+", \
|
|
|
|
"+", "-", "+", "+" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"+", "-", "+", "+", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
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-03-12 21:02:59 +01:00
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
2018-05-02 20:16:41 +02: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-03-14 19:30:27 +01:00
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
2018-05-02 20:16:41 +02: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-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-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-03-12 21:02:59 +01:00
|
|
|
}, \
|
|
|
|
}
|
2018-01-21 18:02:43 +01:00
|
|
|
|
2018-05-02 20:16:41 +02:00
|
|
|
|
2018-05-04 20:25:29 +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-05-04 20:25:29 +02:00
|
|
|
"└", "─", "┴", "╯" \
|
2018-05-02 20:16:41 +02:00
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
2018-05-04 20:25:29 +02:00
|
|
|
"┌", "─", "┬", "┐", \
|
|
|
|
"│", "│", "│", \
|
|
|
|
"├", "─", "┼", "┤", \
|
|
|
|
"└", "─", "┴", "┘" \
|
2018-05-02 20:16:41 +02:00
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
2018-05-04 20:25:29 +02:00
|
|
|
"├", "─", "┼", "┤", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SOLID_ROUND_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"╭", "─", "┬", "╮", \
|
|
|
|
"│", "│", "│", \
|
|
|
|
"", "", "", "", \
|
|
|
|
"╰", "─", "┴", "╯" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"╭", "─", "┬", "╮", \
|
|
|
|
"│", "│", "│", \
|
|
|
|
"├", "─", "┼", "┤", \
|
|
|
|
"╰", "─", "┴", "╯" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"├", "─", "┼", "┤", \
|
2018-05-02 20:16:41 +02:00
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
2018-05-04 20:25:29 +02:00
|
|
|
|
2018-05-02 20:16:41 +02:00
|
|
|
#define DOUBLE_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"╔", "═", "╦", "╗", \
|
|
|
|
"║", "║", "║", \
|
|
|
|
"", "", "", "", \
|
|
|
|
"╚", "═", "╩", "╝" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"╔", "═", "╦", "╗", \
|
|
|
|
"║", "║", "║", \
|
|
|
|
"╠", "═", "╬", "╣", \
|
|
|
|
"╚", "═", "╩", "╝" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"╠", "═", "╬", "╣", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-04 20:25:29 +02:00
|
|
|
#define DOUBLE2_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"╔", "═", "╤", "╗", \
|
|
|
|
"║", "│", "║", \
|
|
|
|
"╟", "─", "┼", "╢", \
|
|
|
|
"╚", "═", "╧", "╝" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"╔", "═", "╤", "╗", \
|
|
|
|
"║", "│", "║", \
|
|
|
|
"╠", "═", "╪", "╣", \
|
|
|
|
"╚", "═", "╧", "╝" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"╠", "═", "╪", "╣", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#define BOLD_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"┏", "━", "┳", "┓", \
|
|
|
|
"┃", "┃", "┃", \
|
|
|
|
"", "", "", "", \
|
|
|
|
"┗", "━", "┻", "┛" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"┏", "━", "┳", "┓", \
|
|
|
|
"┃", "┃", "┃", \
|
|
|
|
"┣", "━", "╋", "┫", \
|
|
|
|
"┗", "━", "┻", "┛" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"┣", "━", "╋", "┫", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BOLD2_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"┏", "━", "┯", "┓", \
|
|
|
|
"┃", "│", "┃", \
|
|
|
|
"┠", "─", "┼", "┨", \
|
|
|
|
"┗", "━", "┷", "┛" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"┏", "━", "┯", "┓", \
|
|
|
|
"┃", "│", "┃", \
|
|
|
|
"┣", "━", "┿", "┫", \
|
|
|
|
"┗", "━", "┷", "┛" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"┣", "━", "┿", "┫", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define FRAME_STYLE { \
|
|
|
|
/* border_chars */ \
|
|
|
|
{ \
|
|
|
|
"▛", "▀", "▀", "▜", \
|
|
|
|
"▌", "┃", "▐", \
|
|
|
|
"", "", "", "", \
|
|
|
|
"▙", "▄", "▄", "▟" \
|
|
|
|
}, \
|
|
|
|
/* header_border_chars */ \
|
|
|
|
{ \
|
|
|
|
"▛", "▀", "▀", "▜", \
|
|
|
|
"▌", "┃", "▐", \
|
|
|
|
"▌", "━", "╋", "▐", \
|
|
|
|
"▙", "▄", "▄", "▟" \
|
|
|
|
}, \
|
|
|
|
/* separator_chars */ \
|
|
|
|
{ \
|
|
|
|
"▌", "━", "╋", "▐", \
|
|
|
|
}, \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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-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-03-25 10:11:08 +02:00
|
|
|
fort_entire_table_options_t g_entire_table_options = {
|
|
|
|
0, /* left_margin */
|
|
|
|
0, /* top_margin */
|
|
|
|
0, /* right_margin */
|
|
|
|
0, /* bottom_margin */
|
|
|
|
};
|
|
|
|
|
|
|
|
static fort_status_t set_entire_table_option_internal(fort_entire_table_options_t *options, uint32_t option, int value)
|
|
|
|
{
|
|
|
|
assert(options);
|
2018-04-16 21:33:05 +02:00
|
|
|
CHECK_NOT_NEGATIVE(value);
|
2018-03-25 10:11:08 +02:00
|
|
|
if (OPTION_IS_SET(option, FT_TOPT_LEFT_MARGIN)) {
|
|
|
|
options->left_margin = value;
|
|
|
|
} else if (OPTION_IS_SET(option, FT_TOPT_TOP_MARGIN)) {
|
|
|
|
options->top_margin = value;
|
|
|
|
} else if (OPTION_IS_SET(option, FT_TOPT_RIGHT_MARGIN)) {
|
|
|
|
options->right_margin = value;
|
|
|
|
} else if (OPTION_IS_SET(option, FT_TOPT_BOTTOM_MARGIN)) {
|
|
|
|
options->bottom_margin = value;
|
|
|
|
} 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
|
|
|
}
|
|
|
|
|
|
|
|
fort_status_t set_entire_table_option(fort_table_options_t *table_options, uint32_t option, int value)
|
|
|
|
{
|
|
|
|
assert(table_options);
|
|
|
|
return set_entire_table_option_internal(&table_options->entire_table_options, option, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
fort_status_t set_default_entire_table_option(uint32_t option, int value)
|
|
|
|
{
|
|
|
|
return set_entire_table_option_internal(&g_entire_table_options, option, value);
|
|
|
|
}
|
|
|
|
|
2018-05-02 20:16:41 +02:00
|
|
|
size_t max_border_elem_strlen(struct fort_table_options *options)
|
|
|
|
{
|
|
|
|
assert(options);
|
|
|
|
size_t result = 1;
|
|
|
|
int i = 0;
|
|
|
|
for (i = 0; i < BorderItemPosSize; ++i) {
|
|
|
|
result = MAX(result, strlen(options->border_style.border_chars[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (i = 0; i < BorderItemPosSize; ++i) {
|
|
|
|
result = MAX(result, strlen(options->border_style.header_border_chars[i]));
|
|
|
|
}
|
2018-03-25 10:11:08 +02:00
|
|
|
|
2018-05-02 20:16:41 +02:00
|
|
|
i = 0;
|
|
|
|
for (i = 0; i < SepratorItemPosSize; ++i) {
|
|
|
|
result = MAX(result, strlen(options->border_style.separator_chars[i]));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2018-03-25 10:11:08 +02:00
|
|
|
|
|
|
|
|
2018-03-12 21:02:59 +01:00
|
|
|
fort_table_options_t g_table_options = {
|
|
|
|
/* border_style */
|
|
|
|
BASIC_STYLE,
|
2018-02-25 09:39:41 +01:00
|
|
|
NULL, /* cell_options */
|
2018-04-16 21:33:05 +02:00
|
|
|
/* entire_table_options */
|
|
|
|
{
|
|
|
|
0, /* left_margin */
|
|
|
|
0, /* top_margin */
|
|
|
|
0, /* right_margin */
|
|
|
|
0 /* bottom_margin */
|
|
|
|
}
|
2018-01-17 19:22:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-04-16 20:15:44 +02:00
|
|
|
fort_table_options_t *create_table_options(void)
|
2018-01-17 19:22:57 +01:00
|
|
|
{
|
2018-03-31 12:33:37 +02:00
|
|
|
fort_table_options_t *options = (fort_table_options_t *)F_CALLOC(sizeof(fort_table_options_t), 1);
|
2018-01-17 19:22:57 +01:00
|
|
|
if (options == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(options, &g_table_options, sizeof(fort_table_options_t));
|
2018-02-25 09:39:41 +01:00
|
|
|
options->cell_options = create_cell_opt_container();
|
|
|
|
if (options->cell_options == NULL) {
|
|
|
|
destroy_table_options(options);
|
2018-04-04 21:13:37 +02:00
|
|
|
return NULL;
|
2018-02-25 09:39:41 +01:00
|
|
|
}
|
2018-03-25 10:11:08 +02:00
|
|
|
memcpy(&options->entire_table_options, &g_entire_table_options, sizeof(fort_entire_table_options_t));
|
2018-01-17 19:22:57 +01:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
fort_table_options_t *copy_table_options(const fort_table_options_t *option)
|
2018-01-21 11:22:46 +01:00
|
|
|
{
|
|
|
|
/* todo: normal implementation, do deep copy of col options */
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
fort_table_options_t *new_opt = create_table_options();
|
2018-01-21 11:22:46 +01:00
|
|
|
if (new_opt == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(new_opt, option, sizeof(fort_table_options_t));
|
2018-02-25 09:39:41 +01:00
|
|
|
|
|
|
|
if (option->cell_options) {
|
|
|
|
destroy_cell_opt_container(new_opt->cell_options);
|
|
|
|
new_opt->cell_options = copy_vector(option->cell_options);
|
|
|
|
if (new_opt->cell_options == NULL) {
|
|
|
|
destroy_table_options(new_opt);
|
|
|
|
new_opt = NULL;
|
|
|
|
}
|
|
|
|
}
|
2018-01-21 11:22:46 +01:00
|
|
|
return new_opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-31 12:33:37 +02:00
|
|
|
void destroy_table_options(fort_table_options_t *options)
|
2018-01-17 19:22:57 +01:00
|
|
|
{
|
|
|
|
if (options == NULL)
|
|
|
|
return;
|
|
|
|
|
2018-02-25 09:39:41 +01:00
|
|
|
if (options->cell_options != NULL) {
|
|
|
|
destroy_cell_opt_container(options->cell_options);
|
|
|
|
}
|
2018-01-17 19:22:57 +01:00
|
|
|
F_FREE(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-02-26 18:25:11 +01:00
|
|
|
|