fix(reader): fit wide vector PDF pages to the screen - #953
Merged
Merged
Conversation
None of pdf-doc.vue's four canvas rules had matched anything since the Vuetify 3 port (Dec 2022). That port moved them from an unscoped block into top-level :deep() selectors, which compile to `[data-v-x] .vue-pdf-embed.X > div > canvas` and need a scoped ancestor. The embed is the component's root, so it has none. vue-pdf-embed 2.x also nests the canvas one div deeper than `> div > canvas`. With the selectors fixed (`.pdfDoc.X :deep(canvas)`), each rule was checked in a browser with Force vector at DPR 2: - Fit to Height/Screen two-page `width: inherit` and Fit to Width two-page `height: inherit` did nothing. vue-pdf-embed already gives the canvas an aspect-correct inline size. Deleted. - Original two-page `width/height: inherit` resolved to auto, so each canvas showed at its bitmap size, 2x on HiDPI (1023x1581 instead of 512x790). Zoom uses these classes too. Deleted. - Fit to Screen `object-fit: contain` did nothing, because the box already matched the bitmap. Kept, and paired with max-width 100vw/50vw as page-img.vue does for images. Wide pages now fit the screen instead of overflowing it: a spread plus a page in two-page mode at 1024px went from a 1491px scroll width to 1024px, and a wide page on a 390px phone from 1092px to 390px. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Follow-up to #951. None of the four canvas rules in
pdf-doc.vuematched the rendered canvas, in any fit mode. They have been dead since the Vuetify 3 port (Dec 2022), when an unscoped<style>block became top-level:deep()selectors::deep(.vue-pdf-embed.X > div > canvas)compiles to[data-v-x] .vue-pdf-embed.X > div > canvas, which needs a scoped ancestor. The embed is the component's root, so there isn't one. The rules now scope on the root (.pdfDoc.X :deep(canvas)→.pdfDoc.X[data-v-x] canvas).> div > div.vue-pdf-embed__page > canvas, one level deeper than> div > canvas. A descendantcanvascovers it.Per-rule decisions
I made each rule match, then measured it live (Force vector, DPR 2, 1024×768 and 390×844, portrait pages plus a wide page):
fitToHeightTwo,fitToScreenTwo:width: inherit !importantautoderives the same width.fitToWidthTwo:height: inherit !importantfitToOrigTwo:width/height: inherit !importantauto, so the canvas shows at its bitmap size: 1023×1581 instead of 512×790, 2x on HiDPI, with a 2046px scroll width. Zoom > 1 also producesfitToOrig*, so zoomed pages would blow up too.fitToScreen*:object-fit: containmax-width: 100vw(single/vertical) or50vw(two-page), aspage-img.vuedoes for imagesOriginal Size already renders like Fit to Width (
pdf-doc.vue'swidthcomputed), and that doesn't change here. ThefitToOrigTworule would only have taken effect once #951 landed. The misleading "Wide PDFs will not fit to SCREEN well" comment is replaced.Visible change
This affects only Fit to Screen, and only pages wider than the screen:
Every other mode (Width, Height, Original × single/two/vertical) measured identical to before, down to the pixel. Zoom (
fitToOrig*class) is not capped: at 2x the canvas stays at 2185×1688.NEWS: "Fit to Screen fits wide pages when PDFs render as vectors."
Tests
make fix: no changes beyond this diff.make lint: clean (two basedpyright warnings incover.pywere already there).bunx vitest run: 88 files, 919 tests passed.🤖 Generated with Claude Code