libhpdftbl 1.5.0
Table construction library for Haru PDF library
|
Common functions for all unit-test/examples. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <execinfo.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/utsname.h>
#include <hpdf.h>
#include <math.h>
#include <setjmp.h>
#include <time.h>
#include "../src/hpdftbl.h"
Go to the source code of this file.
Macros | |
#define | TESTS_DIR "./tests_libharu/" |
#define | TUTEX_MAIN(_tbl_, _showgrid_) |
Macro to create a main() function to call the table creation function for each example. The name to the table function is given as the first and only argument to the macro. More... | |
Typedefs | |
typedef char ** | content_t |
An array of char pointers. | |
Functions | |
void | setup_hpdf (HPDF_Doc *pdf_doc, HPDF_Page *pdf_page, _Bool addgrid) |
Create a new PDF document with one page in A4 format. More... | |
char * | setup_filename (int argc, char **argv) |
Return a pointer to a static buffer that holds the filename to be used for the PDF page. More... | |
int | stroke_to_file (HPDF_Doc pdf_doc, int argc, char **argv) |
Stroke the created PDF page to a file. More... | |
void | setup_dummy_content (content_t *content, size_t rows, size_t cols) |
Create an array of char pointers to simulate real table data. More... | |
void | setup_dummy_content_label (content_t *content, content_t *labels, size_t rows, size_t cols) |
Create both array of char pointers to simulate real table content as well as an array of simulated labels. More... | |
char * | mkfullpath (char *filename) |
Add the full path to the tests directory as prefix to the supplied filename as argument. More... | |
Variables | |
_Bool | run_as_unit_test = FALSE |
For the case when we use this example as a unit/integration test we do not want data such as dates, times, and system-information to be updated since the checks compare the result to a stored copy of the PDF file. More... | |
jmp_buf | _hpdftbl_jmp_env |
For simulated exception handling. More... | |
Common functions for all unit-test/examples.
DO NOT EDIT examples/unit_test.inc.h. Generated from unit_test.inc.h.in by configure.
#define TUTEX_MAIN | ( | _tbl_, | |
_showgrid_ | |||
) |
Macro to create a main() function to call the table creation function for each example. The name to the table function is given as the first and only argument to the macro.
_tbl_ | The name of the main table creation function to be called. |
_showgrid_ | Set to TRUE to display a dot-grid on the paper, FALSE otherwise. |
char * mkfullpath | ( | char * | filename | ) |
Add the full path to the tests directory as prefix to the supplied filename as argument.
This is needed since it is not possible at compile time to know the location of the tests directory due to the autotools feature of VPATH. This makes it possible to build in a arbitrary separate directory from the source. The autotools support the variable '.' which gets replaced with the actual src directory which makes it possible to find the tests directory.
The replacement happens when the autotools creates unit_test.inc.h
from `unit_test.inc.h.in
with the created "config.status"
filename | The base filename (relative to the tests directory) |
void setup_dummy_content | ( | content_t * | content, |
size_t | rows, | ||
size_t | cols | ||
) |
Create an array of char pointers to simulate real table data.
[out] | content | A pointer to an array of char pointers |
[in] | rows | Number of rows in table |
[in] | cols | Number of columns in table |
void setup_dummy_content_label | ( | content_t * | content, |
content_t * | labels, | ||
size_t | rows, | ||
size_t | cols | ||
) |
Create both array of char pointers to simulate real table content as well as an array of simulated labels.
[out] | content | A pointer to an array of char pointers to represent content in a table |
[out] | labels | A pointer to an array of char pointers to represent labels in a table |
[in] | rows | Number of rows in table |
[in] | cols | Number of columns in table |
char * setup_filename | ( | int | argc, |
char ** | argv | ||
) |
Return a pointer to a static buffer that holds the filename to be used for the PDF page.
The filename is create from the program arguments. If there are no arguments the file name will have the same basename as the program (but with an added "*.pdf" suffix and path "out/".
If there are exactly on argument this will in its entirety (incl path) be taken as the full name for the file.
More than one program argument will generate an error (return NULL)
argc | The main() functions argc argument |
argv | The main() functions argv argument |
Referenced by stroke_to_file().
void setup_hpdf | ( | HPDF_Doc * | pdf_doc, |
HPDF_Page * | pdf_page, | ||
_Bool | addgrid | ||
) |
Create a new PDF document with one page in A4 format.
This initializes a basic PDF document object and a page object that can then be used. A typical calling sequence would be:
The pdf_doc and pdf_page can subsequently be used in the other PDF functions.
By setting the addgrid
to TRUE the paper background will be gridlines with coordinate system units in points. This is very useful to precisely position text and graphics on a page.
[out] | pdf_doc | A pointer The document handle |
[out] | pdf_page | A pointer to a page handle |
[in] | addgrid | Set to TRUE to add coordinate grid lines to the paper (in points) |
int stroke_to_file | ( | HPDF_Doc | pdf_doc, |
int | argc, | ||
char ** | argv | ||
) |
Stroke the created PDF page to a file.
The filename to be used is determined by the setup_filename() function
pdf_doc | The PDF document to be written |
argc | The main() functions argc argument |
argv | The main() functions argv argument |
jmp_buf _hpdftbl_jmp_env |
For simulated exception handling.
This specifies the setjmp() buffer to be used in the error handling routine to jump (via a longjmp()) to a specfied recovery point.
_Bool run_as_unit_test = FALSE |
For the case when we use this example as a unit/integration test we do not want data such as dates, times, and system-information to be updated since the checks compare the result to a stored copy of the PDF file.
When this is true it is used as a flag in, for example, the call-back functions to suppress the printing of dates and times so the result may be compared to the styored versions of the document and not be dependent on a specific time and date.