Skip to content

fix: keep zero-width chars in table cells when origin is inside - #5186

Open
fahmiridho07 wants to merge 1 commit into
pymupdf:mainfrom
fahmiridho07:fix-5185-zero-width-cell-chars
Open

fahmiridho07 wants to merge 1 commit into
pymupdf:mainfrom
fahmiridho07:fix-5185-zero-width-cell-chars

Conversation

@fahmiridho07

Copy link
Copy Markdown

Fixes #5185.

With quad corrections unset (e.g. after importing pymupdf4llm, which calls TOOLS.unset_quad_corrections(True) at import), a glyph expanded into two characters gets a zero-width bbox for the second one (e.g. the i of fi: (151.70, 56.35, 151.70, 63.35)).

extract_cells keeps a char only if abs(bbox & cell) > 0.5 * abs(bbox). For a zero-area bbox that is 0 > 0, so the char is dropped and table cells lose letters (fine-tuning -> fne-tuning, figures -> fgures), while prose on the same page is fine. Same for zero-width combining overlays (i + U+0338 -> i = j loses the slash).

This change falls back to testing the char origin for empty bboxes:

  • empty bbox + origin inside cell -> keep
  • empty bbox + origin outside cell -> drop (unchanged behavior for truly outside chars)
  • non-empty bbox -> unchanged 50%-overlap test

Verified locally with synthetic zero-width bboxes (pymupdf 1.28.0): old logic drops, new logic keeps inside-origin and still drops outside-origin, no change for normal chars.

With quad corrections unset (e.g. after importing pymupdf4llm),
a glyph expanded into two characters gets a zero-width bbox for
the second one. The 50%-overlap area test (0 > 0) then drops it,
so table cells lose letters (fine-tuning -> fne-tuning).

Fall back to testing the char origin for empty bboxes.

Fixes pymupdf#5185
@github-actions

Copy link
Copy Markdown
Contributor


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

pymupdf4llm: table cells drop the second letter of a ligature when quad corrections are unset

1 participant