Skip to content

Commit

Permalink
Correct scale factor adjustments
Browse files Browse the repository at this point in the history
We were erroneously setting matrix scaling factor to zero for rotation matrices.

Addresses issue 3591.
  • Loading branch information
JorjMcKie committed Jun 19, 2024
1 parent 0d93499 commit 8f5f3eb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18928,8 +18928,10 @@ def jm_lineart_stroke_path( dev, ctx, path, stroke, ctm, colorspace, color, alph
try:
assert isinstance( ctm, mupdf.fz_matrix)
dev.pathfactor = 1
if abs(ctm.a) == abs(ctm.d):
if ctm.a != 0 and abs(ctm.a) == abs(ctm.d):
dev.pathfactor = abs(ctm.a)
elif ctm.b != 0 and abs(ctm.b) == abs(ctm.c):
dev.pathfactor = abs(ctm.b)
dev.ctm = mupdf.FzMatrix( ctm) # fz_concat(ctm, dev_ptm);
dev.path_type = trace_device_STROKE_PATH

Expand Down
6 changes: 5 additions & 1 deletion src/extra.i
Original file line number Diff line number Diff line change
Expand Up @@ -2647,8 +2647,12 @@ jm_lineart_stroke_path(fz_context *ctx, fz_device *dev_, const fz_path *path,
//printf("extra.jm_lineart_stroke_path(): dev->seqno=%zi\n", dev->seqno);
int i;
dev->pathfactor = 1;
if (fz_abs(ctm.a) == fz_abs(ctm.d)) {
if (ctm.a != 0 && fz_abs(ctm.a) == fz_abs(ctm.d)) {
dev->pathfactor = fz_abs(ctm.a);
} else {
if (ctm.b != 0 && fz_abs(ctm.b) == fz_abs(ctm.c)) {
dev->pathfactor = fz_abs(ctm.b);
}
}
dev->ctm = ctm; // fz_concat(ctm, trace_device_ptm);
dev->path_type = STROKE_PATH;
Expand Down
Binary file added tests/resources/test-3591.pdf
Binary file not shown.
12 changes: 11 additions & 1 deletion tests/test_drawings.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def test_2556():
# following contains an incomplete clip
c = b"q 50 697.6 400 100.0 re W n q 0 0 m W n Q "
xref = doc.get_new_xref() # prepare /Contents object for page
doc.update_object(xref,"<<>>") # new xref now is a dictionary
doc.update_object(xref, "<<>>") # new xref now is a dictionary
doc.update_stream(xref, c) # store drawing commands
page.set_contents(xref) # give the page this xref as /Contents
# following will bring down interpreter if fix not installed
Expand Down Expand Up @@ -218,3 +218,13 @@ def test_3207():
p11 = items[5][2]
assert p0 == p5
assert p6 == p11


def test_3591():
"""Confirm correct scaling factor for rotation matrices."""
filename = os.path.join(scriptdir, "resources", "test-3591.pdf")
doc = pymupdf.open(filename)
page = doc[0]
paths = page.get_drawings()
for p in paths:
assert p["width"] == 15

0 comments on commit 8f5f3eb

Please sign in to comment.