Bug 700466 - Search results sometimes split into horizontally overlapping rectangles
Summary: Search results sometimes split into horizontally overlapping rectangles
Status: UNCONFIRMED
Alias: None
Product: MuPDF
Classification: Unclassified
Component: fitz (show other bugs)
Version: master
Hardware: PC Windows 7
: P4 normal
Assignee: muPDF bugs
QA Contact: Bug traffic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-09 09:12 UTC by Tamir Evan
Modified: 2019-01-14 09:36 UTC (History)
1 user (show)

See Also:
Customer:
Word Size: ---


Attachments
mupdf-gl showing example_033 PDF with search for "commodo", zoomed to show problem (206.74 KB, image/png)
2019-01-09 09:12 UTC, Tamir Evan
Details
test.js mentioned in the first comment (841 bytes, application/x-javascript)
2019-01-09 09:15 UTC, Tamir Evan
Details
The image created by running test.js (423.01 KB, image/png)
2019-01-09 09:17 UTC, Tamir Evan
Details
Image created by running patched test.js with fixed mutool (783.07 KB, image/png)
2019-01-13 11:36 UTC, Tamir Evan
Details
Image created by running patched test.js with fixed mutool (780.39 KB, image/png)
2019-01-13 11:51 UTC, Tamir Evan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tamir Evan 2019-01-09 09:12:39 UTC
Created attachment 16681 [details]
mupdf-gl showing example_033 PDF with search for "commodo", zoomed to show problem

If I download the example 033 PDF from the tcpdf website (https://tcpdf.org/files/examples/example_033.pdf), open it with mupdf-gl, built from the latest git source (commit 6c383df4f897c3ceb562807ed92fe6075efffdaf), and search for "commodo", the last result is shown (see attached image) with two vertical lines, before and after the second 'm', that are darker than the rest of the rectangle. These are caused by overlapping search result rectangles, resulting from splitting the last result there into three rectangles.

To demonstrate that, I created a JavaScript file (test.js, to be attached to my next comment), that prints the coordinates for each search result rectangle, and creates an image illustrating the split and the overlap. when I run, with mutool from the same build as above:

    mutool run test.js

I get:

    Result 1:
        Xul = 185.01202392578126
        Yul = 204.28689575195313
        Xur = 225.01202392578126
        Yur = 204.28689575195313
        Xll = 185.01202392578126
        Yll = 217.62689208984376
        Xlr = 225.01202392578126
        Ylr = 217.62689208984376
    Result 2:
        Xul = 216.7663116455078
        Yul = 349.3339538574219
        Xur = 266.4544677734375
        Yur = 349.3339538574219
        Xll = 216.7663116455078
        Yll = 360.9745788574219
        Xlr = 266.4544677734375
        Ylr = 360.9745788574219
    Result 3:
        Xul = 185.32339477539063
        Yul = 459.0024719238281
        Xur = 203.61138916015626
        Yur = 459.0024719238281
        Xll = 185.32339477539063
        Yll = 471.93548583984377
        Xlr = 203.61138916015626
        Ylr = 471.93548583984377
    Result 4:
        Xul = 202.3243865966797
        Yul = 459.0024719238281
        Xur = 211.10838317871095
        Yur = 459.0024719238281
        Xll = 202.3243865966797
        Yll = 471.93548583984377
        Xlr = 211.10838317871095
        Ylr = 471.93548583984377
    Result 5:
        Xul = 209.82138061523438
        Yul = 459.0024719238281
        Xur = 225.1753692626953
        Yur = 459.0024719238281
        Xll = 209.82138061523438
        Yll = 471.93548583984377
        Xlr = 225.1753692626953
        Ylr = 471.93548583984377

and an image (to be attached to my third comment).

Note that for results 3-5, all upper Ys are the same, all lower Ys are the same, and the right Xs of each result are larger than left Xs of the next one. What I should be getting, is something like:

    [...]
    Result 3:
        Xul = 185.32339477539063
        Yul = 459.0024719238281
        Xur = 225.1753692626953
        Yur = 459.0024719238281
        Xll = 185.32339477539063
        Yll = 471.93548583984377
        Xlr = 225.1753692626953
        Ylr = 471.93548583984377
Comment 1 Tamir Evan 2019-01-09 09:15:09 UTC
Created attachment 16683 [details]
test.js mentioned in the first comment
Comment 2 Tamir Evan 2019-01-09 09:17:06 UTC
Created attachment 16686 [details]
The image created by running test.js
Comment 3 Tor Andersson 2019-01-11 13:31:57 UTC
commit eaa4040b69fbb01f77056a4c40f7404627bc499b
Author: Tor Andersson <tor.andersson@artifex.com>
Date:   Wed Jan 9 15:35:30 2019 +0100

    Bug 700466: Use same quad merging threshold for text search as selection.
Comment 4 Tamir Evan 2019-01-13 11:36:21 UTC
Created attachment 16722 [details]
Image created by running patched test.js with fixed mutool

(In reply to Tor Andersson from comment #3)
> commit eaa4040b69fbb01f77056a4c40f7404627bc499b
> Author: Tor Andersson <tor.andersson@artifex.com>
> Date:   Wed Jan 9 15:35:30 2019 +0100
> 
>     Bug 700466: Use same quad merging threshold for text search as selection.

That commit gives the desired result for the example I brought, but doesn't solve the underlying problem.

Another example:

If I download the PDF from http://beta.hebrewbooks.org/pagefeed/hebrewbooks_org_9717_1.pdf (saved as HebrewBooksOrg_9717_page_1.pdf), patch test.js with:

--- test.js	2019-01-13 12:55:01.155221700 +0200
+++ test1.js	2019-01-13 12:55:06.818031600 +0200
@@ -1,4 +1,4 @@
-var doc = new Document('example_033.pdf');
+var doc = new Document('HebrewBooksOrg_9717_page_1.pdf');
 var page = doc.loadPage(0);
 
 var tansform = [4,0,0,4,0,0];
@@ -6,7 +6,7 @@
 var pixmap = page.toPixmap(tansform, DeviceRGB);
 var device = new DrawDevice(Identity, pixmap);
 
-var arr = page.search('commodo');
+var arr = page.search('\u05d4\u05e0\u05e9\u05de'); // He-Nun-Shin-Mem
 var i;
 for(i = 0; i < arr.length; i++)
 {
@@ -31,4 +31,4 @@
 }
 
 device.close();
-pixmap.saveAsPNG('example_033.png');
+pixmap.saveAsPNG('HebrewBooksOrg_9717_page_1.png');

and run it with mutool built from the latest git (commit eaa4040b69fbb01f77056a4c40f7404627bc499b), I get 11 rectangles (where I should be getting 6 now), and the image attached.

The commit has improved the situation, because if I run the patched test.js with an older version of mutool (built from commit 4f08f6adbbb7d6f5d3dc0257b9fc0bb79a3c55cd), I get 23 rectangles.
Comment 5 Tamir Evan 2019-01-13 11:51:12 UTC
Created attachment 16723 [details]
Image created by running patched test.js with fixed mutool

(By mistake I uploaded the wrong image)