calculatePageFitMatrix method

Matrix4? calculatePageFitMatrix({
  1. required int pageNumber,
  2. double? padding,
})

Calculate the matrix that corresponding to the page position.

Implementation

Matrix4? calculatePageFitMatrix({required int pageNumber, double? padding}) {
  final rect = getPageRect(pageNumber)?.inflate(padding ?? _state!._padding);
  if (rect == null) {
    return null;
  }
  final scale = _state!._lastViewSize!.width / rect.width;
  final left = max(
      0.0,
      min(
        rect.left,
        _state!._docSize!.width - _state!._lastViewSize!.width,
      ));
  final top = max(
      0.0,
      min(
        rect.top,
        _state!._docSize!.height - _state!._lastViewSize!.height,
      ));
  return Matrix4.compose(
    math64.Vector3(-left, -top, 0),
    math64.Quaternion.identity(),
    math64.Vector3(scale, scale, 1),
  );
}