Skip to content

Commit

Permalink
update mupdf
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Kowalczyk committed Jan 13, 2024
1 parent bff4ee4 commit cd2acc3
Show file tree
Hide file tree
Showing 61 changed files with 1,095 additions and 2,721 deletions.
13 changes: 9 additions & 4 deletions mupdf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ VERSION_PATCH = $(shell grep "define FZ_VERSION_PATCH" include/mupdf/fitz/versio

ifeq ($(LINUX_OR_OPENBSD),yes)
SO_VERSION = .$(VERSION_MINOR).$(VERSION_PATCH)
ifeq ($(OS),Linux)
SO_VERSION_LINUX := yes
endif
endif

# --- Commands ---
Expand Down Expand Up @@ -93,9 +96,11 @@ $(OUT)/%.exe: %.c
$(LINK_CMD)

$(OUT)/%.$(SO)$(SO_VERSION):
$(LINK_CMD) $(LIB_LDFLAGS) $(THIRD_LIBS) $(LIBCRYPTO_LIBS)
ifneq ($(SO_VERSION),)
ifeq ($(SO_VERSION_LINUX),yes)
$(LINK_CMD) -Wl,-soname,$(notdir $@) $(LIB_LDFLAGS) $(THIRD_LIBS) $(LIBCRYPTO_LIBS)
ln -sf $(notdir $@) $(patsubst %$(SO_VERSION), %, $@)
else
$(LINK_CMD) $(LIB_LDFLAGS) $(THIRD_LIBS) $(LIBCRYPTO_LIBS)
endif

$(OUT)/%.def: $(OUT)/%.$(SO)$(SO_VERSION)
Expand Down Expand Up @@ -631,14 +636,14 @@ install-shared-c: install-shared-check shared install-headers
install -d $(DESTDIR)$(libdir)
install -m 644 $(OUT)/libmupdf.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/
ifneq ($(OS),OpenBSD)
ln -s libmupdf.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/libmupdf.$(SO)
ln -sf libmupdf.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/libmupdf.$(SO)
endif

install-shared-c++: install-shared-c c++
install -m 644 platform/c++/include/mupdf/*.h $(DESTDIR)$(incdir)/mupdf
install -m 644 $(OUT)/libmupdfcpp.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/
ifneq ($(OS),OpenBSD)
ln -s libmupdfcpp.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/libmupdfcpp.$(SO)
ln -sf libmupdfcpp.$(SO)$(SO_VERSION) $(DESTDIR)$(libdir)/libmupdfcpp.$(SO)
endif

install-shared-python: install-shared-c++ python
Expand Down
38 changes: 38 additions & 0 deletions mupdf/docs/src/language-bindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1547,6 +1547,28 @@ functions and class methods.]
*/
FZ_FUNCTION std::string fz_get_glyph_name2(fz_context *ctx, fz_font *font, int glyph);
/**
Extra struct containing fz_install_load_system_font_funcs()'s args,
which we wrap with virtual_fnptrs set to allow use from Python/C# via
Swig Directors.
*/
typedef struct fz_install_load_system_font_funcs_args
{{
fz_load_system_font_fn *f;
fz_load_system_cjk_font_fn *f_cjk;
fz_load_system_fallback_font_fn *f_fallback;
}} fz_install_load_system_font_funcs_args;
/**
Alternative to fz_install_load_system_font_funcs() that takes args in a
struct, to allow use from Python/C# via Swig Directors.
*/
void fz_install_load_system_font_funcs2(fz_context *ctx, fz_install_load_system_font_funcs_args* args);

/* Internal singleton state to allow Swig Director class to find
fz_install_load_system_font_funcs_args class wrapper instance. */
extern void* fz_install_load_system_font_funcs2_state;


Python/C# bindings details
---------------------------------------------------------------
Expand Down Expand Up @@ -1640,6 +1662,22 @@ Non-standard API or implementation
* `pdf_lookup_metadata(pdfdocument, key)`: Return key value or None if not found:
* `pdf_set_annot_color()`: Takes single `color` arg which must be float or tuple of 1-4 floats.
* `pdf_set_annot_interior_color()`: Takes single `color` arg which must be float or tuple of 1-4 floats.
* `fz_install_load_system_font_funcs()`: Takes Python callbacks with no `ctx` arg,
which can return `None`, `fz_font*` or a `mupdf.FzFont`.

Example usage (from `scripts/mupdfwrap_test.py:test_install_load_system_font()`)::

def font_f(name, bold, italic, needs_exact_metrics):
print(f'font_f(): Looking for font: {name=} {bold=} {italic=} {needs_exact_metrics=}.')
return mupdf.fz_new_font_from_file(...)
def f_cjk(name, ordering, serif):
print(f'f_cjk(): Looking for font: {name=} {ordering=} {serif=}.')
return None
def f_fallback(script, language, serif, bold, italic):
print(f'f_fallback(): looking for font: {script=} {language=} {serif=} {bold=} {italic=}.')
return None
mupdf.fz_install_load_system_font_funcs(font_f, f_cjk, f_fallback)


Making MuPDF function pointers call Python code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
29 changes: 0 additions & 29 deletions mupdf/include/mupdf/fitz/archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,6 @@ int fz_is_tar_archive(fz_context *ctx, fz_stream *file);
*/
int fz_is_libarchive_archive(fz_context *ctx, fz_stream *file);

/**
Detect if stream object is a chm archive.
Assumes that the stream object is seekable.
*/
int fz_is_chm_archive(fz_context *ctx, fz_stream *file);

/**
Detect if stream object is a cfb archive.
Expand Down Expand Up @@ -267,26 +260,6 @@ fz_archive *fz_open_libarchive_archive(fz_context *ctx, const char *filename);
*/
fz_archive *fz_open_libarchive_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
Open a chm file as an archive.
An exception is thrown if the file is not recognised as a chm.
filename: a path to an archive file as it would be given to
open(2).
*/
fz_archive *fz_open_chm_archive(fz_context *ctx, const char *filename);

/**
Open a chm file as an archive.
Open an archive using a seekable stream object rather than
opening a file or directory on disk.
An exception is thrown if the file is not recognised as a chm.
*/
fz_archive *fz_open_chm_archive_with_stream(fz_context *ctx, fz_stream *file);

/**
Open a cfb file as an archive.
Expand Down Expand Up @@ -440,8 +413,6 @@ fz_archive_handler;

FZ_DATA extern const fz_archive_handler fz_libarchive_archive_handler;

FZ_DATA extern const fz_archive_handler fz_chm_archive_handler;

void fz_register_archive_handler(fz_context *ctx, const fz_archive_handler *handler);

/**
Expand Down
114 changes: 74 additions & 40 deletions mupdf/include/mupdf/fitz/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,51 +313,23 @@ typedef fz_link *(fz_page_create_link_fn)(fz_context *ctx, fz_page *page, fz_rec
*/
typedef void (fz_page_delete_link_fn)(fz_context *ctx, fz_page *page, fz_link *link);

/**
Function type to open a document from a file.
filename: file to open
Pointer to opened document. Throws exception in case of error.
*/
typedef fz_document *(fz_document_open_fn)(fz_context *ctx, const char *filename);

/**
Function type to open a
document from a file.
stream: fz_stream to read document data from. Must be
seekable for formats that require it.
Pointer to opened document. Throws exception in case of error.
*/
typedef fz_document *(fz_document_open_with_stream_fn)(fz_context *ctx, fz_stream *stream);

/**
Function type to open a document from a
file, with accelerator data.
filename: file to open
accel: accelerator file
Pointer to opened document. Throws exception in case of error.
*/
typedef fz_document *(fz_document_open_accel_fn)(fz_context *ctx, const char *filename, const char *accel);

/**
Function type to open a document from a file,
with accelerator data.
stream: fz_stream to read document data from. Must be
seekable for formats that require it.
accel: fz_stream to read accelerator data from. May be
NULL. May be ignored.
accel: fz_stream to read accelerator data from. Must be
seekable for formats that require it.
dir: 'Directory context' in which the document is loaded;
associated content from (like images for an html stream
will be loaded from this). Maybe NULL. May be ignored.
Pointer to opened document. Throws exception in case of error.
*/
typedef fz_document *(fz_document_open_accel_with_stream_fn)(fz_context *ctx, fz_stream *stream, fz_stream *accel);
typedef fz_document *(fz_document_open_fn)(fz_context *ctx, fz_stream *stream, fz_stream *accel, fz_archive *dir);

/**
Recognize a document type from
Expand All @@ -375,13 +347,16 @@ typedef int (fz_document_recognize_fn)(fz_context *ctx, const char *magic);
/**
Recognize a document type from stream contents.
stream: stream contents to recognise.
stream: stream contents to recognise (may be NULL if document is
a directory).
dir: directory context from which stream is loaded.
Returns a number between 0 (not recognized) and 100
(fully recognized) based on how certain the recognizer
is that this is of the required type.
*/
typedef int (fz_document_recognize_content_fn)(fz_context *ctx, fz_stream *stream);
typedef int (fz_document_recognize_content_fn)(fz_context *ctx, fz_stream *stream, fz_archive *dir);

/**
Type for a function to be called when processing an already opened page.
Expand Down Expand Up @@ -425,13 +400,29 @@ const fz_document_handler *fz_recognize_document_content(fz_context *ctx, const
Given a magic find a document handler that can handle a
document of this type.
stream: the file stream to sample.
stream: the file stream to sample. May be NULL if the document is
a directory.
magic: Can be a filename extension (including initial period) or
a mimetype.
*/
const fz_document_handler *fz_recognize_document_stream_content(fz_context *ctx, fz_stream *stream, const char *magic);

/**
Given a magic find a document handler that can handle a
document of this type.
stream: the file stream to sample. May be NULL if the document is
a directory.
dir: an fz_archive representing the directory from which the
stream was opened (or NULL).
magic: Can be a filename extension (including initial period) or
a mimetype.
*/
const fz_document_handler *fz_recognize_document_stream_and_dir_content(fz_context *ctx, fz_stream *stream, fz_archive *dir, const char *magic);

/**
Open a document file and read its basic structure so pages and
objects can be located. MuPDF will try to repair broken
Expand Down Expand Up @@ -462,9 +453,30 @@ fz_document *fz_open_accelerated_document(fz_context *ctx, const char *filename,
magic: a string used to detect document type; either a file name
or mime-type.
stream: a stream representing the contents of the document file.
NOTE: The caller retains ownership of 'stream' - the document will take its
own reference if required.
*/
fz_document *fz_open_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream);

/**
Open a document using the specified stream object rather than
opening a file on disk.
magic: a string used to detect document type; either a file name
or mime-type.
stream: a stream representing the contents of the document file.
dir: a 'directory context' for those filetypes that need it.
NOTE: The caller retains ownership of 'stream' and 'dir' - the document will
take its own references if required.
*/
fz_document *fz_open_document_with_stream_and_dir(fz_context *ctx, const char *magic, fz_stream *stream, fz_archive *dir);

/**
Open a document using a buffer rather than opening a file on disk.
*/
Expand All @@ -476,9 +488,34 @@ fz_document *fz_open_document_with_buffer(fz_context *ctx, const char *magic, fz
magic: a string used to detect document type; either a file name
or mime-type.
stream: a stream of the document contents.
accel: NULL, or a stream of the 'accelerator' contents for this document.
NOTE: The caller retains ownership of 'stream' and 'accel' - the document will
take its own references if required.
*/
fz_document *fz_open_accelerated_document_with_stream(fz_context *ctx, const char *magic, fz_stream *stream, fz_stream *accel);

/**
Open a document using the specified stream object rather than
opening a file on disk.
magic: a string used to detect document type; either a file name
or mime-type.
stream: a stream of the document contents.
accel: NULL, or a stream of the 'accelerator' contents for this document.
dir: NULL, or the 'directory context' for the stream contents.
NOTE: The caller retains ownership of 'stream', 'accel' and 'dir' - the document will
take its own references if required.
*/
fz_document *fz_open_accelerated_document_with_stream_and_dir(fz_context *ctx, const char *magic, fz_stream *stream, fz_stream *accel, fz_archive *dir);

/**
Query if the document supports the saving of accelerator data.
*/
Expand Down Expand Up @@ -994,11 +1031,8 @@ struct fz_document_handler
{
fz_document_recognize_fn *recognize;
fz_document_open_fn *open;
fz_document_open_with_stream_fn *open_with_stream;
const char **extensions;
const char **mimetypes;
fz_document_open_accel_fn *open_accel;
fz_document_open_accel_with_stream_fn *open_accel_with_stream;
fz_document_recognize_content_fn *recognize_content;
};

Expand Down
38 changes: 38 additions & 0 deletions mupdf/include/mupdf/fitz/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,44 @@ int fz_unicode_from_glyph_name_strict(const char *name);
const char **fz_duplicate_glyph_names_from_unicode(int unicode);
const char *fz_glyph_name_from_unicode_sc(int unicode);

/**
* A text decoder (to read arbitrary encodings and convert to unicode).
*/
typedef struct fz_text_decoder fz_text_decoder;

struct fz_text_decoder {
// get maximum size estimate of converted text (fast)
int (*decode_bound)(fz_text_decoder *dec, unsigned char *input, int n);

// get exact size of converted text (slow)
int (*decode_size)(fz_text_decoder *dec, unsigned char *input, int n);

// convert text into output buffer
void (*decode)(fz_text_decoder *dec, char *output, unsigned char *input, int n);

// for internal use only; do not touch!
void *table1;
void *table2;
};

/* Initialize a text decoder using an IANA encoding name.
* See source/fitz/text-decoder.c for the exact list of supported encodings.
* Will throw an exception if the requested encoding is not available.
*
* The following is a subset of the supported encodings (see source/fitz/text-decoder.c for the full list):
* iso-8859-1
* iso-8859-7
* koi8-r
* euc-jp
* shift_jis
* euc-kr
* euc-cn
* gb18030
* euc-tw
* big5
*/
void fz_init_text_decoder(fz_context *ctx, fz_text_decoder *dec, const char *encoding);

/**
An abstract font handle.
*/
Expand Down
Loading

0 comments on commit cd2acc3

Please sign in to comment.