Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The position of the square root symbol is incorrect. #4179

Open
crazymxm opened this issue Dec 26, 2024 · 3 comments
Open

The position of the square root symbol is incorrect. #4179

crazymxm opened this issue Dec 26, 2024 · 3 comments

Comments

@crazymxm
Copy link

crazymxm commented Dec 26, 2024

Description of the bug

Get text by page.get_text("dict")["blocks"], the positions (span's bbox ) of regular text and normal symbols are correct. However, the position of the square root symbol is noticeably incorrect. Please refer to the following debug information and the rectangles I redrew on the original PDF page based on the obtained bbox. It can be observed that the bbox positions are off by nearly 1 line-height to the actual positions.

Debug message:
.....
DEBUG: PDF Span:(query with all keys, divide each by) bbox:[108.0, 391.57, 247.56, 401.57] fonts:NimbusRomNo9L-Regu
DEBUG: PDF Span:(√ ) bbox:[250.05, 383.49, 258.35, 393.46] fonts:CMSY10
DEBUG: PDF Span:(d) bbox:[258.35, 391.36, 263.54, 401.33] fonts:CMMI10
DEBUG: PDF Span:(k) bbox:[263.54, 395.19, 267.77, 402.17] fonts:CMMI7
.....

Image : bbox of span and original pdf
image

How to reproduce the bug

TEST PDF File : https://arxiv.org/pdf/1706.03762
Test Page: P.4

PyMuPDF version

1.25.1

Operating system

MacOS

Python version

3.10

@julian-smith-artifex-com
Copy link
Collaborator

I have a reproduced the problem. It looks like it is not the font ascender/descender issue that has just been fixed on main.

@julian-smith-artifex-com
Copy link
Collaborator

@julian-smith-artifex-com julian-smith-artifex-com added the upstream bug bug outside this package label Jan 24, 2025
@julian-smith-artifex-com
Copy link
Collaborator

Thanks for reporting this.

It looks like the font bbox ascender/descender information for the square root symbol is wildly inaccurate.

However there is a partial workaround that you could try, which is in two parts:

  1. Call pymupdf.TOOLS.unset_quad_corrections(True). This is a global setting.
  2. Pass flags=pymupdf.TEXT_ACCURATE_BBOXES to Page.get_text().

Number 1 stops PyMuPDF trying to do its own patching up of bboxes, which allows number 2 to work - TEXT_ACCURATE_BBOXES makes MuPDF calculate the exact bboxes of characters by looking at the actual drawing operations. This will probably make things slower, but it's probably the only way of reliably coping with a broken font.

Using these accurate bboxes for individual characters isn't very good for highlighting whole spans or lines, hence the description as being only a partial workaround.

[We're looking at making number 1 be the default in future releases, but this will need some more testing and isn't certain yet.]

@julian-smith-artifex-com julian-smith-artifex-com removed the upstream bug bug outside this package label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants