From 4bb81417a8484b9399596fe70eec9bb003293617 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sat, 15 May 2021 09:29:37 -0400 Subject: [PATCH] Start fleshing out writing/copying interfaces. --- pdfio-object.c | 16 ++++++++++++++++ pdfio-value.c | 17 ++++++++++++++--- pdfio.h | 1 + 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/pdfio-object.c b/pdfio-object.c index 996cb11..6c8ecf1 100644 --- a/pdfio-object.c +++ b/pdfio-object.c @@ -29,6 +29,22 @@ pdfioObjClose(pdfio_obj_t *obj) // I - Object } +// +// 'pdfioObjCopy()' - Copy an object to another PDF file. +// + +pdfio_obj_t * // O - New object or `NULL` on error +pdfioObjCopy(pdfio_file_t *pdf, // I - PDF file + pdfio_obj_t *srcobj) // I - Object to copy +{ + // TODO: Implement pdfioObjCopy + (void)pdf; + (void)srcobj; + + return (NULL); +} + + // // 'pdfioObjCreateStream()' - Create an object (data) stream for writing. // diff --git a/pdfio-value.c b/pdfio-value.c index e4f907e..9bbfd8b 100644 --- a/pdfio-value.c +++ b/pdfio-value.c @@ -24,6 +24,9 @@ _pdfioValueCopy(pdfio_file_t *pdfdst, // I - Destination PDF file pdfio_file_t *pdfsrc, // I - Source PDF file _pdfio_value_t *vsrc) // I - Source value { + pdfio_obj_t *obj; // Object reference + + if (pdfdst == pdfsrc && vsrc->type != PDFIO_VALTYPE_BINARY) { // For the same document we can copy the values without any other effort @@ -36,9 +39,17 @@ _pdfioValueCopy(pdfio_file_t *pdfdst, // I - Destination PDF file switch (vsrc->type) { case PDFIO_VALTYPE_INDIRECT : - // Object references don't copy to other documents - _pdfioFileError(pdfdst, "Unable to copy indirect object reference between PDF files."); - return (NULL); + if ((obj = _pdfioFileFindMappedObject(pdfdst, pdfsrc, vsrc->value.indirect.number)) == NULL) + { + obj = pdfioObjCopy(pdfdst, pdfioFileFindObject(pdfsrc, vsrc->value.indirect.number)); + } + + if (!obj) + return (NULL); + + vdst->value.indirect.number = obj->number; + vdst->value.indirect.generation = obj->generation; + break; default : return (NULL); diff --git a/pdfio.h b/pdfio.h index d17888a..6052470 100644 --- a/pdfio.h +++ b/pdfio.h @@ -161,6 +161,7 @@ extern const char *pdfioFileGetVersion(pdfio_file_t *pdf) PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileOpen(const char *filename, pdfio_error_cb_t error_cb, void *error_data) PDFIO_PUBLIC; extern bool pdfioObjClose(pdfio_obj_t *obj) PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioObjCopy(pdfio_file_t *pdf, pdfio_obj_t *srcobj) PDFIO_PUBLIC; extern pdfio_stream_t *pdfioObjCreateStream(pdfio_obj_t *obj, pdfio_filter_t compression) PDFIO_PUBLIC; extern pdfio_array_t *pdfioObjGetArray(pdfio_obj_t *obj) PDFIO_PUBLIC; extern pdfio_dict_t *pdfioObjGetDict(pdfio_obj_t *obj) PDFIO_PUBLIC;