From 2e40a0a5fa0d5476ffc2bcd337924f4df3298eef Mon Sep 17 00:00:00 2001 From: AlexVegner Date: Thu, 17 Oct 2024 17:58:52 +0200 Subject: [PATCH 1/3] Implement document progress feature --- packages/pdfx/README.md | 3 +++ .../pdfx/lib/src/viewer/pinch/pdf_controller_pinch.dart | 6 ++++++ packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart | 8 ++++++++ 3 files changed, 17 insertions(+) diff --git a/packages/pdfx/README.md b/packages/pdfx/README.md index d856af92..4fe0ca10 100644 --- a/packages/pdfx/README.md +++ b/packages/pdfx/README.md @@ -116,6 +116,9 @@ _pdfController.nextPage(duration: Duration(milliseconds: 250), curve: Curves.eas // Animate to previous page _pdfController.previousPage(duration: Duration(milliseconds: 250), curve: Curves.easeOut); + +// Get document progrees 0.0 - start, 1.0 - end +_pdfController.documentProgress; ``` ### Additional pdf info: ```dart diff --git a/packages/pdfx/lib/src/viewer/pinch/pdf_controller_pinch.dart b/packages/pdfx/lib/src/viewer/pinch/pdf_controller_pinch.dart index 319178ac..9800fe41 100644 --- a/packages/pdfx/lib/src/viewer/pinch/pdf_controller_pinch.dart +++ b/packages/pdfx/lib/src/viewer/pinch/pdf_controller_pinch.dart @@ -36,6 +36,12 @@ class PdfControllerPinch extends TransformationController _PdfViewPinchState? _state; PdfDocument? _document; + // Provide document progress. + // document start documentProgress = 0.0, + // document end documentProgress = 1.0, + double _documentProgress = 0; + double get documentProgress => _documentProgress; + /// Actual page number wrapped with ValueNotifier @override late final ValueNotifier pageListenable = ValueNotifier(initialPage); diff --git a/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart b/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart index 06760886..8058b5b9 100644 --- a/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart +++ b/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart @@ -289,6 +289,14 @@ class _PdfViewPinchState extends State final r = m.row0[0]; final exposed = Rect.fromLTWH( -m.row0[3], -m.row1[3], _lastViewSize!.width, _lastViewSize!.height); + + final rawDocumentProgress = + (-m.row1[3] / (_docSize!.height - _lastViewSize!.height)); + const precisionFactor = 10000; + _controller._documentProgress = + ((rawDocumentProgress * precisionFactor).round() / precisionFactor) + .clamp(0.0, 1.0); + var pagesToUpdate = 0; var changeCount = 0; _visiblePages.clear(); From 78c9e2ed8c06c75740bb1a650ba4087a274ebf5e Mon Sep 17 00:00:00 2001 From: AlexVegner Date: Thu, 17 Oct 2024 18:35:22 +0200 Subject: [PATCH 2/3] fix for zoom --- packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart b/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart index 8058b5b9..de5e3e18 100644 --- a/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart +++ b/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart @@ -291,7 +291,7 @@ class _PdfViewPinchState extends State -m.row0[3], -m.row1[3], _lastViewSize!.width, _lastViewSize!.height); final rawDocumentProgress = - (-m.row1[3] / (_docSize!.height - _lastViewSize!.height)); + ((-m.row1[3] / r / r) / (_docSize!.height - _lastViewSize!.height)); const precisionFactor = 10000; _controller._documentProgress = ((rawDocumentProgress * precisionFactor).round() / precisionFactor) From 970b78ab5795d766d08f6ac0f03d32cf8c85bdc6 Mon Sep 17 00:00:00 2001 From: AlexVegner Date: Sun, 20 Oct 2024 15:37:32 +0200 Subject: [PATCH 3/3] Fix documentProgress zoom projection calculation. --- .../pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart b/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart index de5e3e18..9a68ed0d 100644 --- a/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart +++ b/packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart @@ -290,12 +290,15 @@ class _PdfViewPinchState extends State final exposed = Rect.fromLTWH( -m.row0[3], -m.row1[3], _lastViewSize!.width, _lastViewSize!.height); - final rawDocumentProgress = - ((-m.row1[3] / r / r) / (_docSize!.height - _lastViewSize!.height)); - const precisionFactor = 10000; - _controller._documentProgress = - ((rawDocumentProgress * precisionFactor).round() / precisionFactor) - .clamp(0.0, 1.0); + if (_lastViewSize?.height != null) { + final rawDocumentProgress = + ((exposed.bottom / r - _lastViewSize!.height) / + (_docSize!.height - _lastViewSize!.height)); + const precisionFactor = 10000; + _controller._documentProgress = + ((rawDocumentProgress * precisionFactor).round() / precisionFactor) + .clamp(0.0, 1.0); + } var pagesToUpdate = 0; var changeCount = 0;