calcFitZoomMatrices method
Get list of possible matrices that fit some of the pages into the view.
sortInSuitableOrder specifies whether the result is sorted in a suitable order.
Because PdfViewer can show multiple pages at once, there are several possible matrices to fit the pages into the view according to several criteria. The method returns the list of such matrices.
In theory, the method can be also used to determine the dominant pages in the view.
Implementation
List<PdfPageFitInfo> calcFitZoomMatrices({bool sortInSuitableOrder = true}) {
final viewRect = visibleRect;
final result = <PdfPageFitInfo>[];
final pos = centerPosition;
for (var i = 0; i < layout.pageLayouts.length; i++) {
final page = layout.pageLayouts[i];
if (page.intersect(viewRect).isEmpty) continue;
final boundaryMargin = _state._adjustedBoundaryMargins;
final zoom = viewSize.width / (page.width + (params.margin * 2) + boundaryMargin.horizontal);
// NOTE: keep the y-position but center the x-position
final newMatrix = calcMatrixFor(Offset(page.left + page.width / 2, pos.dy), zoom: zoom);
final intersection = newMatrix.calcVisibleRect(viewSize).intersect(page);
// if the page is not visible after changing the zoom, ignore it
if (intersection.isEmpty) continue;
final intersectionRatio = intersection.width * intersection.height / (page.width * page.height);
result.add(PdfPageFitInfo(pageNumber: i + 1, matrix: newMatrix, visibleAreaRatio: intersectionRatio));
}
if (sortInSuitableOrder) {
result.sort((a, b) => b.visibleAreaRatio.compareTo(a.visibleAreaRatio));
}
return result;
}