Skip to content

Commit

Permalink
MuPDF 1.12 (#577)
Browse files Browse the repository at this point in the history
* Updated to MuPDF 1.12

* mupdf_new_pixmap_with_data missed parameters

* Make all parameters of fz_get_pixmap_from_image available, remove the unused with and height

* Drop buffer and image as soon as possible as per poire-z's recommendation

* encrypted zip patch for MuPDF 1.12

* external fonts patch for MuPDF 1.12

* Use libjpeg as a shared library

* Wrong patch number

* git.ghostscript.com is slow, so we use the official mirror on GitHub

* html-font patch, just enough to test html & epub rendering

* Regenerated mupdf_h.lua with ffi-cdecl

* fz_new_text_page has been renamed to fz_new_stext_page

* Wrong mupdf_new_text_page parameters, mupdf_new_text_sheet is no longer needed

* getPageText works again

* Adding higlights almost works (width is 50% off), PDF saving works

Requires changes to PdfDocument:saveHighlight too (that is outside of
base).

* Do not select bullet points

* The incompatible bb error messages show the blitbuffer types

* Support blitting from RGB24 to RGB32 in BB_alpha_blit_from

* getPageText returned everything twice

* Unit test update

* 'SIZE_MAX' was undeclared on Android
  • Loading branch information
TnS-hun authored and Frenzie committed Dec 20, 2017
1 parent 145e18a commit bd97e1b
Show file tree
Hide file tree
Showing 16 changed files with 864 additions and 569 deletions.
4 changes: 1 addition & 3 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,7 @@ MUPDF_BUILD_DIR=$(CURDIR)/$(THIRDPARTY_DIR)/mupdf/build/$(MACHINE)
MUPDF_DIR=$(MUPDF_BUILD_DIR)/mupdf-prefix/src/mupdf
MUPDF_LIB_DIR=$(MUPDF_DIR)/build/release
MUPDF_LIB_STATIC=$(MUPDF_LIB_DIR)/libmupdf.a
MUPDF_JS_LIB_STATIC=$(MUPDF_LIB_DIR)/libmujs.a
MUPDF_THIRDPARTY_LIBS=$(MUPDF_LIB_DIR)/libopenjpeg.a \
$(MUPDF_LIB_DIR)/libjbig2dec.a \
MUPDF_THIRDPARTY_LIBS=$(MUPDF_LIB_DIR)/libmupdfthird.a \
$(AES_LIB)
MUPDF_LIB=$(OUTPUT_DIR)/libs/libmupdf$(LIB_EXT)

Expand Down
1 change: 0 additions & 1 deletion Makefile.third
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ $(MUPDF_LIB) $(MUPDF_DIR)/include: $(JPEG_LIB) \
-DAR="$(AR)" -DLDFLAGS="$(LDFLAGS) -L$(CURDIR)/$(OUTPUT_DIR)" \
-DXCFLAGS="$(CFLAGS) -DNOBUILTINFONT -I$(JPEG_DIR)/include -I$(FREETYPE_DIR)/include/freetype2 -I$(ZLIB_DIR) -I$(MINIZIP_DIR)" \
-DMUPDF_LIB_STATIC=$(MUPDF_LIB_STATIC) \
-DMUPDF_JS_LIB_STATIC=$(MUPDF_JS_LIB_STATIC) \
-DMUPDF_THIRDPARTY_LIBS=$(MUPDF_THIRDPARTY_LIBS) \
-DMUPDF_LIB=$(CURDIR)/$(MUPDF_LIB) \
-DMUPDF_SONAME=$(notdir $(MUPDF_LIB)) \
Expand Down
41 changes: 28 additions & 13 deletions blitbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ void BB_add_blit_from(BlitBuffer *dst, BlitBuffer *src,
int sbb_rotation = GET_BB_ROTATION(src);
int dbb_rotation = GET_BB_ROTATION(dst);
if (dbb_type != sbb_type) {
fprintf(stderr, "incompatible bb in file %s, line %d!\r\n",
__FILE__, __LINE__); exit(1);
fprintf(stderr, "incompatible bb (dst: %d, src: %d) in file %s, line %d!\r\n",
dbb_type, sbb_type, __FILE__, __LINE__); exit(1);
}
uint8_t r, g, b;
uint8_t ainv = 0xFF - alpha;
Expand Down Expand Up @@ -686,13 +686,9 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
int sbb_type = GET_BB_TYPE(src);
int sbb_rotation = GET_BB_ROTATION(src);
int dbb_rotation = GET_BB_ROTATION(dst);
if (dbb_type != sbb_type) {
fprintf(stderr, "incompatible bb in file %s, line %d!\r\n",
__FILE__, __LINE__); exit(1);
}
uint8_t r, g, b, ainv, alpha;
int d_x, d_y, o_x, o_y;
if (dbb_type == TYPE_BB8) {
if (dbb_type == TYPE_BB8 && sbb_type == TYPE_BB8) {
o_x = offs_x;
Color8 *dstptr, *srcptr;
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
Expand All @@ -705,7 +701,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
}
o_x += 1;
}
} else if (dbb_type == TYPE_BB8A) {
} else if (dbb_type == TYPE_BB8A && sbb_type == TYPE_BB8A) {
o_x = offs_x;
Color8A *dstptr, *srcptr;
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
Expand All @@ -720,7 +716,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
}
o_x += 1;
}
} else if (dbb_type == TYPE_BBRGB16) {
} else if (dbb_type == TYPE_BBRGB16 && sbb_type == TYPE_BBRGB16) {
o_x = offs_x;
ColorRGB16 *dstptr, *srcptr;
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
Expand All @@ -733,7 +729,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
}
o_x += 1;
}
} else if (dbb_type == TYPE_BBRGB24) {
} else if (dbb_type == TYPE_BBRGB24 && sbb_type == TYPE_BBRGB24) {
o_x = offs_x;
ColorRGB24 *dstptr, *srcptr;
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
Expand All @@ -746,7 +742,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
}
o_x += 1;
}
} else if (dbb_type == TYPE_BBRGB32) {
} else if (dbb_type == TYPE_BBRGB32 && sbb_type == TYPE_BBRGB32) {
o_x = offs_x;
ColorRGB32 *dstptr, *srcptr;
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
Expand All @@ -763,6 +759,25 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
}
o_x += 1;
}
} else if (dbb_type == TYPE_BBRGB32 && sbb_type == TYPE_BBRGB24) {
o_x = offs_x;
ColorRGB32 *dstptr;
ColorRGB24 *srcptr;
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
o_y = offs_y;
for (d_y = dest_y; d_y < dest_y + h; d_y++) {
BB_GET_PIXEL(dst, dbb_rotation, ColorRGB32, d_x, d_y, &dstptr);
BB_GET_PIXEL(src, sbb_rotation, ColorRGB24, o_x, o_y, &srcptr);
dstptr->r = srcptr->r;
dstptr->g = srcptr->g;
dstptr->b = srcptr->b;
o_y += 1;
}
o_x += 1;
}
} else {
fprintf(stderr, "incompatible bb (dst: %d, src: %d) in file %s, line %d!\r\n",
dbb_type, sbb_type, __FILE__, __LINE__); exit(1);
}
}

Expand All @@ -773,8 +788,8 @@ void BB_invert_blit_from(BlitBuffer *dst, BlitBuffer *src,
int sbb_rotation = GET_BB_ROTATION(src);
int dbb_rotation = GET_BB_ROTATION(dst);
if (dbb_type != sbb_type) {
fprintf(stderr, "incompatible bb in file %s, line %d!\r\n",
__FILE__, __LINE__); exit(1);
fprintf(stderr, "incompatible bb (dst: %d, src: %d) in file %s, line %d!\r\n",
dbb_type, sbb_type, __FILE__, __LINE__); exit(1);
}
int d_x, d_y, o_x, o_y;
if (dbb_type == TYPE_BB8) {
Expand Down
77 changes: 39 additions & 38 deletions ffi-cdecl/mupdf_decl.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "ffi-cdecl.h"

cdecl_const(FZ_PAGE_BLOCK_TEXT)
cdecl_const(FZ_STEXT_BLOCK_TEXT)

/* math */
cdecl_type(fz_point)
Expand Down Expand Up @@ -41,9 +41,17 @@ cdecl_func(fz_transform_rect)

/* misc/assorted */
cdecl_type(fz_context)
cdecl_type(fz_font)
cdecl_type(fz_hash_table)
cdecl_type(fz_storable)
cdecl_type(fz_key_storable)
cdecl_type(fz_store_drop_fn)
cdecl_struct(fz_storable_s)
cdecl_struct(fz_key_storable_s)

/* buffer */
cdecl_func(mupdf_new_buffer_from_shared_data)
cdecl_func(mupdf_drop_buffer)

/* context */
cdecl_type(fz_alloc_context)
Expand All @@ -57,27 +65,24 @@ cdecl_type(fz_image)
cdecl_type(fz_pixmap)
cdecl_struct(fz_image_s)
cdecl_struct(fz_pixmap_s)
cdecl_func(fz_new_image_from_data) // compat, use wrapper instead:
cdecl_func(mupdf_new_image_from_data)
cdecl_func(fz_new_pixmap_from_image) // compat, use wrapper instead:
cdecl_func(mupdf_new_pixmap_from_image)
cdecl_func(mupdf_new_image_from_buffer)
cdecl_func(mupdf_get_pixmap_from_image)
cdecl_func(mupdf_save_pixmap_as_png)
cdecl_func(fz_keep_image)
cdecl_func(fz_drop_image)

cdecl_func(fz_load_png)
cdecl_func(fz_runetochar)

/* document */
cdecl_enum(fz_link_kind_e)
cdecl_type(fz_link_dest)
cdecl_struct(fz_link_dest_s)
cdecl_type(fz_annot)
cdecl_struct(fz_annot_s)
cdecl_type(fz_outline)
cdecl_struct(fz_outline_s)
cdecl_type(fz_document)
cdecl_type(fz_page)
cdecl_type(fz_write_options)
cdecl_struct(fz_document_s)
cdecl_type(fz_link)
cdecl_struct(fz_document_s)
cdecl_struct(fz_page_s)

cdecl_func(mupdf_open_document)
Expand All @@ -86,6 +91,7 @@ cdecl_func(fz_authenticate_password)
cdecl_func(fz_drop_document) // NOTE: libk2pdfopt uses old fz_free_document symbol
cdecl_func(mupdf_count_pages)
cdecl_func(fz_lookup_metadata)
cdecl_func(fz_resolve_link)

/* page */
cdecl_func(mupdf_load_page)
Expand All @@ -102,33 +108,20 @@ cdecl_func(mupdf_load_outline)
cdecl_func(fz_drop_outline) // NOTE: libk2pdfopt uses old fz_free_outline symbol

/* structured text */
cdecl_type(fz_text_style)
cdecl_struct(fz_text_style_s)

cdecl_type(fz_text_char)
cdecl_struct(fz_text_char_s)

cdecl_type(fz_text_span)
cdecl_struct(fz_text_span_s)

cdecl_type(fz_text_line)
cdecl_struct(fz_text_line_s)

cdecl_type(fz_text_sheet)
cdecl_struct(fz_text_sheet_s)
cdecl_func(mupdf_new_text_sheet)
cdecl_func(fz_drop_text_sheet) // NOTE: libk2pdfopt uses old fz_free_text_sheet symbol
cdecl_type(fz_stext_char)
cdecl_struct(fz_stext_char_s)

cdecl_type(fz_text_page)
cdecl_type(fz_page_block)
cdecl_struct(fz_text_page_s)
cdecl_func(mupdf_new_text_page)
cdecl_func(fz_drop_text_page) // NOTE: libk2pdfopt uses old fz_free_text_page symbol
cdecl_type(fz_text_block)
cdecl_struct(fz_page_block_s)
cdecl_struct(fz_text_block_s)
cdecl_type(fz_stext_line)
cdecl_struct(fz_stext_line_s)

cdecl_func(fz_text_char_bbox)
cdecl_type(fz_stext_block)
cdecl_struct(fz_stext_block_s)
cdecl_type(fz_stext_options)
cdecl_struct(fz_stext_options_s)
cdecl_type(fz_stext_page)
cdecl_struct(fz_stext_page_s)
cdecl_func(mupdf_new_stext_page_from_page)
cdecl_func(fz_drop_stext_page) // NOTE: libk2pdfopt uses old fz_free_text_page symbol

/* pixmaps */
cdecl_func(mupdf_new_pixmap)
Expand All @@ -141,6 +134,7 @@ cdecl_func(fz_keep_pixmap)
cdecl_func(fz_drop_pixmap)
cdecl_func(fz_clear_pixmap_with_value)
cdecl_func(fz_gamma_pixmap)
cdecl_func(fz_scale_pixmap)
cdecl_func(fz_pixmap_width)
cdecl_func(fz_pixmap_height)
cdecl_func(fz_pixmap_components)
Expand All @@ -154,28 +148,35 @@ cdecl_func(mupdf_new_draw_device)
cdecl_func(mupdf_new_text_device)
cdecl_func(mupdf_new_bbox_device)
cdecl_func(mupdf_run_page)
cdecl_func(fz_close_device)
cdecl_func(fz_drop_device) // NOTE: libk2pdfopt uses old fz_free_device symbol

/* pdf specifics */
cdecl_enum(fz_annot_type)
cdecl_type(pdf_hotspot)
cdecl_struct(pdf_hotspot_s)
cdecl_type(pdf_lexbuf)
cdecl_struct(pdf_lexbuf_s)
cdecl_type(pdf_lexbuf_large)
cdecl_struct(pdf_lexbuf_large_s)
cdecl_type(pdf_obj)
cdecl_type(pdf_xobject)
cdecl_type(pdf_annot)
cdecl_type(pdf_page)
cdecl_struct(pdf_xobject_s)
cdecl_struct(pdf_annot_s)
cdecl_type(pdf_document)
cdecl_struct(pdf_document_s)
cdecl_func(pdf_specifics)
cdecl_func(mupdf_pdf_create_annot)
cdecl_func(mupdf_pdf_set_markup_annot_quadpoints)
cdecl_func(mupdf_pdf_set_annot_quad_points)
cdecl_func(mupdf_pdf_set_text_annot_position)
cdecl_func(mupdf_pdf_set_markup_appearance)

/* saving documents */
cdecl_struct(fz_write_options_s)
cdecl_func(mupdf_write_document)
cdecl_type(pdf_write_options)
cdecl_struct(pdf_write_options_s)
cdecl_func(mupdf_pdf_save_document)

/* the following is for our own wrapper lib: */
cdecl_func(mupdf_get_my_alloc_context)
Expand Down
Loading

0 comments on commit bd97e1b

Please sign in to comment.