Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement document progress feature #537

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/pdfx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions packages/pdfx/lib/src/viewer/pinch/pdf_controller_pinch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> pageListenable = ValueNotifier(initialPage);
Expand Down
11 changes: 11 additions & 0 deletions packages/pdfx/lib/src/viewer/pinch/pdf_view_pinch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,17 @@ class _PdfViewPinchState extends State<PdfViewPinch>
final r = m.row0[0];
final exposed = Rect.fromLTWH(
-m.row0[3], -m.row1[3], _lastViewSize!.width, _lastViewSize!.height);

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;
_visiblePages.clear();
Expand Down