mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2025-04-30 04:16:46 +02:00
Modifications asked.
pdfioDictGetNumKeys -> pdfioDictGetNumPairs pdfioDictGetKeyByIndex: - only return the key string and then only return a const char * test_mod.c: - changed to contemplate the requested modification
This commit is contained in:
parent
ff6c402136
commit
0a1fe0ce73
100
pdfio-dict.c
100
pdfio-dict.c
@ -9,27 +9,23 @@
|
|||||||
|
|
||||||
#include "pdfio-private.h"
|
#include "pdfio-private.h"
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Local functions...
|
// Local functions...
|
||||||
//
|
//
|
||||||
|
|
||||||
static int compare_pairs(_pdfio_pair_t *a, _pdfio_pair_t *b);
|
static int compare_pairs(_pdfio_pair_t *a, _pdfio_pair_t *b);
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictClear()' - Remove a key/value pair from a dictionary.
|
// '_pdfioDictClear()' - Remove a key/value pair from a dictionary.
|
||||||
//
|
//
|
||||||
|
|
||||||
void
|
void _pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
|
||||||
_pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
|
|
||||||
const char *key) // I - Key
|
const char *key) // I - Key
|
||||||
{
|
{
|
||||||
size_t idx; // Index into pairs
|
size_t idx; // Index into pairs
|
||||||
_pdfio_pair_t *pair, // Current pair
|
_pdfio_pair_t *pair, // Current pair
|
||||||
pkey; // Search key
|
pkey; // Search key
|
||||||
|
|
||||||
|
|
||||||
PDFIO_DEBUG("_pdfioDictClear(dict=%p, key=\"%s\")\n", dict, key);
|
PDFIO_DEBUG("_pdfioDictClear(dict=%p, key=\"%s\")\n", dict, key);
|
||||||
|
|
||||||
// See if the key is already set...
|
// See if the key is already set...
|
||||||
@ -52,7 +48,6 @@ _pdfioDictClear(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictCopy()' - Copy a dictionary to a PDF file.
|
// 'pdfioDictCopy()' - Copy a dictionary to a PDF file.
|
||||||
//
|
//
|
||||||
@ -67,7 +62,6 @@ pdfioDictCopy(pdfio_file_t *pdf, // I - PDF file
|
|||||||
const char *key; // Current destination key
|
const char *key; // Current destination key
|
||||||
_pdfio_value_t v; // Current destination value
|
_pdfio_value_t v; // Current destination value
|
||||||
|
|
||||||
|
|
||||||
PDFIO_DEBUG("pdfioDictCopy(pdf=%p, dict=%p(%p))\n", pdf, dict, dict ? dict->pdf : NULL);
|
PDFIO_DEBUG("pdfioDictCopy(pdf=%p, dict=%p(%p))\n", pdf, dict, dict ? dict->pdf : NULL);
|
||||||
|
|
||||||
// Create the new dictionary...
|
// Create the new dictionary...
|
||||||
@ -119,7 +113,6 @@ pdfioDictCopy(pdfio_file_t *pdf, // I - PDF file
|
|||||||
return (ndict);
|
return (ndict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictCreate()' - Create a dictionary to hold key/value pairs.
|
// 'pdfioDictCreate()' - Create a dictionary to hold key/value pairs.
|
||||||
//
|
//
|
||||||
@ -129,7 +122,6 @@ pdfioDictCreate(pdfio_file_t *pdf) // I - PDF file
|
|||||||
{
|
{
|
||||||
pdfio_dict_t *dict; // New dictionary
|
pdfio_dict_t *dict; // New dictionary
|
||||||
|
|
||||||
|
|
||||||
if (!pdf)
|
if (!pdf)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
@ -157,7 +149,6 @@ pdfioDictCreate(pdfio_file_t *pdf) // I - PDF file
|
|||||||
return (dict);
|
return (dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictDecrypt()' - Decrypt the values in a dictionary.
|
// '_pdfioDictDecrypt()' - Decrypt the values in a dictionary.
|
||||||
//
|
//
|
||||||
@ -171,7 +162,6 @@ _pdfioDictDecrypt(pdfio_file_t *pdf, // I - PDF file
|
|||||||
size_t i; // Looping var
|
size_t i; // Looping var
|
||||||
_pdfio_pair_t *pair; // Current pair
|
_pdfio_pair_t *pair; // Current pair
|
||||||
|
|
||||||
|
|
||||||
for (i = dict->num_pairs, pair = dict->pairs; i > 0; i--, pair++)
|
for (i = dict->num_pairs, pair = dict->pairs; i > 0; i--, pair++)
|
||||||
{
|
{
|
||||||
if (strcmp(pair->key, "ID") && !_pdfioValueDecrypt(pdf, obj, &pair->value, depth + 1))
|
if (strcmp(pair->key, "ID") && !_pdfioValueDecrypt(pdf, obj, &pair->value, depth + 1))
|
||||||
@ -181,19 +171,16 @@ _pdfioDictDecrypt(pdfio_file_t *pdf, // I - PDF file
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictDebug()' - Dump a dictionary to stderr.
|
// '_pdfioDictDebug()' - Dump a dictionary to stderr.
|
||||||
//
|
//
|
||||||
|
|
||||||
void
|
void _pdfioDictDebug(pdfio_dict_t *dict, // I - Dictionary
|
||||||
_pdfioDictDebug(pdfio_dict_t *dict, // I - Dictionary
|
|
||||||
FILE *fp) // I - Output file
|
FILE *fp) // I - Output file
|
||||||
{
|
{
|
||||||
size_t i; // Looping var
|
size_t i; // Looping var
|
||||||
_pdfio_pair_t *pair; // Current pair
|
_pdfio_pair_t *pair; // Current pair
|
||||||
|
|
||||||
|
|
||||||
for (i = dict->num_pairs, pair = dict->pairs; i > 0; i--, pair++)
|
for (i = dict->num_pairs, pair = dict->pairs; i > 0; i--, pair++)
|
||||||
{
|
{
|
||||||
fprintf(fp, "/%s", pair->key);
|
fprintf(fp, "/%s", pair->key);
|
||||||
@ -201,13 +188,11 @@ _pdfioDictDebug(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictDelete()' - Free the memory used by a dictionary.
|
// '_pdfioDictDelete()' - Free the memory used by a dictionary.
|
||||||
//
|
//
|
||||||
|
|
||||||
void
|
void _pdfioDictDelete(pdfio_dict_t *dict) // I - Dictionary
|
||||||
_pdfioDictDelete(pdfio_dict_t *dict) // I - Dictionary
|
|
||||||
{
|
{
|
||||||
if (dict)
|
if (dict)
|
||||||
{
|
{
|
||||||
@ -226,7 +211,6 @@ _pdfioDictDelete(pdfio_dict_t *dict) // I - Dictionary
|
|||||||
free(dict);
|
free(dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetArray()' - Get a key array value from a dictionary.
|
// 'pdfioDictGetArray()' - Get a key array value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -237,14 +221,12 @@ pdfioDictGetArray(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_ARRAY)
|
if (value && value->type == PDFIO_VALTYPE_ARRAY)
|
||||||
return (value->value.array);
|
return (value->value.array);
|
||||||
else
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetBinary()' - Get a key binary string value from a dictionary.
|
// 'pdfioDictGetBinary()' - Get a key binary string value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -256,7 +238,6 @@ pdfioDictGetBinary(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (!length)
|
if (!length)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
@ -277,7 +258,6 @@ pdfioDictGetBinary(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetBoolean()' - Get a key boolean value from a dictionary.
|
// 'pdfioDictGetBoolean()' - Get a key boolean value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -288,14 +268,12 @@ pdfioDictGetBoolean(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_BOOLEAN)
|
if (value && value->type == PDFIO_VALTYPE_BOOLEAN)
|
||||||
return (value->value.boolean);
|
return (value->value.boolean);
|
||||||
else
|
else
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetDate()' - Get a date value from a dictionary.
|
// 'pdfioDictGetDate()' - Get a date value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -306,14 +284,12 @@ pdfioDictGetDate(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_DATE)
|
if (value && value->type == PDFIO_VALTYPE_DATE)
|
||||||
return (value->value.date);
|
return (value->value.date);
|
||||||
else
|
else
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetDict()' - Get a key dictionary value from a dictionary.
|
// 'pdfioDictGetDict()' - Get a key dictionary value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -324,14 +300,12 @@ pdfioDictGetDict(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_DICT)
|
if (value && value->type == PDFIO_VALTYPE_DICT)
|
||||||
return (value->value.dict);
|
return (value->value.dict);
|
||||||
else
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetName()' - Get a key name value from a dictionary.
|
// 'pdfioDictGetName()' - Get a key name value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -342,14 +316,12 @@ pdfioDictGetName(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_NAME)
|
if (value && value->type == PDFIO_VALTYPE_NAME)
|
||||||
return (value->value.name);
|
return (value->value.name);
|
||||||
else
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetNumber()' - Get a key number value from a dictionary.
|
// 'pdfioDictGetNumber()' - Get a key number value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -360,14 +332,12 @@ pdfioDictGetNumber(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_NUMBER)
|
if (value && value->type == PDFIO_VALTYPE_NUMBER)
|
||||||
return (value->value.number);
|
return (value->value.number);
|
||||||
else
|
else
|
||||||
return (0.0);
|
return (0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetObj()' - Get a key indirect object value from a dictionary.
|
// 'pdfioDictGetObj()' - Get a key indirect object value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -378,14 +348,12 @@ pdfioDictGetObj(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_INDIRECT)
|
if (value && value->type == PDFIO_VALTYPE_INDIRECT)
|
||||||
return (pdfioFileFindObj(dict->pdf, value->value.indirect.number));
|
return (pdfioFileFindObj(dict->pdf, value->value.indirect.number));
|
||||||
else
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetRect()' - Get a key rectangle value from a dictionary.
|
// 'pdfioDictGetRect()' - Get a key rectangle value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -397,7 +365,6 @@ pdfioDictGetRect(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_ARRAY && pdfioArrayGetSize(value->value.array) == 4)
|
if (value && value->type == PDFIO_VALTYPE_ARRAY && pdfioArrayGetSize(value->value.array) == 4)
|
||||||
{
|
{
|
||||||
rect->x1 = pdfioArrayGetNumber(value->value.array, 0);
|
rect->x1 = pdfioArrayGetNumber(value->value.array, 0);
|
||||||
@ -413,7 +380,6 @@ pdfioDictGetRect(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetString()' - Get a key string value from a dictionary.
|
// 'pdfioDictGetString()' - Get a key string value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -424,14 +390,12 @@ pdfioDictGetString(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
if (value && value->type == PDFIO_VALTYPE_STRING)
|
if (value && value->type == PDFIO_VALTYPE_STRING)
|
||||||
return (value->value.string);
|
return (value->value.string);
|
||||||
else
|
else
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictGetType()' - Get a key value type from a dictionary.
|
// 'pdfioDictGetType()' - Get a key value type from a dictionary.
|
||||||
//
|
//
|
||||||
@ -442,11 +406,9 @@ pdfioDictGetType(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
_pdfio_value_t *value = _pdfioDictGetValue(dict, key);
|
||||||
|
|
||||||
|
|
||||||
return (value ? value->type : PDFIO_VALTYPE_NONE);
|
return (value ? value->type : PDFIO_VALTYPE_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictGetValue()' - Get a key value from a dictionary.
|
// '_pdfioDictGetValue()' - Get a key value from a dictionary.
|
||||||
//
|
//
|
||||||
@ -458,7 +420,6 @@ _pdfioDictGetValue(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
_pdfio_pair_t temp, // Search key
|
_pdfio_pair_t temp, // Search key
|
||||||
*match; // Matching key pair
|
*match; // Matching key pair
|
||||||
|
|
||||||
|
|
||||||
PDFIO_DEBUG("_pdfioDictGetValue(dict=%p, key=\"%s\")\n", dict, key);
|
PDFIO_DEBUG("_pdfioDictGetValue(dict=%p, key=\"%s\")\n", dict, key);
|
||||||
|
|
||||||
if (!dict || !dict->num_pairs || !key)
|
if (!dict || !dict->num_pairs || !key)
|
||||||
@ -483,7 +444,6 @@ _pdfioDictGetValue(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictIterateKeys()' - Iterate the keys in a dictionary.
|
// 'pdfioDictIterateKeys()' - Iterate the keys in a dictionary.
|
||||||
//
|
//
|
||||||
@ -503,8 +463,7 @@ _pdfioDictGetValue(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
// have been iterated.
|
// have been iterated.
|
||||||
//
|
//
|
||||||
|
|
||||||
void
|
void pdfioDictIterateKeys(
|
||||||
pdfioDictIterateKeys(
|
|
||||||
pdfio_dict_t *dict, // I - Dictionary
|
pdfio_dict_t *dict, // I - Dictionary
|
||||||
pdfio_dict_cb_t cb, // I - Callback function
|
pdfio_dict_cb_t cb, // I - Callback function
|
||||||
void *cb_data) // I - Callback data
|
void *cb_data) // I - Callback data
|
||||||
@ -512,7 +471,6 @@ pdfioDictIterateKeys(
|
|||||||
size_t i; // Looping var
|
size_t i; // Looping var
|
||||||
_pdfio_pair_t *pair; // Current pair
|
_pdfio_pair_t *pair; // Current pair
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !cb)
|
if (!dict || !cb)
|
||||||
return;
|
return;
|
||||||
@ -529,9 +487,11 @@ pdfioDictIterateKeys(
|
|||||||
//
|
//
|
||||||
|
|
||||||
size_t // O - Number of keys
|
size_t // O - Number of keys
|
||||||
pdfioDictGetNumKeys(pdfio_dict_t *dict) // I - Dictionary
|
pdfioDictGetNumPairs(pdfio_dict_t *dict) // I - Dictionary
|
||||||
{
|
{
|
||||||
|
if (dict)
|
||||||
return (dict->num_pairs);
|
return (dict->num_pairs);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -539,20 +499,13 @@ pdfioDictGetNumKeys(pdfio_dict_t *dict) // I - Dictionary
|
|||||||
//
|
//
|
||||||
// Alternative form to enumerate the keys of a dictionary
|
// Alternative form to enumerate the keys of a dictionary
|
||||||
|
|
||||||
bool // O - Value
|
const char * // O - Value
|
||||||
pdfioDictGetKeyByIndex(pdfio_dict_t *dict, // I - Dictionary
|
pdfioDictGetKeyByIndex(pdfio_dict_t *dict, // I - Dictionary
|
||||||
size_t index, // I - Index
|
size_t index) // I - Index
|
||||||
pdfio_dictKey_t *key) // I - struct pointer
|
|
||||||
{
|
{
|
||||||
if (index < dict->num_pairs)
|
if (index < dict->num_pairs)
|
||||||
{
|
return (dict->pairs[index].key);
|
||||||
if (key){
|
return (NULL);
|
||||||
key->key = dict->pairs[index].key;
|
|
||||||
key->type = (pdfio_valtype_t **)(dict->pairs[index].value.type);
|
|
||||||
return (true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -571,7 +524,6 @@ _pdfioDictRead(pdfio_file_t *pdf, // I - PDF file
|
|||||||
char key[256]; // Dictionary key
|
char key[256]; // Dictionary key
|
||||||
_pdfio_value_t value; // Dictionary value
|
_pdfio_value_t value; // Dictionary value
|
||||||
|
|
||||||
|
|
||||||
PDFIO_DEBUG("_pdfioDictRead(pdf=%p, obj=%p, tb=%p, depth=%lu)\n", pdf, obj, tb, (unsigned long)depth);
|
PDFIO_DEBUG("_pdfioDictRead(pdf=%p, obj=%p, tb=%p, depth=%lu)\n", pdf, obj, tb, (unsigned long)depth);
|
||||||
|
|
||||||
// Create a dictionary and start reading...
|
// Create a dictionary and start reading...
|
||||||
@ -618,7 +570,6 @@ _pdfioDictRead(pdfio_file_t *pdf, // I - PDF file
|
|||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetArray()' - Set a key array in a dictionary.
|
// 'pdfioDictSetArray()' - Set a key array in a dictionary.
|
||||||
//
|
//
|
||||||
@ -630,7 +581,6 @@ pdfioDictSetArray(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value)
|
if (!dict || !key || !value)
|
||||||
return (false);
|
return (false);
|
||||||
@ -642,12 +592,10 @@ pdfioDictSetArray(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetBinary()' - Set a key binary string in a dictionary.
|
// 'pdfioDictSetBinary()' - Set a key binary string in a dictionary.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
bool // O - `true` on success, `false` on failure
|
bool // O - `true` on success, `false` on failure
|
||||||
pdfioDictSetBinary(
|
pdfioDictSetBinary(
|
||||||
pdfio_dict_t *dict, // I - Dictionary
|
pdfio_dict_t *dict, // I - Dictionary
|
||||||
@ -657,7 +605,6 @@ pdfioDictSetBinary(
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value || !valuelen)
|
if (!dict || !key || !value || !valuelen)
|
||||||
return (false);
|
return (false);
|
||||||
@ -680,7 +627,6 @@ pdfioDictSetBinary(
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetBoolean()' - Set a key boolean in a dictionary.
|
// 'pdfioDictSetBoolean()' - Set a key boolean in a dictionary.
|
||||||
//
|
//
|
||||||
@ -692,7 +638,6 @@ pdfioDictSetBoolean(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key)
|
if (!dict || !key)
|
||||||
return (false);
|
return (false);
|
||||||
@ -704,7 +649,6 @@ pdfioDictSetBoolean(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetDate()' - Set a date value in a dictionary.
|
// 'pdfioDictSetDate()' - Set a date value in a dictionary.
|
||||||
//
|
//
|
||||||
@ -716,7 +660,6 @@ pdfioDictSetDate(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key)
|
if (!dict || !key)
|
||||||
return (false);
|
return (false);
|
||||||
@ -728,7 +671,6 @@ pdfioDictSetDate(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetDict()' - Set a key dictionary in a dictionary.
|
// 'pdfioDictSetDict()' - Set a key dictionary in a dictionary.
|
||||||
//
|
//
|
||||||
@ -740,7 +682,6 @@ pdfioDictSetDict(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value)
|
if (!dict || !key || !value)
|
||||||
return (false);
|
return (false);
|
||||||
@ -752,7 +693,6 @@ pdfioDictSetDict(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetName()' - Set a key name in a dictionary.
|
// 'pdfioDictSetName()' - Set a key name in a dictionary.
|
||||||
//
|
//
|
||||||
@ -764,7 +704,6 @@ pdfioDictSetName(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value)
|
if (!dict || !key || !value)
|
||||||
return (false);
|
return (false);
|
||||||
@ -776,7 +715,6 @@ pdfioDictSetName(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetNull()' - Set a key null in a dictionary.
|
// 'pdfioDictSetNull()' - Set a key null in a dictionary.
|
||||||
//
|
//
|
||||||
@ -787,7 +725,6 @@ pdfioDictSetNull(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key)
|
if (!dict || !key)
|
||||||
return (false);
|
return (false);
|
||||||
@ -798,7 +735,6 @@ pdfioDictSetNull(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetNumber()' - Set a key number in a dictionary.
|
// 'pdfioDictSetNumber()' - Set a key number in a dictionary.
|
||||||
//
|
//
|
||||||
@ -810,7 +746,6 @@ pdfioDictSetNumber(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key)
|
if (!dict || !key)
|
||||||
return (false);
|
return (false);
|
||||||
@ -822,7 +757,6 @@ pdfioDictSetNumber(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetObj()' - Set a key indirect object reference in a dictionary.
|
// 'pdfioDictSetObj()' - Set a key indirect object reference in a dictionary.
|
||||||
//
|
//
|
||||||
@ -834,7 +768,6 @@ pdfioDictSetObj(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value)
|
if (!dict || !key || !value)
|
||||||
return (false);
|
return (false);
|
||||||
@ -847,7 +780,6 @@ pdfioDictSetObj(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetRect()' - Set a key rectangle in a dictionary.
|
// 'pdfioDictSetRect()' - Set a key rectangle in a dictionary.
|
||||||
//
|
//
|
||||||
@ -859,7 +791,6 @@ pdfioDictSetRect(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value)
|
if (!dict || !key || !value)
|
||||||
return (false);
|
return (false);
|
||||||
@ -876,7 +807,6 @@ pdfioDictSetRect(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetString()' - Set a key literal string in a dictionary.
|
// 'pdfioDictSetString()' - Set a key literal string in a dictionary.
|
||||||
//
|
//
|
||||||
@ -888,7 +818,6 @@ pdfioDictSetString(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
{
|
{
|
||||||
_pdfio_value_t temp; // New value
|
_pdfio_value_t temp; // New value
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !value)
|
if (!dict || !key || !value)
|
||||||
return (false);
|
return (false);
|
||||||
@ -900,7 +829,6 @@ pdfioDictSetString(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioDictSetValue(dict, key, &temp));
|
return (_pdfioDictSetValue(dict, key, &temp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'pdfioDictSetStringf()' - Set a key formatted string in a dictionary.
|
// 'pdfioDictSetStringf()' - Set a key formatted string in a dictionary.
|
||||||
//
|
//
|
||||||
@ -915,7 +843,6 @@ pdfioDictSetStringf(
|
|||||||
char buffer[8192]; // String buffer
|
char buffer[8192]; // String buffer
|
||||||
va_list ap; // Argument list
|
va_list ap; // Argument list
|
||||||
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!dict || !key || !format)
|
if (!dict || !key || !format)
|
||||||
return (false);
|
return (false);
|
||||||
@ -928,7 +855,6 @@ pdfioDictSetStringf(
|
|||||||
return (pdfioDictSetString(dict, key, buffer));
|
return (pdfioDictSetString(dict, key, buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictSetValue()' - Set a key value in a dictionary.
|
// '_pdfioDictSetValue()' - Set a key value in a dictionary.
|
||||||
//
|
//
|
||||||
@ -941,7 +867,6 @@ _pdfioDictSetValue(
|
|||||||
{
|
{
|
||||||
_pdfio_pair_t *pair; // Current pair
|
_pdfio_pair_t *pair; // Current pair
|
||||||
|
|
||||||
|
|
||||||
PDFIO_DEBUG("_pdfioDictSetValue(dict=%p, key=\"%s\", value=%p)\n", dict, key, (void *)value);
|
PDFIO_DEBUG("_pdfioDictSetValue(dict=%p, key=\"%s\", value=%p)\n", dict, key, (void *)value);
|
||||||
|
|
||||||
// See if the key is already set...
|
// See if the key is already set...
|
||||||
@ -998,7 +923,6 @@ _pdfioDictSetValue(
|
|||||||
return (true);
|
return (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// '_pdfioDictWrite()' - Write a dictionary to a PDF file.
|
// '_pdfioDictWrite()' - Write a dictionary to a PDF file.
|
||||||
//
|
//
|
||||||
@ -1012,7 +936,6 @@ _pdfioDictWrite(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
size_t i; // Looping var
|
size_t i; // Looping var
|
||||||
_pdfio_pair_t *pair; // Current key/value pair
|
_pdfio_pair_t *pair; // Current key/value pair
|
||||||
|
|
||||||
|
|
||||||
if (length)
|
if (length)
|
||||||
*length = 0;
|
*length = 0;
|
||||||
|
|
||||||
@ -1041,7 +964,6 @@ _pdfioDictWrite(pdfio_dict_t *dict, // I - Dictionary
|
|||||||
return (_pdfioFilePuts(pdf, ">>"));
|
return (_pdfioFilePuts(pdf, ">>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// 'compare_pairs()' - Compare the keys for two pairs.
|
// 'compare_pairs()' - Compare the keys for two pairs.
|
||||||
//
|
//
|
||||||
|
18
pdfio.h
18
pdfio.h
@ -15,17 +15,16 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Version number...
|
// Version number...
|
||||||
//
|
//
|
||||||
|
|
||||||
#define PDFIO_VERSION "1.2.1"
|
#define PDFIO_VERSION "1.2.1"
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Visibility and other annotations...
|
// Visibility and other annotations...
|
||||||
//
|
//
|
||||||
@ -40,7 +39,6 @@ extern "C" {
|
|||||||
#define _PDFIO_DEPRECATED
|
#define _PDFIO_DEPRECATED
|
||||||
#endif // __has_extension || __GNUC__
|
#endif // __has_extension || __GNUC__
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Types and constants...
|
// Types and constants...
|
||||||
//
|
//
|
||||||
@ -123,13 +121,6 @@ typedef enum pdfio_valtype_e // PDF value types
|
|||||||
PDFIO_VALTYPE_NUMBER, // Number (integer or real)
|
PDFIO_VALTYPE_NUMBER, // Number (integer or real)
|
||||||
PDFIO_VALTYPE_STRING // String
|
PDFIO_VALTYPE_STRING // String
|
||||||
} pdfio_valtype_t;
|
} pdfio_valtype_t;
|
||||||
// Alternative PDF dict key enumeration
|
|
||||||
typedef struct pdfio_dictKey_s
|
|
||||||
{
|
|
||||||
const char *key;
|
|
||||||
pdfio_valtype_t **type;
|
|
||||||
} pdfio_dictKey_t;
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Functions...
|
// Functions...
|
||||||
@ -171,8 +162,8 @@ extern pdfio_obj_t *pdfioDictGetObj(pdfio_dict_t *dict, const char *key) _PDFIO_
|
|||||||
extern pdfio_rect_t *pdfioDictGetRect(pdfio_dict_t *dict, const char *key, pdfio_rect_t *rect) _PDFIO_PUBLIC;
|
extern pdfio_rect_t *pdfioDictGetRect(pdfio_dict_t *dict, const char *key, pdfio_rect_t *rect) _PDFIO_PUBLIC;
|
||||||
extern const char *pdfioDictGetString(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
|
extern const char *pdfioDictGetString(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
|
||||||
extern pdfio_valtype_t pdfioDictGetType(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
|
extern pdfio_valtype_t pdfioDictGetType(pdfio_dict_t *dict, const char *key) _PDFIO_PUBLIC;
|
||||||
extern size_t pdfioDictGetNumKeys(pdfio_dict_t *dict) _PDFIO_PUBLIC;
|
extern size_t pdfioDictGetNumPairs(pdfio_dict_t *dict) _PDFIO_PUBLIC;
|
||||||
extern bool pdfioDictGetKeyByIndex(pdfio_dict_t *dict, size_t index, pdfio_dictKey_t *keyData) _PDFIO_PUBLIC;
|
extern const char *pdfioDictGetKeyByIndex(pdfio_dict_t *dict, size_t index) _PDFIO_PUBLIC;
|
||||||
extern void pdfioDictIterateKeys(pdfio_dict_t *dict, pdfio_dict_cb_t cb, void *cb_data) _PDFIO_PUBLIC;
|
extern void pdfioDictIterateKeys(pdfio_dict_t *dict, pdfio_dict_cb_t cb, void *cb_data) _PDFIO_PUBLIC;
|
||||||
extern bool pdfioDictSetArray(pdfio_dict_t *dict, const char *key, pdfio_array_t *value) _PDFIO_PUBLIC;
|
extern bool pdfioDictSetArray(pdfio_dict_t *dict, const char *key, pdfio_array_t *value) _PDFIO_PUBLIC;
|
||||||
extern bool pdfioDictSetBinary(pdfio_dict_t *dict, const char *key, const unsigned char *value, size_t valuelen) _PDFIO_PUBLIC;
|
extern bool pdfioDictSetBinary(pdfio_dict_t *dict, const char *key, const unsigned char *value, size_t valuelen) _PDFIO_PUBLIC;
|
||||||
@ -251,7 +242,6 @@ extern bool pdfioStreamWrite(pdfio_stream_t *st, const void *buffer, size_t byt
|
|||||||
extern char *pdfioStringCreate(pdfio_file_t *pdf, const char *s) _PDFIO_PUBLIC;
|
extern char *pdfioStringCreate(pdfio_file_t *pdf, const char *s) _PDFIO_PUBLIC;
|
||||||
extern char *pdfioStringCreatef(pdfio_file_t *pdf, const char *format, ...) _PDFIO_FORMAT(2, 3) _PDFIO_PUBLIC;
|
extern char *pdfioStringCreatef(pdfio_file_t *pdf, const char *format, ...) _PDFIO_FORMAT(2, 3) _PDFIO_PUBLIC;
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
@ -17,14 +17,15 @@ int main (int argc, char **argv)
|
|||||||
pdfio_obj_t *obj_page = pdfioFileGetPage(pdf, 0);
|
pdfio_obj_t *obj_page = pdfioFileGetPage(pdf, 0);
|
||||||
pdfio_dict_t *dict_page = pdfioObjGetDict(obj_page);
|
pdfio_dict_t *dict_page = pdfioObjGetDict(obj_page);
|
||||||
|
|
||||||
size_t num_keys = pdfioDictGetNumKeys(dict_page);
|
size_t num_keys = pdfioDictGetNumPairs(dict_page);
|
||||||
printf("Number of keys in this page: %d\n", num_keys);
|
printf("Number of keys in this page: %d\n", num_keys);
|
||||||
|
|
||||||
|
const char *key;
|
||||||
for (unsigned int i = 0; i < num_keys; ++i)
|
for (unsigned int i = 0; i < num_keys; ++i)
|
||||||
{
|
{
|
||||||
pdfio_dictKey_t dict_key;
|
key = pdfioDictGetKeyByIndex(dict_page, i);
|
||||||
pdfioDictGetKeyByIndex(dict_page, i, &dict_key);
|
pdfio_valtype_t type = pdfioDictGetType(dict_page, key);
|
||||||
printf("\t%s (%d)\n", dict_key.key, dict_key.type);
|
printf("\t%s (%d)\n", key, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
pdfioFileClose(pdf);
|
pdfioFileClose(pdf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user