fix: restore IoU fallback in _get_effective_y_bounds - #614
Open
Jiajun0413 wants to merge 1 commit into
Open
Conversation
The function was meant to use the visual bbox only when its IoU with the PDF bbox is >= 0.5, and fall back to the PDF bbox otherwise (as stated in its docstring). An early 'return visual_box.y, visual_box.y2' short-circuited the fallback, so the visual bbox was always used. On PDFs where the visual bbox is systematically shorter than the PDF bbox (e.g. ~6pt visual height vs 12pt PDF line height), the collision histogram in _split_paragraph_into_lines found no gap between adjacent lines and the whole paragraph collapsed into a single pseudo-line. This made inline math spanning a line break get merged into one formula block, which then rendered scattered after translation. Restoring the intended fallback fixes the line segmentation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Restores a dead-code fallback in
ParagraphFinder._get_effective_y_boundsthat was already documented in its docstring but silently short-circuited.Problem
_get_effective_y_bounds(inbabeldoc/format/pdf/document_il/midend/paragraph_finder.py) is documented to:>= 0.5, andBut the implementation had an early
return visual_box.y, visual_box.y2before the fallback, so the fallback branch (pdf_box) was unreachable dead code and the visual bbox was always used.Downstream symptom
On PDFs whose
visual_bboxis systematically shorter than the PDF line box (in one Elsevier single-column paper the visual height is ~6pt vs a ~12pt PDF line height, with >52% of characters havingvisual_bbox↔boxIoU < 0.5), the vertical collision histogram in_split_paragraph_into_linesfound no gap between adjacent lines, so an entire multi-line paragraph collapsed into a single 43.8pt pseudo-line.That pseudo-line then made inline math crossing a physical line break (e.g.
p > 0.05,δ < 0.04,temperature τ = 0.1,seed s = 123) get grouped into onePdfFormulablock whose characters kept their original two-line relative coordinates. After translation therelocate()step re-placed those characters at their original relative offsets, producing scattered / mis-ordered inline formula fragments and dropped decimal points.Fix
Remove the early
returnso the intendedvisual_bbox/pdf_boxIoU fallback runs exactly as the docstring describes.visual_box = char.visual_bbox.box - return visual_box.y, visual_box.y2 pdf_box = char.box if calculate_iou_for_boxes(visual_box, pdf_box) >= 0.5: return visual_box.y, visual_box.y2 return pdf_box.y, pdf_box.y2This is a restoration of the author's original intent (the fallback branch already existed) rather than new logic.
Verification
_split_paragraph_into_linesoutput 1 pseudo-line with 43.8pt vertical span for a paragraph that has 5 physical lines. After the fix the ioU<0.5 characters fall back to the PDF box and the collision histogram recovers the inter-line gaps.>= 0.5branch is unchanged).Related
I can add a minimal regression test under
tests/if maintainers prefer, but the fix itself is a one-line deletion.Summary by cubic
Restores the documented IoU fallback in
_get_effective_y_boundsso the PDF bbox is used when it doesn't overlap the visual bbox well.>= 0.5branch is unchanged.Written for commit 2ab5e2d. Summary will update on new commits.