Skip to content

Commit

Permalink
Revert "Fixes #2094 and #2087"
Browse files Browse the repository at this point in the history
This reverts commit 899ac3e.
  • Loading branch information
JorjMcKie committed Nov 30, 2022
1 parent 899ac3e commit 8867791
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
12 changes: 3 additions & 9 deletions fitz/fitz.i
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -12336,7 +12332,6 @@ struct Archive
}
return (struct Archive *) arch;
}

Archive(PyObject *a0=NULL, const char *path=NULL)
{
fz_archive *arch=NULL;
Expand Down Expand Up @@ -13571,7 +13566,6 @@ struct Story
return ret;
}


void draw( struct DeviceWrapper* device, PyObject* matrix=NULL)
{
fz_matrix ctm2 = JM_matrix_from_py( matrix);
Expand Down
44 changes: 29 additions & 15 deletions fitz/helper-devices.i
Expand Up @@ -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);
Expand All @@ -110,35 +109,50 @@ 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.
We will also check orientation of the enclosed area and add this info
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));
Expand Down

0 comments on commit 8867791

Please sign in to comment.