Skip to content

Fix: small glyph line grouping issue#391

Open
marca116 wants to merge 2 commits into
pymupdf:mainfrom
marca116:fix/small-glyph-line-grouping
Open

Fix: small glyph line grouping issue#391
marca116 wants to merge 2 commits into
pymupdf:mainfrom
marca116:fix/small-glyph-line-grouping

Conversation

@marca116

@marca116 marca116 commented May 6, 2026

Copy link
Copy Markdown

Description

In helpers/get_text_lines.py::get_raw_lines, spans are grouped into lines by checking whether their top or bottom y-coordinate aligns within tolerance (default 3). This fails for glyphs that have a small, accurate bbox sitting vertically centered inside the full-height text, like a dash, period, or asterisk. Neither edge of the small bbox aligns with the surrounding text, so the glyph gets treated as a different line and ends up reordered.

The issue occurs with tests/test_370.pdf.

Expected:

To demonstrate the feasibility of our strategy, g- silylallyloxysilane 1a was treated...

Actual (before this PR):

  • To demonstrate the feasibility of our strategy, g silylallyloxysilane 1a was treated...

The dash gets pulled off g- and stuck at the start of the paragraph.

Fix

Added a containment check alongside the existing edge-alignment checks: if the previous span's vertical extent fits inside the current span's (within tolerance), they belong on the same line.

Test

Added test_370_small_glyph_line_assignment in tests/test_370.py, which asserts the dash stays attached to g- and does not get reordered to the start of the paragraph.

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

Successfully merging this pull request may close these issues.

1 participant