diff options
author | Robin Watts <robin.watts@artifex.com> | 2015-05-14 17:12:42 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2015-05-15 13:06:56 +0100 |
commit | 7d5ff30c37c9e5b271fdb2b8cb3219068048322e (patch) | |
tree | 5f60d1d03235f2cff161207e00515c5a4a69ef73 /source/pdf/pdf-object.c | |
parent | 250e8a11e1debfbd9c4fc84ad895bf923aac135e (diff) | |
download | mupdf-7d5ff30c37c9e5b271fdb2b8cb3219068048322e.tar.xz |
Support pdf files larger than 2Gig.
If FZ_LARGEFILE is defined when building, MuPDF uses 64bit offsets
for files; this allows us to open streams larger than 2Gig.
The downsides to this are that:
* The xref entries are larger.
* All PDF ints are held as 64bit things rather than 32bit things
(to cope with /Prev entries, hint stream offsets etc).
* All file positions are stored as 64bits rather than 32.
The implementation works by detecting FZ_LARGEFILE. Some #ifdeffery
in fitz/system.h sets fz_off_t to either int or int64_t as appropriate,
and sets defines for fz_fopen, fz_fseek, fz_ftell etc as required.
These call the fseeko64 etc functions on linux (and so define
_LARGEFILE64_SOURCE) and the explicit 64bit functions on windows.
Diffstat (limited to 'source/pdf/pdf-object.c')
-rw-r--r-- | source/pdf/pdf-object.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index f6c10b63..f0415e98 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -42,7 +42,7 @@ typedef struct pdf_obj_num_s pdf_obj super; union { - int i; + fz_off_t i; float f; } u; } pdf_obj_num; @@ -120,6 +120,18 @@ pdf_new_int(fz_context *ctx, pdf_document *doc, int i) } pdf_obj * +pdf_new_int_offset(fz_context *ctx, pdf_document *doc, fz_off_t i) +{ + pdf_obj_num *obj; + obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj_num)), "pdf_obj(offset)"); + obj->super.refs = 1; + obj->super.kind = PDF_INT; + obj->super.flags = 0; + obj->u.i = i; + return &obj->super; +} + +pdf_obj * pdf_new_real(fz_context *ctx, pdf_document *doc, float f) { pdf_obj_num *obj; @@ -268,12 +280,24 @@ int pdf_to_int(fz_context *ctx, pdf_obj *obj) if (obj < PDF_OBJ__LIMIT) return 0; if (obj->kind == PDF_INT) - return NUM(obj)->u.i; + return (int)NUM(obj)->u.i; if (obj->kind == PDF_REAL) return (int)(NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */ return 0; } +fz_off_t pdf_to_offset(fz_context *ctx, pdf_obj *obj) +{ + RESOLVE(obj); + if (obj < PDF_OBJ__LIMIT) + return 0; + if (obj->kind == PDF_INT) + return NUM(obj)->u.i; + if (obj->kind == PDF_REAL) + return (fz_off_t)(NUM(obj)->u.f + 0.5f); /* No roundf in MSVC */ + return 0; +} + float pdf_to_real(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); |