mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 05:48:20 +01:00
Refactor get_info_string to rely on pdfioDictGetString to convert binary strings to regular ones.
This commit is contained in:
parent
63a7a2cdbd
commit
a81907bdb9
29
pdfio-file.c
29
pdfio-file.c
@ -1412,36 +1412,13 @@ get_info_string(pdfio_file_t *pdf, // I - PDF file
|
|||||||
const char *key) // I - Dictionary key
|
const char *key) // I - Dictionary key
|
||||||
{
|
{
|
||||||
pdfio_dict_t *dict; // Info dictionary
|
pdfio_dict_t *dict; // Info dictionary
|
||||||
_pdfio_value_t *value; // Value
|
|
||||||
|
|
||||||
// Range check input...
|
// Range check input...
|
||||||
if (!pdf || !pdf->info_obj || (dict = pdfioObjGetDict(pdf->info_obj)) == NULL || (value = _pdfioDictGetValue(dict, key)) == NULL)
|
if (!pdf || !pdf->info_obj || (dict = pdfioObjGetDict(pdf->info_obj)) == NULL)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
// If we already have a value, return it...
|
|
||||||
if (value->type == PDFIO_VALTYPE_NAME || value->type == PDFIO_VALTYPE_STRING)
|
|
||||||
{
|
|
||||||
return (value->value.string);
|
|
||||||
}
|
|
||||||
else if (value->type == PDFIO_VALTYPE_BINARY && value->value.binary.datalen < 4096)
|
|
||||||
{
|
|
||||||
// Convert binary string to regular string...
|
|
||||||
char temp[4096]; // Temporary string
|
|
||||||
|
|
||||||
memcpy(temp, value->value.binary.data, value->value.binary.datalen);
|
|
||||||
temp[value->value.binary.datalen] = '\0';
|
|
||||||
|
|
||||||
free(value->value.binary.data);
|
|
||||||
value->type = PDFIO_VALTYPE_STRING;
|
|
||||||
value->value.string = pdfioStringCreate(pdf, temp);
|
|
||||||
|
|
||||||
return (value->value.string);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
return (pdfioDictGetString(dict, key));
|
||||||
// Something else that is not a string...
|
|
||||||
return (NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user