Skip to content

Commit bd97e1b

Browse files
TnS-hunFrenzie
authored andcommitted
MuPDF 1.12 (koreader#577)
* 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
1 parent 145e18a commit bd97e1b

16 files changed

+864
-569
lines changed

Makefile.defs

+1-3
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,7 @@ MUPDF_BUILD_DIR=$(CURDIR)/$(THIRDPARTY_DIR)/mupdf/build/$(MACHINE)
427427
MUPDF_DIR=$(MUPDF_BUILD_DIR)/mupdf-prefix/src/mupdf
428428
MUPDF_LIB_DIR=$(MUPDF_DIR)/build/release
429429
MUPDF_LIB_STATIC=$(MUPDF_LIB_DIR)/libmupdf.a
430-
MUPDF_JS_LIB_STATIC=$(MUPDF_LIB_DIR)/libmujs.a
431-
MUPDF_THIRDPARTY_LIBS=$(MUPDF_LIB_DIR)/libopenjpeg.a \
432-
$(MUPDF_LIB_DIR)/libjbig2dec.a \
430+
MUPDF_THIRDPARTY_LIBS=$(MUPDF_LIB_DIR)/libmupdfthird.a \
433431
$(AES_LIB)
434432
MUPDF_LIB=$(OUTPUT_DIR)/libs/libmupdf$(LIB_EXT)
435433

Makefile.third

-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ $(MUPDF_LIB) $(MUPDF_DIR)/include: $(JPEG_LIB) \
6666
-DAR="$(AR)" -DLDFLAGS="$(LDFLAGS) -L$(CURDIR)/$(OUTPUT_DIR)" \
6767
-DXCFLAGS="$(CFLAGS) -DNOBUILTINFONT -I$(JPEG_DIR)/include -I$(FREETYPE_DIR)/include/freetype2 -I$(ZLIB_DIR) -I$(MINIZIP_DIR)" \
6868
-DMUPDF_LIB_STATIC=$(MUPDF_LIB_STATIC) \
69-
-DMUPDF_JS_LIB_STATIC=$(MUPDF_JS_LIB_STATIC) \
7069
-DMUPDF_THIRDPARTY_LIBS=$(MUPDF_THIRDPARTY_LIBS) \
7170
-DMUPDF_LIB=$(CURDIR)/$(MUPDF_LIB) \
7271
-DMUPDF_SONAME=$(notdir $(MUPDF_LIB)) \

blitbuffer.c

+28-13
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ void BB_add_blit_from(BlitBuffer *dst, BlitBuffer *src,
599599
int sbb_rotation = GET_BB_ROTATION(src);
600600
int dbb_rotation = GET_BB_ROTATION(dst);
601601
if (dbb_type != sbb_type) {
602-
fprintf(stderr, "incompatible bb in file %s, line %d!\r\n",
603-
__FILE__, __LINE__); exit(1);
602+
fprintf(stderr, "incompatible bb (dst: %d, src: %d) in file %s, line %d!\r\n",
603+
dbb_type, sbb_type, __FILE__, __LINE__); exit(1);
604604
}
605605
uint8_t r, g, b;
606606
uint8_t ainv = 0xFF - alpha;
@@ -686,13 +686,9 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
686686
int sbb_type = GET_BB_TYPE(src);
687687
int sbb_rotation = GET_BB_ROTATION(src);
688688
int dbb_rotation = GET_BB_ROTATION(dst);
689-
if (dbb_type != sbb_type) {
690-
fprintf(stderr, "incompatible bb in file %s, line %d!\r\n",
691-
__FILE__, __LINE__); exit(1);
692-
}
693689
uint8_t r, g, b, ainv, alpha;
694690
int d_x, d_y, o_x, o_y;
695-
if (dbb_type == TYPE_BB8) {
691+
if (dbb_type == TYPE_BB8 && sbb_type == TYPE_BB8) {
696692
o_x = offs_x;
697693
Color8 *dstptr, *srcptr;
698694
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
@@ -705,7 +701,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
705701
}
706702
o_x += 1;
707703
}
708-
} else if (dbb_type == TYPE_BB8A) {
704+
} else if (dbb_type == TYPE_BB8A && sbb_type == TYPE_BB8A) {
709705
o_x = offs_x;
710706
Color8A *dstptr, *srcptr;
711707
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
@@ -720,7 +716,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
720716
}
721717
o_x += 1;
722718
}
723-
} else if (dbb_type == TYPE_BBRGB16) {
719+
} else if (dbb_type == TYPE_BBRGB16 && sbb_type == TYPE_BBRGB16) {
724720
o_x = offs_x;
725721
ColorRGB16 *dstptr, *srcptr;
726722
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
@@ -733,7 +729,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
733729
}
734730
o_x += 1;
735731
}
736-
} else if (dbb_type == TYPE_BBRGB24) {
732+
} else if (dbb_type == TYPE_BBRGB24 && sbb_type == TYPE_BBRGB24) {
737733
o_x = offs_x;
738734
ColorRGB24 *dstptr, *srcptr;
739735
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
@@ -746,7 +742,7 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
746742
}
747743
o_x += 1;
748744
}
749-
} else if (dbb_type == TYPE_BBRGB32) {
745+
} else if (dbb_type == TYPE_BBRGB32 && sbb_type == TYPE_BBRGB32) {
750746
o_x = offs_x;
751747
ColorRGB32 *dstptr, *srcptr;
752748
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
@@ -763,6 +759,25 @@ void BB_alpha_blit_from(BlitBuffer *dst, BlitBuffer *src,
763759
}
764760
o_x += 1;
765761
}
762+
} else if (dbb_type == TYPE_BBRGB32 && sbb_type == TYPE_BBRGB24) {
763+
o_x = offs_x;
764+
ColorRGB32 *dstptr;
765+
ColorRGB24 *srcptr;
766+
for (d_x = dest_x; d_x < dest_x + w; d_x++) {
767+
o_y = offs_y;
768+
for (d_y = dest_y; d_y < dest_y + h; d_y++) {
769+
BB_GET_PIXEL(dst, dbb_rotation, ColorRGB32, d_x, d_y, &dstptr);
770+
BB_GET_PIXEL(src, sbb_rotation, ColorRGB24, o_x, o_y, &srcptr);
771+
dstptr->r = srcptr->r;
772+
dstptr->g = srcptr->g;
773+
dstptr->b = srcptr->b;
774+
o_y += 1;
775+
}
776+
o_x += 1;
777+
}
778+
} else {
779+
fprintf(stderr, "incompatible bb (dst: %d, src: %d) in file %s, line %d!\r\n",
780+
dbb_type, sbb_type, __FILE__, __LINE__); exit(1);
766781
}
767782
}
768783

@@ -773,8 +788,8 @@ void BB_invert_blit_from(BlitBuffer *dst, BlitBuffer *src,
773788
int sbb_rotation = GET_BB_ROTATION(src);
774789
int dbb_rotation = GET_BB_ROTATION(dst);
775790
if (dbb_type != sbb_type) {
776-
fprintf(stderr, "incompatible bb in file %s, line %d!\r\n",
777-
__FILE__, __LINE__); exit(1);
791+
fprintf(stderr, "incompatible bb (dst: %d, src: %d) in file %s, line %d!\r\n",
792+
dbb_type, sbb_type, __FILE__, __LINE__); exit(1);
778793
}
779794
int d_x, d_y, o_x, o_y;
780795
if (dbb_type == TYPE_BB8) {

ffi-cdecl/mupdf_decl.c

+39-38
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "ffi-cdecl.h"
55

6-
cdecl_const(FZ_PAGE_BLOCK_TEXT)
6+
cdecl_const(FZ_STEXT_BLOCK_TEXT)
77

88
/* math */
99
cdecl_type(fz_point)
@@ -41,9 +41,17 @@ cdecl_func(fz_transform_rect)
4141

4242
/* misc/assorted */
4343
cdecl_type(fz_context)
44+
cdecl_type(fz_font)
45+
cdecl_type(fz_hash_table)
4446
cdecl_type(fz_storable)
47+
cdecl_type(fz_key_storable)
4548
cdecl_type(fz_store_drop_fn)
4649
cdecl_struct(fz_storable_s)
50+
cdecl_struct(fz_key_storable_s)
51+
52+
/* buffer */
53+
cdecl_func(mupdf_new_buffer_from_shared_data)
54+
cdecl_func(mupdf_drop_buffer)
4755

4856
/* context */
4957
cdecl_type(fz_alloc_context)
@@ -57,27 +65,24 @@ cdecl_type(fz_image)
5765
cdecl_type(fz_pixmap)
5866
cdecl_struct(fz_image_s)
5967
cdecl_struct(fz_pixmap_s)
60-
cdecl_func(fz_new_image_from_data) // compat, use wrapper instead:
61-
cdecl_func(mupdf_new_image_from_data)
62-
cdecl_func(fz_new_pixmap_from_image) // compat, use wrapper instead:
63-
cdecl_func(mupdf_new_pixmap_from_image)
68+
cdecl_func(mupdf_new_image_from_buffer)
69+
cdecl_func(mupdf_get_pixmap_from_image)
70+
cdecl_func(mupdf_save_pixmap_as_png)
6471
cdecl_func(fz_keep_image)
6572
cdecl_func(fz_drop_image)
6673

6774
cdecl_func(fz_load_png)
6875
cdecl_func(fz_runetochar)
6976

7077
/* document */
71-
cdecl_enum(fz_link_kind_e)
72-
cdecl_type(fz_link_dest)
73-
cdecl_struct(fz_link_dest_s)
78+
cdecl_type(fz_annot)
79+
cdecl_struct(fz_annot_s)
7480
cdecl_type(fz_outline)
7581
cdecl_struct(fz_outline_s)
7682
cdecl_type(fz_document)
7783
cdecl_type(fz_page)
78-
cdecl_type(fz_write_options)
79-
cdecl_struct(fz_document_s)
8084
cdecl_type(fz_link)
85+
cdecl_struct(fz_document_s)
8186
cdecl_struct(fz_page_s)
8287

8388
cdecl_func(mupdf_open_document)
@@ -86,6 +91,7 @@ cdecl_func(fz_authenticate_password)
8691
cdecl_func(fz_drop_document) // NOTE: libk2pdfopt uses old fz_free_document symbol
8792
cdecl_func(mupdf_count_pages)
8893
cdecl_func(fz_lookup_metadata)
94+
cdecl_func(fz_resolve_link)
8995

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

104110
/* structured text */
105-
cdecl_type(fz_text_style)
106-
cdecl_struct(fz_text_style_s)
107-
108-
cdecl_type(fz_text_char)
109-
cdecl_struct(fz_text_char_s)
110-
111-
cdecl_type(fz_text_span)
112-
cdecl_struct(fz_text_span_s)
113-
114-
cdecl_type(fz_text_line)
115-
cdecl_struct(fz_text_line_s)
116-
117-
cdecl_type(fz_text_sheet)
118-
cdecl_struct(fz_text_sheet_s)
119-
cdecl_func(mupdf_new_text_sheet)
120-
cdecl_func(fz_drop_text_sheet) // NOTE: libk2pdfopt uses old fz_free_text_sheet symbol
111+
cdecl_type(fz_stext_char)
112+
cdecl_struct(fz_stext_char_s)
121113

122-
cdecl_type(fz_text_page)
123-
cdecl_type(fz_page_block)
124-
cdecl_struct(fz_text_page_s)
125-
cdecl_func(mupdf_new_text_page)
126-
cdecl_func(fz_drop_text_page) // NOTE: libk2pdfopt uses old fz_free_text_page symbol
127-
cdecl_type(fz_text_block)
128-
cdecl_struct(fz_page_block_s)
129-
cdecl_struct(fz_text_block_s)
114+
cdecl_type(fz_stext_line)
115+
cdecl_struct(fz_stext_line_s)
130116

131-
cdecl_func(fz_text_char_bbox)
117+
cdecl_type(fz_stext_block)
118+
cdecl_struct(fz_stext_block_s)
119+
cdecl_type(fz_stext_options)
120+
cdecl_struct(fz_stext_options_s)
121+
cdecl_type(fz_stext_page)
122+
cdecl_struct(fz_stext_page_s)
123+
cdecl_func(mupdf_new_stext_page_from_page)
124+
cdecl_func(fz_drop_stext_page) // NOTE: libk2pdfopt uses old fz_free_text_page symbol
132125

133126
/* pixmaps */
134127
cdecl_func(mupdf_new_pixmap)
@@ -141,6 +134,7 @@ cdecl_func(fz_keep_pixmap)
141134
cdecl_func(fz_drop_pixmap)
142135
cdecl_func(fz_clear_pixmap_with_value)
143136
cdecl_func(fz_gamma_pixmap)
137+
cdecl_func(fz_scale_pixmap)
144138
cdecl_func(fz_pixmap_width)
145139
cdecl_func(fz_pixmap_height)
146140
cdecl_func(fz_pixmap_components)
@@ -154,28 +148,35 @@ cdecl_func(mupdf_new_draw_device)
154148
cdecl_func(mupdf_new_text_device)
155149
cdecl_func(mupdf_new_bbox_device)
156150
cdecl_func(mupdf_run_page)
151+
cdecl_func(fz_close_device)
157152
cdecl_func(fz_drop_device) // NOTE: libk2pdfopt uses old fz_free_device symbol
158153

159154
/* pdf specifics */
155+
cdecl_enum(fz_annot_type)
160156
cdecl_type(pdf_hotspot)
161157
cdecl_struct(pdf_hotspot_s)
162158
cdecl_type(pdf_lexbuf)
163159
cdecl_struct(pdf_lexbuf_s)
164160
cdecl_type(pdf_lexbuf_large)
165161
cdecl_struct(pdf_lexbuf_large_s)
162+
cdecl_type(pdf_obj)
163+
cdecl_type(pdf_xobject)
166164
cdecl_type(pdf_annot)
167165
cdecl_type(pdf_page)
166+
cdecl_struct(pdf_xobject_s)
168167
cdecl_struct(pdf_annot_s)
169168
cdecl_type(pdf_document)
170169
cdecl_struct(pdf_document_s)
171170
cdecl_func(pdf_specifics)
172171
cdecl_func(mupdf_pdf_create_annot)
173-
cdecl_func(mupdf_pdf_set_markup_annot_quadpoints)
172+
cdecl_func(mupdf_pdf_set_annot_quad_points)
173+
cdecl_func(mupdf_pdf_set_text_annot_position)
174174
cdecl_func(mupdf_pdf_set_markup_appearance)
175175

176176
/* saving documents */
177-
cdecl_struct(fz_write_options_s)
178-
cdecl_func(mupdf_write_document)
177+
cdecl_type(pdf_write_options)
178+
cdecl_struct(pdf_write_options_s)
179+
cdecl_func(mupdf_pdf_save_document)
179180

180181
/* the following is for our own wrapper lib: */
181182
cdecl_func(mupdf_get_my_alloc_context)

0 commit comments

Comments
 (0)