Fix RefHover popup region on mupdf per-glyph ink boxes#5719
Merged
Conversation
The citation-hover region detectors keyed off coords[i].y as a line coordinate, assuming glyphs on one line share a top. mupdf's GetTextForPage returns tight per-glyph ink boxes whose tops vary within a line (a period or comma sits well below a capital). This broke entry-start detection on real PDFs: the trailing "." of the previous bibliography entry could fall into the destination band and hijack the start glyph, yielding a narrow clipped strip or a full-page landscape fallback instead of the target entry. - NormalizeGlyphLines: cluster glyphs by baseline (y+dy, stable across a line) and flatten each line to a uniform top-aligned row before detection. RefHoverOnTimer normalizes coords once for both DetectEquationBox and DetectEntryBox. - DetectEntryBox bracket path: derive columnRightX from the body run (bridging the hanging-indent labelsep gap, capped so it can't jump a column gutter) so a narrow biblatex label no longer collapses the box width and clips the entry. - DetectEntryBox bracket path: trailing-gap trim so a last-on-page entry (no sibling "[" below) ends at its last line instead of swallowing the page-number footer. Adds RefHover_ut coverage for baseline normalization, the variable-top entry-start hijack, narrow-label full width, 2-column safety, and the footer trim. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
|
thanks! |
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.
Problem
The citation/reference hover popup (
RefHover) cropped to the wrong region on many real PDFs: a clipped narrow strip, or a full-page landscape fallback showing several entries, instead of the single target bibliography entry.Root cause: the region detectors in
RefHoverDetect.cppkey offcoords[i].yas a line coordinate, assuming glyphs on one line share a top.EngineBase::GetTextForPagereturns mupdf's tight per-glyph ink boxes, whose tops vary within a line (a period/comma sits well below a capital; ascenders and brackets higher). So the trailing.of the previous bibliography entry could fall into the destination band and hijack the entry-start glyph.(This only reproduces against the real engine —
PyMuPDF/fitzrawdict reports near-uniform tops and hides it.)Fix
NormalizeGlyphLines: cluster glyphs by baseline (y + dy, which is stable across a line) and flatten each line to a uniform top-aligned row before detection.RefHoverOnTimernormalizes the page coords once and passes them to bothDetectEquationBoxandDetectEntryBox.DetectEntryBoxbracket path — derivecolumnRightXfrom the body run, bridging the hanging-indent labelsep gap (capped so it can't jump a column gutter). A narrow biblatex label ([TA05]) no longer collapses the box width and clips the entry.DetectEntryBoxbracket path — trailing-gap trim so a last-on-page entry (no sibling[below it) ends at its last line instead of swallowing the page-number footer.Testing
RefHover_ut: added coverage for baseline normalization, the variable-top entry-start hijack, narrow-label full width, 2-column safety, and the footer trim.test_utilpasses all unit tests.🤖 Generated with Claude Code