The low level API extends the High level C API to either fine-tune the report behaviour, or to create a report purely from program code.
Set numeric precision
#The default is 256 bits of floating point precision. The expression string must evaluate to a numeric value, the integer part will be used to set the number of precision bits for numeric calculations.
void ocrpt_set_numeric_precision_bits(opencreport *o, const char *expr_string);
Get numeric precision
#The report XML description may set the numeric precision. This function allows the application to query it.
mpfr_prec_t ocrpt_get_numeric_precision_bits(opencreport *o);
The expression string must evaluate to a string value.
Possible values are: nearest
,
to_minus_inf
,
to_inf
,
to_zero
,
away_from_zero
and
faithful
.
The default is nearest
.
void ocrpt_set_rounding_mode(opencreport *o, const char *expr_string);
Setting up the translation needs two parameters: the so called translation domain and the toplevel directory for the translations. It relies on GNU Gettext.
void ocrpt_bindtextdomain(opencreport *o, const char *domainname, const char *dirname);
Setting up the translation needs two parameters: the so called translation domain and the toplevel directory for the translations. It relies on GNU Gettext. This function allows setting the translation from a supplemental query. The passed in expressions strings must evaluate to string values, with potential fallbacks to plain strings in case of parse errors or if the expressions may be interpreted as query columns but no such column names exist in any query.
void ocrpt_bindtextdomain_from_expr(opencreport *o, const char *domain_expr, const char *dir_expr);
Setting the locale for the report does not affect
the main program or other threads. A locale setting
includes the language and the country. The UTF-8 suffix
is necessary. E.g.: en_GB.UTF-8
or
de_DE.UTF-8
void ocrpt_set_locale(opencreport *o, const char *locale);
This function allows setting the locale from a supplementary query of the report. It is used by the report XML parser code and it's a lower priority setting than the previous function: the application executing the report may need to be run a different locale. The expression string must evaluate to a string value that's a valid locale string.
void ocrpt_set_locale_from_expr(opencreport *o, const char *expr_string);
A customized monetary printing function was implemented for the purposes of the report which MPFR doesn't provide. It is used in OpenCReports both internally and by unit tests.
ssize_t ocrpt_mpfr_strfmon(opencreport *o, char *s, size_t maxsize, const char *format, ...);
The following enum
and
struct
types are used by
OpenCReports for datasources and queries.
enum ocrpt_result_type { OCRPT_RESULT_ERROR, OCRPT_RESULT_STRING, OCRPT_RESULT_NUMBER, OCRPT_RESULT_DATETIME }; struct ocrpt_datasource; typedef struct ocrpt_datasource ocrpt_datasource; struct ocrpt_query; typedef struct ocrpt_query ocrpt_query; struct ocrpt_query_result; typedef struct ocrpt_query_result ocrpt_query_result;
For more details, see Data sources and queries. Multiple queries may use the same data source.
Add a datasource of the specific type to the report handler with the associated source_name, using optional connection parameters.
ocrpt_datasource * ocrpt_datasource_add(opencreport *o, const char *source_name, const char *type, const ocrpt_input_connect_parameter *conn_params);
The pointer to connection parameters can be
NULL for array
,
csv
, json
,
and xml
datasource types.
There are two methods to connect to a MariaDB (or MySQL) database.
The first method uses a MariaDB (MySQL) specific
configuration ini
file and
the group
name in it.
The group
parameter is mandatory
as the main database configuration may also have such
a group section, in which case the separate
optionfile
is not needed.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "group", .param_value = "..." }, { .param_name = "optionfile", .param_value = "..." }, { .param_name = NULL } };
The second method spells out individual connection
parameters. This allows local
and remote database
connections. The dbname
parameter
is mandatory, others are optional.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "dbname", .param_value = "..." }, { .param_name = "host", .param_value = "..." }, { .param_name = "port", .param_value = "..." }, { .param_name = "unix_socket", .param_value = "..." }, { .param_name = "user", .param_value = "..." }, { .param_name = "password", .param_value = "..." }, { .param_name = NULL } };
These connection parameters can be used as XML node attributes, see MariaDB database connection.
There are three methods to connect to a PostgreSQL database.
The first method uses the PostgreSQL specific connection string. It is the only setting and as such, it's mandatory. Its content is almost freeform, with optional elements. See PostgreSQL connection string.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "connstr", .param_value = "..." }, { .param_name = NULL } };
The second method spells out individual connection
parameters. This allows local
database connections on a named socket.
The unix_socket
and
dbname
parameters are mandatory,
others are optional.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "unix_socket", .param_value = "..." }, { .param_name = "dbname", .param_value = "..." }, { .param_name = "user", .param_value = "..." }, { .param_name = "password", .param_value = "..." }, { .param_name = NULL } };
The third method also spells out individual connection
parameters. This allows remote
database connection using the host
and port
parameters. Only the
dbname
parameter is mandatory,
others are optional.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "dbname", .param_value = "..." }, { .param_name = "host", .param_value = "..." }, { .param_name = "port", .param_value = "..." }, { .param_name = "user", .param_value = "..." }, { .param_name = "password", .param_value = "..." }, { .param_name = NULL } };
There are also two optional parameters that control the behaviour of the PostgreSQL driver in OpenCReports, rather than being actual connection parameters to a PostgreSQL server. These parameters may be used with any of the above connection methods.
The parameter
usecursor
may have a boolean value:
true
,
false
,
yes
,
no
, or
a numeric value interpreted
as a boolean value: non-zero
values mean true
,
zero means false
.
When usecursor
is enabled,
the SQL query will be wrapped in
a cursor, and the result is retrieved
in parts. Otherwise, the SQL query is
executed as is and the result is
retrieved in whole.
The default value is usually true
but this can be controlled when OpenCReports is built.
When usecursor
is enabled,
the parameter fetchsize
controls the number of rows retrieved
at once. Default value is 1024.
Using a cursor as a regular SQL query is a PostgreSQL extension. Other SQL databases only allow it in stored procedures. But this allows a trade-off: queries that return a large number of rows may be processed without the risk of running out of memory, with marginally lower performance.
SQL queries added to the same PostgreSQL datasource (connection) will behave the same way. Either all of them are executed as is, or all of them will use a cursor.
These connection parameters can be used as XML node attributes, see PostgreSQL database connection.
There are two methods to connect to an ODBC database.
The first method uses the ODBC specific connection string. It is the only setting, and as such, it's mandatory. Its content is defined by the ODBC knowledge base with optional elements. See Microsoft Open Database Connectivity and Connection string examples .
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "connstr", .param_value = "..." }, { .param_name = NULL } };
The second method spells out some
individual connection parameters. It requires that
an ODBC data source (DSN) is already configured.
Whether the database connections is
local or
remote depends on the
pre-configured DSN. The dbname
parameters is mandatory, others are optional.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "dbname", .param_value = "..." }, { .param_name = "user", .param_value = "..." }, { .param_name = "password", .param_value = "..." }, { .param_name = NULL } };
These connection parameters can be used as XML node attributes, see ODBC database connection.
There is only one connection parameter for spreadsheet based datasources, the file name.
ocrpt_input_connect_parameter conn_params[] = { { .param_name = "filename", .param_value = "..." }, { .param_name = NULL } };
This parameter can be used as an XML node attribute, see Spreadsheet file type.
Find the data source using its name. It returns NULL if the named data source is not found.
ocrpt_datasource * ocrpt_datasource_get(opencreport *o, const char *source_name);
Set the encoding of a datasource
#Set the encoding of a datasource in case if it's not already UTF-8, so data provided by it is automatically converted.
void ocrpt_datasource_set_encoding(ocrpt_datasource *source, const char *encoding);
Free a datasource
#
Free a datasource from the opencreport structure
it was added to. It's not needed to be called,
all datasources are automatically free with
ocrpt_free()
void ocrpt_datasource_free(ocrpt_datasource *source);
Add a direct (application internal) data based query to the report handler.
ocrpt_query * ocrpt_query_add_data(ocrpt_datasource *source, const char *name, const void *data, int32_t rows, int32_t cols, const int32_t *types, int32_t types_cols);
The built-in array
datasource
interprets void *data
as a
two-dimensional array containing pointers to C strings,
a.k.a.
char *array[rows + 1][cols]
The first row of the array are the column (field) names.
The types
array contains
cols
(or fewer) number of
enum ocrpt_result_type
elements to
indicate the column data types.
If the types
pointer is
NULL
, the column values are treated
as string
data. This is how RLIB
worked.
The call is only successful if the datasource is direct data based. See Section 10.1.3.9 and Datasource input driver details.
Add a "symbolic" (discoverable by name) data based query.
ocrpt_query * ocrpt_query_add_symbolic_data(ocrpt_datasource *source, const char *name, const char *data_name, int32_t rows, int32_t cols, const char *types_name, int32_t types_cols);
Symbols of the application can be discovered via
dlsym()
if the application was
built with the compiler option
-rdynamic
.
The call is only successful if the datasource is symbolic data based. See Section 10.1.3.10 and Datasource input driver details.
Add a file based query to the report handler.
ocrpt_query * ocrpt_query_add_file(ocrpt_datasource *source, const char *name, const char *filename, const int32_t *types, int32_t types_cols);
The call is only successful if the datasource is file based. See Section 10.1.3.11 and Datasource input driver details.
The types
array pointer may be NULL.
For file based datasource types that don't support
data type specifiers internally (or they are optional
and omitted), this means that the column values are of
the string
data type. This is how
RLIB worked. In this case, conversion functions like
Section 4.12.4, Section 4.10.16
and Section 4.10.10 are needed to process
the values using their actual data type.
When the types
array pointer is
not NULL, it is used to set the data type specifiers
for built-in file based datasources, even if the file
contains type specifiers.
The JSON file format expected by OpenCReports is defined in JSON file type.
The XML file format expected by OpenCReports is defined in XML file type.
Add an SQL statement based query to the report handler.
ocrpt_query * ocrpt_query_add_sql(ocrpt_datasource *source, const char *name, const char *querystr);
The call is only successful if the datasource is SQL based. See Section 10.1.3.12 and Datasource input driver details.
bool ocrpt_datasource_is_data(ocrpt_datasource *source);
bool ocrpt_datasource_is_symbolic_data(ocrpt_datasource *source);
bool ocrpt_datasource_is_file(ocrpt_datasource *source);
bool ocrpt_datasource_is_sql(ocrpt_datasource *source);
Find a query
#Find a query using its name.
ocrpt_query * ocrpt_query_get(opencreport *o, const char *name);
Get the current data row from a query
#
Create (first call) or get the ocrpt_query_result
array from a query. Output parameter cols
returns the number of columns in the result array. It must
be re-run after ocrpt_navigate_next() since the previously
returned pointer becomes invalid.
ocrpt_query_result * ocrpt_query_get_result(ocrpt_query *q, int32_t *cols);
Get column name
#
Using the ocrpt_query_result *
result
from ocrpt_query_get_result()
,
the column names can be discovered from a query.
const char * ocrpt_query_result_column_name(ocrpt_query_result *qr, int32_t col);
Get column data
#
Using the ocrpt_query_result *
result from
ocrpt_query_get_result()
, get a
pointer to the column data in its internal (hidden)
representation.
ocrpt_result * ocrpt_query_result_column_result(ocrpt_query_result *qr, int32_t col);
Add a follower query
#
Add a follower
query to the
leader
query. The leader is the primary
query and the follower will run in parallel with it until
the leader runs out of rows. In case the leader has more
rows than the follower, then for rows in the leader where
there are no follower rows, the follower fields are set to NULL.
bool ocrpt_query_add_follower(ocrpt_query *leader, ocrpt_query *follower);
Add an N:1 follower query
#
Add an N:1 follower
query to the
leader
query. The leader is the primary
query and rows from the follower will be matched using the
match
expression. If there are multiple
rows in the follower matching the leader row, then the leader
row will be listed that many times. For rows in the leader
where there are no matching rows in the follower, the follower
fields are set to NULL. It is similar to LEFT OUTER
JOIN
in SQL databases. For creating an
ocrpt_expr
expression pointer, see the
next section.
bool ocrpt_query_add_follower_n_to_1(ocrpt_query *leader, ocrpt_query *follower, ocrpt_expr *match);
Call the ocrpt_input::refresh() method for
datasources that support it.
It returns true
if
all queries were successfully refreshed.
bool ocrpt_query_refresh(opencreport *o);
Free a query
#
Free a query and remove it from the report handler.
It's optional. ocrpt_free()
frees
the queries added to the opencreport
structure.
void ocrpt_query_free(ocrpt_query *q);
Start the main query
#
Start query (or query set) navigation.
q
should be the primary query
of the report.
void ocrpt_query_navigate_start(ocrpt_query *q);
Navigate to the next query row
#
Navigate the query (or query set) to the next row. Returns
false
if there was no more rows.
in which case the ocrpt_query_result
arrays for all queries in the query set (returned by
previous ocrpt_query_get_result()
calls contain invalid data.
bool ocrpt_query_navigate_next(ocrpt_query *q);
Navigate use previous/next row
#
These functions expose an implementation
detail of the data traversal in OpenCReports.
There is a 3-row data cache in which there is
always the current row. One past row is kept
so e.g. break boundaries can be detected and
there is one row read-ahead to detect the
end-of-data condition early. These functions
allow to switch back and forth in the 3-row
data cache, making the previous or next row the
"current" one momentarily. The query must always
be the primary query of the report. Used by
unit tests that don't use
ocrpt_execute()
.
void ocrpt_query_navigate_use_prev_row(ocrpt_query *q); void ocrpt_query_navigate_use_next_row(ocrpt_query *q);
API specific data discovery function
#
For direct (application internal) data based data sources
and queries, OpenCReports needs a way to to find the data
pointer and the supplementary type identifier array.
These are language specific. The below ones
are the C specific ones. An override function
is also provided to set a new discovery function.
The discovery function should
return the dimensions for both the (usuall 2D array)
data
and the 1D
types
array.
It also returns whether types
must be freed by the caller.
typedef void (*ocrpt_query_discover_func)(const char *, void **, int32_t *, int32_t *, const char *, void **, int32_t *, bool *); void ocrpt_query_set_discover_func(ocrpt_query_discover_func func); extern ocrpt_query_discover_func ocrpt_query_discover_array; void ocrpt_query_discover_array_c(const char *arrayname, void **array, int32_t *rows, int32_t *cols, const char *typesname, void **types, int32_t *types_cols, bool *free_types);
Note that the C specific generic discovery function
does not and cannot return the array dimensions,
since there is no official API related to
dlsym()
that would return
the size associated with a symbol.
It's up to the application writers to come up
with a smarter (application specific) discovery
function that also returns the array dimensions.
With such a smart discovery function, one can specify
the array and the column types array name without
the related dimensions, i.e. the rows
and cols
specifiers in
Array queries and
File based queries.
Expressions in OpenCReports is explained in the Expressions chapter.
This function parses an expression string and
creates an expression tree. It returns a pointer
to the ocrpt_expr
structure.
If an error occurs, it returns NULL and optionally
returns the error message in err
pointer if it's not NULL
.
ocrpt_expr * ocrpt_expr_parse(opencreport *o, const char *expr_string, char **err);
The returned pointer must be freed with
ocrpt_expr_free()
.
This function parses an expression string,
creates an expression tree and binds it to
a report. It returns a pointer
to the ocrpt_expr
structure.
If an error occurs, it returns NULL and optionally
returns the error message in err
pointer if it's not NULL
.
ocrpt_expr * ocrpt_report_expr_parse(ocrpt_report *r, const char *expr_string, char **err);
The returned pointer is automatically freed by
ocrpt_free()
Free an expression parse tree. If it was bound
to the passed-in ocrpt_report
,
this association is also deleted. Alternatively,
the expression doesn't need to be freed if it was
bound to a report when it was parsed, as it will be
automatically freed when freeing either the report,
or the global opencreport
structure.
void ocrpt_expr_free(ocrpt_expr *e);
Get the original expression string from an expression parse tree.
const char * ocrpt_expr_get_expr_string(ocrpt_expr *e);
This function resolves variable (identifier) references in the expression. This is needed to bind query columns to expressions that use them.
void ocrpt_expr_resolve(ocrpt_expr *e);
This function optimizes an expression so it may needs fewer computation steps during report execution.
void ocrpt_expr_optimize(ocrpt_expr *e);
This function evaluates the expression.
It returns the expression's
ocrpt_result
result structure.
The result must not be freed with
ocrpt_result_free()
.
It will be done by ocrpt_expr_free()
For expressions with query column references,
this function must be called after
ocrpt_query_navigate_next
otherwise the result is not valid.
ocrpt_result * ocrpt_expr_eval(ocrpt_expr *e);
This function returns the expression result
if it was already evaluated.
The result must not be freed with
ocrpt_result_free()
.
It will be done by ocrpt_expr_free()
.
Used by unit tests.
ocrpt_result * ocrpt_expr_get_result(ocrpt_expr *e);
Print an expression tree in its processed form on the standard output. Used by unit tests.
void ocrpt_expr_print(ocrpt_expr *e);
Print an expression tree with subexpressions and their results in its processed form on the standard output. Used by unit tests.
void ocrpt_expr_result_deep_print(ocrpt_expr *e);
This function returns the number of expression nodes. Used by unit tests to validate optimizazion.
int32_t ocrpt_expr_nodes(ocrpt_expr *e);
OpenCReports keeps track of the last three query rows and computes three result values for expressions for internal reasons. These functions initialize the type for either the current result or all results of the expression.
enum ocrpt_result_type { OCRPT_RESULT_ERROR, OCRPT_RESULT_STRING, OCRPT_RESULT_NUMBER, OCRPT_RESULT_DATETIME }; bool ocrpt_expr_init_result(ocrpt_expr *e, enum ocrpt_result_type type); void ocrpt_expr_init_results(ocrpt_expr *e, enum ocrpt_result_type type);
ocrpt_result * ocrpt_expr_make_error_result(ocrpt_expr *e, const char *format, ...);
Set whether the iterative expression's first value is computed from its base expression or from its result expression.
void ocrpt_expr_set_iterative_start_value(ocrpt_expr *e, bool start_with_init);
Get the current value of an expression in a C base type. Used by parsing report description XML files and unit tests.
const char * ocrpt_expr_get_string(ocrpt_expr *e); long ocrpt_expr_get_long(ocrpt_expr *e); double ocrpt_expr_get_double(ocrpt_expr *e);
Used by unit tests.
void ocrpt_expr_set_string(ocrpt_expr *e, const char *s); void ocrpt_expr_set_long(ocrpt_expr *e, long l); void ocrpt_expr_set_double(ocrpt_expr *e, double d);
Expressions use OCRPT_EXPR_RESULTS
number of values. With these functions, any of them
can be set. Used by unit tests.
void ocrpt_expr_set_nth_result_string(ocrpt_expr *e, int which, const char *s); void ocrpt_expr_set_nth_result_long(ocrpt_expr *e, int which, long l); void ocrpt_expr_set_nth_result_double(ocrpt_expr *e, int which, double d);
Compare the current value of an expression with its
previous value and return true
if they are equal. It's used to implement
Report breaks.
bool ocrpt_expr_cmp_results(ocrpt_expr *e);
void ocrpt_expr_set_delayed(ocrpt_expr *e, bool delayed);
If e
contains r.value
,
the expression rvalue
will be used to
resolve this reference.
void ocrpt_expr_set_field_expr(ocrpt_expr *e, ocrpt_expr *rvalue);
The internal type ocrpt_result
holds
values either for query columns or expression results.
The returned pointer must be freed with
ocrpt_result_free()
.
ocrpt_result * ocrpt_result_new(opencreport *o);
enum ocrpt_result_type ocrpt_result_get_type(ocrpt_result *result);
Copy expression result from source to
destination. Both results must have been
created for the same
opencreport
structure,
either explicitly with ocrpt_result_new()
or implicitly with an expression parsed for
this opencreport
structure
or a report structure owned by it.
void ocrpt_result_copy(ocrpt_result *dst, ocrpt_result *src);
Used by unit tests.
void ocrpt_result_print(ocrpt_result *r);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the column value is NULL.
bool ocrpt_result_isnull(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the column value is numeric.
bool ocrpt_result_isnumber(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
get the numeric column value. It returns NULL
if the column is:
not a numeric result
NULL
mpfr_ptr ocrpt_result_get_number(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the column value is string.
bool ocrpt_result_isstring(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
get the string column value. It returns NULL
if the column is
not a string result
NULL
ocrpt_string * ocrpt_result_get_string(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the column value is datetime.
bool ocrpt_result_isdatetime(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
get the datetime column value. It returns NULL
if the column is
not a datetime result
NULL
const struct tm * ocrpt_result_get_datetime(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the datetime column value is interval.
bool ocrpt_result_datetime_is_interval(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the datetime column value has valid date.
bool ocrpt_result_datetime_is_date_valid(ocrpt_result *result);
Using the ocrpt_result *
result from a query column or an expression,
detect whether the datetime column value has valid time.
bool ocrpt_result_datetime_is_time_valid(ocrpt_result *result);
Variables can be created for a report using the API.
Using this function, any variable type except
OCRPT_VARIABLE_CUSTOM
may be created. For a custom variable,
see the next function.
enum ocrpt_var_type { OCRPT_VARIABLE_INVALID, OCRPT_VARIABLE_EXPRESSION, OCRPT_VARIABLE_COUNT, OCRPT_VARIABLE_COUNTALL, OCRPT_VARIABLE_SUM, OCRPT_VARIABLE_AVERAGE, OCRPT_VARIABLE_AVERAGEALL, OCRPT_VARIABLE_LOWEST, OCRPT_VARIABLE_HIGHEST, OCRPT_VARIABLE_CUSTOM }; typedef enum ocrpt_var_type ocrpt_var_type; ocrpt_var * ocrpt_variable_new(ocrpt_report *r, ocrpt_var_type type, const char *name, const char *expr, const char *ignoreexpr, const char *reset_on_break_name, bool precalculate);
Create a custom variable of the specified type with the specified subexpressions.
ocrpt_var * ocrpt_variable_new_full(ocrpt_report *r, enum ocrpt_result_type type, const char *name, const char *baseexpr, const char *ignoreexpr, const char *intermedexpr, const char *intermed2expr, const char *resultexpr, const char *reset_on_break_name, bool precalculate);
Get the type of the variable.
ocrpt_var_type ocrpt_variable_get_type(ocrpt_var *v);
Get subexpressions of a previously created basic or custom variable.
ocrpt_expr * ocrpt_variable_baseexpr(ocrpt_var *v); ocrpt_expr * ocrpt_variable_ignoreexpr(ocrpt_var *v); ocrpt_expr * ocrpt_variable_intermedexpr(ocrpt_var *v); ocrpt_expr * ocrpt_variable_intermed2expr(ocrpt_var *v); ocrpt_expr * ocrpt_variable_resultexpr(ocrpt_var *v);
bool ocrpt_variable_get_precalculate(ocrpt_var *var);
Resolve subexpressions of a variable so it can be evaluated correctly.
void ocrpt_variable_resolve(ocrpt_var *v);
After evaluation, the result is in the
expression returned by
ocrpt_variable_resultexpr()
.
void ocrpt_variable_evaluate(ocrpt_var *v);
Iterate over variables of a report. The first call needs the iterator list pointer to be set to NULL.
ocrpt_var * ocrpt_variable_get_next(ocrpt_report *r, ocrpt_list **list);
Create a break. No need to free it,
ocrpt_free()
does it.
ocrpt_break * ocrpt_break_new(ocrpt_report *r, const char *name);
Set break attributes from expression strings
for headernewpage
and
suppressblank
.
There is a 3rd flag accepted in the report
XML DTD called newpage
which is not represented (ignored) in the API,
because it's also ignored in RLIB and is only
handled for RLIB compatibility.
void ocrpt_break_set_headernewpage(ocrpt_break *br, const char *headernewpage); void ocrpt_break_set_suppressblank(ocrpt_break *br, const char *suppressblank);
headernewpage="yes"
instructs the
layout to render <BreakHeader>
on a new page.
suppressblank="yes"
instructs the
layout to suppress <BreakHeader>
if any of the <BreakField>
s
are NULL
value or an empty string,
if the break field is of the string type.
Get the pointer to the break using its name.
ocrpt_break * ocrpt_break_get(ocrpt_report *r, const char *name);
Get the name of the break using its structure pointer.
const char * ocrpt_break_get_name(ocrpt_break *br);
bool ocrpt_break_add_breakfield(ocrpt_break *br, ocrpt_expr *bf);
Iterate over breaks of a report. The first call needs the iterator list pointer to be set to NULL.
ocrpt_break * ocrpt_break_get_next(ocrpt_report *r, ocrpt_list **list);
The second parameter evaluate
allows skipping evaluating the breakfield values.
(This is an optimization in case it's executed after
ocrpt_break_check_fields()
which
already evaluated the breakfields.)
bool ocrpt_break_check_blank(ocrpt_break *br, bool evaluate);
Add a user defined function by specifying the name, the function pointer that contains the implementation, the number of operands (0 or greater for fixed number or operands, -1 is varying number of operands) and the function mathematical properties that help optimizing it.
bool ocrpt_function_add(opencreport *o, const char *fname, ocrpt_function_call func, void *user_data, int32_t n_ops, bool commutative, bool associative, bool left_associative, bool dont_optimize);
Adding a user defined function with a name of a pre-existing function will override it.
OpenCReports functions are called with the parameters as declared below.
#define OCRPT_FUNCTION_PARAMS \ ocrpt_expr *e, void *user_data
OpenCReports functions may be declared with these convenience symbols below.
#define OCRPT_FUNCTION(name) \ void name(OCRPT_FUNCTION_PARAMS) #define OCRPT_STATIC_FUNCTION(name) \ static void name(OCRPT_FUNCTION_PARAMS)
The above function
(ocrpt_function_add()
)
is called with a function pointer which has
this type:
typedef void (*ocrpt_function_call)(OCRPT_FUNCTION_PARAMS);
const ocrpt_function * ocrpt_function_get(opencreport *o, const char *fname);
In an expression tree, functions are represented as subexpressions with operands. This call may be used by OpenCReports functions to inspect whether the number of operands is in the expected range.
int32_t ocrpt_expr_get_num_operands(ocrpt_expr *e);
This function is used by OpenCReports functions internally to compute the result from its operands.
ocrpt_result * ocrpt_expr_operand_get_result(ocrpt_expr *e, int32_t opnum);
ocrpt_part_column * ocrpt_part_row_new_column(ocrpt_part_row *pr);
ocrpt_report * ocrpt_part_column_new_report(ocrpt_part_column *pd);
Iterators for getting report parts, part rows, columns in rows and reports in columns. Every iterator function must be called the first time with the list pointer set to NULL.
ocrpt_part * ocrpt_part_get_next(opencreport *o, ocrpt_list **list); ocrpt_part_row * ocrpt_part_row_get_next(ocrpt_part *p, ocrpt_list **list); ocrpt_part_column * ocrpt_part_column_get_next(ocrpt_part_row *pr, ocrpt_list **list); ocrpt_report * ocrpt_report_get_next(ocrpt_part_column *pd, ocrpt_list **list);
Set the main query for a report either by the query structure pointer, or from expression. The expression must resolve to a string value, with fallback to a plain string.
void ocrpt_report_set_main_query(ocrpt_report *r, const ocrpt_query *query); void ocrpt_report_set_main_query_from_expr(ocrpt_report *r, const char *expr_string);
See Report query name. Unlike with the XML description, where the first globally declared query is used for the report if its main query is not set, the default via the low level API is unset.
The row number starts from 1.
long ocrpt_report_get_query_rownum(ocrpt_report *r);
void ocrpt_report_evaluate_expressions(ocrpt_report *r);
See Size unit attribute.
The expression string must evaluate to
a string value, where points
will set the layout rendering to use
points for size units.
Any other value will make the layout rendering
use the convoluted RLIB compatible size units,
mostly based on font sizes.
ocrpt_expr * ocrpt_set_size_unit(opencreport *o, const char *expr_string);
The expression also has a getter function, so its result (value) can be queried. Which may be useful, in case it's set in the report XML description and callbacks and the report processing needs to inspect it.
ocrpt_expr * ocrpt_get_size_unit(opencreport *o);
See No query show NoData attribute. The expression string should evaluate to a boolean value.
ocrpt_expr * ocrpt_set_noquery_show_nodata(opencreport *o, const char *expr_string); ocrpt_expr * ocrpt_get_noquery_show_nodata(opencreport *o);
See Report height after last attribute. The expression string should evaluate to a boolean value.
ocrpt_expr * ocrpt_set_report_height_after_last(opencreport *o, const char *expr_string); ocrpt_expr * ocrpt_get_report_height_after_last(opencreport *o);
See Follower match single attribute. The expression string should evaluate to a boolean value.
ocrpt_expr * ocrpt_set_follower_match_single(opencreport *o, const char *expr_string); ocrpt_expr * ocrpt_get_follower_match_single(opencreport *o);
See above and Follower match single attribute. The difference is that the modified behaviour is set directly and immediately. Used by unit tests.
void ocrpt_set_follower_match_single_direct(opencreport *o, bool value); bool ocrpt_get_follower_match_single_direct(opencreport *o);
See Part iterations attribute. The expression string must evaluate to a numeric value.
ocrpt_expr * ocrpt_part_set_iterations(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_iterations(ocrpt_part *p);
See Part font name.
ocrpt_expr * ocrpt_part_set_font_name(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_font_name(ocrpt_part *p);
See Part font size.
ocrpt_expr * ocrpt_part_set_font_size(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_font_size(ocrpt_part *p);
See Paper type.
ocrpt_expr * ocrpt_part_set_paper_type(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_paper_type(ocrpt_part *p);
See Part page orientation.
The expression string must evaluate to a string
value, with possible options of
portrait
and
landscape
. By default,
the part uses portrait
orientation.
ocrpt_expr * ocrpt_part_set_orientation(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_orientation(ocrpt_part *p);
See Margin settings. The margin values must be passed in via strings as they can be expressions.
ocrpt_expr * ocrpt_part_set_top_margin(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_top_margin(ocrpt_part *p); ocrpt_expr * ocrpt_part_set_bottom_margin(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_bottom_margin(ocrpt_part *p); ocrpt_expr * ocrpt_part_set_left_margin(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_left_margin(ocrpt_part *p); ocrpt_expr * ocrpt_part_set_right_margin(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_right_margin(ocrpt_part *p);
See Part suppress attribute. The expression string must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_part_set_suppress(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_suppress(ocrpt_part *p);
See Suppress page header on the first page. The expression string must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_part_set_suppress_pageheader_firstpage(ocrpt_part *p, const char *expr_string); ocrpt_expr * ocrpt_part_get_suppress_pageheader_firstpage(ocrpt_part *p);
See Part row suppress attribute. The expression string must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_part_row_set_suppress(ocrpt_part_row *pr, const char *expr_string); ocrpt_expr * ocrpt_part_row_get_suppress(ocrpt_part_row *pr);
See Part row new page attribute. The expression string must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_part_row_set_newpage(ocrpt_part_row *pr, const char *expr_string); ocrpt_expr * ocrpt_part_row_get_newpage(ocrpt_part_row *pr);
See Part row layout attribute.
The expression string must evaluate
to a string value, with possible options
flow
and
fixed
. This setting
is ignored, it's only accepted for RLIB
compatibility.
ocrpt_expr * ocrpt_part_row_set_layout(ocrpt_part_row *pr, const char *expr_string); ocrpt_expr * ocrpt_part_row_get_layout(ocrpt_part_row *pr);
See Part column suppress attribute. The expression must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_part_column_set_suppress(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_suppress(ocrpt_part_column *pd);
See Part column width attribute. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_part_column_set_width(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_width(ocrpt_part_column *pd);
See Part column height attribute. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_part_column_set_height(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_height(ocrpt_part_column *pd);
See Part column border width. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_part_column_set_border_width(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_border_width(ocrpt_part_column *pd);
See Part column border color. The expression must evaluate to a string value with a valid color name or specification.
ocrpt_expr * ocrpt_part_column_set_border_color(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_border_color(ocrpt_part_column *pd);
See Detail columns. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_part_column_set_detail_columns(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_detail_columns(ocrpt_part_column *pd);
See Column padding. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_part_column_set_column_padding(ocrpt_part_column *pd, const char *expr_string); ocrpt_expr * ocrpt_part_column_get_column_padding(ocrpt_part_column *pd);
See Report suppress attribute. The expression must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_report_set_suppress(ocrpt_report *r, const char *expr_string); ocrpt_expr * ocrpt_report_get_suppress(ocrpt_report *r);
See Report iterations attribute. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_report_set_iterations(ocrpt_report *r, const char *expr_string); ocrpt_expr * ocrpt_report_get_iterations(ocrpt_report *r);
See Report font name. The expression must evaluate to a string value, with fallback to plain string: in case of a parsing error, the value string is taken as is.
ocrpt_expr * ocrpt_report_set_font_name(ocrpt_report *r, const char *expr_string); ocrpt_expr * ocrpt_report_get_font_name(ocrpt_report *r);
See Report font size. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_report_set_font_size(ocrpt_report *r, const char *expr_string); ocrpt_expr * ocrpt_report_get_font_size(ocrpt_report *r);
See Report height. The expression must evaluate to a numeric value.
ocrpt_expr * ocrpt_report_set_height(ocrpt_report *r, const char *expr_string); ocrpt_expr * ocrpt_report_get_height(ocrpt_report *r);
See Report field header priority attribute.
The expression must evaluate to a string
value with the options of high
and low
. Default is
low
.
ocrpt_expr * ocrpt_report_set_fieldheader_priority(ocrpt_report *r, const char *expr_string); ocrpt_expr * ocrpt_report_get_fieldheader_priority(ocrpt_report *r);
Get the part's
<Output>
sections for
<PageHeader>
or <PageFooter>
.
ocrpt_output * ocrpt_layout_part_page_header(ocrpt_part *p); ocrpt_output * ocrpt_layout_part_page_footer(ocrpt_part *p);
Set the report pointer for the part's
<Output>
sections for
<PageHeader>
or <PageFooter>
.
void ocrpt_layout_part_page_header_set_report(ocrpt_part *p, ocrpt_report *r); void ocrpt_layout_part_page_footer_set_report(ocrpt_part *p, ocrpt_report *r);
Get the report's
<Output>
sections for
<NoData>
,
<ReportHeader>
,
<ReportFooter>
,
<FieldHeaders>
or
<FieldDetails>
.
ocrpt_output * ocrpt_layout_report_nodata(ocrpt_report *r); ocrpt_output * ocrpt_layout_report_header(ocrpt_report *r); ocrpt_output * ocrpt_layout_report_footer(ocrpt_report *r); ocrpt_output * ocrpt_layout_report_field_header(ocrpt_report *r); ocrpt_output * ocrpt_layout_report_field_details(ocrpt_report *r);
It is possible to load a report XML descriptor and modify the layout contents defined by it using code.
The first iterator function loops through toplevel
output elements: line, horizontal line, image, barcode.
An abstract opaque pointer type is returned by the
iterator. Further boolean functions determine the
actual element type. The void **iter
pointer must point to a NULL
pointer initially and the iterator function returns
NULL
when there are no more
elements in the output section. Depending on the
boolean function results, the abstract opaque
pointer type can be case to the actual output
element type: ocrpt_line *
,
ocrpt_hline *
,
ocrpt_image *
or
ocrpt_barcode *
.
struct ocrpt_output_element; typedef struct ocrpt_output_element ocrpt_output_element; ocrpt_output_element * ocrpt_output_element_get_next(ocrpt_output *output, ocrpt_list **iter); bool ocrpt_output_element_is_line(ocrpt_output_element *elem); bool ocrpt_output_element_is_hline(ocrpt_output_element *elem); bool ocrpt_output_element_is_image(ocrpt_output_element *elem); bool ocrpt_output_element_is_barcode(ocrpt_output_element *elem);
The second iterator function loops through line
elements: text, image and barcode.
An abstract opaque pointer type is returned by the
iterator. Further boolean functions determine the
actual element type. The void **iter
pointer must point to a NULL
pointer initially and the iterator function returns
NULL
when there are no more
elements in the output section. Depending on the
boolean function results, the abstract opaque
pointer type can be cast to the actual output
element type: ocrpt_text *
,
ocrpt_image *
or
ocrpt_barcode *
.
struct ocrpt_line_element; typedef struct ocrpt_line_element ocrpt_line_element; ocrpt_line_element * ocrpt_line_element_get_next(ocrpt_line *line, void **iter); bool ocrpt_line_element_is_text(ocrpt_line_element *elem); bool ocrpt_line_element_is_image(ocrpt_line_element *elem); bool ocrpt_line_element_is_barcode(ocrpt_line_element *elem);
Get the break's
<Output>
sections for
<BreakHeader>
or
<BreakFooter>
.
ocrpt_output * ocrpt_break_get_header(ocrpt_break *br); ocrpt_output * ocrpt_break_get_footer(ocrpt_break *br);
Note that part (page) header and footer, and report header and footer sections must be constant expressions. Other sections may depend on data derived from query columns. See Expressions.
Set suppression from an expression string.
ocrpt_expr * ocrpt_output_set_suppress(ocrpt_output *output, const char *expr_string); ocrpt_expr * ocrpt_output_get_suppress(ocrpt_output *output);
ocrpt_line * ocrpt_output_add_line(ocrpt_output *output);
Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.
Set the text line's font name from an expression string.
ocrpt_expr * ocrpt_line_set_font_name(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_font_name(ocrpt_line *line);
Set the text line's font size from an expression string.
ocrpt_expr * ocrpt_line_set_font_size(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_font_size(ocrpt_line *line);
Set the text line's bold value from an expression string.
ocrpt_expr * ocrpt_line_set_bold(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_bold(ocrpt_line *line);
Set the text line's italic value from an expression string.
ocrpt_expr * ocrpt_line_set_italic(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_italic(ocrpt_line *line);
Set the text line's suppression value from an expression string.
ocrpt_expr * ocrpt_line_set_suppress(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_suppress(ocrpt_line *line);
Set the text line's text color from an expression string.
ocrpt_expr * ocrpt_line_set_color(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_color(ocrpt_line *line);
Set or get the text line's background color from an expression string.
ocrpt_expr * ocrpt_line_set_bgcolor(ocrpt_line *line, const char *expr_string); ocrpt_expr * ocrpt_line_get_bgcolor(ocrpt_line *line);
Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.
Set the text element's literal value from a string.
ocrpt_expr * ocrpt_text_set_value_string(ocrpt_text *text, const char *string);
Set the text element's value from an expression string.
ocrpt_expr * ocrpt_text_set_value_expr(ocrpt_text *text, const char *expr_string);
The getter function for the text element's value also works when the text value is set as a literal.
ocrpt_expr * ocrpt_text_get_value(ocrpt_text *text);
Set the text element value's delayed property from an expression string.
ocrpt_expr * ocrpt_text_set_value_delayed(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_value_delayed(ocrpt_text *text);
Set the text element's format string from an expression string.
ocrpt_expr * ocrpt_text_set_format(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_format(ocrpt_text *text);
Set the text element's translation from an expression string.
ocrpt_expr * ocrpt_text_set_translate(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_translate(ocrpt_text *text);
OpenCReports will attempt to translate both the format string and the text element's value.
Set the text element's field width from an expression string.
ocrpt_expr * ocrpt_text_set_width(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_width(ocrpt_text *text);
Set the text element's alignment from a string or an expression string.
ocrpt_expr * ocrpt_text_set_alignment(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_alignment(ocrpt_text *text);
String values left
,
right
,
center
and
justified
are
accepted either as is, or as an expression.
Set the text element's text color from an expression string.
ocrpt_expr * ocrpt_text_set_color(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_color(ocrpt_text *text);
Set the text element's background color from an expression string.
ocrpt_expr * ocrpt_text_set_bgcolor(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_bgcolor(ocrpt_text *text);
Set the text element's font name from an expression string.
ocrpt_expr * ocrpt_text_set_font_name(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_font_name(ocrpt_text *text);
Set the text element's font size from an expression string.
ocrpt_expr * ocrpt_text_set_font_size(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_font_size(ocrpt_text *text);
Set the text element's bold value from an expression string.
ocrpt_expr * ocrpt_text_set_bold(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_bold(ocrpt_text *text);
Set the text element's italic value from an expression string.
ocrpt_expr * ocrpt_text_set_italic(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_italic(ocrpt_text *text);
Set the text element's link URL from an expression string.
ocrpt_expr * ocrpt_text_set_link(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_link(ocrpt_text *text);
Set the text element's multiline property from an expression string. The expression must evaluate to a numeric (boolean) value.
ocrpt_expr * ocrpt_text_set_memo(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_memo(ocrpt_text *text);
Set the text element's "wrap at characters"
property from an expression string.
The expression must evaluate to a numeric
(boolean) value. This setting is only used
for multiline fields. When unset or set to
false
, multiline text
fields wrap at word boundaries.
ocrpt_expr * ocrpt_text_set_memo_wrap_chars(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_memo_wrap_chars(ocrpt_text *text);
Set the text element's maximum lines
property from an expression string.
The expression must evaluate to a numeric
value. This setting is only used for multiline
fields. When unset or set to 0
,
the whole content of the multiline field is
rendered. Otherwise, not more than the
maximum lines are rendered from the multiline
field value. The used font size, the field's width
and word/character wrapping influence the
number of lines the field value is rendered into.
ocrpt_expr * ocrpt_text_set_memo_max_lines(ocrpt_text *text, const char *expr_string); ocrpt_expr * ocrpt_text_get_memo_max_lines(ocrpt_text *text);
ocrpt_hline * ocrpt_output_add_hline(ocrpt_output *output);
Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.
Set the horizontal line's size (width) from an expression string.
ocrpt_expr * ocrpt_hline_set_size(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_size(ocrpt_hline *hline);
Set the horizontal line's alignment from
an expression string. Possibly values are
left
,
right
and
center
. Default is
left
alignment.
The alignment is only applied if the line
length is shorter than the designated page
or column width without the margins.
ocrpt_expr * ocrpt_hline_set_alignment(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_alignment(ocrpt_hline *hline);
Set the horizontal line's indentation value from
an expression string. The indentation is used if
left
alignment is set.
ocrpt_expr * ocrpt_hline_set_indentation(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_indentation(ocrpt_hline *hline);
Set the horizontal line's length from an expression string.
ocrpt_expr * ocrpt_hline_set_length(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_length(ocrpt_hline *hline);
Set the horizontal line's font size from
an expression string. It's used in indentation
and length calculations if Size unit attribute
is set to rlib
.
ocrpt_expr * ocrpt_hline_set_font_size(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_font_size(ocrpt_hline *hline);
Set the horizontal line's suppression from an expression string.
ocrpt_expr * ocrpt_hline_set_suppress(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_suppress(ocrpt_hline *hline);
Set the horizontal line's color from an expression string.
ocrpt_expr * ocrpt_hline_set_color(ocrpt_hline *hline, const char *expr_string); ocrpt_expr * ocrpt_hline_get_color(ocrpt_hline *hline);
ocrpt_barcode * ocrpt_output_add_barcode(ocrpt_output *output);
ocrpt_barcode * ocrpt_line_add_barcode(ocrpt_line *line);
Set the barcode's value from an expression string. The expression must evaluate to a string, whose value is the string to be encoded as a barcode.
ocrpt_expr * ocrpt_barcode_set_value(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_value(ocrpt_barcode *bc);
Set the barcode's value delayed from an expression string. The expression must evaluate to a boolean value.
ocrpt_expr * ocrpt_barcode_set_value_delayed(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_value_delayed(ocrpt_barcode *bc);
Set the barcode's suppression value from an expression string. The expression must evaluate to a boolean value.
ocrpt_expr * ocrpt_barcode_set_suppress(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_suppress(ocrpt_barcode *bc);
Default value is false
,
i.e. no suppression.
Set the barcode's type from an expression string.
ocrpt_expr * ocrpt_barcode_set_type(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_type(ocrpt_barcode *bc);
The type may be optional, in which
case it's autodetected and the barcode
is rendered in the format that first
allows the value
string
to be rendered. Possible types (in the order of
autodetection) are:
upc-a
,
ean-13
,
upc-e
,
ean-8
,
isbn
,
code39
,
code39ext
,
code128b
code128c
, or
code128
.
If type
is specified,
the value
is
rendered in that barcode type if
the string is valid for the type.
If value
is invalid
for the specified type
,
or autodetection fails, because the
value
is invalid
for any of the above listed types,
the barcode is not rendered.
Set the barcode's width from an expression string.
ocrpt_expr * ocrpt_barcode_set_width(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_width(ocrpt_barcode *bc);
The width is set according to
Size unit attribute,
either in points (1/72th inch) or
in (monospace) font width units
set by <Line>
.
Set the barcode's height from an expression string.
ocrpt_expr * ocrpt_barcode_set_height(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_height(ocrpt_barcode *bc);
This setting is always in points, i.e.
1/72th of an inch. The line height will
be determined by greatest height
of all the <field>
,
<literal>
and
<Barcode>
fields
in the same <Line>
in a way that the elements of the same line
will appear (approximately) centered vertically.
Set the barcode's line color from an expression string.
ocrpt_expr * ocrpt_barcode_set_color(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_color(ocrpt_barcode *bc);
Set the barcode's background color from an expression string.
ocrpt_expr * ocrpt_barcode_set_bgcolor(ocrpt_barcode *bc, const char *expr_string); ocrpt_expr * ocrpt_barcode_get_bgcolor(ocrpt_barcode *bc);
ocrpt_image * ocrpt_output_add_image(ocrpt_output *output);
Note that settings in the part (page) header and footer sections must be constant expressions. Settings in other sections may depend on data derived from query columns. See Expressions.
Set the image's value (filename) from an expression string.
ocrpt_expr * ocrpt_image_set_value(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_value(ocrpt_image *image);
Set the image's suppression from an expression string.
ocrpt_expr * ocrpt_image_set_suppress(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_suppress(ocrpt_image *image);
Set the image's type from an expression string.
ocrpt_expr * ocrpt_image_set_type(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_type(ocrpt_image *image);
Set the image's width from an expression string. Used when the image is directly added to an output section.
ocrpt_expr * ocrpt_image_set_width(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_width(ocrpt_image *image);
Set the image's width from an expression string. Used when the image is directly added to an output section.
ocrpt_expr * ocrpt_image_set_height(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_height(ocrpt_image *image);
Set the image's alignment from an expression string. Used when the image is added to text line.
ocrpt_expr * ocrpt_image_set_alignment(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_alignment(ocrpt_image *image);
Set the image's background color from an expression string.
ocrpt_expr * ocrpt_image_set_bgcolor(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_bgcolor(ocrpt_image *image);
Set the image's field width from an expression string. Used when the image is added to a text line.
ocrpt_expr * ocrpt_image_set_text_width(ocrpt_image *image, const char *expr_string); ocrpt_expr * ocrpt_image_get_text_width(ocrpt_image *image);
void ocrpt_output_add_image_end(ocrpt_output *output);
Certain stages of the report execution can notify the application about the stage being executed or finished.
Every "add a callback" function below return
true
for success,
false
for failure.
typedef void (*ocrpt_part_cb)(opencreport *, ocrpt_part *, void *data); bool ocrpt_add_part_added_cb(opencreport *o, ocrpt_part_cb func, void *data);
typedef void (*ocrpt_report_cb)(opencreport *, ocrpt_report *, void *data); bool ocrpt_add_report_added_cb(opencreport *o, ocrpt_report_cb func, void *data);
typedef void (*ocrpt_cb)(opencreport *, void *data); bool ocrpt_add_precalculation_done_cb(opencreport *o, ocrpt_cb func, void *data);
bool ocrpt_part_add_iteration_cb(ocrpt_part *r, ocrpt_part_cb func, void *data); bool ocrpt_part_add_iteration_cb2(opencreport *o, ocrpt_part_cb func, void *data);
The second variant adds the callback in the
opencreport
structure
context, making the callback apply to
every report part. It's for RLIB compatibility.
bool ocrpt_report_add_start_cb(ocrpt_report *r, ocrpt_report_cb func, void *data); bool ocrpt_report_add_start_cb2(opencreport *o, ocrpt_report_cb func, void *data);
The second variant adds the callback in the
opencreport
structure
context, making the callback apply to
every report. It's for RLIB compatibility.
bool ocrpt_report_add_done_cb(ocrpt_report *r, ocrpt_report_cb func, void *data); bool ocrpt_report_add_done_cb2(opencreport *o, ocrpt_report_cb func, void *data);
The second variant adds the callback in the
opencreport
structure
context, making the callback apply to
every report. It's for RLIB compatibility.
bool ocrpt_report_add_new_row_cb(ocrpt_report *r, ocrpt_report_cb func, void *data); bool ocrpt_report_add_new_row_cb2(opencreport *o, ocrpt_report_cb func, void *data);
The second variant adds the callback in the
opencreport
structure
context, making the callback apply to
every report. It's for RLIB compatibility.
bool ocrpt_report_add_iteration_cb(ocrpt_report *r, ocrpt_report_cb func, void *data); bool ocrpt_report_add_iteration_cb2(opencreport *o, ocrpt_report_cb func, void *data);
The second variant adds the callback in the
opencreport
structure
context, making the callback apply to
every report. It's for RLIB compatibility.
bool ocrpt_report_add_precalculation_done_cb(ocrpt_report *r, ocrpt_report_cb func, void *data); bool ocrpt_report_add_precalculation_done_cb2(opencreport *o, ocrpt_report_cb func, void *data);
The second variant adds the callback in the
opencreport
structure
context, making the callback apply to
every report. It's for RLIB compatibility.
typedef void (*ocrpt_break_trigger_cb)(opencreport *, ocrpt_report *, ocrpt_break *, void *); bool ocrpt_break_add_trigger_cb(ocrpt_break *br, ocrpt_break_trigger_cb func, void *data);
typedef ocrpt_result * (*ocrpt_env_query_func)(opencreport *, const char *); extern ocrpt_env_query_func ocrpt_env_get;
void ocrpt_env_set_query_func(ocrpt_env_query_func func);
ocrpt_result * ocrpt_env_get_c(opencreport *o, const char *env);
Set an "m" domain variable.
If such a variable name
didn't exist yet, and value
is not NULL
, then
the variable is set. If value
is NULL
, the variable is
removed. Such an explicit variable takes
precedence over the environment variable
of the same name when used in expressions.
void ocrpt_set_mvariable(opencreport *o, const char *name, const char *value);
The returned path contains only single directory separators and doesn't contains symlinks.
char * ocrpt_canonicalize_path(const char *path);
Add a new directory path to the list of search paths. It's useful to find files referenced with relative path.
void ocrpt_add_search_path(opencreport *o, const char *path);
Add a new directory path from an expression string
to the list of search paths. It's useful to find
files referenced with relative path.
The expression must evaluate to a string value.
It is evaluated at the beginning of the report
execution. This function may be used explicitly
but it's also used when parsing the
<Path>
nodes in a
report XML description.
void ocrpt_add_search_path_from_expr(opencreport *o, const char *expr_string);
Resolve expressions added by
ocrpt_add_search_path_from_expr()
.
It's used internally when executing the report.
void ocrpt_resolve_search_paths(opencreport *o);
Find a file and return the canonicalized path to it. This function takes the search paths into account.
char * ocrpt_find_file(opencreport *o, const char *filename);
Note that search paths added by
ocrpt_add_search_path()
and ocrpt_add_search_path_from_expr()
are used in their order of appearance when searching
for files during executing the report.
The function fills in the
ocrpt_color
structure with
RGB values in Cairo values (0.0 ... 1.0).
If the color name starts with
#
or 0x
or
0X
then it must be in HTML
notation.
Otherwise, the color name is looked up in the color name database in a case insensitive way. If found, the passed-in ocrpt_color structure is filled with the RGB color value of that name.
If not found or the passed-in color name is NULL,
depending on the the expected usage (foreground
or background color), the ocrpt_color
structure is filled with either white or black.
void ocrpt_get_color(opencreport *o, const char *cname, ocrpt_color *color, bool bgcolor);
Paper size in OpenCReports is handled via libpaper.
This structure is used in OpenCReports to represent paper name and size:
struct ocrpt_paper { const char *name; double width; double height; }; typedef struct ocrpt_paper ocrpt_paper;
const ocrpt_paper * ocrpt_get_paper_by_name(const char *paper);
Set global paper using an
ocrpt_paper
structure.
The contents of the structure is copied.
void ocrpt_set_paper(opencreport *o, const ocrpt_paper *paper);
Set paper for the report using a paper name. If the paper name is unknown, the system default paper is set.
void ocrpt_set_paper_by_name(opencreport *o, const char *paper);
Get the next ocrpt_paper
structure
in the iterator. For the first call, the iterator
pointer must be NULL. It returns NULL when there are
no more papers known to the system.
const ocrpt_paper * ocrpt_paper_next(opencreport *o, void **iter);
Memory handling is done through an indirection, to help with bindings (that may do their own memory handling) override the default.
typedef void * (*ocrpt_mem_malloc_t)(size_t); typedef void * (*ocrpt_mem_realloc_t)(void *, size_t); typedef void * (*ocrpt_mem_reallocarray_t)(void *, size_t, size_t); typedef void (*ocrpt_mem_free_t)(const void *); typedef char * (*ocrpt_mem_strdup_t)(const char *); typedef char * (*ocrpt_mem_strndup_t)(const char *, size_t); typedef void (*ocrpt_mem_free_size_t)(void *, size_t); extern ocrpt_mem_malloc_t ocrpt_mem_malloc0; extern ocrpt_mem_realloc_t ocrpt_mem_realloc0; extern ocrpt_mem_reallocarray_t ocrpt_mem_reallocarray0; extern ocrpt_mem_free_t ocrpt_mem_free0; extern ocrpt_mem_strdup_t ocrpt_mem_strdup0; extern ocrpt_mem_strndup_t ocrpt_mem_strndup0;
void * ocrpt_mem_reallocarray(void *ptr, size_t nmemb, size_t sz);
void * ocrpt_mem_strndup(const char *ptr, size_t sz);
It'a convenience alias for
ocrpt_mem_free()
.
void ocrpt_strfree(const char *s);
void ocrpt_mem_set_alloc_funcs(ocrpt_mem_malloc_t rmalloc, ocrpt_mem_realloc_t rrealloc, ocrpt_mem_reallocarray_t rreallocarray, ocrpt_mem_free_t rfree, ocrpt_mem_strdup_t rstrdup, ocrpt_mem_strndup_t rstrndup);
These functions implement a single linked list. The list element structure is hidden:
struct ocrpt_list; typedef struct ocrpt_list ocrpt_list;
This function can be used with variable number of arguments.
ocrpt_list * ocrpt_makelist(const void *data1, ...);
ocrpt_list * ocrpt_list_nth(const ocrpt_list *l, uint32_t n);
ocrpt_list * ocrpt_list_append(ocrpt_list *l, const void *data);
This function make appending to the list work O(1) instead of O(n).
ocrpt_list * ocrpt_list_end_append(ocrpt_list *l, ocrpt_list **e, const void *data);
ocrpt_list * ocrpt_list_prepend(ocrpt_list *l, const void *data);
ocrpt_list * ocrpt_list_remove(ocrpt_list *l, const void *data);
ocrpt_list * ocrpt_list_end_remove(ocrpt_list *l, ocrpt_list **endptr, const void *data);
This can be used to iterate through a list.
It returns NULL
if the
passed-in link is the last list in the list
or it's an empty list.
ocrpt_list * ocrpt_list_next(ocrpt_list *l);
void ocrpt_list_free_deep(ocrpt_list *l, ocrpt_mem_free_t freefunc);
For memory safety and higher performance, a wrapper structure is used over C functions.
struct ocrpt_string { char *str; size_t allocated_len; size_t len; }; typedef struct ocrpt_string ocrpt_string;
Create a new string from a C string. The ownership of the input string may be taken over, or the original string's contents are copied.
ocrpt_string * ocrpt_mem_string_new(const char *str, bool copy);
Create a new string with specified allocated length so future growth can be done without reallocation. The input string is always copied.
ocrpt_string * ocrpt_mem_string_new_with_len(const char *str, size_t len);
ocrpt_string * ocrpt_mem_string_new_vnprintf(size_t len, const char *format, va_list va);
ocrpt_string * ocrpt_mem_string_new_printf(const char *format, ...);
Resize the string to the specified allocated length.
ocrpt_string * ocrpt_mem_string_resize(ocrpt_string *string, size_t len);
void ocrpt_mem_string_append_len(ocrpt_string *string, const char *str, const size_t len);
void ocrpt_mem_string_append_len_binary(ocrpt_string *string, const char *str, const size_t len);
void ocrpt_mem_string_append(ocrpt_string *string, const char *str);
void ocrpt_mem_string_append_c(ocrpt_string *string, const char c);
void ocrpt_mem_string_append_printf(ocrpt_string *string, const char *format, ...);