From 04c4f44324c924b6c5a121259495ecc652e04334 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Wed, 25 Sep 2024 17:04:25 +0300 Subject: [PATCH 1/6] Get name from simple object. For example, Image ColorSpace is the reference to other object. --- pdfio-object.c | 20 ++++++++++++++++++++ pdfio.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/pdfio-object.c b/pdfio-object.c index 89c7835..f4bc85e 100644 --- a/pdfio-object.c +++ b/pdfio-object.c @@ -267,6 +267,26 @@ pdfioObjGetDict(pdfio_obj_t *obj) // I - Object return (NULL); } +// +// 'pdfioObjGetName()' - Get the name value associated with an object. +// + +const char * // O - Dictionary or `NULL` on error +pdfioObjGetName(pdfio_obj_t *obj) // I - Object +{ + if (!obj) + return (NULL); + + if (obj->value.type == PDFIO_VALTYPE_NONE) + _pdfioObjLoad(obj); + + if (obj->value.type == PDFIO_VALTYPE_NAME) + return (obj->value.value.name); + else + return (NULL); +} + + // // '_pdfioObjGetExtension()' - Get the extension pointer for an object. diff --git a/pdfio.h b/pdfio.h index f905c82..b53a262 100644 --- a/pdfio.h +++ b/pdfio.h @@ -220,6 +220,8 @@ extern pdfio_obj_t *pdfioObjCopy(pdfio_file_t *pdf, pdfio_obj_t *srcobj) _PDFIO_ 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; +extern const char *pdfioObjGetName(pdfio_obj_t *obj) _PDFIO_PUBLIC; + extern unsigned short pdfioObjGetGeneration(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern size_t pdfioObjGetLength(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern size_t pdfioObjGetNumber(pdfio_obj_t *obj) _PDFIO_PUBLIC; From a19949834b894877455f6018f602374748424f7b Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Wed, 25 Sep 2024 18:06:17 +0300 Subject: [PATCH 2/6] PR comments --- pdfio-object.c | 2 +- pdfio.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pdfio-object.c b/pdfio-object.c index f4bc85e..b7e963b 100644 --- a/pdfio-object.c +++ b/pdfio-object.c @@ -267,6 +267,7 @@ pdfioObjGetDict(pdfio_obj_t *obj) // I - Object return (NULL); } + // // 'pdfioObjGetName()' - Get the name value associated with an object. // @@ -287,7 +288,6 @@ pdfioObjGetName(pdfio_obj_t *obj) // I - Object } - // // '_pdfioObjGetExtension()' - Get the extension pointer for an object. // diff --git a/pdfio.h b/pdfio.h index b53a262..c078e76 100644 --- a/pdfio.h +++ b/pdfio.h @@ -220,10 +220,10 @@ extern pdfio_obj_t *pdfioObjCopy(pdfio_file_t *pdf, pdfio_obj_t *srcobj) _PDFIO_ 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; -extern const char *pdfioObjGetName(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern unsigned short pdfioObjGetGeneration(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern size_t pdfioObjGetLength(pdfio_obj_t *obj) _PDFIO_PUBLIC; +extern const char *pdfioObjGetName(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern size_t pdfioObjGetNumber(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern const char *pdfioObjGetSubtype(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern const char *pdfioObjGetType(pdfio_obj_t *obj) _PDFIO_PUBLIC; From 4312933409b4fedd2b87e317b04b73cf9d3456b8 Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Wed, 25 Sep 2024 18:40:36 +0300 Subject: [PATCH 3/6] pdfioFileCreateNameObj implemented --- pdfio-file.c | 29 +++++++++++++++++++++++++++++ pdfio.h | 1 + 2 files changed, 30 insertions(+) diff --git a/pdfio-file.c b/pdfio-file.c index f675bf4..cc3475c 100644 --- a/pdfio-file.c +++ b/pdfio-file.c @@ -244,6 +244,35 @@ pdfioFileCreateArrayObj( } +// +// 'pdfioFileCreateNameObj()' - Create a new object in a PDF file containing a name. +// +// This function creates a new object with a name value in a PDF file. +// You must call @link pdfioObjClose@ to write the object to the file. +// + +pdfio_obj_t * // O - New object +pdfioFileCreateNameObj( + pdfio_file_t *pdf, // I - PDF file + const char *name) // I - Name value +{ + _pdfio_value_t value; // Object value + + + // Range check input... + if (!pdf || !name) + return (NULL); + + value.type = PDFIO_VALTYPE_NAME; + value.value.name = pdfioStringCreate(pdf, name); + + if (!value.value.name) + return (NULL); + + return (_pdfioFileCreateObj(pdf, NULL, &value)); +} + + // // 'pdfioFileCreateNumberObj()' - Create a new object in a PDF file containing a number. // diff --git a/pdfio.h b/pdfio.h index c078e76..529b107 100644 --- a/pdfio.h +++ b/pdfio.h @@ -182,6 +182,7 @@ extern bool pdfioDictSetStringf(pdfio_dict_t *dict, const char *key, const char extern bool pdfioFileClose(pdfio_file_t *pdf) _PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileCreate(const char *filename, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileCreateArrayObj(pdfio_file_t *pdf, pdfio_array_t *array) _PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateNameObj(pdfio_file_t *pdf, const char* name) _PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileCreateNumberObj(pdfio_file_t *pdf, double number) _PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict) _PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileCreateOutput(pdfio_output_cb_t output_cb, void *output_ctx, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC; From f4409146e3ad3f52d63730777b9e06a34fb7dd0c Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Wed, 25 Sep 2024 18:42:38 +0300 Subject: [PATCH 4/6] minor --- pdfio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdfio.h b/pdfio.h index 529b107..eae6162 100644 --- a/pdfio.h +++ b/pdfio.h @@ -182,7 +182,7 @@ extern bool pdfioDictSetStringf(pdfio_dict_t *dict, const char *key, const char extern bool pdfioFileClose(pdfio_file_t *pdf) _PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileCreate(const char *filename, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileCreateArrayObj(pdfio_file_t *pdf, pdfio_array_t *array) _PDFIO_PUBLIC; -extern pdfio_obj_t *pdfioFileCreateNameObj(pdfio_file_t *pdf, const char* name) _PDFIO_PUBLIC; +extern pdfio_obj_t *pdfioFileCreateNameObj(pdfio_file_t *pdf, const char *name) _PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileCreateNumberObj(pdfio_file_t *pdf, double number) _PDFIO_PUBLIC; extern pdfio_obj_t *pdfioFileCreateObj(pdfio_file_t *pdf, pdfio_dict_t *dict) _PDFIO_PUBLIC; extern pdfio_file_t *pdfioFileCreateOutput(pdfio_output_cb_t output_cb, void *output_ctx, const char *version, pdfio_rect_t *media_box, pdfio_rect_t *crop_box, pdfio_error_cb_t error_cb, void *error_data) _PDFIO_PUBLIC; From 121b933307aec276ec7c4e4f53dac85f9585b2aa Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Wed, 25 Sep 2024 18:44:34 +0300 Subject: [PATCH 5/6] minor --- pdfio.h | 1 - 1 file changed, 1 deletion(-) diff --git a/pdfio.h b/pdfio.h index eae6162..732334a 100644 --- a/pdfio.h +++ b/pdfio.h @@ -221,7 +221,6 @@ extern pdfio_obj_t *pdfioObjCopy(pdfio_file_t *pdf, pdfio_obj_t *srcobj) _PDFIO_ 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; - extern unsigned short pdfioObjGetGeneration(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern size_t pdfioObjGetLength(pdfio_obj_t *obj) _PDFIO_PUBLIC; extern const char *pdfioObjGetName(pdfio_obj_t *obj) _PDFIO_PUBLIC; From ee3109601901306ef8ee97ae6fb6d5e37f70809d Mon Sep 17 00:00:00 2001 From: Sergey Vlasov Date: Fri, 27 Sep 2024 20:38:15 +0300 Subject: [PATCH 6/6] PR comment --- pdfio-object.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/pdfio-object.c b/pdfio-object.c index b7e963b..880557c 100644 --- a/pdfio-object.c +++ b/pdfio-object.c @@ -268,26 +268,6 @@ pdfioObjGetDict(pdfio_obj_t *obj) // I - Object } -// -// 'pdfioObjGetName()' - Get the name value associated with an object. -// - -const char * // O - Dictionary or `NULL` on error -pdfioObjGetName(pdfio_obj_t *obj) // I - Object -{ - if (!obj) - return (NULL); - - if (obj->value.type == PDFIO_VALTYPE_NONE) - _pdfioObjLoad(obj); - - if (obj->value.type == PDFIO_VALTYPE_NAME) - return (obj->value.value.name); - else - return (NULL); -} - - // // '_pdfioObjGetExtension()' - Get the extension pointer for an object. // @@ -353,6 +333,26 @@ pdfioObjGetLength(pdfio_obj_t *obj) // I - Object } +// +// 'pdfioObjGetName()' - Get the name value associated with an object. +// + +const char * // O - Dictionary or `NULL` on error +pdfioObjGetName(pdfio_obj_t *obj) // I - Object +{ + if (!obj) + return (NULL); + + if (obj->value.type == PDFIO_VALTYPE_NONE) + _pdfioObjLoad(obj); + + if (obj->value.type == PDFIO_VALTYPE_NAME) + return (obj->value.value.name); + else + return (NULL); +} + + // // 'pdfioObjGetNumber()' - Get the object's number. //