Skip to content

Commit 53a723f

Browse files
JorjMcKiejulian-smith-artifex-com
authored andcommitted
Several Bug Fixes
Fix #2110 (Discussion item #2111): File `__main__.py` - also include the font's xref in the generated file name. Fix #2094: File `helper-device.i' - also ensure equality of x coordinates of relevant corners before assuming a rectangle. Fix #2087: File `fitz.i`- if JPX image format is already known, make sure to read the decoded image stream, instead of raw stream in the other cases.
1 parent 0a5476b commit 53a723f

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

fitz/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ def extract_objects(args):
512512
if ext == "n/a" or not buffer:
513513
continue
514514
outname = os.path.join(
515-
out_dir, fontname.replace(" ", "-") + "." + ext
515+
out_dir, f"{fontname.replace(' ', '-')}-{xref}.{ext}"
516516
)
517517
outfile = open(outname, "wb")
518518
outfile.write(buffer)

fitz/fitz.i

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2775,14 +2775,16 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
27752775

27762776
if (pdf_is_jpx_image(gctx, obj)) {
27772777
img_type = FZ_IMAGE_JPX;
2778+
res = pdf_load_stream(gctx, obj);
27782779
ext = "jpx";
27792780
}
27802781
if (JM_is_jbig2_image(gctx, obj)) {
27812782
img_type = FZ_IMAGE_JBIG2;
2783+
res = pdf_load_stream(gctx, obj);
27822784
ext = "jb2";
27832785
}
2784-
res = pdf_load_raw_stream(gctx, obj);
27852786
if (img_type == FZ_IMAGE_UNKNOWN) {
2787+
res = pdf_load_raw_stream(gctx, obj);
27862788
unsigned char *c = NULL;
27872789
fz_buffer_storage(gctx, res, &c);
27882790
img_type = fz_recognize_image_format(gctx, c);
@@ -2795,9 +2797,10 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
27952797
res = fz_new_buffer_from_image_as_png(gctx, img,
27962798
fz_default_color_params);
27972799
ext = "png";
2798-
} else /*if (smask == 0)*/ {
2800+
} else {
27992801
img = fz_new_image_from_buffer(gctx, res);
28002802
}
2803+
28012804
fz_image_resolution(img, &xres, &yres);
28022805
width = img->w;
28032806
height = img->h;
@@ -2835,7 +2838,8 @@ if len(pyliste) == 0 or min(pyliste) not in range(len(self)) or max(pyliste) not
28352838

28362839
fz_catch(gctx) {
28372840
Py_CLEAR(rc);
2838-
Py_RETURN_NONE;
2841+
fz_warn(gctx, fz_caught_message(gctx));
2842+
Py_RETURN_FALSE;
28392843
}
28402844
if (!rc)
28412845
Py_RETURN_NONE;
@@ -12332,6 +12336,7 @@ struct Archive
1233212336
}
1233312337
return (struct Archive *) arch;
1233412338
}
12339+
1233512340
Archive(PyObject *a0=NULL, const char *path=NULL)
1233612341
{
1233712342
fz_archive *arch=NULL;
@@ -13566,6 +13571,7 @@ struct Story
1356613571
return ret;
1356713572
}
1356813573

13574+
1356913575
void draw( struct DeviceWrapper* device, PyObject* matrix=NULL)
1357013576
{
1357113577
fz_matrix ctm2 = JM_matrix_from_py( matrix);

fitz/helper-devices.i

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ jm_checkrect()
101101
dev_linecount = 0; // reset line count
102102
long orientation = 0;
103103
fz_point ll, lr, ur, ul;
104+
fz_rect r;
104105
PyObject *rect;
105106
PyObject *line0, *line2;
106107
PyObject *items = PyDict_GetItem(dev_pathdict, dictkey_items);
@@ -109,50 +110,35 @@ jm_checkrect()
109110
line0 = PyList_GET_ITEM(items, len - 3);
110111
ll = JM_point_from_py(PyTuple_GET_ITEM(line0, 1));
111112
lr = JM_point_from_py(PyTuple_GET_ITEM(line0, 2));
112-
113+
// no need to extract "line1"!
113114
line2 = PyList_GET_ITEM(items, len - 1);
114115
ur = JM_point_from_py(PyTuple_GET_ITEM(line2, 1));
115116
ul = JM_point_from_py(PyTuple_GET_ITEM(line2, 2));
116117

117118
/*
118119
---------------------------------------------------------------------
119-
Three connected lines: at least a quad! Check whether even a rect.
120-
For this, the lines must be parallel to the axes.
121120
Assumption:
122121
For decomposing rects, MuPDF always starts with a horizontal line,
123122
followed by a vertical line, followed by a horizontal line.
124123
We will also check orientation of the enclosed area and add this info
125124
as '+1' for anti-clockwise, '-1' for clockwise orientation.
126125
---------------------------------------------------------------------
127126
*/
128-
if (ll.y != lr.y) { // not horizontal
129-
goto drop_out;
130-
}
131-
if (lr.x != ur.x) { // not vertical
132-
goto drop_out;
133-
}
134-
if (ur.y != ul.y) { // not horizontal
135-
goto drop_out;
127+
if (ll.y != lr.y ||
128+
ll.x != ul.x ||
129+
ur.y != ul.y ||
130+
ur.x != lr.x) {
131+
goto drop_out; // not a rectangle
136132
}
137-
// we have a rect, determine orientation
138-
if (ll.x < lr.x) { // move left to right
139-
if (lr.y > ur.y) { // move upwards
140-
orientation = 1;
141-
} else {
142-
orientation = -1;
143-
}
144-
} else { // move right to left
145-
if (lr.y < ur.y) { // move downwards
146-
orientation = 1;
147-
} else {
148-
orientation = -1;
149-
}
133+
134+
// we have a rect, replace last 3 "l" items by one "re" item.
135+
if (ul.y < lr.y) {
136+
r = fz_make_rect(ul.x, ul.y, lr.x, lr.y);
137+
orientation = 1;
138+
} else {
139+
r = fz_make_rect(ll.x, ll.y, ur.x, ur.y);
140+
orientation = -1;
150141
}
151-
// Replace last 3 "l" items by one "re" item.
152-
fz_rect r = fz_make_rect(ul.x, ul.y, ul.x, ul.y);
153-
r = fz_include_point_in_rect(r, ur);
154-
r = fz_include_point_in_rect(r, ll);
155-
r = fz_include_point_in_rect(r, lr);
156142
rect = PyTuple_New(3);
157143
PyTuple_SET_ITEM(rect, 0, PyUnicode_FromString("re"));
158144
PyTuple_SET_ITEM(rect, 1, JM_py_from_rect(r));

0 commit comments

Comments
 (0)