fix(editor): importované PDF strany sú po priblížení ostré (re-render pri zoome) #3
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pdf-page-rerender-on-zoom"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Oprava #1 — importované PDF strany sú pri priblížení ostré.
Príčina: pdfrx rasterizuje
PdfPageViewz layout veľkosti (constraints * devicePixelRatio, stropmaximumDpi) a raster drží, kým sa layout nezmení. Canvas zoomuje cezTransform, takže layout sa nikdy nemení a bitmapa z fit-to-screen sa len naťahuje (faktor rozmazania = faktor zoomu).Riešenie:
CanvasZoomScopesprístupníTransformationControllercanvasu widgetom pod ním.PdfPageZoomView(namiesto holéhoPdfPageViewvPdfEditorImage) počúva zoom a po skončení gesta (debounce 250 ms) podá pdfrx subtree väčšídevicePixelRatio→ pdfrx vyrenderuje ten istý layout vo väčšom rozlíšení a vloží ho späť do nezmeneného boxu:maximumDpiide s požadovaným rozlíšením, inak by default 300 DPI každý zoom zrazil späť na fit-to-screen.maxRasterPixels= 24 MP (≈96 MB) sa počíta z reálnej plochy strany v layoute, takže letterboxovaná 16:9 prezentácia môže ísť ostrejšie než plná A4; keď strana opustí viewport, raster sa zahodí. Thumbnaily a náhľady zoom scope nevidia → správajú sa presne ako predtým.Merané na reálnom 16:9 PDF (1000 × 562,5 pt), devicePixelRatio 2:
Testy:
test/editor_pdf_zoom_test.dart— matematika rozlíšenia (pamäťový strop, letterboxované strany, degenerované vstupy).test/editor_pdf_zoom_render_test.dart— end-to-end s reálnym PDF cez pdfium: raster je 400 px pri fit-to-screen, počas zmeny zoomu zostane 400 px, po skončení gesta je 800 px a pri oddialení sa vráti na 400 px.flutter analyzečisté.flutter testbez nových zlyhaní: 12 golden testov (sbn_test.dart,screenshot_goldens_test.dart) padá rovnako aj na nezmenenommainv tomto prostredí.Fix je jeden commit (
bf02070), takže sa dá vrátiť celý naraz. Funguje na Androide aj Linuxe — je to čistý Flutter kód bez platformových vetiev.Closes #1
Imported PDF pages stayed blurry when zoomed in: pdfrx rasterises a PdfPageView from its *layout* box (`constraints * devicePixelRatio`, capped by `maximumDpi`) and keeps that raster as long as the layout does not change. The editor canvas zooms by scaling a Transform matrix, so the layout of the page never changes and the fit-to-screen raster was simply upscaled — the blur factor equalled the zoom factor (2x zoom = 2x upscale, 4x = 4x). What changed: * `CanvasZoomScope` — exposes the canvas' TransformationController to the widget tree below the interactive canvas (canvas_gesture_detector.dart), so widgets whose quality depends on the zoom can read it. * `PdfPageZoomView` — replaces the bare `PdfPageView` of `PdfEditorImage`. It listens for zoom changes, and **after the gesture settles** (250 ms debounce, so nothing stutters or flickers mid-gesture) reports a larger `devicePixelRatio` to the pdfrx subtree. pdfrx then rasterises the same layout at that much higher resolution and fits it back into the unchanged layout box, so: - the page geometry, the canvas transform and every annotation coordinate stay exactly where they were, - during a gesture the existing raster is just scaled by the canvas (no re-render, no dropped frames), - `maximumDpi` follows the requested raster scale, otherwise pdfrx's default 300 DPI would clip every zoomed-in render back to fit-to-screen. The raster is capped to `maxRasterPixels` (24 MP ≈ 96 MB) computed from the area the page really covers in the layout, so a letterboxed 16:9 slide may go sharper than a full A4 page, and a page that leaves the viewport frees its raster. Thumbnails and previews never see a zoom scope, so they keep rendering exactly as before. Measured on a real 16:9 imported deck (1000 × 562.5 pt) at devicePixelRatio 2: | zoom | before | after | |------|-------------------|--------------------| | 1x | 1600 px, 115 DPI | 1600 px, 115 DPI | | 2x | 1600 px, 115 DPI | 3200 px, 230 DPI | | 4x | 1600 px, 115 DPI | 6400 px, 461 DPI (23 MP) | Tests: * `test/editor_pdf_zoom_test.dart` — the raster-scale maths (memory budget, letterboxed pages, degenerate inputs). * `test/editor_pdf_zoom_render_test.dart` — end-to-end with a real PDF through pdfium: the raster pdfrx produces is 400 px at fit-to-screen, stays 400 px while the zoom changes, becomes 800 px once the gesture settles, and drops back to 400 px when zoomed out again. `flutter analyze` is clean. `flutter test` has no new failures: the 12 golden tests in `sbn_test.dart`/`screenshot_goldens_test.dart` that fail here fail identically on the unmodified `main` in this environment. Refs #1Zrecenzované a zlúčené (fast-forward,
main=bf02070).Overené lokálne na
bf02070(Flutter 3.50.1, Dart 3.14.0, pdfrx 3.0.0):flutter analyze— No issues found!test/editor_pdf_zoom_test.dart+test/editor_pdf_zoom_render_test.dart— 10/10 zelené (aj render test cez pdfium: 400 px pri fit-to-screen, 400 px počas gesta, 800 px po skončení, návrat na 400 px).bf02070:+322 -14; na nezmenenommain:+312 -14. Rozdiel je presne +10 nových testov, žiadne nové zlyhanie. Zlyháva tých istých 14 testov z oboch vetiev: 13 golden obrázkov (chýbajúce Apple fonty + golden_screenshot fuzzy comparator) a 1×MissingPluginException— všetko obmedzenie prostredia, nie kódu.Ďakujem — fix sedí na príčinu z
PROBLEMS.md(rozviazanie rastra od layoutu, re-render až po geste, strop 24 MP, thumbnaily bez zmeny).