2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-05-30 13:10:44 +02:00
|
|
|
|
// PDF array functions for PDFio.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
// Copyright © 2021 by Michael R Sweet.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under Apache License v2.0. See the file "LICENSE" for more
|
|
|
|
|
// information.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Include necessary headers...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include "pdfio-private.h"
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 17:28:56 +02:00
|
|
|
|
//
|
|
|
|
|
// Local functions...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static bool append_value(pdfio_array_t *a, _pdfio_value_t *v);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// 'pdfioArrayAppendArray()' - Add an array value to an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendArray(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
pdfio_array_t *value) // I - Value
|
|
|
|
|
{
|
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a || !value)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add an array...
|
2021-04-25 17:28:56 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_ARRAY;
|
|
|
|
|
v.value.array = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
//
|
|
|
|
|
// 'pdfioArrayAppendBinary()' - Add a binary string value to an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendBinary(
|
2021-06-05 17:28:32 +02:00
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
const unsigned char *value, // I - Value
|
|
|
|
|
size_t valuelen) // I - Length of value
|
2021-04-30 14:02:54 +02:00
|
|
|
|
{
|
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input
|
|
|
|
|
if (!a || !value || !valuelen)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a binary string...
|
|
|
|
|
v.type = PDFIO_VALTYPE_BINARY;
|
|
|
|
|
v.value.binary.datalen = valuelen;
|
|
|
|
|
|
|
|
|
|
if ((v.value.binary.data = (unsigned char *)malloc(valuelen)) == NULL)
|
|
|
|
|
{
|
|
|
|
|
_pdfioFileError(a->pdf, "Unable to allocate memory for binary string - %s", strerror(errno));
|
|
|
|
|
return (false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
memcpy(v.value.binary.data, value, valuelen);
|
|
|
|
|
|
2021-05-01 13:36:19 +02:00
|
|
|
|
if (!append_value(a, &v))
|
|
|
|
|
{
|
|
|
|
|
free(v.value.binary.data);
|
|
|
|
|
return (false);
|
|
|
|
|
}
|
2021-04-30 14:02:54 +02:00
|
|
|
|
|
2021-05-01 13:36:19 +02:00
|
|
|
|
return (true);
|
2021-04-30 14:02:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayAppendBoolean()' - Add a boolean value to an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendBoolean(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
bool value) // I - Value
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a boolean...
|
2021-04-26 00:12:24 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_BOOLEAN;
|
|
|
|
|
v.value.boolean = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-08 04:06:25 +02:00
|
|
|
|
//
|
|
|
|
|
// 'pdfioArrayAppendDate()' - Add a date value to an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendDate(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
time_t value) // I - Value
|
|
|
|
|
{
|
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Range check input
|
|
|
|
|
if (!a)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a dictionary...
|
|
|
|
|
v.type = PDFIO_VALTYPE_DATE;
|
|
|
|
|
v.value.date = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayAppendDict()' - Add a dictionary to an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendDict(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
pdfio_dict_t *value) // I - Value
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a || !value)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a dictionary...
|
2021-04-26 00:12:24 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_DICT;
|
|
|
|
|
v.value.dict = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayAppendName()' - Add a name to an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendName(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
const char *value) // I - Value
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a || !value)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a name string...
|
2021-04-26 00:12:24 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_NAME;
|
|
|
|
|
v.value.name = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayAppendNumber()' - Add a number to an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendNumber(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
2021-05-30 03:16:21 +02:00
|
|
|
|
double value) // I - Value
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a number...
|
2021-04-26 00:12:24 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_NUMBER;
|
|
|
|
|
v.value.number = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-06-07 14:34:30 +02:00
|
|
|
|
// 'pdfioArrayAppendObj()' - Add an indirect object reference to an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
2021-06-07 14:34:30 +02:00
|
|
|
|
pdfioArrayAppendObj(
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
pdfio_obj_t *value) // I - Value
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a || !value || a->pdf != value->pdf)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add an indirect reference...
|
2021-05-04 16:34:17 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_INDIRECT;
|
|
|
|
|
v.value.indirect.number = value->number;
|
|
|
|
|
v.value.indirect.generation = value->generation;
|
2021-04-26 00:12:24 +02:00
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayAppendString()' - Add a string to an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - `true` on success, `false` on failure
|
|
|
|
|
pdfioArrayAppendString(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
const char *value) // I - Value
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t v; // Value for array
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Range check input
|
|
|
|
|
if (!a || !value)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Add a string...
|
2021-04-26 00:12:24 +02:00
|
|
|
|
v.type = PDFIO_VALTYPE_STRING;
|
|
|
|
|
v.value.string = value;
|
|
|
|
|
|
|
|
|
|
return (append_value(a, &v));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-28 03:22:34 +02:00
|
|
|
|
//
|
|
|
|
|
// 'pdfioArrayCopy()' - Copy an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
pdfio_array_t * // O - New array or `NULL` on error
|
|
|
|
|
pdfioArrayCopy(pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
pdfio_array_t *a) // I - Original array
|
|
|
|
|
{
|
2021-04-30 14:02:54 +02:00
|
|
|
|
pdfio_array_t *na; // New array
|
|
|
|
|
size_t i; // Looping var
|
|
|
|
|
_pdfio_value_t *vsrc, // Current source value
|
|
|
|
|
vdst; // Current destination value
|
|
|
|
|
|
|
|
|
|
|
2021-05-30 02:00:48 +02:00
|
|
|
|
PDFIO_DEBUG("pdfioArrayCopy(pdf=%p, a=%p(%p))\n", pdf, a, a ? a->pdf : NULL);
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
// Create the new array...
|
|
|
|
|
if ((na = pdfioArrayCreate(pdf)) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
// Pre-allocate the values array to make this a little faster...
|
|
|
|
|
if ((na->values = (_pdfio_value_t *)malloc(a->num_values * sizeof(_pdfio_value_t))) == NULL)
|
|
|
|
|
return (NULL); // Let pdfioFileClose do the cleanup...
|
|
|
|
|
|
|
|
|
|
na->alloc_values = a->num_values;
|
|
|
|
|
|
|
|
|
|
// Copy and add each of the source array's values...
|
|
|
|
|
for (i = a->num_values, vsrc = a->values; i > 0; i --, vsrc ++)
|
|
|
|
|
{
|
|
|
|
|
if (!_pdfioValueCopy(pdf, &vdst, a->pdf, vsrc))
|
|
|
|
|
return (NULL); // Let pdfioFileClose do the cleanup...
|
|
|
|
|
|
2021-04-30 14:21:21 +02:00
|
|
|
|
// Cannot fail since we already allocated memory...
|
|
|
|
|
append_value(na, &vdst);
|
2021-04-30 14:02:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Successfully copied the array, so return it...
|
|
|
|
|
return (na);
|
2021-04-28 03:22:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayCreate()' - Create an empty array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_array_t * // O - New array or `NULL` on error
|
|
|
|
|
pdfioArrayCreate(pdfio_file_t *pdf) // I - PDF file
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_array_t *a; // Array
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!pdf)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
|
|
if ((a = (pdfio_array_t *)calloc(1, sizeof(pdfio_array_t))) == NULL)
|
|
|
|
|
return (NULL);
|
|
|
|
|
|
2021-04-26 02:12:52 +02:00
|
|
|
|
a->pdf = pdf;
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (pdf->num_arrays >= pdf->alloc_arrays)
|
|
|
|
|
{
|
|
|
|
|
pdfio_array_t **temp = realloc(pdf->arrays, (pdf->alloc_arrays + 16) * sizeof(pdfio_array_t *));
|
|
|
|
|
|
|
|
|
|
if (!temp)
|
|
|
|
|
{
|
|
|
|
|
free(a);
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pdf->arrays = temp;
|
|
|
|
|
pdf->alloc_arrays += 16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pdf->arrays[pdf->num_arrays ++] = a;
|
|
|
|
|
|
|
|
|
|
return (a);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-06 15:51:48 +02:00
|
|
|
|
//
|
|
|
|
|
// '_pdfioArrayDebug()' - Print the contents of an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
void
|
2021-05-10 14:40:52 +02:00
|
|
|
|
_pdfioArrayDebug(pdfio_array_t *a, // I - Array
|
|
|
|
|
FILE *fp) // I - Output file
|
2021-05-06 15:51:48 +02:00
|
|
|
|
{
|
|
|
|
|
size_t i; // Looping var
|
|
|
|
|
_pdfio_value_t *v; // Current value
|
|
|
|
|
|
|
|
|
|
|
2021-05-10 14:40:52 +02:00
|
|
|
|
putc('[', fp);
|
2021-05-06 15:51:48 +02:00
|
|
|
|
for (i = a->num_values, v = a->values; i > 0; i --, v ++)
|
2021-05-10 14:40:52 +02:00
|
|
|
|
_pdfioValueDebug(v, fp);
|
|
|
|
|
putc(']', fp);
|
2021-05-06 15:51:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 03:09:43 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// '_pdfioArrayDelete()' - Free the memory used by an array.
|
2021-04-17 03:09:43 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
void
|
|
|
|
|
_pdfioArrayDelete(pdfio_array_t *a) // I - Array
|
2021-04-17 03:09:43 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (a)
|
|
|
|
|
free(a->values);
|
|
|
|
|
|
|
|
|
|
free(a);
|
2021-04-17 03:09:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetArray()' - Get an array value from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_array_t * // O - Value
|
|
|
|
|
pdfioArrayGetArray(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_ARRAY)
|
|
|
|
|
return (NULL);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.array);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-30 14:02:54 +02:00
|
|
|
|
//
|
|
|
|
|
// 'pdfioArrayGetBinary()' - Get a binary string value from an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
unsigned char * // O - Value
|
|
|
|
|
pdfioArrayGetBinary(
|
|
|
|
|
pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n, // I - Index
|
|
|
|
|
size_t *length) // O - Length of string
|
|
|
|
|
{
|
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_BINARY || !length)
|
|
|
|
|
{
|
|
|
|
|
if (length)
|
|
|
|
|
*length = 0;
|
|
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*length = a->values[n].value.binary.datalen;
|
|
|
|
|
return (a->values[n].value.binary.data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetBoolean()' - Get a boolean value from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
bool // O - Value
|
|
|
|
|
pdfioArrayGetBoolean(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_BOOLEAN)
|
|
|
|
|
return (false);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.boolean);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-08 04:06:25 +02:00
|
|
|
|
//
|
|
|
|
|
// 'pdfioArrayGetDate()' - Get a date value from an array.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
time_t // O - Value
|
|
|
|
|
pdfioArrayGetDate(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
|
|
|
|
{
|
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_DATE)
|
|
|
|
|
return (0);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetDict()' - Get a dictionary value from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_dict_t * // O - Value
|
|
|
|
|
pdfioArrayGetDict(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_DICT)
|
|
|
|
|
return (NULL);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.dict);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetName()' - Get a name value from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
const char * // O - Value
|
|
|
|
|
pdfioArrayGetName(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_NAME)
|
|
|
|
|
return (NULL);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.name);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetNumber()' - Get a number from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-05-30 03:16:21 +02:00
|
|
|
|
double // O - Value
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfioArrayGetNumber(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_NUMBER)
|
2021-05-30 03:16:21 +02:00
|
|
|
|
return (0.0);
|
2021-04-26 00:12:24 +02:00
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.number);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetObject()' - Get an indirect object reference from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_obj_t * // O - Value
|
2021-06-07 14:34:30 +02:00
|
|
|
|
pdfioArrayGetObj(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_INDIRECT)
|
|
|
|
|
return (NULL);
|
|
|
|
|
else
|
2021-06-07 14:34:30 +02:00
|
|
|
|
return (pdfioFileFindObj(a->pdf, a->values[n].value.indirect.number));
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetSize()' - Get the length of an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
size_t // O - Length of array
|
|
|
|
|
pdfioArrayGetSize(pdfio_array_t *a) // I - Array
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
return (a ? a->num_values : 0);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetString()' - Get a string value from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
const char * // O - Value
|
|
|
|
|
pdfioArrayGetString(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values || a->values[n].type != PDFIO_VALTYPE_STRING)
|
|
|
|
|
return (NULL);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].value.string);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// 'pdfioArrayGetType()' - Get a value type from an array.
|
2021-04-17 02:41:46 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
pdfio_valtype_t // O - Value type
|
|
|
|
|
pdfioArrayGetType(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-17 02:41:46 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values)
|
|
|
|
|
return (PDFIO_VALTYPE_NONE);
|
|
|
|
|
else
|
|
|
|
|
return (a->values[n].type);
|
2021-04-17 02:41:46 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 17:28:56 +02:00
|
|
|
|
//
|
2021-04-26 00:12:24 +02:00
|
|
|
|
// '_pdfioArrayGetValue()' - Get a value from an array.
|
2021-04-25 17:28:56 +02:00
|
|
|
|
//
|
|
|
|
|
|
2021-04-26 00:12:24 +02:00
|
|
|
|
_pdfio_value_t * // O - Value
|
|
|
|
|
_pdfioArrayGetValue(pdfio_array_t *a, // I - Array
|
|
|
|
|
size_t n) // I - Index
|
2021-04-25 17:28:56 +02:00
|
|
|
|
{
|
2021-04-26 00:12:24 +02:00
|
|
|
|
if (!a || n >= a->num_values)
|
|
|
|
|
return (NULL);
|
|
|
|
|
else
|
|
|
|
|
return (a->values + n);
|
2021-04-25 17:28:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-05-04 16:34:17 +02:00
|
|
|
|
//
|
|
|
|
|
// '_pdfioArrayRead()' - Read an array from a file.
|
|
|
|
|
//
|
|
|
|
|
// At this point the initial "[" has been seen...
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
pdfio_array_t * // O - New array
|
2021-05-08 13:38:44 +02:00
|
|
|
|
_pdfioArrayRead(pdfio_file_t *pdf, // I - PDF file
|
|
|
|
|
_pdfio_token_t *tb) // I - Token buffer/stack
|
2021-05-04 16:34:17 +02:00
|
|
|
|
{
|
|
|
|
|
pdfio_array_t *array; // New array
|
|
|
|
|
char token[8192]; // Token from file
|
|
|
|
|
_pdfio_value_t value; // Value
|
|
|
|
|
|
|
|
|
|
|
2021-05-10 23:37:57 +02:00
|
|
|
|
PDFIO_DEBUG("_pdfioArrayRead(pdf=%p, tb=%p)\n", pdf, tb);
|
|
|
|
|
|
2021-05-04 16:34:17 +02:00
|
|
|
|
// Create an array...
|
|
|
|
|
array = pdfioArrayCreate(pdf);
|
|
|
|
|
|
|
|
|
|
// Read until we get "]" to end the array...
|
2021-05-08 13:38:44 +02:00
|
|
|
|
while (_pdfioTokenGet(tb, token, sizeof(token)))
|
2021-05-04 16:34:17 +02:00
|
|
|
|
{
|
|
|
|
|
if (!strcmp(token, "]"))
|
|
|
|
|
{
|
|
|
|
|
// End of array...
|
|
|
|
|
return (array);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Push the token and decode the value...
|
2021-05-08 13:38:44 +02:00
|
|
|
|
_pdfioTokenPush(tb, token);
|
|
|
|
|
if (!_pdfioValueRead(pdf, tb, &value))
|
2021-05-04 16:34:17 +02:00
|
|
|
|
break;
|
|
|
|
|
|
2021-08-23 20:31:54 +02:00
|
|
|
|
// PDFIO_DEBUG("_pdfioArrayRead(%p): Appending ", (void *)array);
|
|
|
|
|
// PDFIO_DEBUG_VALUE(&value);
|
|
|
|
|
// PDFIO_DEBUG("\n");
|
2021-05-10 23:37:57 +02:00
|
|
|
|
|
2021-05-04 16:34:17 +02:00
|
|
|
|
append_value(array, &value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-28 03:22:34 +02:00
|
|
|
|
//
|
|
|
|
|
// '_pdfioArrayWrite()' - Write an array to a PDF file.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
bool // O - `true` on success, `false` otherwise
|
|
|
|
|
_pdfioArrayWrite(pdfio_array_t *a) // I - Array
|
|
|
|
|
{
|
|
|
|
|
pdfio_file_t *pdf = a->pdf; // PDF file
|
|
|
|
|
size_t i; // Looping var
|
|
|
|
|
_pdfio_value_t *v; // Current value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Arrays are surrounded by square brackets ([ ... ])
|
|
|
|
|
if (!_pdfioFilePuts(pdf, "["))
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
// Write each value...
|
|
|
|
|
for (i = a->num_values, v = a->values; i > 0; i --, v ++)
|
|
|
|
|
{
|
2021-05-16 17:39:05 +02:00
|
|
|
|
if (!_pdfioValueWrite(pdf, v, NULL))
|
2021-04-28 03:22:34 +02:00
|
|
|
|
return (false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Closing bracket...
|
|
|
|
|
return (_pdfioFilePuts(pdf, "]"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-25 17:28:56 +02:00
|
|
|
|
//
|
|
|
|
|
// 'append_value()' - Append a value.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
static bool // O - `true` on success, `false` otherwise
|
|
|
|
|
append_value(pdfio_array_t *a, // I - Array
|
|
|
|
|
_pdfio_value_t *v) // I - Value
|
|
|
|
|
{
|
|
|
|
|
if (a->num_values >= a->alloc_values)
|
|
|
|
|
{
|
|
|
|
|
_pdfio_value_t *temp = (_pdfio_value_t *)realloc(a->values, (a->alloc_values + 16) * sizeof(_pdfio_value_t));
|
|
|
|
|
|
|
|
|
|
if (!temp)
|
|
|
|
|
return (false);
|
|
|
|
|
|
|
|
|
|
a->values = temp;
|
|
|
|
|
a->alloc_values += 16;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a->values[a->num_values ++] = *v;
|
|
|
|
|
|
|
|
|
|
return (true);
|
|
|
|
|
}
|