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 30, 2024
1 parent ec26eb9 commit 0b06ed3
Show file tree
Hide file tree
Showing 47 changed files with 789 additions and 7,666 deletions.
6 changes: 2 additions & 4 deletions mupdf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ install-docs:

install -d $(DESTDIR)$(docdir)
install -d $(DESTDIR)$(docdir)/examples
install -m 644 README COPYING CHANGES $(DESTDIR)$(docdir)
install -m 644 README CHANGES $(DESTDIR)$(docdir)
install -m 644 $(wildcard COPYING LICENSE) $(DESTDIR)$(docdir)
install -m 644 docs/examples/* $(DESTDIR)$(docdir)/examples

install: install-libs install-apps install-docs
Expand Down Expand Up @@ -523,9 +524,6 @@ watch:
watch-recompile:
@ while ! inotifywait -q -e modify $(WATCH_SRCS) ; do time -p $(MAKE) ; done

wasm:
$(MAKE) -C platform/wasm

java:
$(MAKE) -C platform/java build=$(build)

Expand Down
199 changes: 115 additions & 84 deletions mupdf/docs/src/language-bindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1484,90 +1484,121 @@ functions and class methods.]

.. code-block:: c++

/**
C++ alternative to `fz_lookup_metadata()` that returns a `std::string`
or calls `fz_throw()` if not found.
*/
FZ_FUNCTION std::string fz_lookup_metadata2(fz_context* ctx, fz_document* doc, const char* key);

/**
C++ alternative to `pdf_lookup_metadata()` that returns a `std::string`
or calls `fz_throw()` if not found.
*/
FZ_FUNCTION std::string pdf_lookup_metadata2(fz_context* ctx, pdf_document* doc, const char* key);

/**
C++ alternative to `fz_md5_pixmap()` that returns the digest by value.
*/
FZ_FUNCTION std::vector<unsigned char> fz_md5_pixmap2(fz_context* ctx, fz_pixmap* pixmap);

/**
C++ alternative to fz_md5_final() that returns the digest by value.
*/
FZ_FUNCTION std::vector<unsigned char> fz_md5_final2(fz_md5* md5);

/** */
FZ_FUNCTION long long fz_pixmap_samples_int(fz_context* ctx, fz_pixmap* pixmap);

/**
Provides simple (but slow) access to pixmap data from Python and C#.
*/
FZ_FUNCTION int fz_samples_get(fz_pixmap* pixmap, int offset);

/**
Provides simple (but slow) write access to pixmap data from Python and
C#.
*/
FZ_FUNCTION void fz_samples_set(fz_pixmap* pixmap, int offset, int value);

/**
C++ alternative to fz_highlight_selection() that returns quads in a
std::vector.
*/
FZ_FUNCTION std::vector<fz_quad> fz_highlight_selection2(fz_context* ctx, fz_stext_page* page, fz_point a, fz_point b, int max_quads);

struct fz_search_page2_hit
{{
fz_quad quad;
int mark;
}};

/**
C++ alternative to fz_search_page() that returns information in a std::vector.
*/
FZ_FUNCTION std::vector<fz_search_page2_hit> fz_search_page2(fz_context* ctx, fz_document *doc, int number, const char *needle, int hit_max);
/**
C++ alternative to fz_string_from_text_language() that returns information in a std::string.
*/
FZ_FUNCTION std::string fz_string_from_text_language2(fz_text_language lang);
/**
C++ alternative to fz_get_glyph_name() that returns information in a std::string.
*/
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;
/**
C++ alternative to `fz_lookup_metadata()` that returns a `std::string`
or calls `fz_throw()` if not found.
*/
FZ_FUNCTION std::string fz_lookup_metadata2(fz_context* ctx, fz_document* doc, const char* key);

/**
C++ alternative to `pdf_lookup_metadata()` that returns a `std::string`
or calls `fz_throw()` if not found.
*/
FZ_FUNCTION std::string pdf_lookup_metadata2(fz_context* ctx, pdf_document* doc, const char* key);

/**
C++ alternative to `fz_md5_pixmap()` that returns the digest by value.
*/
FZ_FUNCTION std::vector<unsigned char> fz_md5_pixmap2(fz_context* ctx, fz_pixmap* pixmap);

/**
C++ alternative to fz_md5_final() that returns the digest by value.
*/
FZ_FUNCTION std::vector<unsigned char> fz_md5_final2(fz_md5* md5);

/** */
FZ_FUNCTION long long fz_pixmap_samples_int(fz_context* ctx, fz_pixmap* pixmap);

/**
Provides simple (but slow) access to pixmap data from Python and C#.
*/
FZ_FUNCTION int fz_samples_get(fz_pixmap* pixmap, int offset);

/**
Provides simple (but slow) write access to pixmap data from Python and
C#.
*/
FZ_FUNCTION void fz_samples_set(fz_pixmap* pixmap, int offset, int value);

/**
C++ alternative to fz_highlight_selection() that returns quads in a
std::vector.
*/
FZ_FUNCTION std::vector<fz_quad> fz_highlight_selection2(fz_context* ctx, fz_stext_page* page, fz_point a, fz_point b, int max_quads);

struct fz_search_page2_hit
{{
fz_quad quad;
int mark;
}};

/**
C++ alternative to fz_search_page() that returns information in a std::vector.
*/
FZ_FUNCTION std::vector<fz_search_page2_hit> fz_search_page2(fz_context* ctx, fz_document* doc, int number, const char* needle, int hit_max);

/**
C++ alternative to fz_string_from_text_language() that returns information in a std::string.
*/
FZ_FUNCTION std::string fz_string_from_text_language2(fz_text_language lang);
/**
C++ alternative to fz_get_glyph_name() that returns information in a std::string.
*/
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.
*/
FZ_FUNCTION 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. */
FZ_DATA extern void* fz_install_load_system_font_funcs2_state;

/** Helper for calling a `fz_document_open_fn` function pointer via Swig
from Python/C#. */
FZ_FUNCTION fz_document* fz_document_open_fn_call(fz_context* ctx, fz_document_open_fn fn, fz_stream* stream, fz_stream* accel, fz_archive* dir);

/** Helper for calling a `fz_document_recognize_content_fn` function
pointer via Swig from Python/C#. */
FZ_FUNCTION int fz_document_recognize_content_fn_call(fz_context* ctx, fz_document_recognize_content_fn fn, fz_stream* stream, fz_archive* dir);

/* Swig-friendly wrapper for pdf_choice_widget_options(), returns the
options directly in a vector. */
FZ_FUNCTION std::vector<std::string> pdf_choice_widget_options2(fz_context* ctx, pdf_annot* tw, int exportval);

/** Swig-friendly wrapper for fz_new_image_from_compressed_buffer(),
uses specified `decode` and `colorkey` if they are not null (in which
case we assert that they have size `2*fz_colorspace_n(colorspace)`). */
FZ_FUNCTION fz_image* fz_new_image_from_compressed_buffer2(
fz_context* ctx,
int w,
int h,
int bpc,
fz_colorspace* colorspace,
int xres,
int yres,
int interpolate,
int imagemask,
const std::vector<float>* decode,
const std::vector<int>* colorkey,
fz_compressed_buffer* buffer,
fz_image* mask
);


Python/C# bindings details
Expand Down
8 changes: 7 additions & 1 deletion mupdf/include/mupdf/fitz/compressed-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ typedef struct
*/
typedef struct
{
int refs;
fz_compression_params params;
fz_buffer *buffer;
} fz_compressed_buffer;

/**
Take a reference to an fz_compressed_buffer.
*/
fz_compressed_buffer *fz_keep_compressed_buffer(fz_context *ctx, fz_compressed_buffer *cbuf);

/**
Return the storage size used for a buffer and its data.
Used in implementing store handling.
Expand Down Expand Up @@ -172,7 +178,7 @@ enum
void fz_drop_compressed_buffer(fz_context *ctx, fz_compressed_buffer *buf);

/**
Create a new, UNKNOWN format, compressed_buffer;
Create a new, UNKNOWN format, compressed_buffer.
*/
fz_compressed_buffer *fz_new_compressed_buffer(fz_context *ctx);

Expand Down
6 changes: 3 additions & 3 deletions mupdf/include/mupdf/fitz/image.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ fz_image *fz_new_image_of_size(fz_context *ctx,
int yres,
int interpolate,
int imagemask,
float *decode,
int *colorkey,
const float *decode,
const int *colorkey,
fz_image *mask,
size_t size,
fz_image_get_pixmap_fn *get_pixmap,
Expand Down Expand Up @@ -243,7 +243,7 @@ fz_image *fz_new_image_of_size(fz_context *ctx,
A new reference is taken to this image. Supplying a masked
image as a mask to another image is illegal!
*/
fz_image *fz_new_image_from_compressed_buffer(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, int xres, int yres, int interpolate, int imagemask, float *decode, int *colorkey, fz_compressed_buffer *buffer, fz_image *mask);
fz_image *fz_new_image_from_compressed_buffer(fz_context *ctx, int w, int h, int bpc, fz_colorspace *colorspace, int xres, int yres, int interpolate, int imagemask, const float *decode, const int *colorkey, fz_compressed_buffer *buffer, fz_image *mask);

/**
Create an image from the given
Expand Down
32 changes: 29 additions & 3 deletions mupdf/include/mupdf/fitz/story.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,21 @@ fz_story *fz_new_story(fz_context *ctx, fz_buffer *buf, const char *user_css, fl
*/
const char *fz_story_warnings(fz_context *ctx, fz_story *story);

/*
Equivalent to fz_place_story_flags with flags being 0.
*/
int fz_place_story(fz_context *ctx, fz_story *story, fz_rect where, fz_rect *filled);

/*
Place (or continue placing) a story into the supplied rectangle
'where', updating 'filled' with the actual area that was used.
Returns zero if all the content fitted, non-zero if there is
more to fit.
Returns zero (FZ_PLACE_STORY_RETURN_ALL_FITTED) if all the
content fitted, non-zero if there is more to fit.
If the FZ_PLACE_STORY_FLAG_NO_OVERFLOW flag is set, then a
return code of FZ_PLACE_STORY_RETURN_OVERFLOW_WIDTH will be
returned when the next item (word) to be placed would not fit
in a rectangle of that given width.
Note, that filled may not be returned as a strict subset of
where, due to padding/margins at the bottom of pages, and
Expand All @@ -95,8 +105,24 @@ const char *fz_story_warnings(fz_context *ctx, fz_story *story);
After this function is called, the DOM is no longer accessible,
and any fz_xml pointer retrieved from fz_story_document is no
longer valid.
flags: Additional flags controlling layout. Pass 0 if none
required.
*/
int fz_place_story(fz_context *ctx, fz_story *story, fz_rect where, fz_rect *filled);
int fz_place_story_flags(fz_context *ctx, fz_story *story, fz_rect where, fz_rect *filled, int flags);

enum
{
/* Avoid the usual HTML behaviour of overflowing the box horizontally
* in some circumstances. We now abort the place in such cases and
* return with */
FZ_PLACE_STORY_FLAG_NO_OVERFLOW = 1,

/* Specific return codes from fz_place_story_flags. Also
* "non-zero" for 'more to fit'. */
FZ_PLACE_STORY_RETURN_ALL_FITTED = 0,
FZ_PLACE_STORY_RETURN_OVERFLOW_WIDTH = 2
};

/*
Draw the placed story to the given device.
Expand Down
9 changes: 9 additions & 0 deletions mupdf/include/mupdf/pdf/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pdf_obj *pdf_page_resources(fz_context *ctx, pdf_page *page);
pdf_obj *pdf_page_contents(fz_context *ctx, pdf_page *page);
pdf_obj *pdf_page_group(fz_context *ctx, pdf_page *page);

void pdf_set_page_box(fz_context *ctx, pdf_page *page, fz_box_type box, fz_rect rect);

/*
Get the separation details for a page.
*/
Expand Down Expand Up @@ -163,10 +165,17 @@ enum {
PDF_REDACT_IMAGE_PIXELS,
};

enum {
PDF_REDACT_LINE_ART_NONE,
PDF_REDACT_LINE_ART_REMOVE_IF_COVERED,
PDF_REDACT_LINE_ART_REMOVE_IF_TOUCHED
};

typedef struct
{
int black_boxes;
int image_method;
int line_art;
} pdf_redact_options;

int pdf_redact_page(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_redact_options *opts);
Expand Down
7 changes: 4 additions & 3 deletions mupdf/platform/gl/gl-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,7 @@ void do_redact_panel(void)
int i;

int num_redact = 0;
static pdf_redact_options redact_opts = { 1, PDF_REDACT_IMAGE_PIXELS };
static pdf_redact_options redact_opts = { 1, PDF_REDACT_IMAGE_PIXELS, PDF_REDACT_LINE_ART_REMOVE_IF_TOUCHED };
int search_valid;

if (pdf_has_redactions_doc != pdf)
Expand Down Expand Up @@ -1486,9 +1486,10 @@ void do_redact_panel(void)
if (ui_button_aux("Redact Page", num_redact == 0))
{
ui_select_annot(NULL);
trace_action("page.applyRedactions(%s, %d);\n",
trace_action("page.applyRedactions(%s, %d, %d);\n",
redact_opts.black_boxes ? "true" : "false",
redact_opts.image_method);
redact_opts.image_method,
redact_opts.line_art);
pdf_redact_page(ctx, pdf, page, &redact_opts);
trace_page_update();
load_page();
Expand Down
4 changes: 3 additions & 1 deletion mupdf/platform/java/jni/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,13 @@ fz_java_device_begin_mask(fz_context *ctx, fz_device *dev, fz_rect rect, int lum
}

static void
fz_java_device_end_mask(fz_context *ctx, fz_device *dev)
fz_java_device_end_mask(fz_context *ctx, fz_device *dev, fz_function *tr)
{
fz_java_device *jdev = (fz_java_device *)dev;
JNIEnv *env = jdev->env;

// TODO: pass transfer function

(*env)->CallVoidMethod(env, jdev->self, mid_Device_endMask);
if ((*env)->ExceptionCheck(env))
fz_throw_java(ctx, env);
Expand Down
Loading

0 comments on commit 0b06ed3

Please sign in to comment.