mirror of
https://github.com/michaelrsweet/pdfio.git
synced 2024-12-27 21:58:22 +01:00
Clean up object stream support.
This commit is contained in:
parent
f9084400cd
commit
6f726602c6
37
pdfio-file.c
37
pdfio-file.c
@ -990,7 +990,8 @@ load_obj_stream(pdfio_obj_t *obj) // I - Object to load
|
|||||||
pdfio_stream_t *st; // Stream
|
pdfio_stream_t *st; // Stream
|
||||||
_pdfio_token_t tb; // Token buffer/stack
|
_pdfio_token_t tb; // Token buffer/stack
|
||||||
char buffer[32]; // Token
|
char buffer[32]; // Token
|
||||||
size_t cur_obj, // Current object
|
size_t number, // Object number
|
||||||
|
cur_obj, // Current object
|
||||||
num_objs = 0; // Number of objects
|
num_objs = 0; // Number of objects
|
||||||
pdfio_obj_t *objs[16384]; // Objects
|
pdfio_obj_t *objs[16384]; // Objects
|
||||||
|
|
||||||
@ -1022,7 +1023,12 @@ load_obj_stream(pdfio_obj_t *obj) // I - Object to load
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the object in memory...
|
// Add the object in memory...
|
||||||
objs[num_objs ++] = add_obj(obj->pdf, (size_t)strtoimax(buffer, NULL, 10), 0, 0);
|
number = (size_t)strtoimax(buffer, NULL, 10);
|
||||||
|
|
||||||
|
if ((objs[num_objs] = pdfioFileFindObj(obj->pdf, number)) == NULL)
|
||||||
|
objs[num_objs] = add_obj(obj->pdf, number, 0, 0);
|
||||||
|
|
||||||
|
num_objs ++;
|
||||||
|
|
||||||
// Skip offset
|
// Skip offset
|
||||||
_pdfioTokenGet(&tb, buffer, sizeof(buffer));
|
_pdfioTokenGet(&tb, buffer, sizeof(buffer));
|
||||||
@ -1173,6 +1179,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file
|
|||||||
unsigned char buffer[32]; // Read buffer
|
unsigned char buffer[32]; // Read buffer
|
||||||
size_t num_sobjs = 0, // Number of object streams
|
size_t num_sobjs = 0, // Number of object streams
|
||||||
sobjs[4096]; // Object streams to load
|
sobjs[4096]; // Object streams to load
|
||||||
|
pdfio_obj_t *current; // Current object
|
||||||
|
|
||||||
if ((number = strtoimax(line, &ptr, 10)) < 1)
|
if ((number = strtoimax(line, &ptr, 10)) < 1)
|
||||||
{
|
{
|
||||||
@ -1264,7 +1271,7 @@ load_xref(pdfio_file_t *pdf, // I - PDF file
|
|||||||
|
|
||||||
while (pdfioStreamRead(st, buffer, w_total) > 0)
|
while (pdfioStreamRead(st, buffer, w_total) > 0)
|
||||||
{
|
{
|
||||||
PDFIO_DEBUG("load_xref: %02X%02X%02X%02X%02X\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
|
PDFIO_DEBUG("load_xref: number=%u %02X%02X%02X%02X%02X\n", (unsigned)number, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4]);
|
||||||
|
|
||||||
// Check whether this is an object definition...
|
// Check whether this is an object definition...
|
||||||
if (w[0] > 0)
|
if (w[0] > 0)
|
||||||
@ -1294,10 +1301,22 @@ load_xref(pdfio_file_t *pdf, // I - PDF file
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a placeholder for the object in memory...
|
// Create a placeholder for the object in memory...
|
||||||
if (pdfioFileFindObj(pdf, (size_t)number))
|
if ((current = pdfioFileFindObj(pdf, (size_t)number)) != NULL)
|
||||||
{
|
{
|
||||||
number ++;
|
PDFIO_DEBUG("load_xref: existing object, prev offset=%u\n", (unsigned)current->offset);
|
||||||
continue; // Don't replace newer object...
|
|
||||||
|
if (w[0] == 0 || buffer[0] == 1)
|
||||||
|
{
|
||||||
|
// Location of object...
|
||||||
|
current->offset = offset;
|
||||||
|
}
|
||||||
|
else if (number != offset)
|
||||||
|
{
|
||||||
|
// Object is part of a stream, offset is the object number...
|
||||||
|
current->offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
PDFIO_DEBUG("load_xref: new offset=%u\n", (unsigned)current->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w[0] > 0 && buffer[0] == 2)
|
if (w[0] > 0 && buffer[0] == 2)
|
||||||
@ -1313,8 +1332,12 @@ load_xref(pdfio_file_t *pdf, // I - PDF file
|
|||||||
if (i >= num_sobjs && num_sobjs < (sizeof(sobjs) / sizeof(sobjs[0])))
|
if (i >= num_sobjs && num_sobjs < (sizeof(sobjs) / sizeof(sobjs[0])))
|
||||||
sobjs[num_sobjs ++] = (size_t)offset;
|
sobjs[num_sobjs ++] = (size_t)offset;
|
||||||
}
|
}
|
||||||
else if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset))
|
else if (!current)
|
||||||
|
{
|
||||||
|
// Add this object...
|
||||||
|
if (!add_obj(pdf, (size_t)number, (unsigned short)generation, offset))
|
||||||
return (false);
|
return (false);
|
||||||
|
}
|
||||||
|
|
||||||
number ++;
|
number ++;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,10 @@ do_test_file(const char *filename, // I - PDF filename
|
|||||||
|
|
||||||
// Try opening the file...
|
// Try opening the file...
|
||||||
if (!objnum)
|
if (!objnum)
|
||||||
|
{
|
||||||
printf("%s: ", filename);
|
printf("%s: ", filename);
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
if ((pdf = pdfioFileOpen(filename, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
if ((pdf = pdfioFileOpen(filename, (pdfio_error_cb_t)error_cb, &error)) != NULL)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user