[A] Added top and bottom margin
This commit is contained in:
parent
8fd57267e9
commit
52c100bdf9
@ -6,10 +6,10 @@
|
||||
static FTABLE *create_basic_table()
|
||||
{
|
||||
FTABLE *table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
FT_NWRITE_LN(table, "Rank", "Title", "Year", "Rating");
|
||||
|
||||
FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||
@ -26,10 +26,10 @@ int main()
|
||||
FTABLE *table = NULL;
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362);
|
||||
|
||||
ft_printf_ln(table, "%d|%s|%5.2f km/s", 1, "Mercury", 47.362);
|
||||
@ -43,10 +43,10 @@ int main()
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
ft_printf_ln(table, "Rank|Title|Year|Rating");
|
||||
|
||||
FT_NWRITE_LN(table, "1", "The Shawshank Redemption", "1994", "9.5");
|
||||
@ -62,10 +62,10 @@ int main()
|
||||
/*-------------------------------------------------------------*/
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
ft_printf_ln(table, "Commodity|Farm price|Avg. spread");
|
||||
|
||||
const char *row1[] = {"Potatoes", "$1.60", "200.94%"};
|
||||
@ -80,10 +80,10 @@ int main()
|
||||
/*-------------------------------------------------------------*/
|
||||
#if !defined(__cplusplus) && !defined(FT_MICROSOFT_COMPILER)
|
||||
table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
ft_printf_ln(table, "No.|Name|Avg. Mark");
|
||||
const char *ctab[2][3] = {
|
||||
{"1", "Joe Public", "3.14"},
|
||||
@ -100,10 +100,10 @@ int main()
|
||||
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
ft_printf_ln(table, "No.|Name|Avg. Mark");
|
||||
const char **tab[2] = {
|
||||
row1,
|
||||
@ -148,10 +148,10 @@ int main()
|
||||
setlocale(LC_CTYPE, "");
|
||||
|
||||
table = ft_create_table();
|
||||
ft_set_option(table, FT_ANY_ROW, 0, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 0, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
FT_NWWRITE_LN(table, L"Ранг", L"Название", L"Год", L"Рейтинг");
|
||||
|
||||
FT_NWWRITE_LN(table, L"1", L"Побег из Шоушенка", L"1994", L"9.5");
|
||||
|
@ -280,14 +280,25 @@ FT_EXTERN const char* ft_to_string(const FTABLE *FT_RESTRICT table);
|
||||
#define FT_ROW_UNSPEC (UINT_MAX-1)
|
||||
#define FT_COLUMN_UNSPEC (UINT_MAX-1)
|
||||
|
||||
#define FT_OPT_MIN_WIDTH ((uint32_t)(0x01U << (0)))
|
||||
#define FT_OPT_TEXT_ALIGN ((uint32_t)(0x01U << (1)))
|
||||
#define FT_OPT_TOP_PADDING ((uint32_t)(0x01U << (2)))
|
||||
#define FT_OPT_BOTTOM_PADDING ((uint32_t)(0x01U << (3)))
|
||||
#define FT_OPT_LEFT_PADDING ((uint32_t)(0x01U << (4)))
|
||||
#define FT_OPT_RIGHT_PADDING ((uint32_t)(0x01U << (5)))
|
||||
#define FT_OPT_EMPTY_STR_HEIGHT ((uint32_t)(0x01U << (6)))
|
||||
#define FT_OPT_ROW_TYPE ((uint32_t)(0x01U << (7)))
|
||||
/*
|
||||
* Cell options
|
||||
*/
|
||||
#define FT_COPT_MIN_WIDTH ((uint32_t)(0x01U << (0)))
|
||||
#define FT_COPT_TEXT_ALIGN ((uint32_t)(0x01U << (1)))
|
||||
#define FT_COPT_TOP_PADDING ((uint32_t)(0x01U << (2)))
|
||||
#define FT_COPT_BOTTOM_PADDING ((uint32_t)(0x01U << (3)))
|
||||
#define FT_COPT_LEFT_PADDING ((uint32_t)(0x01U << (4)))
|
||||
#define FT_COPT_RIGHT_PADDING ((uint32_t)(0x01U << (5)))
|
||||
#define FT_COPT_EMPTY_STR_HEIGHT ((uint32_t)(0x01U << (6)))
|
||||
#define FT_COPT_ROW_TYPE ((uint32_t)(0x01U << (7)))
|
||||
|
||||
/*
|
||||
* Table options
|
||||
*/
|
||||
#define FT_TOPT_LEFT_MARGIN ((uint32_t)(0x01U << (0)))
|
||||
#define FT_TOPT_TOP_MARGIN ((uint32_t)(0x01U << (1)))
|
||||
#define FT_TOPT_RIGHT_MARGIN ((uint32_t)(0x01U << (2)))
|
||||
#define FT_TOPT_BOTTOM_MARGIN ((uint32_t)(0x01U << (3)))
|
||||
|
||||
enum TextAlignment
|
||||
{
|
||||
@ -330,8 +341,11 @@ extern struct ft_border_style * FT_EMPTY_STYLE;
|
||||
FT_EXTERN int ft_set_default_border_style(struct ft_border_style *style);
|
||||
FT_EXTERN int ft_set_border_style(FTABLE * FT_RESTRICT table, struct ft_border_style *style);
|
||||
|
||||
FT_EXTERN int ft_set_default_option(uint32_t option, int value);
|
||||
FT_EXTERN int ft_set_option(FTABLE * FT_RESTRICT table, unsigned row, unsigned col, uint32_t option, int value);
|
||||
FT_EXTERN int ft_set_default_cell_option(uint32_t option, int value);
|
||||
FT_EXTERN int ft_set_cell_option(FTABLE * FT_RESTRICT table, unsigned row, unsigned col, uint32_t option, int value);
|
||||
|
||||
FT_EXTERN int ft_set_default_tbl_option(uint32_t option, int value);
|
||||
FT_EXTERN int ft_set_tbl_option(FTABLE * FT_RESTRICT table, uint32_t option, int value);
|
||||
|
||||
|
||||
|
||||
|
24
src/cell.c
24
src/cell.c
@ -47,13 +47,13 @@ int hint_width_cell(const fort_cell_t *cell, const context_t *context)
|
||||
|
||||
assert(cell);
|
||||
assert(context);
|
||||
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_LEFT_PADDING);
|
||||
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_RIGHT_PADDING);
|
||||
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
|
||||
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
|
||||
int result = cell_padding_left + cell_padding_right;
|
||||
if (cell->str_buffer && cell->str_buffer->str.data) {
|
||||
result += buffer_text_width(cell->str_buffer);
|
||||
}
|
||||
result = MAX(result, get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_MIN_WIDTH));
|
||||
result = MAX(result, get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_MIN_WIDTH));
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -61,9 +61,9 @@ int hint_height_cell(const fort_cell_t *cell, const context_t *context)
|
||||
{
|
||||
assert(cell);
|
||||
assert(context);
|
||||
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TOP_PADDING);
|
||||
int cell_padding_bottom = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_BOTTOM_PADDING);
|
||||
int cell_empty_string_height = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_EMPTY_STR_HEIGHT);
|
||||
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
|
||||
int cell_padding_bottom = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_BOTTOM_PADDING);
|
||||
int cell_empty_string_height = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_EMPTY_STR_HEIGHT);
|
||||
int result = cell_padding_top + cell_padding_bottom;
|
||||
if (cell->str_buffer && cell->str_buffer->str.data) {
|
||||
size_t text_height = buffer_text_height(cell->str_buffer);
|
||||
@ -107,9 +107,9 @@ int cell_printf(fort_cell_t *cell, size_t row, size_t column, char *buf, size_t
|
||||
return -1;
|
||||
}
|
||||
|
||||
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TOP_PADDING);
|
||||
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_LEFT_PADDING);
|
||||
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_RIGHT_PADDING);
|
||||
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
|
||||
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
|
||||
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
|
||||
|
||||
if (row >= hint_height_cell(cell, context)
|
||||
|| row < cell_padding_top
|
||||
@ -145,9 +145,9 @@ int cell_wprintf(fort_cell_t *cell, size_t row, size_t column, wchar_t *buf, siz
|
||||
return -1;
|
||||
}
|
||||
|
||||
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TOP_PADDING);
|
||||
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_LEFT_PADDING);
|
||||
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_RIGHT_PADDING);
|
||||
int cell_padding_top = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TOP_PADDING);
|
||||
int cell_padding_left = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_LEFT_PADDING);
|
||||
int cell_padding_right = get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_RIGHT_PADDING);
|
||||
|
||||
if (row >= hint_height_cell(cell, context)
|
||||
|| row < cell_padding_top
|
||||
|
56
src/fort.c
56
src/fort.c
@ -441,6 +441,8 @@ const char* ft_to_string(const FTABLE *FT_RESTRICT table)
|
||||
typedef char char_type;
|
||||
const char_type *empty_string = "";
|
||||
const enum str_buf_type buf_type = CharBuf;
|
||||
char space_char = ' ';
|
||||
char new_line_char = '\n';
|
||||
#define cur_F_STRDUP F_STRDUP
|
||||
int (*snprintf_row_)(const fort_row_t *, char *, size_t, size_t *, size_t, size_t, const context_t *) = snprintf_row;
|
||||
int (*print_row_separator_)(char *, size_t ,
|
||||
@ -448,6 +450,7 @@ const char* ft_to_string(const FTABLE *FT_RESTRICT table)
|
||||
const fort_row_t *, const fort_row_t *,
|
||||
enum HorSeparatorPos , const separator_t *,
|
||||
const context_t *) = print_row_separator;
|
||||
int (*snprint_n_chars_)(char *, size_t , size_t , char) = snprint_n_chars;
|
||||
assert(table);
|
||||
|
||||
/* Determing size of table string representation */
|
||||
@ -487,13 +490,20 @@ const char* ft_to_string(const FTABLE *FT_RESTRICT table)
|
||||
|
||||
int dev = 0;
|
||||
int k = 0;
|
||||
size_t i = 0;
|
||||
context_t context;
|
||||
context.table_options = (table->options ? table->options : &g_table_options);
|
||||
fort_row_t *prev_row = NULL;
|
||||
fort_row_t *cur_row = NULL;
|
||||
separator_t *cur_sep = NULL;
|
||||
size_t sep_size = vector_size(table->separators);
|
||||
size_t i = 0;
|
||||
|
||||
/* Print top margin */
|
||||
for (i = 0; i < context.table_options->entire_table_options.top_margin; ++i) {
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
||||
}
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
||||
cur_row = *(fort_row_t**)vector_at(table->rows, i);
|
||||
@ -507,6 +517,12 @@ const char* ft_to_string(const FTABLE *FT_RESTRICT table)
|
||||
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
||||
CHECK_RESULT_AND_MOVE_DEV(print_row_separator_(buffer + dev, sz - dev, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context));
|
||||
|
||||
/* Print bottom margin */
|
||||
for (i = 0; i < context.table_options->entire_table_options.bottom_margin; ++i) {
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
||||
}
|
||||
|
||||
|
||||
F_FREE(col_width_arr);
|
||||
F_FREE(row_height_arr);
|
||||
@ -535,6 +551,8 @@ const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table)
|
||||
typedef wchar_t char_type;
|
||||
const char_type *empty_string = L"";
|
||||
const enum str_buf_type buf_type = WCharBuf;
|
||||
wchar_t space_char = L' ';
|
||||
wchar_t new_line_char = L'\n';
|
||||
#define cur_F_STRDUP F_WCSDUP
|
||||
int (*snprintf_row_)(const fort_row_t *, wchar_t *, size_t, size_t *, size_t, size_t, const context_t *) = wsnprintf_row;
|
||||
int (*print_row_separator_)(wchar_t *, size_t ,
|
||||
@ -542,6 +560,8 @@ const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table)
|
||||
const fort_row_t *, const fort_row_t *,
|
||||
enum HorSeparatorPos , const separator_t *,
|
||||
const context_t *) = wprint_row_separator;
|
||||
int (*snprint_n_chars_)(wchar_t *, size_t , size_t , wchar_t) = wsnprint_n_chars;
|
||||
|
||||
assert(table);
|
||||
|
||||
/* Determing size of table string representation */
|
||||
@ -581,13 +601,20 @@ const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table)
|
||||
|
||||
int dev = 0;
|
||||
int k = 0;
|
||||
size_t i = 0;
|
||||
context_t context;
|
||||
context.table_options = (table->options ? table->options : &g_table_options);
|
||||
fort_row_t *prev_row = NULL;
|
||||
fort_row_t *cur_row = NULL;
|
||||
separator_t *cur_sep = NULL;
|
||||
size_t sep_size = vector_size(table->separators);
|
||||
size_t i = 0;
|
||||
|
||||
/* Print top margin */
|
||||
for (i = 0; i < context.table_options->entire_table_options.top_margin; ++i) {
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
||||
}
|
||||
|
||||
for (i = 0; i < rows; ++i) {
|
||||
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
||||
cur_row = *(fort_row_t**)vector_at(table->rows, i);
|
||||
@ -601,6 +628,11 @@ const wchar_t* ft_to_wstring(const FTABLE *FT_RESTRICT table)
|
||||
cur_sep = (i < sep_size) ? (*(separator_t **)vector_at(table->separators, i)) : NULL;
|
||||
CHECK_RESULT_AND_MOVE_DEV(print_row_separator_(buffer + dev, sz - dev, col_width_arr, cols, prev_row, cur_row, BottomSeparator, cur_sep, &context));
|
||||
|
||||
/* Print bottom margin */
|
||||
for (i = 0; i < context.table_options->entire_table_options.bottom_margin; ++i) {
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, width - 1/* minus new_line*/, space_char));
|
||||
CHECK_RESULT_AND_MOVE_DEV(snprint_n_chars_(buffer + dev, sz - dev, 1, new_line_char));
|
||||
}
|
||||
|
||||
F_FREE(col_width_arr);
|
||||
F_FREE(row_height_arr);
|
||||
@ -770,7 +802,7 @@ int ft_set_border_style(FTABLE *table, struct ft_border_style *style)
|
||||
|
||||
|
||||
|
||||
int ft_set_option(FTABLE *table, unsigned row, unsigned col, uint32_t option, int value)
|
||||
int ft_set_cell_option(FTABLE *table, unsigned row, unsigned col, uint32_t option, int value)
|
||||
{
|
||||
assert(table);
|
||||
|
||||
@ -788,9 +820,25 @@ int ft_set_option(FTABLE *table, unsigned row, unsigned col, uint32_t option, in
|
||||
return set_cell_option(table->options->cell_options, row, col, option, value);
|
||||
}
|
||||
|
||||
int ft_set_default_option(uint32_t option, int value)
|
||||
int ft_set_default_cell_option(uint32_t option, int value)
|
||||
{
|
||||
return set_default_cell_option(option, value);
|
||||
}
|
||||
|
||||
|
||||
FT_EXTERN int ft_set_default_tbl_option(uint32_t option, int value)
|
||||
{
|
||||
return set_default_entire_table_option(option, value);
|
||||
}
|
||||
|
||||
FT_EXTERN int ft_set_tbl_option(FTABLE * FT_RESTRICT table, uint32_t option, int value)
|
||||
{
|
||||
assert(table);
|
||||
|
||||
if (table->options == NULL) {
|
||||
table->options = create_table_options();
|
||||
if (table->options == NULL)
|
||||
return FT_MEMORY_ERROR;
|
||||
}
|
||||
return set_entire_table_option(table->options, option, value);
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ typedef int fort_status_t;
|
||||
#define FT_SUCCESS 0
|
||||
#define FT_MEMORY_ERROR -1
|
||||
#define FT_ERROR -2
|
||||
#define FT_EINVAL -3
|
||||
#define IS_SUCCESS(arg) ((arg) >= 0)
|
||||
#define IS_ERROR(arg) ((arg) < 0)
|
||||
|
||||
|
@ -13,9 +13,9 @@ struct fort_cell_options g_default_cell_option =
|
||||
FT_ANY_COLUMN, /* cell_col */
|
||||
|
||||
/* options */
|
||||
FT_OPT_MIN_WIDTH | FT_OPT_TEXT_ALIGN | FT_OPT_TOP_PADDING
|
||||
| FT_OPT_BOTTOM_PADDING | FT_OPT_LEFT_PADDING | FT_OPT_RIGHT_PADDING
|
||||
| FT_OPT_EMPTY_STR_HEIGHT ,
|
||||
FT_COPT_MIN_WIDTH | FT_COPT_TEXT_ALIGN | FT_COPT_TOP_PADDING
|
||||
| FT_COPT_BOTTOM_PADDING | FT_COPT_LEFT_PADDING | FT_COPT_RIGHT_PADDING
|
||||
| FT_COPT_EMPTY_STR_HEIGHT ,
|
||||
|
||||
0, /* col_min_width */
|
||||
RightAligned, /* align */
|
||||
@ -35,21 +35,21 @@ static int get_option_value_if_exists_otherwise_default(const struct fort_cell_o
|
||||
}
|
||||
|
||||
switch (option) {
|
||||
case FT_OPT_MIN_WIDTH:
|
||||
case FT_COPT_MIN_WIDTH:
|
||||
return cell_opts->col_min_width;
|
||||
case FT_OPT_TEXT_ALIGN:
|
||||
case FT_COPT_TEXT_ALIGN:
|
||||
return cell_opts->align;
|
||||
case FT_OPT_TOP_PADDING:
|
||||
case FT_COPT_TOP_PADDING:
|
||||
return cell_opts->cell_padding_top;
|
||||
case FT_OPT_BOTTOM_PADDING:
|
||||
case FT_COPT_BOTTOM_PADDING:
|
||||
return cell_opts->cell_padding_bottom;
|
||||
case FT_OPT_LEFT_PADDING:
|
||||
case FT_COPT_LEFT_PADDING:
|
||||
return cell_opts->cell_padding_left;
|
||||
case FT_OPT_RIGHT_PADDING:
|
||||
case FT_COPT_RIGHT_PADDING:
|
||||
return cell_opts->cell_padding_right;
|
||||
case FT_OPT_EMPTY_STR_HEIGHT:
|
||||
case FT_COPT_EMPTY_STR_HEIGHT:
|
||||
return cell_opts->cell_empty_string_height;
|
||||
case FT_OPT_ROW_TYPE:
|
||||
case FT_COPT_ROW_TYPE:
|
||||
return cell_opts->row_type;
|
||||
default:
|
||||
/* todo: implement later */
|
||||
@ -157,21 +157,21 @@ static fort_status_t set_cell_option_impl(fort_cell_options_t *opt, uint32_t opt
|
||||
assert(opt);
|
||||
|
||||
OPTION_SET(opt->options, option);
|
||||
if (OPTION_IS_SET(option, FT_OPT_MIN_WIDTH)) {
|
||||
if (OPTION_IS_SET(option, FT_COPT_MIN_WIDTH)) {
|
||||
opt->col_min_width = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_TEXT_ALIGN)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_TEXT_ALIGN)) {
|
||||
opt->align = (enum TextAlignment)value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_TOP_PADDING)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_TOP_PADDING)) {
|
||||
opt->cell_padding_top = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_BOTTOM_PADDING)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_BOTTOM_PADDING)) {
|
||||
opt->cell_padding_bottom = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_LEFT_PADDING)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_LEFT_PADDING)) {
|
||||
opt->cell_padding_left = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_RIGHT_PADDING)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_RIGHT_PADDING)) {
|
||||
opt->cell_padding_right = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_EMPTY_STR_HEIGHT)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_EMPTY_STR_HEIGHT)) {
|
||||
opt->cell_empty_string_height = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_ROW_TYPE)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_ROW_TYPE)) {
|
||||
opt->row_type = (enum RowType)value;
|
||||
}
|
||||
|
||||
@ -188,9 +188,9 @@ fort_status_t set_cell_option(fort_cell_opt_container_t *cont, unsigned row, uns
|
||||
return set_cell_option_impl(opt, option, value);
|
||||
/*
|
||||
OPTION_SET(opt->options, option);
|
||||
if (OPTION_IS_SET(option, FT_OPT_MIN_WIDTH)) {
|
||||
if (OPTION_IS_SET(option, FT_COPT_MIN_WIDTH)) {
|
||||
opt->col_min_width = value;
|
||||
} else if (OPTION_IS_SET(option, FT_OPT_TEXT_ALIGN)) {
|
||||
} else if (OPTION_IS_SET(option, FT_COPT_TEXT_ALIGN)) {
|
||||
opt->align = value;
|
||||
}
|
||||
|
||||
@ -321,6 +321,44 @@ struct fort_border_style FORT_EMPTY_STYLE = EMPTY_STYLE;
|
||||
|
||||
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
fort_table_options_t g_table_options = {
|
||||
/* border_style */
|
||||
BASIC_STYLE,
|
||||
@ -340,7 +378,7 @@ fort_table_options_t* create_table_options()
|
||||
destroy_table_options(options);
|
||||
options = NULL;
|
||||
}
|
||||
|
||||
memcpy(&options->entire_table_options, &g_entire_table_options, sizeof(fort_entire_table_options_t));
|
||||
return options;
|
||||
}
|
||||
|
||||
|
@ -40,14 +40,14 @@ typedef struct vector vector_t;
|
||||
#define FT_ROW_UNSPEC (UINT_MAX-1)
|
||||
#define FT_COLUMN_UNSPEC (UINT_MAX-1)
|
||||
|
||||
#define FT_OPT_MIN_WIDTH ((uint32_t)(0x01U << (0)))
|
||||
#define FT_OPT_TEXT_ALIGN ((uint32_t)(0x01U << (1)))
|
||||
#define FT_OPT_TOP_PADDING ((uint32_t)(0x01U << (2)))
|
||||
#define FT_OPT_BOTTOM_PADDING ((uint32_t)(0x01U << (3)))
|
||||
#define FT_OPT_LEFT_PADDING ((uint32_t)(0x01U << (4)))
|
||||
#define FT_OPT_RIGHT_PADDING ((uint32_t)(0x01U << (5)))
|
||||
#define FT_OPT_EMPTY_STR_HEIGHT ((uint32_t)(0x01U << (6)))
|
||||
#define FT_OPT_ROW_TYPE ((uint32_t)(0x01U << (7)))
|
||||
#define FT_COPT_MIN_WIDTH ((uint32_t)(0x01U << (0)))
|
||||
#define FT_COPT_TEXT_ALIGN ((uint32_t)(0x01U << (1)))
|
||||
#define FT_COPT_TOP_PADDING ((uint32_t)(0x01U << (2)))
|
||||
#define FT_COPT_BOTTOM_PADDING ((uint32_t)(0x01U << (3)))
|
||||
#define FT_COPT_LEFT_PADDING ((uint32_t)(0x01U << (4)))
|
||||
#define FT_COPT_RIGHT_PADDING ((uint32_t)(0x01U << (5)))
|
||||
#define FT_COPT_EMPTY_STR_HEIGHT ((uint32_t)(0x01U << (6)))
|
||||
#define FT_COPT_ROW_TYPE ((uint32_t)(0x01U << (7)))
|
||||
|
||||
#define OPTION_IS_SET(ft_opts, option) ((ft_opts) & (option))
|
||||
#define OPTION_SET(ft_opts, option) ((ft_opts) |=(option))
|
||||
@ -152,11 +152,23 @@ extern struct fort_border_style FORT_DOT_STYLE;
|
||||
extern struct fort_border_style FORT_EMPTY_STYLE;
|
||||
|
||||
|
||||
struct fort_entire_table_options
|
||||
{
|
||||
int left_margin;
|
||||
int top_margin;
|
||||
int right_margin;
|
||||
int bottom_margin;
|
||||
};
|
||||
typedef fort_entire_table_options fort_entire_table_options_t;
|
||||
extern fort_entire_table_options_t g_entire_table_options;
|
||||
fort_status_t set_entire_table_option(fort_table_options_t *table_options, uint32_t option, int value);
|
||||
fort_status_t set_default_entire_table_option(uint32_t option, int value);
|
||||
|
||||
struct fort_table_options
|
||||
{
|
||||
struct fort_border_style border_style;
|
||||
fort_cell_opt_container_t * cell_options;
|
||||
fort_entire_table_options_t entire_table_options;
|
||||
};
|
||||
typedef struct fort_table_options fort_table_options_t;
|
||||
extern fort_table_options_t g_table_options;
|
||||
|
12
src/row.c
12
src/row.c
@ -137,11 +137,11 @@ int print_row_separator(char *buffer, size_t buffer_sz,
|
||||
|
||||
enum RowType lower_row_type = Common;
|
||||
if (lower_row != NULL) {
|
||||
lower_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
lower_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
||||
}
|
||||
enum RowType upper_row_type = Common;
|
||||
if (upper_row != NULL) {
|
||||
upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row-1, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row-1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
||||
}
|
||||
|
||||
|
||||
@ -244,11 +244,11 @@ int wprint_row_separator(wchar_t *buffer, size_t buffer_sz,
|
||||
|
||||
enum RowType lower_row_type = Common;
|
||||
if (lower_row != NULL) {
|
||||
lower_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
lower_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
||||
}
|
||||
enum RowType upper_row_type = Common;
|
||||
if (upper_row != NULL) {
|
||||
upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row-1, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
upper_row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row-1, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
||||
}
|
||||
|
||||
/* Row separator anatomy
|
||||
@ -478,7 +478,7 @@ int snprintf_row(const fort_row_t *row, char *buffer, size_t buf_sz, size_t *col
|
||||
*/
|
||||
|
||||
typedef const char (*border_chars_point_t)[BorderItemPosSize];
|
||||
enum RowType row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
enum RowType row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
||||
const char (*bord_chars)[BorderItemPosSize] = (row_type == Header)
|
||||
? (border_chars_point_t) (&context->table_options->border_style.header_border_chars)
|
||||
: (border_chars_point_t) (&context->table_options->border_style.border_chars);
|
||||
@ -537,7 +537,7 @@ int wsnprintf_row(const fort_row_t *row, wchar_t *buffer, size_t buf_sz, size_t
|
||||
*/
|
||||
|
||||
typedef const char (*border_chars_point_t)[BorderItemPosSize];
|
||||
enum RowType row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_OPT_ROW_TYPE);
|
||||
enum RowType row_type = (enum RowType)get_cell_opt_value_hierarcial(context->table_options, context->row, FT_ANY_COLUMN, FT_COPT_ROW_TYPE);
|
||||
const char (*bord_chars)[BorderItemPosSize] = (row_type)
|
||||
? (border_chars_point_t) (&context->table_options->border_style.header_border_chars)
|
||||
: (border_chars_point_t) (&context->table_options->border_style.border_chars);
|
||||
|
@ -295,7 +295,7 @@ int buffer_printf(string_buffer_t *buffer, size_t buffer_row, size_t table_colum
|
||||
int left = 0;
|
||||
int right = 0;
|
||||
|
||||
switch (get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TEXT_ALIGN)) {
|
||||
switch (get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TEXT_ALIGN)) {
|
||||
case LeftAligned:
|
||||
left = 0;
|
||||
right = (buf_len - 1) - content_width;
|
||||
@ -379,7 +379,7 @@ int buffer_wprintf(string_buffer_t *buffer, size_t buffer_row, size_t table_colu
|
||||
int left = 0;
|
||||
int right = 0;
|
||||
|
||||
switch (get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_OPT_TEXT_ALIGN)) {
|
||||
switch (get_cell_opt_value_hierarcial(context->table_options, context->row, context->column, FT_COPT_TEXT_ALIGN)) {
|
||||
case LeftAligned:
|
||||
left = 0;
|
||||
right = (buf_len - 1) - content_width;
|
||||
|
@ -181,6 +181,14 @@ fort_status_t table_geometry(const FTABLE *table, size_t *height, size_t *width)
|
||||
}
|
||||
F_FREE(col_width_arr);
|
||||
F_FREE(row_height_arr);
|
||||
|
||||
if (table->options) {
|
||||
*height += table->options->entire_table_options.top_margin;
|
||||
*height += table->options->entire_table_options.bottom_margin;
|
||||
*width += table->options->entire_table_options.left_margin;
|
||||
*width += table->options->entire_table_options.right_margin;
|
||||
}
|
||||
|
||||
return FT_SUCCESS;
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,8 @@ struct test_case test_suit [] = {
|
||||
{"test_wcs_table_boundaries", test_wcs_table_boundaries},
|
||||
{"test_table_write", test_table_write},
|
||||
{"test_table_border_style", test_table_border_style},
|
||||
{"test_table_options", test_table_options},
|
||||
{"test_table_cell_options", test_table_cell_options},
|
||||
{"test_table_tbl_options", test_table_tbl_options},
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
|
@ -10,7 +10,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
@ -40,7 +40,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
@ -72,7 +72,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWRITE_LN(table, "3", "c", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "c", "234", "3.140000", "3") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "234", "3.140000", "3", "c") == FT_SUCCESS);
|
||||
@ -102,7 +102,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWWRITE_LN(table, L"3", L"c", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"c", L"234", L"3.140000", L"3") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"234", L"3.140000", L"3", L"c") == FT_SUCCESS);
|
||||
@ -132,7 +132,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWRITE_LN(table, "", "", "234", "3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "c", "234", "3.140000", "") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "234", "3.140000", "", "") == FT_SUCCESS);
|
||||
@ -162,7 +162,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWWRITE_LN(table, L"", L"", L"234", L"3.140000") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"c", L"234", L"3.140000", L"") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"234", L"3.140000", L"", L"") == FT_SUCCESS);
|
||||
@ -192,7 +192,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS);
|
||||
assert_true( FT_NWRITE_LN(table, "", "", "", "") == FT_SUCCESS);
|
||||
@ -222,7 +222,7 @@ void test_table_basic(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||
assert_true( FT_NWWRITE_LN(table, L"", L"", L"", L"") == FT_SUCCESS);
|
||||
@ -260,7 +260,7 @@ void test_wcs_table_boundaries(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
assert_true( FT_NWWRITE_LN(table, L"3", L"12345\x8888\x8888", L"c") == FT_SUCCESS); /* \x8888,\x8888 - occupy 2 columns each */
|
||||
assert_true( FT_NWWRITE_LN(table, L"c", L"12345678\x500", L"c") == FT_SUCCESS); /* \x500 - occupies 1 column */
|
||||
assert_true( FT_NWWRITE_LN(table, L"234", L"123456789", L"c") == FT_SUCCESS);
|
||||
@ -297,7 +297,7 @@ void test_table_write(void)
|
||||
assert_true( table != NULL );
|
||||
assert_true( set_test_options_for_table(table) == FT_SUCCESS);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 3, 'c', "234", 3.14);
|
||||
assert_true( n == 4 );
|
||||
n = ft_printf_ln(table, "%c|%s|%f|%d", 'c', "234", 3.14, 3);
|
||||
|
@ -70,11 +70,11 @@ void test_table_border_style(void)
|
||||
|
||||
ft_set_default_border_style(&brdr_style);
|
||||
|
||||
ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_TOP_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_EMPTY_STR_HEIGHT, 0);
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 0);
|
||||
|
||||
|
||||
table = create_test_int_table(0);
|
||||
@ -96,7 +96,7 @@ void test_table_border_style(void)
|
||||
table = create_test_int_table(1);
|
||||
ft_add_separator(table);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
|
||||
|
||||
assert_true( n == 4 );
|
||||
|
@ -9,10 +9,70 @@
|
||||
|
||||
|
||||
|
||||
void test_table_tbl_options(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
|
||||
WHEN("Test setting entire table options") {
|
||||
set_test_options_as_default();
|
||||
|
||||
table = create_test_int_table(0);
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true( table_str != NULL );
|
||||
const char *table_str_etalon =
|
||||
"+---+---+----+----+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
/* Now set table options */
|
||||
ft_set_tbl_option(table, FT_TOPT_TOP_MARGIN, 3);
|
||||
ft_set_tbl_option(table, FT_TOPT_BOTTOM_MARGIN, 4);
|
||||
// ft_set_tbl_option(table, FT_TOPT_LEFT_MARGIN, 1);
|
||||
// ft_set_tbl_option(table, FT_TOPT_RIGHT_MARGIN, 2);
|
||||
table_str = ft_to_string(table);
|
||||
assert_true( table_str != NULL );
|
||||
table_str_etalon =
|
||||
" \n"
|
||||
" \n"
|
||||
" \n"
|
||||
"+---+---+----+----+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n"
|
||||
"| | | | |\n"
|
||||
"| 3 | 4 | 55 | 67 |\n"
|
||||
"| | | | |\n"
|
||||
"+---+---+----+----+\n"
|
||||
" \n"
|
||||
" \n"
|
||||
" \n"
|
||||
" \n";
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_table_options(void)
|
||||
void test_table_cell_options(void)
|
||||
{
|
||||
FTABLE *table = NULL;
|
||||
|
||||
@ -20,10 +80,10 @@ void test_table_options(void)
|
||||
WHEN("All paddings = 1") {
|
||||
set_test_options_as_default();
|
||||
|
||||
ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_TOP_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
|
||||
@ -51,10 +111,10 @@ void test_table_options(void)
|
||||
|
||||
WHEN("Top and bottom padding = 0") {
|
||||
|
||||
ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_TOP_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
|
||||
@ -74,10 +134,10 @@ void test_table_options(void)
|
||||
|
||||
WHEN("Left and right padding = 0") {
|
||||
|
||||
ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_TOP_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_LEFT_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_RIGHT_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 0);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
|
||||
@ -103,10 +163,10 @@ void test_table_options(void)
|
||||
|
||||
WHEN("All paddings = 0") {
|
||||
|
||||
ft_set_default_option(FT_OPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_TOP_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_LEFT_PADDING, 0);
|
||||
ft_set_default_option(FT_OPT_RIGHT_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 0);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
|
||||
@ -126,11 +186,11 @@ void test_table_options(void)
|
||||
|
||||
WHEN("Empty string has 0 heigt") {
|
||||
|
||||
ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_TOP_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_option(FT_OPT_EMPTY_STR_HEIGHT, 0);
|
||||
ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 0);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
int n = ft_printf_ln(table, "|||");
|
||||
@ -165,10 +225,10 @@ void test_table_options(void)
|
||||
table = create_test_int_table(0);
|
||||
set_test_options_for_table(table);
|
||||
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 0);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 0);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 0);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0);
|
||||
|
||||
const char *table_str = ft_to_string(table);
|
||||
assert_true( table_str != NULL );
|
||||
@ -183,11 +243,11 @@ void test_table_options(void)
|
||||
assert_str_equal(table_str, table_str_etalon);
|
||||
|
||||
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 1);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 1);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 0);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 0);
|
||||
ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_EMPTY_STR_HEIGHT, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 0);
|
||||
ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 0);
|
||||
|
||||
table_str = ft_to_string(table);
|
||||
assert_true( table_str != NULL );
|
||||
@ -218,13 +278,13 @@ void test_table_options(void)
|
||||
table = create_test_int_table(0);
|
||||
int status = FT_SUCCESS;
|
||||
|
||||
status |= ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_MIN_WIDTH, 7);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, 1, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, 2, FT_OPT_MIN_WIDTH, 8);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, 2, FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_MIN_WIDTH, 7);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 1, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_COPT_MIN_WIDTH, 8);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, 2, FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
|
||||
status |= ft_set_option(table, 2, 3, FT_OPT_MIN_WIDTH, 6);
|
||||
status |= ft_set_option(table, 2, 3, FT_OPT_TEXT_ALIGN, LeftAligned);
|
||||
status |= ft_set_cell_option(table, 2, 3, FT_COPT_MIN_WIDTH, 6);
|
||||
status |= ft_set_cell_option(table, 2, 3, FT_COPT_TEXT_ALIGN, LeftAligned);
|
||||
assert_true( status == FT_SUCCESS);
|
||||
|
||||
|
||||
@ -253,8 +313,8 @@ void test_table_options(void)
|
||||
set_test_options_as_default();
|
||||
|
||||
int status = FT_SUCCESS;
|
||||
status |= ft_set_default_option(FT_OPT_MIN_WIDTH, 5);
|
||||
status |= ft_set_default_option(FT_OPT_TEXT_ALIGN, CenterAligned);
|
||||
status |= ft_set_default_cell_option(FT_COPT_MIN_WIDTH, 5);
|
||||
status |= ft_set_default_cell_option(FT_COPT_TEXT_ALIGN, CenterAligned);
|
||||
assert_true( status == FT_SUCCESS);
|
||||
|
||||
table = create_test_int_table(0);
|
||||
@ -279,12 +339,12 @@ void test_table_options(void)
|
||||
ft_destroy_table(table);
|
||||
}
|
||||
|
||||
WHEN("All columns are equal and not empty") {
|
||||
WHEN("Multiline cell") {
|
||||
set_test_options_as_default();
|
||||
|
||||
table = ft_create_table();
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
int n = ft_printf_ln(table, "%d|%c|%s|%f", 4, 'c', "234", 3.14);
|
||||
|
||||
assert_true( n == 4 );
|
||||
|
@ -5,11 +5,11 @@ int set_test_options_for_table(FTABLE *table)
|
||||
{
|
||||
assert(table);
|
||||
int status = FT_SUCCESS;
|
||||
status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_BOTTOM_PADDING, 1);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_TOP_PADDING, 1);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_LEFT_PADDING, 1);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_RIGHT_PADDING, 1);
|
||||
status |= ft_set_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_OPT_EMPTY_STR_HEIGHT, 1);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_BOTTOM_PADDING, 1);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_TOP_PADDING, 1);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_LEFT_PADDING, 1);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_RIGHT_PADDING, 1);
|
||||
status |= ft_set_cell_option(table, FT_ANY_ROW, FT_ANY_COLUMN, FT_COPT_EMPTY_STR_HEIGHT, 1);
|
||||
|
||||
assert_true( status == FT_SUCCESS );
|
||||
|
||||
@ -37,14 +37,14 @@ int set_test_options_as_default()
|
||||
{
|
||||
int status = FT_SUCCESS;
|
||||
|
||||
status |= ft_set_default_option(FT_OPT_MIN_WIDTH, 0);
|
||||
status |= ft_set_default_option(FT_OPT_TEXT_ALIGN, RightAligned);
|
||||
status |= ft_set_default_cell_option(FT_COPT_MIN_WIDTH, 0);
|
||||
status |= ft_set_default_cell_option(FT_COPT_TEXT_ALIGN, RightAligned);
|
||||
|
||||
status |= ft_set_default_option(FT_OPT_BOTTOM_PADDING, 1);
|
||||
status |= ft_set_default_option(FT_OPT_TOP_PADDING, 1);
|
||||
status |= ft_set_default_option(FT_OPT_LEFT_PADDING, 1);
|
||||
status |= ft_set_default_option(FT_OPT_RIGHT_PADDING, 1);
|
||||
status |= ft_set_default_option(FT_OPT_EMPTY_STR_HEIGHT, 1);
|
||||
status |= ft_set_default_cell_option(FT_COPT_BOTTOM_PADDING, 1);
|
||||
status |= ft_set_default_cell_option(FT_COPT_TOP_PADDING, 1);
|
||||
status |= ft_set_default_cell_option(FT_COPT_LEFT_PADDING, 1);
|
||||
status |= ft_set_default_cell_option(FT_COPT_RIGHT_PADDING, 1);
|
||||
status |= ft_set_default_cell_option(FT_COPT_EMPTY_STR_HEIGHT, 1);
|
||||
|
||||
assert_true( status == FT_SUCCESS );
|
||||
|
||||
@ -84,7 +84,7 @@ FTABLE *create_test_int_table(int set_test_opts)
|
||||
|
||||
assert_true (table != NULL);
|
||||
|
||||
ft_set_option(table, 0, FT_ANY_COLUMN, FT_OPT_ROW_TYPE, Header);
|
||||
ft_set_cell_option(table, 0, FT_ANY_COLUMN, FT_COPT_ROW_TYPE, Header);
|
||||
int n = ft_printf_ln(table, "%d|%d|%d|%d", 3, 4, 55, 67);
|
||||
|
||||
assert_true( n == 4 );
|
||||
|
@ -22,7 +22,8 @@ void test_table_basic(void);
|
||||
void test_wcs_table_boundaries(void);
|
||||
void test_table_write(void);
|
||||
void test_table_border_style(void);
|
||||
void test_table_options(void);
|
||||
void test_table_cell_options(void);
|
||||
void test_table_tbl_options(void);
|
||||
|
||||
struct test_case
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user