From 5985fb9ecf89a5cab3c3be228e478f9e3dc33736 Mon Sep 17 00:00:00 2001 From: "Jorj X. McKie" Date: Wed, 30 Nov 2022 13:32:04 -0400 Subject: [PATCH] Revert "Fixes #2094 and #2087" This reverts commit 899ac3e90efa85a9228d6f5d8e615f65ac14ac8a. --- fitz/fitz.i | 12 +++--------- fitz/helper-devices.i | 44 ++++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/fitz/fitz.i b/fitz/fitz.i index c2a21f2fd..52fa03031 100644 --- a/fitz/fitz.i +++ b/fitz/fitz.i @@ -2775,16 +2775,14 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not if (pdf_is_jpx_image(gctx, obj)) { img_type = FZ_IMAGE_JPX; - res = pdf_load_stream(gctx, obj); ext = "jpx"; } if (JM_is_jbig2_image(gctx, obj)) { img_type = FZ_IMAGE_JBIG2; - res = pdf_load_stream(gctx, obj); ext = "jb2"; } + res = pdf_load_raw_stream(gctx, obj); if (img_type == FZ_IMAGE_UNKNOWN) { - res = pdf_load_raw_stream(gctx, obj); unsigned char *c = NULL; fz_buffer_storage(gctx, res, &c); img_type = fz_recognize_image_format(gctx, c); @@ -2797,10 +2795,9 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not res = fz_new_buffer_from_image_as_png(gctx, img, fz_default_color_params); ext = "png"; - } else { + } else /*if (smask == 0)*/ { img = fz_new_image_from_buffer(gctx, res); } - fz_image_resolution(img, &xres, &yres); width = img->w; height = img->h; @@ -2838,8 +2835,7 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not fz_catch(gctx) { Py_CLEAR(rc); - fz_warn(gctx, fz_caught_message(gctx)); - Py_RETURN_FALSE; + Py_RETURN_NONE; } if (!rc) Py_RETURN_NONE; @@ -12336,7 +12332,6 @@ struct Archive } return (struct Archive *) arch; } - Archive(PyObject *a0=NULL, const char *path=NULL) { fz_archive *arch=NULL; @@ -13571,7 +13566,6 @@ struct Story return ret; } - void draw( struct DeviceWrapper* device, PyObject* matrix=NULL) { fz_matrix ctm2 = JM_matrix_from_py( matrix); diff --git a/fitz/helper-devices.i b/fitz/helper-devices.i index b19dda3a5..e4253bfe9 100644 --- a/fitz/helper-devices.i +++ b/fitz/helper-devices.i @@ -101,7 +101,6 @@ jm_checkrect() dev_linecount = 0; // reset line count long orientation = 0; fz_point ll, lr, ur, ul; - fz_rect r; PyObject *rect; PyObject *line0, *line2; PyObject *items = PyDict_GetItem(dev_pathdict, dictkey_items); @@ -110,13 +109,15 @@ jm_checkrect() line0 = PyList_GET_ITEM(items, len - 3); ll = JM_point_from_py(PyTuple_GET_ITEM(line0, 1)); lr = JM_point_from_py(PyTuple_GET_ITEM(line0, 2)); - // no need to extract "line1"! + line2 = PyList_GET_ITEM(items, len - 1); ur = JM_point_from_py(PyTuple_GET_ITEM(line2, 1)); ul = JM_point_from_py(PyTuple_GET_ITEM(line2, 2)); /* --------------------------------------------------------------------- + Three connected lines: at least a quad! Check whether even a rect. + For this, the lines must be parallel to the axes. Assumption: For decomposing rects, MuPDF always starts with a horizontal line, followed by a vertical line, followed by a horizontal line. @@ -124,21 +125,34 @@ jm_checkrect() as '+1' for anti-clockwise, '-1' for clockwise orientation. --------------------------------------------------------------------- */ - if (ll.y != lr.y || - ll.x != ul.x || - ur.y != ul.y || - ur.x != lr.x) { - goto drop_out; // not a rectangle + if (ll.y != lr.y) { // not horizontal + goto drop_out; } - - // we have a rect, replace last 3 "l" items by one "re" item. - if (ul.y < lr.y) { - r = fz_make_rect(ul.x, ul.y, lr.x, lr.y); - orientation = 1; - } else { - r = fz_make_rect(ll.x, ll.y, ur.x, ur.y); - orientation = -1; + if (lr.x != ur.x) { // not vertical + goto drop_out; + } + if (ur.y != ul.y) { // not horizontal + goto drop_out; + } + // we have a rect, determine orientation + if (ll.x < lr.x) { // move left to right + if (lr.y > ur.y) { // move upwards + orientation = 1; + } else { + orientation = -1; + } + } else { // move right to left + if (lr.y < ur.y) { // move downwards + orientation = 1; + } else { + orientation = -1; + } } + // Replace last 3 "l" items by one "re" item. + fz_rect r = fz_make_rect(ul.x, ul.y, ul.x, ul.y); + r = fz_include_point_in_rect(r, ur); + r = fz_include_point_in_rect(r, ll); + r = fz_include_point_in_rect(r, lr); rect = PyTuple_New(3); PyTuple_SET_ITEM(rect, 0, PyUnicode_FromString("re")); PyTuple_SET_ITEM(rect, 1, JM_py_from_rect(r));