libhpdftbl 1.5.0
Table construction library for Haru PDF library
|
Functions for json serializing of table data structure. More...
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <hpdf.h>
#include "hpdftbl.h"
#include <jansson.h>
Macros | |
#define | jsonprint(...) if( _string_ ) { sprintf (_sbuff_, __VA_ARGS__);size_t _len_=xstrlcat(_jsonbuff_,_sbuff_,_jsonbuff_size_); if(_len_>=_jsonbuff_size_) return -1;} else {fprintf(fh,__VA_ARGS__);} |
#define | OUTJSON_NEWBLK() do { jsonprint("%*s{\n", tab,""); } while(0) |
#define | OUTJSON_ENDDOC() do { jsonprint( "}\n"); } while(0) |
#define | OUTJSON_INDENT() do { jsonprint( "%*s", tab,""); } while(0) |
#define | OUTJSON_NEWLINE() do { jsonprint( "\n"); } while(0) |
#define | OUTJSON_STRINT(k, v, e) do { jsonprint( "%*s\"%s\": %d%c\n",tab,"",k,(int)v,e); } while(0) |
#define | OUTJSON_STRREAL(k, v, e) do { jsonprint( "%*s\"%s\": %.8f%c\n",tab,"",k,v,e); } while(0) |
#define | OUTJSON_STRSTR(k, v) do { if( v==NULL ) {jsonprint( "%*s\"%s\": \"\",\n",tab,"",k) } else { jsonprint( "%*s\"%s\": \"%s\",\n",tab,"",k,v);} } while(0) |
#define | OUTJSON_STRBLK(k) do { jsonprint( "%*s\"%s\": {\n",tab,"",k); } while(0) |
#define | OUTJSON_STRLIST(k) do { jsonprint( "%*s\"%s\": [\n",tab,"",k); } while(0) |
#define | OUTJSON_ENDLIST(e) do { jsonprint( "\n%*s]%c\n",tab,"",e); } while(0) |
#define | OUTJSON_STARTBLK() do { jsonprint( "%*s{\n",tab,""); } while(0) |
#define | OUTJSON_ENDBLK(c) do { jsonprint( "%*s}%c\n",tab,"",c); } while(0) |
#define | OUTJSON_BOOL(k, v) do { if(v) { jsonprint( "%*s\"%s\": true,\n",tab,"",k);} else { jsonprint( "%*s\"%s\": false,\n",tab,"",k);} } while(0) |
#define | OUTJSON_RGB(k, v) do { jsonprint( "%*s\"%s\": [%.5f, %.5f, %.5f],\n",tab,"",k,v.r,v.g,v.b); } while(0) |
#define | OUTJSON_GRID(k, v) |
#define | OUTJSON_TXTSTYLE(k, v, c) |
Functions | |
int | hpdftbl_theme_dump (hpdftbl_theme_t *theme, char *filename) |
Serialize the specified theme structure to a named file. More... | |
int | hpdftbl_theme_dumps (hpdftbl_theme_t *theme, char *buff, const size_t buffsize) |
Serialize theme structure to a string buffer. More... | |
int | hpdftbl_dump (hpdftbl_t tbl, char *filename) |
Serialize a table structure as a JSON file. More... | |
int | hpdftbl_dumps (hpdftbl_t tbl, char *buff, size_t buffsize) |
Serialize a table structure to a string buffer. More... | |
Functions for json serializing of table data structure.
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.
#define OUTJSON_GRID | ( | k, | |
v | |||
) |
#define OUTJSON_TXTSTYLE | ( | k, | |
v, | |||
c | |||
) |
int hpdftbl_dump | ( | hpdftbl_t | tbl, |
char * | filename | ||
) |
Serialize a table structure as a JSON file.
The table is serialized as JSON file and have whitespaces and newlines to make it more human readable. The serialization is a complete representation of a table.
tbl | Table handle |
filename | Filename to write to. Any path specified must exists |
int hpdftbl_dumps | ( | hpdftbl_t | tbl, |
char * | buff, | ||
size_t | buffsize | ||
) |
Serialize a table structure to a string buffer.
The table is serialized as JSON and have whitespaces and newlines to make it more human readable. Note is is the callers responsibility to make sure the buffer is large enough to hold the serialized table.
tbl | Table handle of table to dump |
buff | Buffer to dump structure to |
buffsize | Size of buffer |
Referenced by hpdftbl_dump().
int hpdftbl_theme_dump | ( | hpdftbl_theme_t * | theme, |
char * | filename | ||
) |
Serialize the specified theme structure to a named file.
The theme is serialized as JSON string array and have whitespaces and newlines to make it more human readable.
theme | Pointer to theme structure to be serialized |
filename | Filename to write to |
int hpdftbl_theme_dumps | ( | hpdftbl_theme_t * | theme, |
char * | buff, | ||
const size_t | buffsize | ||
) |
Serialize theme structure to a string buffer.
The theme is serialized as JSON string array and have whitespaces and newlines to make it more human readable.
theme | Theme to serialize |
buff | Buffer to write serialized theme to. It should be a minimum of 2k chars. |
buffsize | Buffer size (including ending string NULL) |
Referenced by hpdftbl_theme_dump().