Skip to content

Commit

Permalink
Merge pull request #76 from vlasovsoft1979/master
Browse files Browse the repository at this point in the history
Get name from object
  • Loading branch information
michaelrsweet authored Oct 25, 2024
2 parents 9c04d1d + ee31096 commit 0e45e49
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions pdfio-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
20 changes: 20 additions & 0 deletions pdfio-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,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.
//
Expand Down
2 changes: 2 additions & 0 deletions pdfio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -222,6 +223,7 @@ 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;
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;
Expand Down

0 comments on commit 0e45e49

Please sign in to comment.