Refactor get_info_string to rely on pdfioDictGetString to convert binary strings to regular ones.

This commit is contained in:
Michael R Sweet 2024-06-24 11:49:38 -04:00
parent 63a7a2cdbd
commit a81907bdb9
No known key found for this signature in database
GPG Key ID: BE67C75EC81F3244

View File

@ -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);
}
} }