Lib:Reference Manual

From GNUpdf

Example sunflower image
Note: This page is automatically generated


Contents

GNU PDF Library Reference

GNU PDF Library Reference

This is the first edition of the GNU PDF Library Reference, updated for libgnupdf version 0.1.

Copyright © 2007, 2008 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".


Overview

Base Layer

Overview

The base layer of the GNU PDF Library provide system-independent access to several facilities.

The implemented facilities are organized into modules. Each module export an API to be used by the client application or other layers of the library. Some modules make use of the facilities implemented in other modules (such as allocation or error functions).

Error Management

The Error module provides procedures for error reporting to the client as well as for error tracing (via debug messages) to developers. Here we also define status types returned by most procedures (there are exceptions though).


Status types

Data Type: pdf_status_t

A status variable. This type of variable is returned by many library functions in order to communicate the status of the performed operation.

The following constants defines the valid values to be hold in a pdf_status_t variable:

Constant: PDF_OK

Success

Constant: PDF_ERROR

A serious error

Constant: PDF_EBADDATA

Invalid or bad arguments

Constant: PDF_ENOMEM

Insufficient memory

Constant: PDF_EEOF

End of file

Constant: PDF_EDIVBYZERO

Divison by zero

Constant: PDF_ENONODE

No node found

Constant: PDF_EINVRANGE

Invalid range

Constant: PDF_ETEXTENC

Error in text encoding

Constant: PDF_ENOMATCH

No matching found

This list will grow as we get closer to a mature state of development.


Error Reporting procedures

Function: void pdf_perror (const pdf_status_t status, const char *str)

Prints the message corresponding to status to stderr followed by str.

Parameters
status

status code

str

a user-defined message

Returns

nothing

Usage example

Function: void pdf_error (const pdf_status_t status, FILE *fd, const char *format, ...)

Prints a message with `fprintf (fd, format, ...)'; if status is nonzero, also prints the corresponding message.

Parameters
status

status code

fd

file descriptor open for writing

format

string format for the message

...

format's arguments

Returns

nothing

Usage example


Debugging procedures

For each layer there is a macro procedure defined. The file name and the line number at which the error ocurred is printed to stderr followed by message.

Macro: PDF_DEBUG_BASE (message, ...)

Macro: PDF_DEBUG_OBJECT (message, ...)

Macro: PDF_DEBUG_DOCUMENT (message, ...)

Macro: PDF_DEBUG_PAGE (message, ...)

Parameters
message

a 'const char*' string

...

message's arguments

Returns

nothing

Usage example

Output format

The output format for these macros is,

GNU PDF:***DEBUG <layer>***:<file-name>:<line-number>: <message>.

For example,

GNU PDF:***DEBUG BASE***:pdf-memory.c:344: insufficient memory.

Memory Allocation

The memory allocation module provides system-independent heap memory allocation and deallocation. The usual malloc/free/realloc schema is used to provide this service.

Function: void* pdf_alloc (const pdf_size_t size)

Allocates heap memory.

Parameters
size

The requested number of octects to allocate.


Returns

A pointer to the newly allocated memory.

If there is not enough available memory to satisfy the petition then NULL is returned.

Usage example

Function: void pdf_dealloc (void *pointer)

Deallocates heap memory.

Parameters
pointer

A pointer pointing to the memory we want to deallocate. The memory to deallocate should have been previously allocated using pdf_alloc.


Returns

None.

Usage Example

Function: void* pdf_realloc (void *pointer, const pdf_size_t size)

Reallocates memory.

Parameters
pointer

A pointer to previously allocated memory.

The memory to reallocate should have been allocated using pdf_alloc or pdf_realloc.

size

The new size of the allocated memory chunk.

If the requested size is shorter than the original size of the allocated memory then it is truncated. Any previous contents in the memory will be lost.

If the requested size is larger or equal than the original size of the allocated memory then the previous contents of the allocated memory remains. The contents of newly allocated memory are undetermined.

If there is not enough available memory to satisfy the petition a fatal error is signaled killing the current process. An error status is returned to the operating system.


Returns

A pointer to the reallocated memory.

Usage Example


Basic Types

Boolean Types

Data Type: pdf_bool_t

A boolean value.

The following constants defines the valid values to be hold in a pdf_bool_t variable:

Constant: PDF_TRUE

Logical true.

Constant: PDF_FALSE

Logical false.


Numeric Types

Data Type: pdf_i32_t

Signed 32 bits integer.

Data Type: pdf_u32_t

Unsigned 32 bits integer.

The following constants are defined in order to define the valid value ranges for these data types:

Constant: PDF_I32_MAX

Maximum value able to be stored in a pdf_i32_t variable.

Constant: PDF_I32_MIN

Minimum value able to be stored in a pdf_i32_t variable.

Constant: PDF_U32_MAX

Maximum value able to be stored in a pdf_u32_t variable.

Constant: PDF_U32_MIN

Minimum value able to be stored in a pdf_u32_t variable.


Big Numbers

An implementation of Big numbers (64 bit) is also provided. These bignums can be used in machines not providing true 64 bit integers.

Data Type: pdf_i64_t

A variable of type pdf_i64_t is capabable of representing 64 bit signed integers.

Function: pdf_i64_t pdf_i64_new (const pdf_i32_t high, const pdf_u32_t low)

Create a new i64 variable from one 32 bit signed integer and a 32 bit unsigned integer.

Parameters
high

The high (signed) part of the 64 bit integer.

low

The low (unsigned) part of the 64 bit integer.

Returns

The newly created i64 object.

Usage example

Function: pdf_status_t pdf_i64_assign (pdf_i64_t *bignum, const pdf_i32_t high, const pdf_u32_t low)

Assign a value coming from one 32 bit signed integer and a 32 bit unsigned integer to a i64 integer.

Parameters
high

The high (signed) part of the 64 bit integer.

low

The low (unsigned) part of the 64 bit integer.

bignum

Variable that stores 64 bit integer

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_assign_quick (pdf_i64_t *bignum, const pdf_i32_t value)

Assign a value coming from one 32 bit signed integer to a i64 integer.

Parameters
value

A signed 32 bit integer

bignum

Variable that stores 64 bit integer

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example


Function: pdf_status_t pdf_i64_copy (const pdf_i64_t orig, pdf_i64_t *copy)

Copies the data from orig to copy.

Parameters
orig

Original variable whose data is to be copied.

copy

Variable where data is copied to.

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_add (pdf_i64_t *dest, const pdf_i64_t addend1, const pdf_i64_t addend2)

Adds two 64 bit numbers

Parameters
addend1

First addend of the sum

addend2

Second addend of the sum

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_add_i32 (pdf_i64_t *dest, const pdf_i64_t addend1, const pdf_i32_t addend2)

Adds a 64bit number and a 32bit number.

Parameters
addend1

First addend of the sum (64bit type)

addend2

Second addend of the sum (32 bit)

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example


Function: pdf_status_t pdf_i64_subtraction (pdf_i64_t *dest, const pdf_i64_t minuend, const pdf_i64_t subtrahend)

Finds the difference between two 64 bit numbers

Parameters
minuend

The minuend of the subtraction

subtrahend

The subtrahend of the subtraction

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_subtraction_i32_min (pdf_i64_t *dest, const pdf_i32_t minuend, const pdf_i64_t subtrahend)

Finds the difference between a 32bit number and a 64bit number

Parameters
minuend

The minuend of the subtraction (32 bits)

subtrahend

The subtrahend of the subtraction (64 bits type)

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example


Function: pdf_status_t pdf_i64_subtraction_i32_sub (pdf_i64_t *dest, const pdf_i64_t minuend, const pdf_i32_t subtrahend)

Finds the difference between a 64bit number and a 32bit number

Parameters
minuend

The minuend of the subtraction (64 bits type)

subtrahend

The subtrahend of the subtraction (32 bits)

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example


Function: pdf_status_t pdf_i64_mult (pdf_i64_t *dest, const pdf_i64_t factor_1, const pdf_i64_t factor_2)

Multiplication of two 64 bit numbers

Parameters
factor_1

First factor in the multiplication

factor_2

Second factor in the multiplication

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_mult_i32 (pdf_i64_t *dest, const pdf_i64_t factor_1, const pdf_i32_t factor_2)

Multiplication of a 64bit number and a 32bit number

Parameters
factor_1

First factor in the multiplication (64 bits)

factor_2

Second factor in the multiplication (32bits)

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_div (pdf_i64_t *dest, const pdf_i64_t dividend, const pdf_i64_t divisor)

Division of two 64 bit numbers

Parameters
dividend

The dividend in the division

divisor

The divisor in the division

dest

Where 64 bit result is stored

Returns

PDF_OK Operation successful

Usage example

Function: pdf_status_t pdf_i64_div_i32_dividend (pdf_i64_t *dest, const pdf_i32_t dividend, const pdf_i64_t divisor)

Division of a 32bit number and a 64bit number

Parameters
dividend

The dividend in the division (64 bits)

divisor

The divisor in the division (32 bits)

dest

Where 64 bit result is stored

Returns

PDF_OK Operation successful

Usage example

Function: pdf_status_t pdf_i64_div_i32_divisor (pdf_i64_t *dest, const pdf_i64_t dividend, const pdf_i32_t divisor)

Division of a 64bit number and a 32bit number

Parameters
dividend

The dividend in the division (64 bits)

divisor

The divisor in the division (32 bits)

dest

Where 64 bit result is stored

Returns

PDF_OK Operation successful

Usage example


Function: pdf_status_t pdf_i64_mod (pdf_i64_t *dest, const pdf_i64_t dividend, const pdf_i64_t divisor)

Returns the remainder of the division between two 64 bit numbers

Parameters
dividend

The dividend in the division

divisor

The divisor in the division

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_mod_i32_dividend (pdf_i64_t *dest, const pdf_i32_t dividend, const pdf_i64_t divisor)

Returns the remainder of the division between a 32bit number and a 64bit number

Parameters
dividend

The dividend in the division (32bits)

divisor

The divisor in the division (64bits)

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_mod_i32_divisor (pdf_i64_t *dest, const pdf_i64_t dividend, const pdf_i32_t divisor)

Returns the remainder of the division between a 64bit number and a 32bit number

Parameters
dividend

The dividend in the division (64 bits)

divisor

The divisor in the division (32 bits)

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_status_t pdf_i64_abs (pdf_i64_t *dest, const pdf_i64_t number)

Returns the absolute value

Parameters
number

pdf_i64_t type variable

dest

Where 64 bit result is stored

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: int pdf_i64_cmp (const pdf_i64_t number_1, const pdf_i64_t number_2)

Compares two 64 bit integers

Parameters
number_1

pdf_i64_t type variable

number_2

pdf_i64_t type variable

Returns

An integer:

0

If numbers are equal

1

If number_1 is greater than number_2

-1

If number_2 is greater than number_1

Usage example

Function: int pdf_i64_cmp_i32 (const pdf_i64_t number_1, const pdf_i32_t number_2)

Compares a 64bit number and a 32bit number

Parameters
number_1

pdf_i64_t type variable

number_2

pdf_i32_t type variable

Returns

An integer:

0

If numbers are equal

1

If number_1 is greater than number_2

-1

If number_2 is greater than number_1

Usage example

Function: pdf_status_t pdf_i64_neg (pdf_i64_t *dest, const pdf_i64_t number)

Changes sign of 64 bit integer

Parameters
number

pdf_i64_t type variable

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example

Function: pdf_i32_t pdf_i64_to_i32 (const pdf_i64_t bignum)

Converts a pdf_i64_t to a 32bit value. If number can't be represented in 32 bits the result is undefined, so should be used with caution.

Parameters
bignum

pdf_i64_t type variable

Returns

A pdf status value:

PDF_OK

Operation successful

Usage example


Hash Tables

Hash Table Types

Data Type: pdf_hash_t

A Hash Table able to store key/value pairs. A key may be any NULL-terminated string.

Data Type: pdf_hash_iterator_t

An iterator over the keys of a Hash Table.

Data Type: void (*pdf_hash_element_dispose_fn_t) (const void *elt)

A function type for disposing hash elements.

Data Type: void (*pdf_hash_key_dispose_fn_t) (const void *key)

A function type for disposing hash keys.


Creating and Destroying Hash Tables

Function: pdf_status_t pdf_hash_create (pdf_hash_key_dispose_fn_t dispose_key_fn, pdf_hash_element_dispose_fn_t dispose_fn, pdf_hash_t *table)

Create a new empty hash table. When some element is removed dispose_fn and dispose_key_fn are called, can be NULL.

Parameters
dispose_key_fn

A pointer to a hash table element key dispose function or NULL.

dispose_fn

A pointer to a hash table element dispose function or NULL.

table

A pointer to a hash table.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENOMEM

Not enough memory.

PDF_EBADDATA

Invalid table pointer.

Usage example

Function: pdf_status_t pdf_hash_destroy (pdf_hash_t *table)

Destroy a hash table. The elements of the table are disposed first.

Parameters
table

A hash table pointer.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

Usage example



Hash Table properties

Function: pdf_size_t pdf_hash_size (const pdf_hash_t table)

Returns the number of entries in table.

Parameters
table

A hash table.

Returns

The number of entries.

Usage example


Working with keys

Function: pdf_bool_t pdf_hash_key_p (const pdf_hash_t table, const char *key)

Returns a boolean value indicating whether an element with key key exists in table.

Parameters
table

A hash table.

key

A valid key string.

Returns

A pdf boolean value:

PDF_TRUE

An element associated with key exists.

PDF_FALSE

There is no element associated with key.

Usage example

Function: pdf_status_t pdf_hash_rename (pdf_hash_t table, const char *key, const char *new_key)

Renames the key key to new_key in table.

Parameters
table

A hash table.

key

A valid key string.

new_key

A valid key string.

Returns

A pdf status value:

PDF_OK

The operation succeded.

PDF_ERROR

The key is not associated with any element in table.

PDF_EBADDATA

Either table or a key string is invalid or NULL.

Usage example


Adding and removing elements

Function: pdf_status_t pdf_hash_add (pdf_hash_t table, const char *key, const void *element)

Adds the element element with the associated key key to table. If key already exists nothing is done.

Parameters
table

A hash table.

key

A valid key string.

element

A pointer to the element being added.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENOMEM

Not enough memory.

PDF_EBADDATA

Either table, key or element is invalid.

Usage example

Function: pdf_status_t pdf_hash_remove (pdf_hash_t table, const char *key)

Removes the element associated with key from table. The element is disposed first.

Parameters
table

A hash table.

key

A valid key string.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EBADDATA

Invalid table or key.

PDF_ERROR

The key wasn't found.

Usage example


Searching elements

Function: pdf_status_t pdf_hash_search (const pdf_hash_t table, const char *key, const void **elem_pointer)

Searches for the element associated with the given key in table and store it in elem_pointer.

Parameters
table

A hash table.

key

A valid null-terminated string key.

elem_pointer

A pointer where to store the element.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EBADDATA

Either elem_pointer is NULL, key or the table is invalid.

PDF_ERROR

The key wasn't found.

Usage example


Working with iterators

Function: pdf_status_t pdf_hash_iterator (const pdf_hash_t table, pdf_hash_iterator_t *iterator)

Creates an iterator over the keys of table and saves it in iterator. Keys composed only by numbers are returned first followed by keys in the order imposed by the "strcmp()" function.

Parameters
table

A hash table.

iterator

A pointer to an iterator.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENOMEM

Not enough memory.

PDF_EBADDATA

Either iterator is NULL or table is invalid.

Usage example

Function: pdf_status_t pdf_hash_iterator_next (pdf_hash_iterator_t *iterator, const char **key)

Retrieves the next key from iterator.

Parameters
iterator

A Hash Table iterator pointer.

key

A pointer where to save the key.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EBADDATA

Either iterator is invalid or key is NULL.

PDF_ERROR

There are no more keys to traverse over.

Usage example

Function: pdf_status_t pdf_hash_iterator_free (pdf_hash_iterator_t *iterator)

Free all resources used by iterator.

Parameters
iterator

A Hash Table iterator pointer.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

Usage example


Lists

This section describes how to work with unsorted and sorted lists. In case you're going to work with a sorted list, you should use the sorted version of each function if it's available. See section Working with sorted lists.


List Data Types

Data Type: pdf_list_t

A list composed by zero or more nodes.

Data Type: pdf_list_node_t

A list node. Each node is able to contain a data structure via a void npointer.

Data Type: pdf_list_iterator_t

A list iterator.

Data Type: bool (*pdf_list_element_equals_fn_t) (const void *elt1, const void *elt2)

A function type for comparing list elements equality. Should return PDF_TRUE in case they are equal and PDF_FALSE otherwise.

Data Type: void (*pdf_list_element_dispose_fn_t) (const void *elt)

A function type for disposing list elements.

Data Type: int (*pdf_list_element_compar_fn_t) (const void *elt1, const void *elt2)

A function type for comparing list elements. Should return an integer less than, equal to, or greater than zero corresponding to whether the first element is considered less than, equal to, or greater than the second element.

Data Type: pdf_size_t (*pdf_list_element_hashcode_fn_t) (const void *elt)

A function type for calculating a Hash code given a list element. Should return the corresponding hash code.


Creating and Destroying Lists

Function: pdf_status_t pdf_list_create (pdf_list_element_equals_fn_t equals_fn, pdf_list_element_dispose_fn_t dispose_fn, const pdf_bool_t allow_duplicates, pdf_list_t *list)

Create a new list containing no elements.

Parameters
equals_fn

A function to compare list elements. It is used in sort operations.

dispose_fn

A function to dispose list elements. It is used when destroying list elements.

allow_duplicates

This parameter indicate if the list is allowed to contain duplicate elements (elements for which equals_fn evaluate to PDF_TRUE).

list

A pointer to a list where the new one will be saved.

Returns

A status variable:

PDF_OK

list contains a new empty list.

PDF_EBADDATA

list points to NULL.

PDF_ERROR

An unexpected error or no memory available.

Usage example

Function: pdf_status_t pdf_list_destroy (pdf_list_t list)

Destroy a list freeing all used resources. The elements of the list are disposed first.

Parameters
list

The list to be destroyed.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

Usage example


Managing List Properties

Function: pdf_size_t pdf_list_size (const pdf_list_t list)

Get the number of elements contained into a given list.

Parameters
list

A list.

Returns

The number of elements inside list.

Usage example


Searching for List Elements

Function: pdf_status_t pdf_list_search (const pdf_list_t list, const void* element, pdf_list_node_t *node)

Search whether an element is already in the list.

Parameters
list

A list.

element

The element to search for.

node

The searched node if it was found.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid node pointer.

Usage example

Function: pdf_status_t pdf_list_search_from (const pdf_list_t list, const pdf_size_t start_index, const void* element, pdf_list_node_t *node)

Search whether an element is already in the list, at a position >= start_index.

Parameters
list

A list.

start_index

Index indicating the begin of the search.

node

The searched node if it was found.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid node pointer.

PDF_EINVRANGE

start_index is greater than the list size or less than 0.

Usage example

Function: pdf_status_t pdf_list_search_from_to (const pdf_list_t list, const pdf_size_t start_index, const pdf_size_t end_index, const void* element, pdf_list_node_t *node)

Search whether an element is already in the list, at a position >= start_index and < end_index.

Parameters
list

A list.

start_index

Index to the first list position to be searched.

end_index

Index to the last list position to be searched.

element

The element to search for.

node

The seached node if it was found.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid node pointer.

PDF_EINVRANGE

start_index or end_index is greater than the list size or less than 0.

Usage example

Function: pdf_status_t pdf_list_next_node (const pdf_list_t list, const pdf_list_node_t node, pdf_list_node_t *next)

Return the node immediately after the given node in the list.

Parameters
list

A list.

node

A node contained in list.

prev

A pointer where the next node will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

Next node not found.

PDF_EBADDATA

Invalid next pointer.

Usage example

Function: pdf_status_t pdf_list_previous_node (const pdf_list_t list, const pdf_list_node_t node, pdf_list_node_t *prev)

Return the node immediately before the given node in the list.

Parameters
list

A list.

node

A node contained in list.

prev

A pointer where the previous node will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

Previous node not found.

PDF_EBADDATA

Invalid prev pointer.

Usage example

Function: pdf_status_t pdf_list_indexof (const pdf_list_t list, const void* element, pdf_size_t *position)

Search whether an element is already in the list.

Parameters
list

A list.

element

A pointer to user data.

position

A pointer where the element position will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid or NULL pointers.

Usage Example

Function: pdf_status_t pdf_list_indexof_from (const pdf_list_t list, const pdf_size_t start_index, const void* element, pdf_size_t *position)

Search whether an element is already in the list, at a position >= start_index.

Parameters
list

A list.

start_index

An index to a position in list.

element

The element to search for.

position

A pointer where the element position will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid or NULL pointers.

PDF_EINVRANGE

start_index or end_index is greater than the list size or less than 0.

Usage example

Function: pdf_status_t pdf_list_indexof_from_to (const pdf_list_t list, const pdf_size_t start_index, const pdf_size_t end_index, const void* element, pdf_size_t *position)

Search whether an element is already in the list, at a position >= start_index and < end_index.

Parameters
list

A list.

start_index

A position in list.

end_index

A position in list.

element

A pointer to some user data.

position

A pointer where the element position will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid or NULL pointers.

PDF_EINVRANGE

start_index or end_index is greater than the list size or less than 0.

Usage example


Setting and Getting List Elements

Function: void * pdf_list_node_value (const pdf_list_t list, const pdf_list_node_t node)

Get the element value represented by a list node.

Parameters
list

A list.

node

A node of list.

Returns

The element value represented by node.

Usage example

Function: pdf_status_t pdf_list_get_at (const pdf_list_t list, const pdf_size_t position, const void **value)

Get the element at a given position in the list.

Parameters
list

A list.

position

A position in list. Must be >= 0 and < pdf_list_size (list).

value

A pointer to which the element will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EINVRANGE

Invalid position

PDF_EBADDATA

Invalid value pointer.

Usage example

Function: pdf_status_t pdf_list_set_at (pdf_list_t list, const pdf_size_t position, const void* element, pdf_list_node_t *node)

Replace the element at a given position in a list.

Parameters
list

A list.

position

A position in list. Must be >= 0 and < pdf_list_size (list).

element

The new element.

node

A pointer to save the node containing the replaced element or NULL.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EINVRANGE

Invalid position range.

PDF_BADDATA

The list do not allow duplicated values and already contain element.

Usage example


Adding and Removing List Elements

Function: pdf_status_t pdf_list_add_first (pdf_list_t list, const void* element, pdf_list_node_t *node)

Add an element as the first element of the list. If node is not NULL then a reference to the newly created node is copied to it.

Parameters
list

A list.

element

A pointer to the user data to be stored as a list element.

node

If non NULL, a list node variable used to contain the added element.

Returns

A PDF status value:

PDF_OK

The element was inserted successfully.

PDF_EBADDATA

The list do not allow duplicated values and already contain element.

Usage example

Function: pdf_status_t pdf_list_add_last (pdf_list_t list, const void* element, pdf_list_node_t *node)

Add an element as the last element of the list. If node is not NULL then a reference to the newly created node is copied to it.

Parameters
list

A list.

element

A pointer to the user data to be stored as a list element.

node

If non NULL, a list node variable used to contain the added element.

Returns

A PDF status value:

PDF_OK

The element was inserted successfully.

PDF_EBADDATA

The list do not allow duplicated values and already contain element.

Usage example

Function: pdf_status_t pdf_list_add_at (pdf_list_t list, const pdf_size_t position, const void* element, pdf_list_node_t *node)

Add an element at a given position in the list.

Parameters
list

A list.

position

A position in the list. Should be >= 0 and <= pdf_list_size (list).

element

A pointer to the user data to be stored as a list element.

node

A pointer to the node where the given element was stored or NULL.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EINVRANGE

Invalid range of given position.

PDF_BADDATA

The list do not allow duplicated values and already contain element.

Usage example

Function: pdf_status_t pdf_list_remove_node (pdf_list_t list, const pdf_list_node_t node)

Remove an element from the list.

Parameters
list

A list.

node

The node to be removed.

Returns

A pdf status value:

PDF_OK

Usage example

Function: pdf_status_t pdf_list_remove_at (pdf_list_t list, const pdf_size_t position)

Remove an element at a given position from the list.

Parameters
list

A list.

position

A position in list. Must be >= 0 and < pdf_list_size (list).

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EINVRANGE

Invalid position range.

Usage example

Function: pdf_status_t pdf_list_remove (pdf_list_t list, const void * element)

Search and remove an element from the lsit.

Parameters
list

A list.

element

The element to be removed.

Returns

A pdf status value:

PDF_OK

element was found in the list and was removed.

PDF_EBADDATA

element was not found in the list.

Usage example


Working with sorted lists

Function: pdf_status_t pdf_list_sorted_add (pdf_list_t list, pdf_list_element_compar_fn_t compar_fn, const void* element, pdf_list_node_t * element_node)

Add an element to the list.

Parameters
list

A list.

compar_fn

A comparision function.

element

A pointer to the user data to be stored as a list element.

element_node

A pointer where the added element node will be saved. Can be NULL.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_EBADDATA

Invalid compar_fn pointer.

Usage example

Function: pdf_status_t pdf_list_sorted_remove (pdf_list_t list, pdf_list_element_compar_fn_t compar_fn, const void * element)

Search and remove an element from the list.

Parameters
list

A list.

compar_fn

A comparision function.

element

The element to be removed.

Returns

A pdf status value:

PDF_OK

element was found in the list and was removed.

PDF_ENONODE

element was not found in the list.

PDF_EBADDATA

Invalid compar_fn.

Usage example

Function: pdf_status_t pdf_list_sorted_search (const pdf_list_t list, pdf_list_element_compar_fn_t compar_fn, const void* element, pdf_list_node_t *node)

Search whether an element is already in the list.

Parameters
list

A list.

compar_fn

A comparision function.

element

The element to search for.

node

The searched node if it was found.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid node pointer or compar_fn.

Usage example

Function: pdf_status_t pdf_list_sorted_search_from_to (const pdf_list_t list, pdf_list_element_compar_fn_t compar_fn, const pdf_size_t start_index, const pdf_size_t end_index, const void* element, pdf_list_node_t *node)

Search whether an element is already in the list, at a position >= start_index and < end_index.

Parameters
list

A list.

compar_fn

A comparision function.

start_index

Index to the first list position to be searched.

end_index

Index to the last list position to be searched.

element

The element to search for.

node

The seached node if it was found.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid node pointer or compar_fn.

PDF_EINVRANGE

start_index or end_index is greater than the list size or less than 0.

Usage example

Function: pdf_status_t pdf_list_sorted_indexof (const pdf_list_t list, pdf_list_element_compar_fn_t compar_fn, const void* element, pdf_size_t *position)

Search whether an element is already in the list.

Parameters
list

A list.

compar_fn

A comparision function.

element

A pointer to user data.

position

A pointer where the element position will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid or NULL pointers.

Usage Example

Function: pdf_status_t pdf_list_sorted_indexof_from_to (const pdf_list_t list, pdf_list_element_compar_fn_t compar_fn, const pdf_size_t start_index, const pdf_size_t end_index, const void* element, pdf_size_t *position)

Search whether an element is already in the list, at a position >= start_index and < end_index.

Parameters
list

A list.

compar_fn

A comparision function.

start_index

A position in list.

end_index

A position in list.

element

A pointer to some user data.

position

A pointer where the element position will be saved.

Returns

A pdf status value:

PDF_OK

The operation succeeded.

PDF_ENONODE

element not found.

PDF_EBADDATA

Invalid or NULL pointers.

PDF_EINVRANGE

start_index or end_index is greater than the list size or less than 0.

Usage example


Working with Iterators

Function: pdf_status_t pdf_list_iterator (const pdf_list_t list, pdf_list_iterator_t *itr)

Create an iterator traversing a list.

The list contents must not be modified while the iterator is in use, except for replacing or removing the last returned element.

Parameters
list

A list.

itr

A pointer to where the new iterator will be saved.

Returns

A status variable:

PDF_OK

itr contains a new iterator for list.

PDF_ENOMEM

There is no memory available for a new iterator.

PDF_EBADDATA

itr points to NULL.

Usage example

Function: pdf_status_t pdf_list_iterator_from_to (const pdf_list_t list, const pdf_size_t start_index, const pdf_size_t end_index, pdf_list_iterator_t *itr)

Create an iterator traversing the element with indices i, start_index <= i < end_index, of a list.

The list contents must not be modified while the iterator is in use, except for replacing or removing the last returned element.

Parameters
list

A list.

start_index

A position in list.

end_index

A position in list.

itr

A pointer to an iterator where the new one will be saved.

Returns

A status variable:

PDF_OK

itr contains a new iterator for list pointing to start_index.

PDF_ENOMEM

There is no memory available for a new iterator.

PDF_EINVRANGE

start_index or end_index is greater than the list size or less than 0.

PDF_EBADDATA

itr points to NULL.

Usage example

Function: pdf_status_t pdf_list_iterator_next (pdf_list_iterator_t *iterator, const void **element_pointer, pdf_list_node_t *node_pointer)

If there is a next element, store the next element in *element_pointer, store its node in *node_pointer if it is non-NULL, and advance the iterator.

Parameters
iterator

A list iterator.

element_pointer

A pointer to a pointer to user data.

node_pointer

A pointer to a list node.

Returns

A pdf status value:

PDF_OK

There is a next element.

PDF_ERROR

There is not a next element.

Usage example

Function: pdf_status_t pdf_list_iterator_free (pdf_list_iterator_t *iterator)

Free an iterator releasing any used resource.

Parameters
iterator

A list iterator.

Returns

A pdf status value:

PDF_OK

Usage example


Filtered Streams

This module provides read/write streams of data to memory buffers and open files adding the following functionality:

  • - Filtering.
  • - Buffering.

Several streams can be created to operate in the same open file. This provides a convenient access to files with several parts requiring different filters to read or write its contents.

Filters (such as the PDF standard ones) are supported for both reading and writing. Many filters may be used in a single stream (those filters are applied in an order when writing and in the inverse order when reading).

The file streams maintain a buffer for both reading and writing. The size of the buffer is specified by the client in creation time. This is used, for example, to provide efficient character-based I/O.

Note that the streams operating in memory buffers do not provide buffering.


Stream Types

Data Type: pdf_stm_t

A stm variable.

Data Type: enum pdf_stm_mode_e

The operation mode of a stm object.

PDF_STM_READ

The stm will be used to read data from the open file or memory buffer.

PDF_STM_WRITE

The stm will be used to write data into the open file or memory buffer.


Creating and Destroying Streams

Function: pdf_status_t pdf_stm_file_new (pdf_fsys_file_t file, enum pdf_stm_mode_e mode, pdf_size_t buffer_size)

Create a new stream operating in a given open file.

Parameters
file

An open file.

mode

The operation mode for the stream.

buffer_size

The desired size for the stream buffer, measured in octects. If it is 0 then the default size (4kb) is used.

Returns

A PDF status value:

PDF_OK

The stream object was successfully created.

PDF_ERROR

There was an error and the stream was not created.

Usage example

Function: pdf_status_t pdf_stm_mem_new (enum pdf_stm_mode_e mode, pdf_size_t size)

Create a new stream operating in a memory buffer.

Parameters
mode

The operation mode for the stream.

size

The desired size for the memory buffer, measured in octects.

Returns

A PDF status value:

PDF_OK

The stream was successfully created.

PDF_ERROR

There was an error and the stream was not created.

Usage example

Function: pdf_status_t pdf_stm_destroy (pdf_stm_t stm)

Destroy a stream freeing all the used resources.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The stream was successfully destroyed.

PDF_ERROR

There was an error destroying the stream.

Usage example


Managing the Filter Chain

Function: pdf_status_t pdf_stm_uninstall_filters (pdf_stm_t stm)

Uninstall any installed filter in a given stream.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The operation succeeded.

Usage example


The following functions can be used to build the filter chain of a given stream.

Function: pdf_status_t pdf_stm_install_null_filter (pdf_stm_t stm)

Add a NULL filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_flatedec_filter (pdf_stm_t stm)

Add a flate decode filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_flateenc_filter (pdf_stm_t stm)

Add a flate encode filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_pred_filter (pdf_stm_t stm, pdf_u32_t predictor, pdf_u32_t colors, pdf_u32_t bits_per_component, pdf_u32_t columns)

Add a PDF or TIFF predictor filter to a stream filter chain.

Parameters
stm

A stream.

predictor

The predictor function to use.

Valid values are:

1

The filter assumes that the normal algorithm was used to encode the data, without prediction.

2

Use the TIFF 2 predictor function.

10

Use the PNG NONE ALL ROWS predictor function.

11

Use the PNG SUB ALL ROWS predictor function.

12

Use the PNG UP ALL ROWS predictor function.

13

Use the PNG AVERAGE ALL ROWS predictor function.

14

Use the PNG Paeth predictor function.

15

Use the PNG optimum predictor function.

colors

The number of colors.

bits_per_component

The number of bits per component (pixel).

columns

The number of columns in each row.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_ahexdec_filter (pdf_stm_t stm)

Add an ASCII Hex decoder filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_ahexenc_filter (pdf_stm_t stm)

Add an ASCII Hex encoder filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_a85dec_filter (pdf_stm_t stm)

Add an ASCII 85 decoder filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_a85enc_filter (pdf_stm_t stm)

Add an ASCII 85 encoder filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_rldec_filter (pdf_stm_t stm)

Add a RL decoder filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_rlenc_filter (pdf_stm_t stm)

Add a RL encoder filter to a stream filter chain.

Parameters
stm

A stream.

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_faxdec_filter (pdf_stm_t stm, pdf_u32_t k, pdf_bool_t end_of_line_p, pdf_bool_t encoded_byte_align_p, pdf_u32_t columns, pdf_u32_t rows, pdf_bool_t end_of_block_p, pdf_bool_t blackls1_p, pdf_u32_t damaged_rows_before_error)

Add a CCITT (FAX) decoder filter to a stream filter chain.

Parameters
stm

A stream.

k

XXX

end_on_line_P

XXX

encoded_byte_align_p

XXX

columns

XXX

rows

XXX

end_of_block_p

XXX

blackls1_p

XXX

damaged_rows_before_error

XXX

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_faxenc_filter (pdf_stm_t stm, pdf_u32_t k, pdf_bool_t end_of_line_p, pdf_bool_t encoded_byte_align_p, pdf_u32_t columns, pdf_u32_t rows, pdf_bool_t end_of_block_p, pdf_bool_t blackls1_p, pdf_u32_t damaged_rows_before_error)

Add a CCITT (FAX) encoder filter to a stream filter chain.

Parameters
stm

A stream.

k

XXX

end_on_line_P

XXX

encoded_byte_align_p

XXX

columns

XXX

rows

XXX

end_of_block_p

XXX

blackls1_p

XXX

damaged_rows_before_error

XXX

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_lzwdec_filter (pdf_stm_t stm, pdf_u32_t early_change)

Add a LZW decoder filter to a stream filter chain.

Parameters
stm

A stream.

early_change

XXX

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example

Function: pdf_status_t pdf_stm_install_lzwenc_filter (pdf_stm_t stm, pdf_u32_t early_change)

Add a LZW encoder filter to a stream filter chain.

Parameters
stm

A stream.

early_change

XXX

Returns

A PDF status value:

PDF_OK

The filter was successfully installed in the stream.

PDF_ERROR

There was an error and the filter was not installed in the stream.

Usage example


Reading and Writing Data

Function: pdf_size_t pdf_stm_read (pdf_stm_t stm, pdf_char_t **buf, pdf_size_t bytes)

Read a chunk of data from a given stream.

Parameters
stm

A stream.

buf

The buffer to hold the readed data.

bytes

The number of octects to read.

Returns

A PDF size value containing the number of octects actually readed. If the returned value is less than bytes then an end of file condition occurred.

Usage example

Function: pdf_size_t pdf_stm_write (pdf_stm_t stm, const pdf_size_t elem_size, const pdf_size_t elem_count, pdf_char_t *buf)

Write a chunk of data into a given stream.

Parameters
stm

A stream.

elem_size

Size (in octects) of the elements to write.

elem_count

Number of elements to write.

buf

The buffer containing the written information.

Returns

A PDF size value containing the number of octects actually readed. If the returned value is less than elem_count * elem_size then a disk full condition has occured.

Usage example

Function: pdf_u32_t pdf_stm_read_char (pdf_stm_t stm)

Read a character from a given stream.

Parameters
stm

A stream.

Returns

An unsigned integer containing PDF_EOF or the readed character code.

Usage example

Function: pdf_u32_t pdf_stm_peek_char (pdf_stm_t stm)

Peek a character from a given stream.

Parameters
stm

A stream.

Returns

An unsigned integer containing PDF_EOF or the peeked character code.

Usage example

Function: pdf_size_t pdf_stm_flush (pdf_stm_t stm)

Flush any pending writing data in a given stream. It is a no-op in a memory stream.

Parameters
stm

A stream.

Returns

A PDF size value containing the number of octects that has been flushed. May be 0.

Usage example


Stream Positioning

Function: pdf_off_t pdf_stm_seek (pdf_stm_t stm, pdf_off_t pos)

Seek into a given stream.

Parameters
stm

A stream.

pos

The position to seek, measured in octects from the beginning of the stream.

Returns

The new position of the stream read/write pointer. If it is equal to the current position then there was an error.

Usage example

Function: pdf_off_t pdf_stm_tell (pdf_stm_t stm)

Get the current position of the read/write pointer of a stream.

Parameters
stm

A stream.

Returns

The current position (measured in octets from the beginning of the stream) of the read/write pointer.

Usage example


Floating Point Arithmetic

Floating Point Types

Data Type: pdf_real_t

A floating-point number.

Data Type: struct pdf_point_s

This structure represents a single point. The coordinates of the point are made using floating point numbers.

pdf_real_t h

Horizontal coordinate.

pdf_real_t v

Vertical coordinate.

Data Type: struct pdf_rect_s

This structure represents a rectangle. It is composed by the coordinates for its four sides.

The rectangle sides should be horizontal and vertical and opposite sides should be parallel.

pdf_real_t left

x coordinate for the left points.

pdf_real_t top

y coordinate for the upper points.

pdf_real_t right

x coordinate for the right points.

pdf_real_t bottom

y coordinate for the bottom points.

Data Type: struct pdf_quad_s

This structure represents a quadrilateral. It is composed by four corners (floating-point points).

pdf_point_t tl

Top-left point.

pdf_point_t tr

Top-right point.

pdf_point_t bl

Bottom-left point.

pdf_point_t br

Bottom-right point.

Data Type: struct pdf_matrix_s

This structure represents a 3x3 matrix.

pdf_real_t a11
pdf_real_t a12
pdf_real_t a13

First row.

pdf_real_t a21
pdf_real_t a22
pdf_real_t a23

Second row.

pdf_real_t a31
pdf_real_t a32
pdf_real_t a33

Third row.


Point Manipulation Functions

Quadrilateral Manipulation Functions

Rectangle Manipulation Functions

Matrix Manipulation Functions

Function: pdf_status_t pdf_fp_matrix_concat (pdf_matrix_t result, const pdf_matrix_t m1, const pdf_matrix_t m2)

Function: pdf_status_t pdf_fp_matrix_invert (pdf_matrix_t result, const pdf_matrix_t m)

Function: pdf_status_t pdf_fp_matrix_transform (pdf_point_t result, const pdf_matrix_t m, const pdf_point_t p)

Function: pdf_status_t pdf_fp_matrix_transform_rect (pdf_rect_t result, const pdf_matrix_t m, const pdf_rect_t rect)


Interpolation Functions

Encoded Text

Text Data Types

Data Type: enum pdf_text_unicode_encoding_e

Enumeration of supported Unicode encodings.

PDF_TEXT_UTF8

UTF-8 encoding.

PDF_TEXT_UTF16_BE

Big Endian UTF-16 encoding.

PDF_TEXT_UTF16_LE

Little Endian UTF-16 encoding.

PDF_TEXT_UTF16_HE

Host Endian UTF-16 encoding (may be little-endian or big-endian).

PDF_TEXT_UTF32_BE

Big Endian UTF-32 encoding.

PDF_TEXT_UTF32_LE

Little Endian UTF-32 encoding.

PDF_TEXT_UTF32_HE

Host Endian UTF-32 encoding (may be little-endian or big-endian).


Data Type: pdf_text_unicode_options_e

Enumeration of extra options to get the contents of a pdf_text_t in a given UNICODE encoding (see function `pdf_text_get_unicode').