Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions DocTest/DocumentRepresentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,23 @@ def _process_pattern_ignore_area_from_pdf(self, ignore_area: Dict):
if self.pdf_text_words:
for word in self.pdf_text_words:
if search_pattern.match(word[4]):
(x, y, w, h) = (word[0]*self.dpi/72, word[1]*self.dpi/72, word[2]*self.dpi/72, word[3]*self.dpi/72)
text_mask = {"x": int(x) - xoffset, "y": int(y) - yoffset, "width": int(w) + 2 * xoffset, "height": int(h) + 2 * yoffset}
x0, y0 = word[0], word[1]
x = x0 * self.dpi / 72
y = y0 * self.dpi / 72
if word[2] > x0:
# PyMuPDF >= 1.25 returns (x0, y0, x1, y1, text, ...)
w = (word[2] - x0) * self.dpi / 72
h = (word[3] - y0) * self.dpi / 72
else:
# Older versions return (x0, y0, width, height, text, ...)
w = word[2] * self.dpi / 72
h = word[3] * self.dpi / 72
text_mask = {
"x": int(x) - xoffset,
"y": int(y) - yoffset,
"width": int(w) + 2 * xoffset,
"height": int(h) + 2 * yoffset,
}
self.pixel_ignore_areas.append(text_mask)
else:
if self.pdf_text_dict:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ homepage = "https://github.com/manykarim/robotframework-doctestlibrary"
[tool.poetry.dependencies]
python = "^3.8.1"
PyMuPDF = [
{ version = ">=1.23.1, <1.25.0", python = ">=3.8, <3.9" },
{ version = ">=1.23.1, !=1.25.0, <1.26.0", python = ">=3.8, <3.9" },
{ version = ">=1.26.0", python = ">=3.9" },
]
imutils = "*"
Expand Down
13 changes: 12 additions & 1 deletion utest/test_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,15 @@ def test_pdf_area_mask(testdata_dir):
def test_pdf_text_mask(testdata_dir):
img = DocumentRepresentation(testdata_dir / 'sample_1_page.pdf', ignore_area_file=testdata_dir / 'pdf_pattern_mask.json')
assert len(img.abstract_ignore_areas)==2
assert np.not_equal(img.pages[0].get_image_with_ignore_areas(), img.pages[0].image).any()
assert np.not_equal(img.pages[0].get_image_with_ignore_areas(), img.pages[0].image).any()


def test_pdf_word_pattern_mask_dimensions(testdata_dir):
img = DocumentRepresentation(
testdata_dir / 'sample_1_page.pdf',
dpi=300,
ignore_area_file=testdata_dir / 'pdf_pattern_mask.json',
)
word_mask = img.pages[0].pixel_ignore_areas[0]
assert word_mask['width'] == 350
assert word_mask['height'] == 47
Loading