libhpdftbl 1.5.0
Table construction library for Haru PDF library
|
Main module for flexible table drawing with HPDF library. More...
#include <stdlib.h>
#include <string.h>
#include <iconv.h>
#include <hpdf.h>
#include <libgen.h>
#include <sys/stat.h>
#include "hpdftbl.h"
Data Structures | |
struct | line_dash_style |
Definition of a dashed line style. More... | |
Typedefs | |
typedef struct line_dash_style | line_dash_style_t |
Definition of a dashed line style. | |
Functions | |
int | hpdftbl_set_line_dash (hpdftbl_t t, hpdftbl_line_dashstyle_t style) |
Internal helper to set the line style. More... | |
void | hpdftbl_set_anchor_top_left (hpdftbl_t tbl, const _Bool anchor) |
Switch stroking anchor point. More... | |
_Bool | hpdftbl_get_anchor_top_left (hpdftbl_t tbl) |
Get stroking anchor point. More... | |
void | hpdftbl_set_text_encoding (char *target, char *source) |
Determine text source encoding. More... | |
int | hpdftbl_encoding_text_out (HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, char *text) |
Strke text with current encoding. More... | |
void | HPDF_RoundedCornerRectangle (HPDF_Page page, HPDF_REAL xpos, HPDF_REAL ypos, HPDF_REAL width, HPDF_REAL height, HPDF_REAL rad) |
Draw rectangle with rounded corner. More... | |
void | hpdftbl_set_bottom_vmargin_factor (hpdftbl_t t, HPDF_REAL f) |
The margin from the bottom of the cell to the baseline of the text is calculated as a fraction of the font size. The margin is calculated as: More... | |
hpdftbl_t | hpdftbl_create (size_t rows, size_t cols) |
Create a new table with no title. More... | |
hpdftbl_t | hpdftbl_create_title (size_t rows, size_t cols, char *title) |
Create a new table with title top row. More... | |
int | hpdftbl_set_min_rowheight (hpdftbl_t t, float h) |
Set the minimum row height in the table. More... | |
int | hpdftbl_set_colwidth_percent (hpdftbl_t t, size_t c, float w) |
Set column width as percentage of overall table width. More... | |
int | hpdftbl_set_outer_grid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle) |
Set outer border grid style. More... | |
int | hpdftbl_set_inner_grid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle) |
Set inner border grid style. More... | |
int | hpdftbl_set_inner_hgrid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle) |
Set inner horizontal border grid style. More... | |
int | hpdftbl_set_inner_vgrid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle) |
Set inner vertical border grid style. More... | |
int | hpdftbl_set_inner_tgrid_style (hpdftbl_t t, HPDF_REAL width, HPDF_RGBColor color, hpdftbl_line_dashstyle_t dashstyle) |
Set inner horizontal top border grid style. More... | |
int | hpdftbl_set_zebra (hpdftbl_t t, _Bool use, int phase) |
int | hpdftbl_set_zebra_color (hpdftbl_t t, HPDF_RGBColor z1, HPDF_RGBColor z2) |
Specify first and second color for a zebra grid table. More... | |
int | hpdftbl_set_header_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Specify style for table header row. More... | |
int | hpdftbl_set_background (hpdftbl_t t, HPDF_RGBColor background) |
Set table background color. More... | |
int | hpdftbl_set_header_halign (hpdftbl_t t, hpdftbl_text_align_t align) |
Set table header horizontal text align. More... | |
int | hpdftbl_use_header (hpdftbl_t t, _Bool use) |
Enable/disable the interpretation of the top row as a header row. More... | |
int | hpdftbl_use_labels (hpdftbl_t t, _Bool use) |
Enable/Disable the use of cell labels. More... | |
int | hpdftbl_use_labelgrid (hpdftbl_t t, _Bool use) |
Shorter vertical line to mark labels. More... | |
int | hpdftbl_set_tag (hpdftbl_t t, void *tag) |
Set an optional tag for the table. More... | |
int | hpdftbl_destroy (hpdftbl_t t) |
Destroy a table and free all memory. More... | |
_Bool | chktbl (hpdftbl_t t, size_t r, size_t c) |
Internal function. Check that a row and column are within the table. More... | |
int | hpdftbl_set_cell (hpdftbl_t t, size_t r, size_t c, char *label, char *content) |
Set content for specific cell. More... | |
int | hpdftbl_set_cellspan (hpdftbl_t t, size_t r, size_t c, size_t rowspan, size_t colspan) |
Set cell spanning. More... | |
int | hpdftbl_clear_spanning (hpdftbl_t t) |
Clear all cell spanning. More... | |
int | hpdftbl_set_labels (hpdftbl_t t, char **labels) |
Set the text for the cell labels. More... | |
int | hpdftbl_set_content (hpdftbl_t t, char **content) |
Set the content for the table. More... | |
int | hpdftbl_set_label_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Set the text style for labels in the entire table. More... | |
int | hpdftbl_set_content_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Set text style for text content. More... | |
int | hpdftbl_set_row_content_style (hpdftbl_t t, size_t r, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Set the text style for an entire row of cells. More... | |
int | hpdftbl_set_col_content_style (hpdftbl_t t, size_t c, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Set the text style for an entire column of cells. More... | |
int | hpdftbl_set_cell_content_style (hpdftbl_t t, size_t r, size_t c, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Set the text style for content of specified cell. More... | |
int | hpdftbl_set_title_style (hpdftbl_t t, char *font, HPDF_REAL fsize, HPDF_RGBColor color, HPDF_RGBColor background) |
Set the table title text style. More... | |
int | hpdftbl_set_title (hpdftbl_t t, char *title) |
Set table title. More... | |
int | hpdftbl_set_title_halign (hpdftbl_t t, hpdftbl_text_align_t align) |
Set horizontal alignment for table title. More... | |
int | hpdftbl_stroke_from_data (HPDF_Doc pdf_doc, HPDF_Page pdf_page, hpdftbl_spec_t *tbl_spec, hpdftbl_theme_t *theme) |
Construct the table from a array specification. More... | |
int | hpdftbl_get_last_auto_height (HPDF_REAL *height) |
Get the height calculated for the last constructed table. More... | |
int | hpdftbl_setpos (hpdftbl_t t, const HPDF_REAL xpos, const HPDF_REAL ypos, const HPDF_REAL width, HPDF_REAL height) |
Set size and position for table. More... | |
int | hpdftbl_stroke_pos (HPDF_Doc pdf, const HPDF_Page page, hpdftbl_t t) |
Stroke the table using the already specified size and position within the table. More... | |
int | hpdftbl_stroke (HPDF_Doc pdf, const HPDF_Page page, hpdftbl_t t, const HPDF_REAL xpos, const HPDF_REAL ypos, const HPDF_REAL width, HPDF_REAL height) |
Stroke the table. More... | |
int | hpdftbl_stroke_pdfdoc (HPDF_Doc pdf_doc, char *file) |
Stroke PDF document to file with check that the directory in path exists. More... | |
Variables | |
hpdftbl_error_handler_t | hpdftbl_err_handler = NULL |
This stores a pointer to the function acting as the error handler callback. | |
Main module for flexible table drawing with HPDF library.
Copyright (C) 2022 Johan Persson
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.
_Bool chktbl | ( | hpdftbl_t | t, |
size_t | r, | ||
size_t | c | ||
) |
Internal function. Check that a row and column are within the table.
Internal function. Check that a row and column are within the table
t | Table handle |
r | Row |
c | Column |
Referenced by hpdftbl_set_cell(), hpdftbl_set_cell_canvas_cb(), hpdftbl_set_cell_content_cb(), hpdftbl_set_cell_content_style(), hpdftbl_set_cell_content_style_cb(), hpdftbl_set_cell_label_cb(), and hpdftbl_set_cellspan().
void HPDF_RoundedCornerRectangle | ( | HPDF_Page | page, |
HPDF_REAL | xpos, | ||
HPDF_REAL | ypos, | ||
HPDF_REAL | width, | ||
HPDF_REAL | height, | ||
HPDF_REAL | rad | ||
) |
Draw rectangle with rounded corner.
Draw a rectangle with rounded corner with the current line width, color. The rectangle will not be stroked.
page | Page handle |
xpos | Lower left x-position of rectangle |
ypos | Lower left y-position of rectangle |
width | Width of rectangle |
height | Height of rectangle |
rad | Radius of corners |
Referenced by hpdftbl_widget_slide_button().
int hpdftbl_clear_spanning | ( | hpdftbl_t | t | ) |
Clear all cell spanning.
Reset all spanning cells to no spanning
t | Table handle |
hpdftbl_t hpdftbl_create | ( | size_t | rows, |
size_t | cols | ||
) |
Create a new table with no title.
Create a new table structure. This is the basic handler needed for most other API functions.
rows | Number of rows |
cols | Number of columns |
hpdftbl_t hpdftbl_create_title | ( | size_t | rows, |
size_t | cols, | ||
char * | title | ||
) |
Create a new table with title top row.
Create a new table structure. This is the basic handler needed for most other API functions.
rows | Number of rows |
cols | Number of columns |
title | Title of table |
Referenced by hpdftbl_create(), and hpdftbl_stroke_from_data().
int hpdftbl_destroy | ( | hpdftbl_t | t | ) |
Destroy a table and free all memory.
Destroy a table previous created with table_create(), It is the calling routines responsibility not to acceess t
again.
t | Handle to table |
Referenced by hpdftbl_loads(), and hpdftbl_stroke_from_data().
int hpdftbl_encoding_text_out | ( | HPDF_Page | page, |
HPDF_REAL | xpos, | ||
HPDF_REAL | ypos, | ||
char * | text | ||
) |
Strke text with current encoding.
Utility function to stroke text with character encoding. It is the calling routines responsibility to enclose text in a HPDF_Page_BeginText() / HPDF_Page_EndText()
page | Page handle |
xpos | X coordinate |
ypos | Y coordinate |
text | Text to print |
_Bool hpdftbl_get_anchor_top_left | ( | hpdftbl_t | tbl | ) |
Get stroking anchor point.
Get anchor point for table positioning. By default the top left is used.
tbl | Table handle |
int hpdftbl_get_last_auto_height | ( | HPDF_REAL * | height | ) |
Get the height calculated for the last constructed table.
Get the last automatically calculated height when stroking a table. (The height will be automatically calculated if it was specified as 0)
height | Returned height |
void hpdftbl_set_anchor_top_left | ( | hpdftbl_t | tbl, |
const _Bool | anchor | ||
) |
Switch stroking anchor point.
Set anchor point for table positioning. By default the top left is used as anchor. Calling this function with FALSE can sets the anchor to bottom left instead.
tbl | Table handle |
anchor | Set to TRUE to use top left as anchor, FALSE for bottom left |
int hpdftbl_set_background | ( | hpdftbl_t | t, |
HPDF_RGBColor | background | ||
) |
Set table background color.
t | Table handle |
background | Background color |
void hpdftbl_set_bottom_vmargin_factor | ( | hpdftbl_t | t, |
HPDF_REAL | f | ||
) |
The margin from the bottom of the cell to the baseline of the text is calculated as a fraction of the font size. The margin is calculated as:
The default margin is specified by the define DEFAULT_AUTO_VBOTTOM_MARGIN_FACTOR
t | Table handle |
f | Bottom margin factor |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_cell | ( | hpdftbl_t | t, |
size_t | r, | ||
size_t | c, | ||
char * | label, | ||
char * | content | ||
) |
Set content for specific cell.
Set label and content for a specific cell. If the specified cell is part of another cells spanning an error occurs (returns -1),
t | Table handle |
r | Row |
c | Column |
label | Label |
content | Text content |
Referenced by hpdftbl_stroke_from_data().
int hpdftbl_set_cell_content_style | ( | hpdftbl_t | t, |
size_t | r, | ||
size_t | c, | ||
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Set the text style for content of specified cell.
SSet the font style for content of specified cell. This will override the global cell content setting.
t | Table handle |
r | Cell row |
c | Cell column |
font | Font name |
fsize | Font size |
color | Color |
background | Background color |
Referenced by hpdftbl_set_col_content_style(), and hpdftbl_set_row_content_style().
int hpdftbl_set_cellspan | ( | hpdftbl_t | t, |
size_t | r, | ||
size_t | c, | ||
size_t | rowspan, | ||
size_t | colspan | ||
) |
Set cell spanning.
Set row and column spanning for a cell, an expanded cell is referenced via the position of it's top-left cell
t | Table handle |
r | Row |
c | Column |
rowspan | Row span |
colspan | Column span |
Referenced by hpdftbl_stroke_from_data().
int hpdftbl_set_col_content_style | ( | hpdftbl_t | t, |
size_t | c, | ||
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Set the text style for an entire column of cells.
Set font options for the specified column of cells. This will override the global cell content setting.
t | Table handle |
c | Column to affect |
font | Font name |
fsize | Font size |
color | Color |
background | Background color |
int hpdftbl_set_colwidth_percent | ( | hpdftbl_t | t, |
size_t | c, | ||
float | w | ||
) |
Set column width as percentage of overall table width.
Specify column width as percentage of total column width. Note that this will only take effect if the table has an overall width specified when stroked. Too avoid errors one column should be left unspecified to let the library use whatever space is left for that column.
t | Table handle |
c | Column to set width of first column has index 0 |
w | Width as percentage in range [0.0, 100.0] |
int hpdftbl_set_content | ( | hpdftbl_t | t, |
char ** | content | ||
) |
Set the content for the table.
Set content for all cells. It is the calling functions responsibility that the content array is big enough to cover the entire table. The string array corresponds to a flattened 2-d array and the label for cell (r,c) is calculated as (r * num_cols + c) where num_cols is the number of columns in the table.
It is allowed to specify NULL as placeholder for empty labels. The actual text in the table will be allocated with strdup() so it is safe to free the memory for the labels after the call to this function. Please note that even if the table contains spanning cells the content data must include empty data for covered cells. For a N x M table the data must have (N*M) entries.
Another way to specify the content is to use the callback mechanism. By setting up a content callback function that returns the content for a cell.
t | Table handle |
content | A one dimensional string array of content string |
int hpdftbl_set_content_style | ( | hpdftbl_t | t, |
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Set text style for text content.
Set style options for cell content (font, color, background). This will be applied for all cells in the table. If a style callback have been specified for either the table or a cell that style take precedence.
t | Table handle |
font | Font name |
fsize | Font size |
color | Color |
background | Background color |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_header_halign | ( | hpdftbl_t | t, |
hpdftbl_text_align_t | align | ||
) |
Set table header horizontal text align.
t | Table handle |
align | Alignment |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_header_style | ( | hpdftbl_t | t, |
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Specify style for table header row.
Set the font properties and background for the header row which is the top row if enabled. The header row will be automatically enabled after calling this function. The header can be enabled/disabled separately with hpdftbl_use_header()
t | Table handle |
font | Font name |
fsize | Font size |
color | Font color |
background | Cell background color |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_inner_grid_style | ( | hpdftbl_t | t, |
HPDF_REAL | width, | ||
HPDF_RGBColor | color, | ||
hpdftbl_line_dashstyle_t | dashstyle | ||
) |
Set inner border grid style.
This is a shortform to set both the vertical and horizontal gridline style with one call.
t | Table handle |
width | Line width (in pt) |
color | Line color |
dashstyle | Line dash style |
int hpdftbl_set_inner_hgrid_style | ( | hpdftbl_t | t, |
HPDF_REAL | width, | ||
HPDF_RGBColor | color, | ||
hpdftbl_line_dashstyle_t | dashstyle | ||
) |
Set inner horizontal border grid style.
t | Table handle |
width | Line width (in pt) |
color | Line color |
dashstyle | Line dash style |
Referenced by hpdftbl_apply_theme(), and hpdftbl_set_inner_grid_style().
int hpdftbl_set_inner_tgrid_style | ( | hpdftbl_t | t, |
HPDF_REAL | width, | ||
HPDF_RGBColor | color, | ||
hpdftbl_line_dashstyle_t | dashstyle | ||
) |
Set inner horizontal top border grid style.
This would be the gridline just below the header row.
t | Table handle |
width | Line width (in pt) |
color | Line color |
dashstyle | Line dash style |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_inner_vgrid_style | ( | hpdftbl_t | t, |
HPDF_REAL | width, | ||
HPDF_RGBColor | color, | ||
hpdftbl_line_dashstyle_t | dashstyle | ||
) |
Set inner vertical border grid style.
t | Table handle |
width | Line width (in pt) |
color | Line color |
dashstyle | Line dash style |
Referenced by hpdftbl_apply_theme(), and hpdftbl_set_inner_grid_style().
int hpdftbl_set_label_style | ( | hpdftbl_t | t, |
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Set the text style for labels in the entire table.
Set font, color and background options for cell labels. If a style callback have been specified for either the table or a cell that style take precedence.
t | Table handle |
font | Font name |
fsize | Font size |
color | Color |
background | Background color |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_labels | ( | hpdftbl_t | t, |
char ** | labels | ||
) |
Set the text for the cell labels.
Set labels for all the cell. It is the calling functions responsibility that the labels array is big enough to cover the entire table. The string array corresponds to a flattened 2-d array and the label for cell (r,c) is calculated as (r * num_cols + c) where num_cols is the number of columns in the table.
It is allowed to specify NULL as placeholder for empty labels. The actual text in the table will be allocated with strdup() so it is safe to free the memory for the labels after the call to this function. Please note that even if the table contains spanning cells the content data must include empty data for covered cells. For a N x M table the data must have (N*M) entries.
t | Table handle |
labels | A one dimensional string array of labels |
int hpdftbl_set_line_dash | ( | hpdftbl_t | t, |
hpdftbl_line_dashstyle_t | style | ||
) |
Internal helper to set the line style.
The drawing of a dashed line uses the underlying HPDF function HPDF_Page_SetDash()
t | Table handle |
style |
Referenced by hpdftbl_stroke().
int hpdftbl_set_min_rowheight | ( | hpdftbl_t | t, |
float | h | ||
) |
Set the minimum row height in the table.
The row height is normally calculated based on the font size and if labels are displayed or not. However, it is not possible for the table to know the height of specific widgets (for example) without a two-pass table drawing algorithm.
To handle thos odd cases when the calculated height is not sufficient a manual minimum height can be specified.
t | Table handler |
h | The minimum height (in points). If specified as 0 the min height will have no effect. |
int hpdftbl_set_outer_grid_style | ( | hpdftbl_t | t, |
HPDF_REAL | width, | ||
HPDF_RGBColor | color, | ||
hpdftbl_line_dashstyle_t | dashstyle | ||
) |
Set outer border grid style.
t | Table handle |
width | Line width (in pt) |
color | Line color |
dashstyle | Line dash style |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_row_content_style | ( | hpdftbl_t | t, |
size_t | r, | ||
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Set the text style for an entire row of cells.
Set font options for the specified row of cells. This will override the global cell content.
t | Table handle |
r | Row to affect |
font | Font name |
fsize | Font size |
color | Color |
background | Background color |
int hpdftbl_set_tag | ( | hpdftbl_t | t, |
void * | tag | ||
) |
Set an optional tag for the table.
Set an optional tag in the table. The tag can be a pointer to anything. The tag is passed as the first argument in the various callbacks and can be used to supply table specific information or identify a specific table in the case the same callback is used for multiple tables.
t | The table handle |
tag | The tag (pointer to any object) |
void hpdftbl_set_text_encoding | ( | char * | target, |
char * | source | ||
) |
Determine text source encoding.
The default HPDF encoding is a standard PDF encoding. The problem with that is that now almost 100% of all code is written in UTF-8 encoding and trying to print text strings with accented characters will simply not work. For example the default encoding assumes that strings are given in UTF-8 and sets the target to ISO8859-4 which includes northern europe accented characters. The conversion is internally handled by the standard iconv() routines.
target | The target encoding. See HPDF documentation for supported encodings. |
source | The source encodings, i.e. what encodings are sth strings in the source specified in. |
int hpdftbl_set_title | ( | hpdftbl_t | t, |
char * | title | ||
) |
Set table title.
Set table title. A title will occupy a separate row above the table that is not included in the row count. A table is enabled when the table text is <> NULL and disabled when the title text is == NULL.
t | Table handle |
title | Title string |
int hpdftbl_set_title_halign | ( | hpdftbl_t | t, |
hpdftbl_text_align_t | align | ||
) |
Set horizontal alignment for table title.
t | Table handle |
align | Alignment |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_title_style | ( | hpdftbl_t | t, |
char * | font, | ||
HPDF_REAL | fsize, | ||
HPDF_RGBColor | color, | ||
HPDF_RGBColor | background | ||
) |
Set the table title text style.
Set font options for title
t | Table handle |
font | Font name |
fsize | Font size |
color | Color |
background | Background color |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_zebra | ( | hpdftbl_t | t, |
_Bool | use, | ||
int | phase | ||
) |
t | Table handle |
use | TRUE=Use Zebra, FALSE=Don't use zebra |
phase | 0=Start with color 1, 1=Start with color 1 |
Referenced by hpdftbl_apply_theme().
int hpdftbl_set_zebra_color | ( | hpdftbl_t | t, |
HPDF_RGBColor | z1, | ||
HPDF_RGBColor | z2 | ||
) |
Specify first and second color for a zebra grid table.
By default the colors start with z1
color. To have the top row (below any potential header row) instead start with z2 specify phase=1
in the hpdftbl_set_zebra() function.
t | Table handle |
z1 | Color 1 |
z2 | Color 2 |
Referenced by hpdftbl_apply_theme().
int hpdftbl_setpos | ( | hpdftbl_t | t, |
const HPDF_REAL | xpos, | ||
const HPDF_REAL | ypos, | ||
const HPDF_REAL | width, | ||
HPDF_REAL | height | ||
) |
Set size and position for table.
The position is by default specified as the upper left corner of the table. Use the hpdftbl_set_origin_top_left() to use the bottom left of the table as reference point.
Ths standard stroke function hpdftbl_stroke() also take the size and position as argument for ease of use but the hpdftbl_stroke_pos() do assume that the table has it's size set.
t | Table handle |
xpos | x position for table |
ypos | y position for table |
width | width of table |
height | height of table. If the height is specified as 0 it will be automatically calculated. The calculated height can be retrieved after the table has been stroked by a call to hpdftbl_get_last_auto_height() |
int hpdftbl_stroke | ( | HPDF_Doc | pdf, |
const HPDF_Page | page, | ||
hpdftbl_t | t, | ||
const HPDF_REAL | xpos, | ||
const HPDF_REAL | ypos, | ||
const HPDF_REAL | width, | ||
HPDF_REAL | height | ||
) |
Stroke the table.
Stroke the table at the specified position and size. The position is by default specified as the upper left corner of the table. Use the hpdftbl_set_origin_top_left(FALSE) to use the bottom left of the table as reference point.
The HPDF document handle | |
page | The HPDF page handle |
t | Table handle |
xpos | x position for table |
ypos | y position for table |
width | width of table |
height | height of table. If the height is specified as 0 it will be automatically calculated. The calculated height can be retrieved after the table has been stroked by a call to hpdftbl_get_last_auto_height() |
Referenced by hpdftbl_stroke_from_data(), and hpdftbl_stroke_pos().
int hpdftbl_stroke_from_data | ( | HPDF_Doc | pdf_doc, |
HPDF_Page | pdf_page, | ||
hpdftbl_spec_t * | tbl_spec, | ||
hpdftbl_theme_t * | theme | ||
) |
Construct the table from a array specification.
Create and stroke a table specified by a data structure. This makes it easier to separate the view of the data from the model which provides the data. The intended use case is that the data structure specifies the core layout of the table together with the labels and callback functions to handle the content in each cell. Using this method to create a table also makes it much more maintainable.
pdf_doc | The PDF overall document |
pdf_page | The pageto stroke to |
tbl_spec | The table specification |
theme | Table theme to be applied |
int hpdftbl_stroke_pdfdoc | ( | HPDF_Doc | pdf_doc, |
char * | file | ||
) |
Stroke PDF document to file with check that the directory in path exists.
Note: It is a checked error if the full path is longer than 1014 characters
pdf_doc | Haru PDF document handle |
file | Full pathname of file to write to |
Referenced by stroke_to_file().
int hpdftbl_stroke_pos | ( | HPDF_Doc | pdf, |
const HPDF_Page | page, | ||
hpdftbl_t | t | ||
) |
Stroke the table using the already specified size and position within the table.
Stroke the table at the specified position and size. The position is by default specified as the upper left corner of the table. Use the hpdftbl_set_origin_top_left(FALSE) to use the bottom left of the table as reference point.
This is a convenient method to use when stroking a serialized table as the table already holds the size and position. Stroking a table read back ccan be done with just two lines of code
The HPDF document handle | |
page | The HPDF page handle |
t | Table handle |
int hpdftbl_use_header | ( | hpdftbl_t | t, |
_Bool | use | ||
) |
Enable/disable the interpretation of the top row as a header row.
A header row will have a different style and labels will be disabled on this row. In addition the text will be centered vertically and horizontal in the cell.
t | Table handle |
use | TRUE to enable, FALSE to disable |
Referenced by hpdftbl_stroke_from_data().
int hpdftbl_use_labelgrid | ( | hpdftbl_t | t, |
_Bool | use | ||
) |
Shorter vertical line to mark labels.
Set the usage of special grid style where the vertical grid only covers the label text and a gap to the next line. Horizontal lines are drawn as usual. The label grid style gives the table a "lighter" look.
t | Table handle |
use | TRUE to use label grid, FALSE o disable it |
Referenced by hpdftbl_stroke_from_data().
int hpdftbl_use_labels | ( | hpdftbl_t | t, |
_Bool | use | ||
) |
Enable/Disable the use of cell labels.
By default a newly created table will not use cell labels. Enabling labels will also by default enable the special label grid style. To adjust the grid style separately us the hpdftbl_use_labelgrid() method.
t | Table handle |
use | Set to TRUE for cell labels |
Referenced by hpdftbl_stroke_from_data().