From cad932c3e03f0f79bbd3acc6c14964ac946cb20e Mon Sep 17 00:00:00 2001 From: Krzysztof Kowalczyk Date: Tue, 10 Sep 2024 15:41:35 +0200 Subject: [PATCH] update mupdf --- mupdf/include/mupdf/fitz/font.h | 4 +- mupdf/include/mupdf/pdf/annot.h | 2 + mupdf/include/mupdf/pdf/object.h | 4 ++ mupdf/platform/gl/gl-annotate.c | 7 +- mupdf/platform/java/jni/pdfdocument.c | 15 ++++ mupdf/platform/java/mupdf_native.h | 8 +++ .../com/artifex/mupdf/fitz/PDFDocument.java | 1 + mupdf/source/fitz/font.c | 70 ++++++------------- mupdf/source/pdf/pdf-annot.c | 47 +++++++++++-- mupdf/source/pdf/pdf-font.c | 6 ++ mupdf/source/pdf/pdf-image.c | 4 +- mupdf/source/pdf/pdf-object.c | 31 ++++++++ mupdf/source/pdf/pdf-parse.c | 9 +++ mupdf/source/pdf/pdf-type3.c | 4 +- mupdf/source/tools/murun.c | 31 ++++++++ mupdf/source/tools/pdfextract.c | 5 +- 16 files changed, 187 insertions(+), 61 deletions(-) diff --git a/mupdf/include/mupdf/fitz/font.h b/mupdf/include/mupdf/fitz/font.h index 369bc57df5e5..4b153ec7ed6f 100644 --- a/mupdf/include/mupdf/fitz/font.h +++ b/mupdf/include/mupdf/fitz/font.h @@ -748,7 +748,6 @@ struct fz_font void *t3resources; fz_buffer **t3procs; /* has 256 entries if used */ struct fz_display_list **t3lists; /* has 256 entries if used */ - float *t3widths; /* has 256 entries if used */ unsigned short *t3flags; /* has 256 entries if used */ void *t3doc; /* a pdf_document for the callback */ void (*t3run)(fz_context *ctx, void *doc, void *resources, fz_buffer *contents, struct fz_device *dev, fz_matrix ctm, void *gstate, fz_default_colorspaces *default_cs); @@ -756,6 +755,9 @@ struct fz_font fz_rect bbox; /* font bbox is used only for t3 fonts */ + float ascender; + float descender; + int glyph_count; /* per glyph bounding box cache. */ diff --git a/mupdf/include/mupdf/pdf/annot.h b/mupdf/include/mupdf/pdf/annot.h index d99053e90203..2c68a9a74478 100644 --- a/mupdf/include/mupdf/pdf/annot.h +++ b/mupdf/include/mupdf/pdf/annot.h @@ -768,8 +768,10 @@ int pdf_annot_has_intent(fz_context *ctx, pdf_annot *annot); enum pdf_intent pdf_annot_intent(fz_context *ctx, pdf_annot *annot); void pdf_set_annot_intent(fz_context *ctx, pdf_annot *annot, enum pdf_intent it); +void pdf_parse_default_appearance_unmapped(fz_context *ctx, const char *da, char *font_name, int font_name_len, float *size, int *n, float color[4]); void pdf_parse_default_appearance(fz_context *ctx, const char *da, const char **font, float *size, int *n, float color[4]); void pdf_print_default_appearance(fz_context *ctx, char *buf, int nbuf, const char *font, float size, int n, const float *color); +void pdf_annot_default_appearance_unmapped(fz_context *ctx, pdf_annot *annot, char *font_name, int font_name_len, float *size, int *n, float color[4]); void pdf_annot_default_appearance(fz_context *ctx, pdf_annot *annot, const char **font, float *size, int *n, float color[4]); void pdf_set_annot_default_appearance(fz_context *ctx, pdf_annot *annot, const char *font, float size, int n, const float *color); diff --git a/mupdf/include/mupdf/pdf/object.h b/mupdf/include/mupdf/pdf/object.h index 24ad9e645635..393a8dae922b 100644 --- a/mupdf/include/mupdf/pdf/object.h +++ b/mupdf/include/mupdf/pdf/object.h @@ -54,6 +54,7 @@ pdf_obj *pdf_new_text_string(fz_context *ctx, const char *s); pdf_obj *pdf_new_indirect(fz_context *ctx, pdf_document *doc, int num, int gen); pdf_obj *pdf_new_array(fz_context *ctx, pdf_document *doc, int initialcap); pdf_obj *pdf_new_dict(fz_context *ctx, pdf_document *doc, int initialcap); +pdf_obj *pdf_new_point(fz_context *ctx, pdf_document *doc, fz_point point); pdf_obj *pdf_new_rect(fz_context *ctx, pdf_document *doc, fz_rect rect); pdf_obj *pdf_new_matrix(fz_context *ctx, pdf_document *doc, fz_matrix mtx); pdf_obj *pdf_new_date(fz_context *ctx, pdf_document *doc, int64_t time); @@ -198,6 +199,7 @@ void pdf_dict_put_real(fz_context *ctx, pdf_obj *dict, pdf_obj *key, double x); void pdf_dict_put_name(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const char *x); void pdf_dict_put_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const char *x, size_t n); void pdf_dict_put_text_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key, const char *x); +void pdf_dict_put_point(fz_context *ctx, pdf_obj *dict, pdf_obj *key, fz_point x); void pdf_dict_put_rect(fz_context *ctx, pdf_obj *dict, pdf_obj *key, fz_rect x); void pdf_dict_put_matrix(fz_context *ctx, pdf_obj *dict, pdf_obj *key, fz_matrix x); void pdf_dict_put_date(fz_context *ctx, pdf_obj *dict, pdf_obj *key, int64_t time); @@ -213,6 +215,7 @@ const char *pdf_dict_get_name(fz_context *ctx, pdf_obj *dict, pdf_obj *key); const char *pdf_dict_get_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key, size_t *sizep); const char *pdf_dict_get_text_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key); const char *pdf_dict_get_text_string_opt(fz_context *ctx, pdf_obj *dict, pdf_obj *key); +fz_point pdf_dict_get_point(fz_context *ctx, pdf_obj *dict, pdf_obj *key); fz_rect pdf_dict_get_rect(fz_context *ctx, pdf_obj *dict, pdf_obj *key); fz_matrix pdf_dict_get_matrix(fz_context *ctx, pdf_obj *dict, pdf_obj *key); int64_t pdf_dict_get_date(fz_context *ctx, pdf_obj *dict, pdf_obj *key); @@ -301,6 +304,7 @@ char *pdf_new_utf8_from_pdf_stream_obj(fz_context *ctx, pdf_obj *src); char *pdf_load_stream_or_string_as_utf8(fz_context *ctx, pdf_obj *src); fz_quad pdf_to_quad(fz_context *ctx, pdf_obj *array, int offset); +fz_point pdf_to_point(fz_context *ctx, pdf_obj *array, int offset); fz_rect pdf_to_rect(fz_context *ctx, pdf_obj *array); fz_matrix pdf_to_matrix(fz_context *ctx, pdf_obj *array); int64_t pdf_to_date(fz_context *ctx, pdf_obj *time); diff --git a/mupdf/platform/gl/gl-annotate.c b/mupdf/platform/gl/gl-annotate.c index 038476a18386..5086ad563a88 100644 --- a/mupdf/platform/gl/gl-annotate.c +++ b/mupdf/platform/gl/gl-annotate.c @@ -1092,6 +1092,7 @@ void do_annotate_panel(void) int q; const char *text_lang; const char *text_font; + char text_font_buf[20]; char lang_buf[8]; static float text_size_f, text_color[4]; static int text_size; @@ -1115,10 +1116,10 @@ void do_annotate_panel(void) pdf_set_annot_language(ctx, ui.selected_annot, fz_text_language_from_string(text_lang)); } - pdf_annot_default_appearance(ctx, ui.selected_annot, &text_font, &text_size_f, &n, text_color); + pdf_annot_default_appearance_unmapped(ctx, ui.selected_annot, text_font_buf, sizeof text_font_buf, &text_size_f, &n, text_color); text_size = text_size_f; ui_label("Text Font:"); - font_choice = ui_select("DA/Font", text_font, font_names, nelem(font_names)); + font_choice = ui_select("DA/Font", text_font_buf, font_names, nelem(font_names)); ui_label("Text Size: %d", text_size); size_changed = ui_slider(&text_size, 8, 36, 256); ui_label("Text Color:"); @@ -1127,6 +1128,8 @@ void do_annotate_panel(void) { if (font_choice != -1) text_font = font_names[font_choice]; + else + text_font = text_font_buf; if (color_choice != -1) { n = 3; diff --git a/mupdf/platform/java/jni/pdfdocument.c b/mupdf/platform/java/jni/pdfdocument.c index 2c17bd5de908..f96c45208835 100644 --- a/mupdf/platform/java/jni/pdfdocument.c +++ b/mupdf/platform/java/jni/pdfdocument.c @@ -1589,6 +1589,21 @@ FUN(PDFDocument_verifyEmbeddedFileChecksum)(JNIEnv *env, jobject self, jobject j return valid ? JNI_TRUE : JNI_FALSE; } +JNIEXPORT jboolean JNICALL +FUN(PDFDocument_isEmbeddedFile)(JNIEnv *env, jobject self, jobject jfs) +{ + fz_context *ctx = get_context(env); + pdf_obj *fs = from_PDFObject_safe(env, jfs); + int embedded = 0; + + fz_try(ctx) + embedded = pdf_is_embedded_file(ctx, fs); + fz_catch(ctx) + jni_rethrow(env, ctx); + + return embedded ? JNI_TRUE : JNI_FALSE; +} + JNIEXPORT void JNICALL FUN(PDFDocument_setPageLabels)(JNIEnv *env, jobject self, jint index, jint style, jstring jprefix, jint start) { diff --git a/mupdf/platform/java/mupdf_native.h b/mupdf/platform/java/mupdf_native.h index 85ec3b18cb63..be302386d851 100644 --- a/mupdf/platform/java/mupdf_native.h +++ b/mupdf/platform/java/mupdf_native.h @@ -4347,6 +4347,14 @@ JNIEXPORT jobject JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_loadEmbeddedFi JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_verifyEmbeddedFileChecksum (JNIEnv *, jobject, jobject); +/* + * Class: com_artifex_mupdf_fitz_PDFDocument + * Method: isEmbeddedFile + * Signature: (Lcom/artifex/mupdf/fitz/PDFObject;)Z + */ +JNIEXPORT jboolean JNICALL Java_com_artifex_mupdf_fitz_PDFDocument_isEmbeddedFile + (JNIEnv *, jobject, jobject); + /* * Class: com_artifex_mupdf_fitz_PDFDocument * Method: countAssociatedFiles diff --git a/mupdf/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java b/mupdf/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java index aab50f5e3c80..56ebaaf697d6 100644 --- a/mupdf/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java +++ b/mupdf/platform/java/src/com/artifex/mupdf/fitz/PDFDocument.java @@ -249,6 +249,7 @@ public static String appendDestToURI(String uri, LinkDestination dest) { public native PDFFilespecParams getFilespecParams(PDFObject fs); public native Buffer loadEmbeddedFileContents(PDFObject fs); public native boolean verifyEmbeddedFileChecksum(PDFObject fs); + public native boolean isEmbeddedFile(PDFObject fs); public PDFObject addEmbeddedFile(String filename, String mimetype, InputStream stream, Date created, Date modified, boolean addChecksum) { Buffer contents = new Buffer(); diff --git a/mupdf/source/fitz/font.c b/mupdf/source/fitz/font.c index c9f0da9df444..f929338ed0f1 100755 --- a/mupdf/source/fitz/font.c +++ b/mupdf/source/fitz/font.c @@ -114,7 +114,6 @@ fz_new_font(fz_context *ctx, const char *name, int use_glyph_bbox, int glyph_cou font->t3resources = NULL; font->t3procs = NULL; font->t3lists = NULL; - font->t3widths = NULL; font->t3flags = NULL; font->t3doc = NULL; font->t3run = NULL; @@ -206,7 +205,6 @@ fz_drop_font(fz_context *ctx, fz_font *font) fz_drop_display_list(ctx, font->t3lists[i]); fz_free(ctx, font->t3procs); fz_free(ctx, font->t3lists); - fz_free(ctx, font->t3widths); fz_free(ctx, font->t3flags); if (font->ft_face) @@ -274,28 +272,12 @@ fz_set_font_bbox(fz_context *ctx, fz_font *font, float xmin, float ymin, float x float fz_font_ascender(fz_context *ctx, fz_font *font) { - if (font->t3procs) - return font->bbox.y1; - else - { - FT_Face face = font->ft_face; - if (face->ascender == 0) - return 0.8f; - return (float)face->ascender / face->units_per_EM; - } + return font->ascender; } float fz_font_descender(fz_context *ctx, fz_font *font) { - if (font->t3procs) - return font->bbox.y0; - else - { - FT_Face face = font->ft_face; - if (face->descender == 0) - return -0.2f; - return (float)face->descender / face->units_per_EM; - } + return font->descender; } /* @@ -787,6 +769,16 @@ fz_new_font_from_buffer(fz_context *ctx, const char *name, fz_buffer *buffer, in (float) face->bbox.xMax / face->units_per_EM, (float) face->bbox.yMax / face->units_per_EM); + if (face->ascender == 0) + font->ascender = 0.8f; + else + font->ascender = (float)face->ascender / face->units_per_EM; + + if (face->descender == 0) + font->descender = -0.2f; + else + font->descender = (float)face->descender / face->units_per_EM; + font->subfont = index; font->flags.is_mono = !!(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); @@ -1538,7 +1530,6 @@ fz_new_type3_font(fz_context *ctx, const char *name, fz_matrix matrix) { font->t3procs = fz_calloc(ctx, 256, sizeof(fz_buffer*)); font->t3lists = fz_calloc(ctx, 256, sizeof(fz_display_list*)); - font->t3widths = fz_calloc(ctx, 256, sizeof(float)); font->t3flags = fz_calloc(ctx, 256, sizeof(unsigned short)); } fz_catch(ctx) @@ -1835,17 +1826,6 @@ fz_advance_ft_glyph_aux(fz_context *ctx, fz_font *font, int gid, int wmode, int FT_Fixed adv = 0; int mask; - /* PDF and substitute font widths. */ - if (font->flags.ft_stretch) - { - if (font->width_table) - { - if (gid < font->width_count) - return font->width_table[gid] / 1000.0f; - return font->width_default / 1000.0f; - } - } - mask = FT_LOAD_NO_SCALE | FT_LOAD_NO_HINTING | FT_LOAD_IGNORE_TRANSFORM; if (wmode) mask |= FT_LOAD_VERTICAL_LAYOUT; @@ -1857,12 +1837,7 @@ fz_advance_ft_glyph_aux(fz_context *ctx, fz_font *font, int gid, int wmode, int if (fterr && fterr != FT_Err_Invalid_Argument) { fz_warn(ctx, "FT_Get_Advance(%s,%d): %s", font->name, gid, ft_error_string(fterr)); - if (font->width_table) - { - if (gid < font->width_count) - return font->width_table[gid] / 1000.0f; - return font->width_default / 1000.0f; - } + return 0; } return (float) adv / ((FT_Face)font->ft_face)->units_per_EM; } @@ -1873,14 +1848,6 @@ fz_advance_ft_glyph(fz_context *ctx, fz_font *font, int gid, int wmode) return fz_advance_ft_glyph_aux(ctx, font, gid, wmode, 0); } -static float -fz_advance_t3_glyph(fz_context *ctx, fz_font *font, int gid) -{ - if (gid < 0 || gid > 255) - return 0; - return font->t3widths[gid]; -} - void fz_get_glyph_name(fz_context *ctx, fz_font *font, int glyph, char *buf, int size) { @@ -1908,6 +1875,14 @@ fz_get_glyph_name(fz_context *ctx, fz_font *font, int glyph, char *buf, int size float fz_advance_glyph(fz_context *ctx, fz_font *font, int gid, int wmode) { + /* Use PDF font widths table if available */ + if (font->width_table) + { + if (gid < font->width_count) + return font->width_table[gid] / 1000.0f; + return font->width_default / 1000.0f; + } + if (font->ft_face) { if (wmode) @@ -1953,8 +1928,7 @@ fz_advance_glyph(fz_context *ctx, fz_font *font, int gid, int wmode) return fz_advance_ft_glyph(ctx, font, gid, 0); } - if (font->t3procs) - return fz_advance_t3_glyph(ctx, font, gid); + return 0; } diff --git a/mupdf/source/pdf/pdf-annot.c b/mupdf/source/pdf/pdf-annot.c index 8152ba889dd9..6b9a35dbd1f8 100644 --- a/mupdf/source/pdf/pdf-annot.c +++ b/mupdf/source/pdf/pdf-annot.c @@ -3319,13 +3319,13 @@ pdf_set_annot_intent(fz_context *ctx, pdf_annot *annot, enum pdf_intent it) } void -pdf_parse_default_appearance(fz_context *ctx, const char *da, const char **font, float *size, int *n, float color[4]) +pdf_parse_default_appearance_unmapped(fz_context *ctx, const char *da, char *font_name, int font_name_size, float *size, int *n, float color[4]) { char buf[100], *p = buf, *tok, *end; float stack[4] = { 0, 0, 0, 0 }; int top = 0; - *font = "Helv"; + fz_strlcpy(font_name, "Helv", font_name_size); *size = 12; *n = 0; color[0] = color[1] = color[2] = color[3] = 0; @@ -3337,11 +3337,7 @@ pdf_parse_default_appearance(fz_context *ctx, const char *da, const char **font, ; else if (tok[0] == '/') { - if (!strcmp(tok+1, "Cour")) *font = "Cour"; - if (!strcmp(tok+1, "Helv")) *font = "Helv"; - if (!strcmp(tok+1, "TiRo")) *font = "TiRo"; - if (!strcmp(tok+1, "Symb")) *font = "Symb"; - if (!strcmp(tok+1, "ZaDb")) *font = "ZaDb"; + fz_strlcpy(font_name, tok+1, font_name_size); } else if (!strcmp(tok, "Tf")) { @@ -3384,6 +3380,21 @@ pdf_parse_default_appearance(fz_context *ctx, const char *da, const char **font, } } +void +pdf_parse_default_appearance(fz_context *ctx, const char *da, const char **font, float *size, int *n, float color[4]) +{ + char font_name[100]; + + pdf_parse_default_appearance_unmapped(ctx, da, font_name, sizeof font_name, size, n, color); + + if (!strcmp(font_name, "Cour")) *font = "Cour"; + else if (!strcmp(font_name, "Helv")) *font = "Helv"; + else if (!strcmp(font_name, "TiRo")) *font = "TiRo"; + else if (!strcmp(font_name, "Symb")) *font = "Symb"; + else if (!strcmp(font_name, "ZaDb")) *font = "ZaDb"; + else *font = "Helv"; +} + void pdf_print_default_appearance(fz_context *ctx, char *buf, int nbuf, const char *font, float size, int n, const float *color) { @@ -3397,6 +3408,28 @@ pdf_print_default_appearance(fz_context *ctx, char *buf, int nbuf, const char *f fz_snprintf(buf, nbuf, "/%s %g Tf", font, size); } +void +pdf_annot_default_appearance_unmapped(fz_context *ctx, pdf_annot *annot, char *font_name, int font_name_len, float *size, int *n, float color[4]) +{ + pdf_obj *da; + pdf_annot_push_local_xref(ctx, annot); + + fz_try(ctx) + { + da = pdf_dict_get_inheritable(ctx, annot->obj, PDF_NAME(DA)); + if (!da) + { + pdf_obj *trailer = pdf_trailer(ctx, annot->page->doc); + da = pdf_dict_getl(ctx, trailer, PDF_NAME(Root), PDF_NAME(AcroForm), PDF_NAME(DA), NULL); + } + pdf_parse_default_appearance_unmapped(ctx, pdf_to_str_buf(ctx, da), font_name, font_name_len, size, n, color); + } + fz_always(ctx) + pdf_annot_pop_local_xref(ctx, annot); + fz_catch(ctx) + fz_rethrow(ctx); +} + void pdf_annot_default_appearance(fz_context *ctx, pdf_annot *annot, const char **font, float *size, int *n, float color[4]) { diff --git a/mupdf/source/pdf/pdf-font.c b/mupdf/source/pdf/pdf-font.c index 09d0a490166d..d014682d641c 100755 --- a/mupdf/source/pdf/pdf-font.c +++ b/mupdf/source/pdf/pdf-font.c @@ -1493,6 +1493,12 @@ pdf_load_font_descriptor(fz_context *ctx, pdf_document *doc, pdf_font_desc *font if (fontdesc->descent == 0.0f) fontdesc->descent = 1000.0f * face->descender / face->units_per_EM; } + + /* Prefer FontDescriptor Ascent/Descent values to embedded font's */ + if (fontdesc->ascent) + fontdesc->font->ascender = fontdesc->ascent / 1000.0f; + if (fontdesc->descent) + fontdesc->font->descender = fontdesc->descent / 1000.0f; } static void diff --git a/mupdf/source/pdf/pdf-image.c b/mupdf/source/pdf/pdf-image.c index d4a6a069c5c6..e445b0d5029d 100755 --- a/mupdf/source/pdf/pdf-image.c +++ b/mupdf/source/pdf/pdf-image.c @@ -156,7 +156,9 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di decode[i] = i & 1 ? maxval : 0; } - obj = pdf_dict_geta(ctx, dict, PDF_NAME(SMask), PDF_NAME(Mask)); + obj = pdf_dict_get(ctx, dict, PDF_NAME(SMask)); + if (!pdf_is_dict(ctx, obj)) + obj = pdf_dict_get(ctx, dict, PDF_NAME(Mask)); if (pdf_is_dict(ctx, obj)) { /* Not allowed for inline images or soft masks */ diff --git a/mupdf/source/pdf/pdf-object.c b/mupdf/source/pdf/pdf-object.c index 2bbedf9a1f96..0b14ce1d1833 100755 --- a/mupdf/source/pdf/pdf-object.c +++ b/mupdf/source/pdf/pdf-object.c @@ -1655,6 +1655,8 @@ void pdf_deserialise_journal(fz_context *ctx, pdf_document *doc, fz_stream *stm) obj = pdf_parse_dict(ctx, doc, stm, &doc->lexbuf.base); nis = pdf_dict_get_int(ctx, obj, PDF_NAME(NumSections)); + if (nis < 0 || nis > doc->num_xref_sections) + fz_throw(ctx, FZ_ERROR_FORMAT, "Bad journal format"); pdf_fingerprint_file(ctx, doc, digest, nis); file_size = pdf_dict_get_int(ctx, obj, PDF_NAME(FileSize)); @@ -1721,6 +1723,9 @@ void pdf_deserialise_journal(fz_context *ctx, pdf_document *doc, fz_stream *stm) doc->journal->current = NULL; if (pos > 0) { + if (doc->journal->head == NULL) + fz_throw(ctx, FZ_ERROR_FORMAT, "Badly formed journal"); + doc->journal->current = doc->journal->head; while (--pos) { @@ -2034,6 +2039,22 @@ pdf_array_find(fz_context *ctx, pdf_obj *arr, pdf_obj *obj) return -1; } +pdf_obj *pdf_new_point(fz_context *ctx, pdf_document *doc, fz_point point) +{ + pdf_obj *arr = pdf_new_array(ctx, doc, 2); + fz_try(ctx) + { + pdf_array_push_real(ctx, arr, point.x); + pdf_array_push_real(ctx, arr, point.y); + } + fz_catch(ctx) + { + pdf_drop_obj(ctx, arr); + fz_rethrow(ctx); + } + return arr; +} + pdf_obj *pdf_new_rect(fz_context *ctx, pdf_document *doc, fz_rect rect) { pdf_obj *arr = pdf_new_array(ctx, doc, 4); @@ -3807,6 +3828,11 @@ void pdf_dict_put_text_string(fz_context *ctx, pdf_obj *dict, pdf_obj *key, cons pdf_dict_put_drop(ctx, dict, key, pdf_new_text_string(ctx, x)); } +void pdf_dict_put_point(fz_context *ctx, pdf_obj *dict, pdf_obj *key, fz_point x) +{ + pdf_dict_put_drop(ctx, dict, key, pdf_new_point(ctx, pdf_get_bound_document(ctx, dict), x)); +} + void pdf_dict_put_rect(fz_context *ctx, pdf_obj *dict, pdf_obj *key, fz_rect x) { pdf_dict_put_drop(ctx, dict, key, pdf_new_rect(ctx, pdf_get_bound_document(ctx, dict), x)); @@ -3989,6 +4015,11 @@ const char *pdf_dict_get_text_string_opt(fz_context *ctx, pdf_obj *dict, pdf_obj return pdf_to_text_string(ctx, obj); } +fz_point pdf_dict_get_point(fz_context *ctx, pdf_obj *dict, pdf_obj *key) +{ + return pdf_to_point(ctx, pdf_dict_get(ctx, dict, key), 0); +} + fz_rect pdf_dict_get_rect(fz_context *ctx, pdf_obj *dict, pdf_obj *key) { return pdf_to_rect(ctx, pdf_dict_get(ctx, dict, key)); diff --git a/mupdf/source/pdf/pdf-parse.c b/mupdf/source/pdf/pdf-parse.c index 40dda0be6f9c..f5563e87d459 100755 --- a/mupdf/source/pdf/pdf-parse.c +++ b/mupdf/source/pdf/pdf-parse.c @@ -67,6 +67,15 @@ pdf_to_quad(fz_context *ctx, pdf_obj *array, int offset) return q; } +fz_point +pdf_to_point(fz_context *ctx, pdf_obj *array, int offset) +{ + fz_point p; + p.x = pdf_array_get_real(ctx, array, offset+0); + p.y = pdf_array_get_real(ctx, array, offset+1); + return p; +} + fz_matrix pdf_to_matrix(fz_context *ctx, pdf_obj *array) { diff --git a/mupdf/source/pdf/pdf-type3.c b/mupdf/source/pdf/pdf-type3.c index 324a66ea502f..d992f882eb6a 100644 --- a/mupdf/source/pdf/pdf-type3.c +++ b/mupdf/source/pdf/pdf-type3.c @@ -85,6 +85,9 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d fz_set_font_bbox(ctx, font, bbox.x0, bbox.y0, bbox.x1, bbox.y1); + font->ascender = bbox.y1; + font->descender = bbox.y0; + /* Encoding */ for (i = 0; i < 256; i++) @@ -156,7 +159,6 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d { float w = pdf_array_get_real(ctx, widths, i - first); w = font->t3matrix.a * w * 1000; - font->t3widths[i] = w * 0.001f; pdf_add_hmtx(ctx, fontdesc, i, i, w); } diff --git a/mupdf/source/tools/murun.c b/mupdf/source/tools/murun.c index 883cea456f5c..b57dc661bcd1 100644 --- a/mupdf/source/tools/murun.c +++ b/mupdf/source/tools/murun.c @@ -3444,6 +3444,18 @@ static void ffi_Buffer_save(js_State *J) rethrow(J); } +static void ffi_Buffer_asString(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + fz_buffer *buf = js_touserdata(J, 0, "fz_buffer"); + const char *str = NULL; + fz_try(ctx) + str = fz_string_from_buffer(ctx, buf); + fz_catch(ctx) + rethrow(J); + js_pushstring(J, str); +} + static void ffi_Buffer_slice(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -6558,6 +6570,23 @@ static void ffi_PDFDocument_verifyEmbeddedFileChecksum(js_State *J) js_pushboolean(J, valid); } +static void ffi_PDFDocument_isEmbeddedFile(js_State *J) +{ + fz_context *ctx = js_getcontext(J); + pdf_document *pdf = js_touserdata(J, 0, "pdf_document"); + pdf_obj *fs = ffi_toobj(J, pdf, 1); + int result = 0; + + fz_try(ctx) + result = pdf_is_embedded_file(ctx, fs); + fz_always(ctx) + pdf_drop_obj(ctx, fs); + fz_catch(ctx) + rethrow(J); + + js_pushboolean(J, result); +} + static void ffi_PDFDocument_addImage(js_State *J) { fz_context *ctx = js_getcontext(J); @@ -10486,6 +10515,7 @@ int murun_main(int argc, char **argv) jsB_propfun(J, "Buffer.write", ffi_Buffer_write, 1); jsB_propfun(J, "Buffer.save", ffi_Buffer_save, 1); jsB_propfun(J, "Buffer.slice", ffi_Buffer_slice, 2); + jsB_propfun(J, "Buffer.asString", ffi_Buffer_asString, 0); } js_setregistry(J, "fz_buffer"); @@ -10873,6 +10903,7 @@ int murun_main(int argc, char **argv) jsB_propfun(J, "PDFDocument.getFilespecParams", ffi_PDFDocument_getFilespecParams, 1); jsB_propfun(J, "PDFDocument.getEmbeddedFileContents", ffi_PDFDocument_getEmbeddedFileContents, 1); jsB_propfun(J, "PDFDocument.verifyEmbeddedFileChecksum", ffi_PDFDocument_verifyEmbeddedFileChecksum, 1); + jsB_propfun(J, "PDFDocument.isEmbeddedFile", ffi_PDFDocument_isEmbeddedFile, 1); jsB_propfun(J, "PDFDocument.addPage", ffi_PDFDocument_addPage, 4); jsB_propfun(J, "PDFDocument.insertPage", ffi_PDFDocument_insertPage, 2); diff --git a/mupdf/source/tools/pdfextract.c b/mupdf/source/tools/pdfextract.c index dd10670ef66c..d966d4f134f0 100644 --- a/mupdf/source/tools/pdfextract.c +++ b/mupdf/source/tools/pdfextract.c @@ -119,6 +119,7 @@ static void saveimage(pdf_obj *ref) int type; fz_var(image); + fz_var(mask); fz_var(pix); fz_try(ctx) @@ -251,7 +252,9 @@ static void savefont(pdf_obj *dict) static void extractobject(int num) { - pdf_obj *ref; + pdf_obj *ref = NULL; + + fz_var(ref); fz_try(ctx) {