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

Routines for plain and dynamic callback function. More...

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <iconv.h>
#include <hpdf.h>
#include <libgen.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include "hpdftbl.h"

Functions

void hpdftbl_set_dlhandle (void *handle)
 Set the handle for scope of dynamic function search. More...
 
int hpdftbl_set_content_cb (hpdftbl_t t, hpdftbl_content_callback_t cb)
 Set table content callback. More...
 
int hpdftbl_set_cell_content_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_content_callback_t cb)
 Set cell content callback. More...
 
int hpdftbl_set_cell_label_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_content_callback_t cb)
 Set cell label callback. More...
 
int hpdftbl_set_cell_canvas_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_canvas_callback_t cb)
 Set cell canvas callback. More...
 
int hpdftbl_set_label_cb (hpdftbl_t t, hpdftbl_content_callback_t cb)
 Set table label callback. More...
 
int hpdftbl_set_post_cb (hpdftbl_t t, hpdftbl_callback_t cb)
 Set table post processing callback. More...
 
int hpdftbl_set_canvas_cb (hpdftbl_t t, hpdftbl_canvas_callback_t cb)
 Set cell canvas callback. More...
 
int hpdftbl_set_content_dyncb (hpdftbl_t t, const char *cb_name)
 Specify dynamic (late) loading callback content function. More...
 
int hpdftbl_set_canvas_dyncb (hpdftbl_t t, const char *cb_name)
 Specify dynamic (late) loading callback content function. More...
 
int hpdftbl_set_label_dyncb (hpdftbl_t t, const char *cb_name)
 Specify dynamic (late) loading callback for table label function. More...
 
int hpdftbl_set_cell_label_dyncb (hpdftbl_t t, size_t r, size_t c, const char *cb_name)
 Specify dynamic (late) loading callback for cell label function. More...
 
int hpdftbl_set_content_style_dyncb (hpdftbl_t t, const char *cb_name)
 Specify dynamic (late) loading callback for table style function. More...
 
int hpdftbl_set_cell_content_style_dyncb (hpdftbl_t t, size_t r, size_t c, const char *cb_name)
 Specify dynamic (late) loading callback for cell style function. More...
 
int hpdftbl_set_cell_content_dyncb (hpdftbl_t t, size_t r, size_t c, const char *cb_name)
 Specify dynamic (late) loading callback cell content function. More...
 
int hpdftbl_set_cell_canvas_dyncb (hpdftbl_t t, size_t r, size_t c, const char *cb_name)
 Specify dynamic (late) loading callback cell canvas function. More...
 
int hpdftbl_set_post_dyncb (hpdftbl_t t, const char *cb_name)
 Set table post processing callback. More...
 
int hpdftbl_set_cell_content_style_cb (hpdftbl_t t, size_t r, size_t c, hpdftbl_content_style_callback_t cb)
 Set cell specific callback to specify cell content style. More...
 
int hpdftbl_set_content_style_cb (hpdftbl_t t, hpdftbl_content_style_callback_t cb)
 Set callback to specify cell content style. More...
 

Detailed Description

Routines for plain and dynamic callback function.

All functions ending with _cb are used to specify standard callback functions which stores a function pointer bounded at compile time. All functions ending i _dyncb are used to set dynamic callback functions which are bound at run time. The function name are stored as string and resolved at runtime.

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

Copyright (C) 2022 Johan Persson

See also
LICENSE

Function Documentation

◆ hpdftbl_set_canvas_cb()

int hpdftbl_set_canvas_cb ( hpdftbl_t  t,
hpdftbl_canvas_callback_t  cb 
)

Set cell canvas callback.

Set cell canvas callback. This callback gets called for each cell in the table. The purpose is to allow the client to add dynamic content to the specified cell. The callback is made before the cell border and content is drawn making it possible to for example add a background color to individual cells. The callback function will receive the Table tag, the row and column, the x, y position of the lower left corner of the table and the width and height of the cell. To set the canvas callback only for a specific cell use the hpdftbl_set_cell_canvas_cb() function

Parameters
tTable handle
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_set_cell_canvas_cb()

Referenced by hpdftbl_set_canvas_dyncb().

◆ hpdftbl_set_canvas_dyncb()

int hpdftbl_set_canvas_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback content function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as canvas callback. This function must follow the signature of a callback function as specified in hpdftbl_canvas_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_canvas_cb(), hpdftbl_canvas_callback_t

◆ hpdftbl_set_cell_canvas_cb()

int hpdftbl_set_cell_canvas_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_canvas_callback_t  cb 
)

Set cell canvas callback.

Set a canvas callback for an individual cell. This will override the table canvas callback. The canvas callback is called with arguments that give the bounding box for the cell. In that way a callback function may draw arbitrary graphic in the cell. The callback is made before the cell border and content is drawn making it possible to for example add a background color to individual cells. The callback function will receive the Table tag, the row and column, the x, y position of the lower left corner of the table and the width and height of the cell.

Parameters
tTable handle
rCell row
cCell column
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_canvas_callback_t
hpdftbl_set_canvas_cb()

Referenced by hpdftbl_set_cell_canvas_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_canvas_dyncb()

int hpdftbl_set_cell_canvas_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback cell canvas function.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCelll row
cCell column
cb_nameName of the function to be used as canvas callback. This function must follow the signature of a callback function as specified in hpdftbl_canvas_callback_t
Returns
See also
hpdftbl_set_cell_canvas_cb(), hpdftbl_canvas_callback_t

◆ hpdftbl_set_cell_content_cb()

int hpdftbl_set_cell_content_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_content_callback_t  cb 
)

Set cell content callback.

Set a content callback for an individual cell. This will override the table content callback. The callback function will receive the Table tag and the row and column for the cell the callback is made for.

Parameters
tTable handle
cbCallback function
rCell row
cCell column
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_set_content_cb()

Referenced by hpdftbl_set_cell_content_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_content_dyncb()

int hpdftbl_set_cell_content_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback cell content function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCell row
cCell column
cb_nameName of the function to be used as content callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_content_cb(), hpdftbl_content_callback_t

◆ hpdftbl_set_cell_content_style_cb()

int hpdftbl_set_cell_content_style_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_content_style_callback_t  cb 
)

Set cell specific callback to specify cell content style.

Set callback to format the style for the specified cell

Parameters
tTable handle
rCell row
cCell column
cbCallback function
Returns
0 on success, -1 on failure
See also
hpdftbl_set_ontent_style_cb()

Referenced by hpdftbl_set_cell_content_style_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_content_style_dyncb()

int hpdftbl_set_cell_content_style_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback for cell style function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. The callback function must have the signature defined by hpdftbl_content_style_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCell row
cCell column
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_style_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_cell_content_style_cb(), hpdftbl_content_style_callback_t

◆ hpdftbl_set_cell_label_cb()

int hpdftbl_set_cell_label_cb ( hpdftbl_t  t,
size_t  r,
size_t  c,
hpdftbl_content_callback_t  cb 
)

Set cell label callback.

Set a label callback for an individual cell. This will override the table label callback. The callback function will receive the Table tag and the row and column for the cell the callback is made for.

Parameters
tTable handle
cbCallback function
rCell row
cCell column
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_set_label_cb()

Referenced by hpdftbl_set_cell_label_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_cell_label_dyncb()

int hpdftbl_set_cell_label_dyncb ( hpdftbl_t  t,
size_t  r,
size_t  c,
const char *  cb_name 
)

Specify dynamic (late) loading callback for cell label function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. The callback function must have the signature defined by hpdftbl_content_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
rCell row
cCell column
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_cell_label_cb(), hpdftbl_content_callback_t

◆ hpdftbl_set_content_cb()

int hpdftbl_set_content_cb ( hpdftbl_t  t,
hpdftbl_content_callback_t  cb 
)

Set table content callback.

This callback gets called for each cell in the table and the returned string will be used as the content. The string will be duplicated so it is safe for a client to reuse the string space. If NULL is returned from the callback then the content will be set to the content specified with the direct content setting. The callback function will receive the Table tag and the row and column for the cell the callback is made for.

Parameters
tTable handle
cbCallback function
Returns
-1 for error , 0 otherwise
See also
hpdftbl_set_cell_content_cb()

Referenced by hpdftbl_set_content_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_content_dyncb()

int hpdftbl_set_content_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback content function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol.

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as content callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_content_cb(), hpdftbl_content_callback_t

◆ hpdftbl_set_content_style_cb()

int hpdftbl_set_content_style_cb ( hpdftbl_t  t,
hpdftbl_content_style_callback_t  cb 
)

Set callback to specify cell content style.

Set callback to format the style for cells in the table. If a cell has its own content style callback that callback will override the generic table callback.

Parameters
tTable handle
cbCallback function
Returns
0 on success, -1 on failure
See also
hpdftbl_set_cell_content_style_cb()

Referenced by hpdftbl_set_content_style_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_content_style_dyncb()

int hpdftbl_set_content_style_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback for table style function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. The callback function must have the signature defined by hpdftbl_content_style_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_style_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_content_style_cb(), hpdftbl_content_style_callback_t

◆ hpdftbl_set_dlhandle()

void hpdftbl_set_dlhandle ( void *  handle)

Set the handle for scope of dynamic function search.

When using late binding (some os _dyncb() functions) the scope for where the runtime searches for the functions can be specified as is discussed in man 3 dlsym. By default the library uses dl_handle which make the library first searches the current image and then all images it was built against.

If the dynamic callbacks are located in a runtime loaded library then the handle returned by dlopen() must be specified as the function will not be found otherwise.

Parameters
handlePredefined values or the handle returned by dlopen() (see man dlopen)

◆ hpdftbl_set_label_cb()

int hpdftbl_set_label_cb ( hpdftbl_t  t,
hpdftbl_content_callback_t  cb 
)

Set table label callback.

Set label callback. This callback gets called for each cell in the table and the returned string will be used as the label. The string will be duplicated so it is safe for a client to reuse the string space. If NULL is returned from the callback then the label will be set to the content specified with the direct label setting. The callback function will receive the Table tag and the row and column

Parameters
tTable handle
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_content_callback_t
hpdftbl_set_cell_label_cb()

Referenced by hpdftbl_set_label_dyncb(), and hpdftbl_stroke_from_data().

◆ hpdftbl_set_label_dyncb()

int hpdftbl_set_label_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Specify dynamic (late) loading callback for table label function.

The dynamic loading of callback function is a runtime binding of the named function as a callback. The library uses the dlsym() loading of external symbols. For the external symbol to be found it can not be defined as a static symbol. symbols. The callback function must have the signature defined by hpdftbl_content_callback_t

In case of error the extrainfo extra information is set to the name of the callback which failed to be resolved at run time. This can be retrieved in an error handler by using the hpdftbl_get_last_err_file() to read it back.

Parameters
tTable handle
cb_nameName of the function to be used as label callback. This function must follow the signature of a callback function as specified in hpdftbl_content_callback_t.
Returns
-1 on failure, 0 on success
See also
hpdftbl_set_label_cb(), hpdftbl_content_callback_t

◆ hpdftbl_set_post_cb()

int hpdftbl_set_post_cb ( hpdftbl_t  t,
hpdftbl_callback_t  cb 
)

Set table post processing callback.

This is an optional post processing callback for anything in general to do after the table has been constructed. The callback happens after the table has been fully constructed and just before it is stroked.

Parameters
tTable handle
cbCallback function
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_callback_t

Referenced by hpdftbl_set_post_dyncb().

◆ hpdftbl_set_post_dyncb()

int hpdftbl_set_post_dyncb ( hpdftbl_t  t,
const char *  cb_name 
)

Set table post processing callback.

This is an optional post processing callback for anything in general to do after the table has been constructed. The callback only gets the table as its first and only argument. The callback happens after the table has been fully constructed and just before it is stroked.

Parameters
tTable handle
cb_nameCallback function name
Returns
-1 on failure, 0 otherwise
See also
hpdftbl_callback_t, hpdftbl_set_post_cb()