pdfrx icon indicating copy to clipboard operation
pdfrx copied to clipboard

Pinch zooming speed gets faster when page width gets smaller than view width

Open dhruvhighspot opened this issue 1 year ago • 5 comments

It seems that the animation for zooming in is scaling a lot in landscape mode - causing a small pinch to zoom a lot.

https://github.com/espresso3389/pdfrx/assets/156050023/33cb555f-09e1-4258-8fa9-82b5bc2f66c6

dhruvhighspot avatar Apr 19 '24 16:04 dhruvhighspot

@espresso3389 Hey, can you fix this? Zoom is a little bit fast and/or not smooth.

dhruvhighspot avatar May 07 '24 04:05 dhruvhighspot

Ah, zoom suddenly gets speed-up when the page width gets smaller than the screen width. It occurrs not only on landscape mode but also on portrait mode The sample's page 3 has the same issue...

espresso3389 avatar May 07 '24 13:05 espresso3389

I could not determine the mechanism behind the behavior so far.

espresso3389 avatar May 07 '24 13:05 espresso3389

Please prioritize the task and fix it as soon as possible.

dhruvhighspot avatar May 07 '24 15:05 dhruvhighspot

Hi, is there any fixing or workaround? I have the same issue

edwinkomalaICI avatar Sep 03 '24 09:09 edwinkomalaICI

Could you please share the fix?

srinivasghighspot avatar Feb 04 '25 16:02 srinivasghighspot

Maybe the bug is the normalizeMatrix pre-settings. I set the bellow code and zoom gets smooth, but the viewer do not respect the document limits and the user can slide the pdf out of the viewer.

normalizeMatrix: (matrix, viewSize, layout, controller) => matrix, @espresso3389 can you check this?

jeffpontocom avatar Apr 10 '25 10:04 jeffpontocom

Maybe the bug is the normalizeMatrix pre-settings. I set the bellow code and zoom gets smooth, but the viewer do not respect the document limits and the user can slide the pdf out of the viewer.

normalizeMatrix: (matrix, viewSize, layout, controller) => matrix, @espresso3389 can you check this?

Actually I found out a great solution using the normalize example in documentation: The problem is in the z axis of the third line in controller.calcMatrizFor method that always return 1.0. I just change the result matrix with .scaled(1.0,1.0,newzoom).

// before [0] zoom, 0.0, 0.0, X axis [1] 0.0, zoom, 0.0, Y axis [2] 0.0, 0.0, 1.0, 0.0 [3] 0.0, 0.0, 0.0, 1.0

// after .scaled method [0] zoom, 0.0, 0.0, X axis [1] 0.0, zoom, 0.0, Y axis [2] 0.0, 0.0, zoom, 0.0 [3] 0.0, 0.0, 0.0, 1.0

// code // (do not forget to copy the extension on num [_RangeDouble] to use the range method.)

normalizeMatrix: (matrix, viewSize, layout, controller) {
                // If the controller is not ready, just return the input matrix.
                if (controller == null || !controller.isReady) return matrix;
                final newValue = Matrix4.copy(matrix);
                final position = newValue.calcPosition(viewSize);
                final newZoom = controller.params.boundaryMargin != null
                    ? newValue.zoom
                    : max(newValue.zoom, controller.minScale);
                final hw = viewSize.width / 2 / newZoom;
                final hh = viewSize.height / 2 / newZoom;
                final x = position.dx.range(hw, layout.documentSize.width - hw);
                final y =
                    position.dy.range(hh, layout.documentSize.height - hh);
                return controller
                    .calcMatrixFor(Offset(x, y),
                        zoom: newZoom, viewSize: viewSize)
                    .scaled(1.0, 1.0, newZoom);
              },
extension _RangeDouble<T extends num> on T {
  /// Identical to [num.clamp] but it does nothing if [a] is larger or equal to [b].
  T range(T a, T b) => a < b ? clamp(a, b) as T : (a + b) / 2 as T;
}

jeffpontocom avatar Apr 10 '25 11:04 jeffpontocom

Very interesting. I'll check it later.

espresso3389 avatar Apr 10 '25 11:04 espresso3389

@espresso3389 please fix this asap

dhruvhighspot avatar Apr 11 '25 05:04 dhruvhighspot

1.1.27 applies the proposed fix by @jeffpontocom but I' not sure if it works well or not. Personally, I don't feel any difference...

espresso3389 avatar May 02 '25 05:05 espresso3389

1.1.27 applies the proposed fix by @jeffpontocom but I' not sure if it works well or not. Personally, I don't feel any difference...

works great! thank you guys!

Reyrey14-1 avatar May 03 '25 01:05 Reyrey14-1