Hash :
bc50dcec
Author :
Thomas de Grivel
Date :
2025-09-24T15:58:05
fix pdf tests
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
/* kc3
* Copyright from 2022 to 2025 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software granted the above
* copyright notice and this permission paragraph are included in all
* copies and substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include "../libkc3/kc3.h"
#include "pdf_file.h"
#include "pdf_name.h"
#include "pdf_trailer.h"
s_pdf_file * pdf_file_init (s_pdf_file *pdf_file)
{
s_pdf_file tmp = {0};
*pdf_file = tmp;
return pdf_file;
}
void pdf_file_clean (s_pdf_file *pdf_file)
{
pdf_trailer_clean(&pdf_file->trailer);
str_clean(&pdf_file->header);
map_clean(&pdf_file->body);
map_clean(&pdf_file->xref);
pdf_name_list_delete_all(&pdf_file->name_list);
}
s_tag * pdf_file_get_indirect_object (s_pdf_file *pdf_file,
s_tag *ref, s_tag *dest)
{
u32 object_number;
u16 generation_number;
uw i;
if (! pdf_file)
return tag_init_void(dest);
if (ref->type != TAG_TUPLE ||
ref->data.tuple.count != 3 ||
ref->data.tuple.tag[0].type != TAG_PSYM ||
ref->data.tuple.tag[0].data.psym != sym_1("indirect_object") ||
ref->data.tuple.tag[1].type != TAG_U32 ||
ref->data.tuple.tag[2].type != TAG_U16) {
err_puts("pdf_file_get_indirect_object: invalid indirect object"
" reference:");
err_inspect_tag(ref);
assert(!("pdf_file_get_indirect_object: invalid indirect object"
" reference"));
return NULL;
}
object_number = ref->data.tuple.tag[1].data.u32;
generation_number = ref->data.tuple.tag[2].data.u16;
i = 0;
while (i < pdf_file->body.count) {
if (pdf_file->body.key[i].type != TAG_TUPLE ||
pdf_file->body.key[i].data.tuple.count != 2 ||
pdf_file->body.key[i].data.tuple.tag[0].type != TAG_U32 ||
pdf_file->body.key[i].data.tuple.tag[1].type != TAG_U16) {
err_puts("pdf_file_get_indirect_object: invalid pdf file body");
assert(! "pdf_file_get_indirect_object: invalid pdf file body");
return NULL;
}
if (pdf_file->body.key[i].data.tuple.tag[0].data.u32 ==
object_number &&
pdf_file->body.key[i].data.tuple.tag[1].data.u16 ==
generation_number)
return tag_init_copy(dest, pdf_file->body.value + i);
i++;
}
return tag_init_void(dest);
}