libhpdftbl 1.5.0
Table construction library for Haru PDF library
Loading...
Searching...
No Matches
hpdftbl_theme.c File Reference

Functions for theme handling. More...

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <hpdf.h>
#include "hpdftbl.h"

Macros

#define HPDFTBL_DEFAULT_TITLE_STYLE   (hpdf_text_style_t){HPDF_FF_HELVETICA_BOLD,11,(HPDF_RGBColor){0,0,0},(HPDF_RGBColor){0.9f,0.9f,0.9f}, LEFT}
 Default style for table title.
 
#define HPDFTBL_DEFAULT_HEADER_STYLE   (hpdf_text_style_t){HPDF_FF_HELVETICA_BOLD,10,(HPDF_RGBColor){0,0,0},(HPDF_RGBColor){0.9f,0.9f,0.97f}, CENTER}
 Default style for table header row. More...
 
#define HPDFTBL_DEFAULT_LABEL_STYLE   (hpdf_text_style_t){HPDF_FF_TIMES_ITALIC,9,(HPDF_RGBColor){0.4f,0.4f,0.4f},(HPDF_RGBColor){1,1,1}, LEFT}
 Default style for table header row. More...
 
#define HPDFTBL_DEFAULT_CONTENT_STYLE   (hpdf_text_style_t){HPDF_FF_COURIER,10,(HPDF_RGBColor){0.2f,0.2f,0.2f},(HPDF_RGBColor){1,1,1}, LEFT}
 Default style for table header row. More...
 
#define HPDFTBL_DEFAULT_INNER_VGRID_STYLE   (hpdftbl_grid_style_t){0.7, (HPDF_RGBColor){0.5f,0.5f,0.5f},0}
 Default style for table vertical inner grid. More...
 
#define HPDFTBL_DEFAULT_INNER_HGRID_STYLE   (hpdftbl_grid_style_t){0.7, (HPDF_RGBColor){0.5f,0.5f,0.5f},0}
 Default style for table horizontal inner grid. More...
 
#define HPDFTBL_DEFAULT_OUTER_GRID_STYLE   (hpdftbl_grid_style_t){1.0f, (HPDF_RGBColor){0.2f,0.2f,0.2f},0}
 Default style for table outer grid (border) More...
 
#define HPDFTBL_DEFAULT_ZEBRA_COLOR1   HPDF_COLOR_WHITE
 Default style for alternating row backgrounds color 1.
 
#define HPDFTBL_DEFAULT_ZEBRA_COLOR2   HPDF_COLOR_XLIGHT_GRAY
 Default style for alternating row backgrounds color 2.
 

Functions

int hpdftbl_apply_theme (hpdftbl_t t, hpdftbl_theme_t *theme)
 Apply a specified theme to a table. More...
 
int hpdftbl_get_theme (hpdftbl_t tbl, hpdftbl_theme_t *theme)
 Extract theme from settings of a specific table. More...
 
hpdftbl_theme_thpdftbl_get_default_theme (void)
 Return the default theme. More...
 
int hpdftbl_destroy_theme (hpdftbl_theme_t *theme)
 Destroy existing theme structure and free memory. More...
 

Detailed Description

Functions for theme handling.

Author
Johan Persson (johan.nosp@m.162@.nosp@m.gmail.nosp@m..com)

Copyright (C) 2022 Johan Persson

See also
LICENSE

Released under the MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Macro Definition Documentation

◆ HPDFTBL_DEFAULT_CONTENT_STYLE

#define HPDFTBL_DEFAULT_CONTENT_STYLE   (hpdf_text_style_t){HPDF_FF_COURIER,10,(HPDF_RGBColor){0.2f,0.2f,0.2f},(HPDF_RGBColor){1,1,1}, LEFT}

Default style for table header row.

See also
hpdftbl_set_content_style()

◆ HPDFTBL_DEFAULT_HEADER_STYLE

#define HPDFTBL_DEFAULT_HEADER_STYLE   (hpdf_text_style_t){HPDF_FF_HELVETICA_BOLD,10,(HPDF_RGBColor){0,0,0},(HPDF_RGBColor){0.9f,0.9f,0.97f}, CENTER}

Default style for table header row.

See also
hpdftbl_set_header_style()

◆ HPDFTBL_DEFAULT_INNER_HGRID_STYLE

#define HPDFTBL_DEFAULT_INNER_HGRID_STYLE   (hpdftbl_grid_style_t){0.7, (HPDF_RGBColor){0.5f,0.5f,0.5f},0}

Default style for table horizontal inner grid.

See also
hpdftbl_set_inner_hgrid_style()

◆ HPDFTBL_DEFAULT_INNER_VGRID_STYLE

#define HPDFTBL_DEFAULT_INNER_VGRID_STYLE   (hpdftbl_grid_style_t){0.7, (HPDF_RGBColor){0.5f,0.5f,0.5f},0}

Default style for table vertical inner grid.

See also
hpdftbl_set_inner_vgrid_style()

◆ HPDFTBL_DEFAULT_LABEL_STYLE

#define HPDFTBL_DEFAULT_LABEL_STYLE   (hpdf_text_style_t){HPDF_FF_TIMES_ITALIC,9,(HPDF_RGBColor){0.4f,0.4f,0.4f},(HPDF_RGBColor){1,1,1}, LEFT}

Default style for table header row.

See also
hpdftbl_set_label_style()

◆ HPDFTBL_DEFAULT_OUTER_GRID_STYLE

#define HPDFTBL_DEFAULT_OUTER_GRID_STYLE   (hpdftbl_grid_style_t){1.0f, (HPDF_RGBColor){0.2f,0.2f,0.2f},0}

Default style for table outer grid (border)

See also
hpdftbl_set_outer_grid_style()

Function Documentation

◆ hpdftbl_apply_theme()

int hpdftbl_apply_theme ( hpdftbl_t  t,
hpdftbl_theme_t theme 
)

Apply a specified theme to a table.

Note however that a limitation (by design) of themes is that settings in individual cells are not recorded in a theme since a theme can be applied to any table despite the structure. This mean only settings that are generic to a table is stored in a theme. Not individal cells.

The default table theme can be retrieved with hpdftbl_get_default_theme()

Parameters
tTable handle
themeTheme reference
Returns
0 on success, -1 on failure
See also
hpdftbl_get_default_theme()

Referenced by hpdftbl_create_title(), and hpdftbl_stroke_from_data().

◆ hpdftbl_destroy_theme()

int hpdftbl_destroy_theme ( hpdftbl_theme_t theme)

Destroy existing theme structure and free memory.

Free all memory allocated by a theme

Parameters
themeThe theme to free
Returns
-1 for error , 0 for success

Referenced by hpdftbl_create_title(), and hpdftbl_theme_loads().

◆ hpdftbl_get_default_theme()

hpdftbl_theme_t * hpdftbl_get_default_theme ( void  )

Return the default theme.

Create and return a theme corresponding to the default table theme. It is the calling functions responsibility to call hpdftbl_destroy_theme() to free the allocated memory. The default theme is a good starting point to just make minor modifications without having to define all elements.

Returns
A new theme initialized to the default settings. It is the calling routines responsibility to free memory used in the returned theme with hpdftbl_destroy_theme()
See also
hpdftbl_apply_theme(), hpdftbl_destroy_theme()

Referenced by hpdftbl_create_title().

◆ hpdftbl_get_theme()

int hpdftbl_get_theme ( hpdftbl_t  tbl,
hpdftbl_theme_t theme 
)

Extract theme from settings of a specific table.

This is useful if a table has been specified with some specific look & feel and another table should be given the same l&f.

Note however that a limitation (by design) of themes is that settings in individual cells are not recorded in a theme since a theme can be applied to any table despite the structure. This mean only settings that are generic to a table is stored in a theme. Not individal cells.

Parameters
tblTable handle for table to have its settings extracted
themeTheme to be read out to.
Returns
0 on success, -1 on failure