Save work.

This commit is contained in:
Michael R Sweet
2021-04-27 21:22:34 -04:00
parent 11588ce2f5
commit e2e2192ea9
10 changed files with 672 additions and 113 deletions

View File

@ -14,25 +14,6 @@
#include "pdfio-private.h"
//
// Dictionary structures
//
typedef struct _pdfio_pair_s // Key/value pair
{
const char *key; // Key string
_pdfio_value_t value; // Value
} _pdfio_pair_t;
struct _pdfio_dict_s
{
pdfio_file_t *pdf; // PDF file
size_t num_pairs, // Number of pairs in use
alloc_pairs; // Number of allocated pairs
_pdfio_pair_t *pairs; // Array of pairs
};
//
// Local functions...
//
@ -40,6 +21,21 @@ struct _pdfio_dict_s
static int compare_pairs(_pdfio_pair_t *a, _pdfio_pair_t *b);
//
// 'pdfioDictCopy()' - Copy a dictionary to a PDF file.
//
pdfio_dict_t * // O - New dictionary
pdfioDictCopy(pdfio_file_t *pdf, // I - PDF file
pdfio_dict_t *dict) // I - Original dictionary
{
// TODO: Implement me
(void)pdf;
(void)dict;
return (NULL);
}
//
// 'pdfioDictCreate()' - Create a dictionary to hold key/value pairs.
//
@ -531,6 +527,48 @@ _pdfioDictSetValue(
}
//
// '_pdfioDictWrite()' - Write a dictionary to a PDF file.
//
bool // O - `true` on success, `false` on failure
_pdfioDictWrite(pdfio_dict_t *dict, // I - Dictionary
off_t *length) // I - Offset to length value
{
pdfio_file_t *pdf = dict->pdf; // PDF file
size_t i; // Looping var
_pdfio_pair_t *pair; // Current key/value pair
if (length)
*length = 0;
// Dictionaries are bounded by "<<" and ">>"...
if (!_pdfioFilePuts(pdf, "<<"))
return (false);
// Write all of the key/value pairs...
for (i = dict->num_pairs, pair = dict->pairs; i > 0; i --, pair ++)
{
if (!_pdfioFilePrintf(pdf, "/%s", pair->key))
return (false);
if (length && !strcmp(pair->key, "Length"))
{
// Writing an object dictionary with an undefined length
*length = _pdfioFileTell(pdf);
if (!_pdfioFilePuts(pdf, " 999999999"))
return (false);
}
else if (!_pdfioValueWrite(pdf, &pair->value))
return (false);
}
// Close it up...
return (_pdfioFilePuts(pdf, ">>"));
}
//
// 'compare_pairs()' - Compare the keys for two pairs.
//