Skip to content

Commit ca9014f

Browse files
src/ src_classic/: fixes to work with latest MuPDF master.
fnptr `fz_document_open_fn` has changed.
1 parent 069e4dd commit ca9014f

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

src/__init__.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,14 +2689,24 @@ def __init__(self, filename=None, stream=None, filetype=None, rect=None, width=0
26892689
#log( f'{handler.open=}')
26902690
#log( f'{dir(handler.open)=}')
26912691
try:
2692-
doc = mupdf.ll_fz_document_open_fn_call( handler.open, filename)
2692+
if mupdf_version_tuple >= (1, 24):
2693+
doc = mupdf.ll_fz_document_open_fn_call(
2694+
handler.open,
2695+
mupdf.FzStream(filename),
2696+
mupdf.FzStream(),
2697+
mupdf.FzArchive(),
2698+
)
2699+
else:
2700+
doc = mupdf.ll_fz_document_open_fn_call( handler.open, filename)
26932701
except Exception as e:
26942702
if g_exceptions_verbose > 1: exception_info()
26952703
raise FileDataError( MSG_BAD_DOCUMENT) from e
26962704
doc = mupdf.FzDocument( doc)
2697-
elif handler.open_with_stream:
2698-
data = mupdf.fz_open_file( filename)
2699-
doc = mupdf.fz_document_open_with_stream_fn_call( handler.open_with_stream, data)
2705+
else:
2706+
if mupdf_version_tuple < (1, 24):
2707+
if handler.open_with_stream:
2708+
data = mupdf.fz_open_file( filename)
2709+
doc = mupdf.fz_document_open_with_stream_fn_call( handler.open_with_stream, data)
27002710
else:
27012711
raise ValueError( MSG_BAD_FILETYPE)
27022712
else:

src/extra.i

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,6 +1858,17 @@ static mupdf::FzDocument Document_init(
18581858
{
18591859
throw std::runtime_error(MSG_BAD_FILETYPE);
18601860
}
1861+
#if FZ_VERSION_MINOR >= 24
1862+
if (handler->open)
1863+
{
1864+
doc = mupdf::fz_document_open_fn_call(
1865+
handler->open,
1866+
mupdf::FzStream(filename),
1867+
mupdf::FzStream(),
1868+
mupdf::FzArchive()
1869+
);
1870+
}
1871+
#else
18611872
if (handler->open)
18621873
{
18631874
doc = mupdf::FzDocument(mupdf::ll_fz_document_open_fn_call(handler->open, filename));
@@ -1872,6 +1883,7 @@ static mupdf::FzDocument Document_init(
18721883
)
18731884
);
18741885
}
1886+
#endif
18751887
}
18761888
}
18771889
else

src_classic/fitz_old.i

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,31 @@ struct Document
517517
if (!handler) {
518518
RAISEPY(gctx, MSG_BAD_FILETYPE, PyExc_ValueError);
519519
}
520+
#if FZ_VERSION_MINOR >= 24
521+
if (handler->open)
522+
{
523+
fz_stream* filename_stream = fz_open_file(gctx, filename);
524+
fz_try(gctx)
525+
{
526+
doc = handler->open(gctx, filename_stream, NULL, NULL);
527+
}
528+
fz_always(gctx)
529+
{
530+
fz_drop_stream(gctx, filename_stream);
531+
}
532+
fz_catch(gctx)
533+
{
534+
fz_rethrow(gctx);
535+
}
536+
}
537+
#else
520538
if (handler->open) {
521539
doc = handler->open(gctx, filename);
522540
} else if (handler->open_with_stream) {
523541
data = fz_open_file(gctx, filename);
524542
doc = handler->open_with_stream(gctx, data);
525543
}
544+
#endif
526545
}
527546
} else {
528547
pdf_document *pdf = pdf_create_document(gctx);

0 commit comments

Comments
 (0)