constrainSizeAndAttemptToPreserveAspectRatio method

PdfPoint constrainSizeAndAttemptToPreserveAspectRatio(
  1. PdfPoint size
)

Returns a size that attempts to meet the conditions

Implementation

PdfPoint constrainSizeAndAttemptToPreserveAspectRatio(PdfPoint size) {
  if (isTight) {
    final result = smallest;
    return result;
  }

  var width = size.x;
  var height = size.y;
  assert(width > 0.0);
  assert(height > 0.0);
  final aspectRatio = width / height;

  if (width > maxWidth) {
    width = maxWidth;
    height = width / aspectRatio;
  }

  if (height > maxHeight) {
    height = maxHeight;
    width = height * aspectRatio;
  }

  if (width < minWidth) {
    width = minWidth;
    height = width / aspectRatio;
  }

  if (height < minHeight) {
    height = minHeight;
    width = height * aspectRatio;
  }

  final result = PdfPoint(constrainWidth(width), constrainHeight(height));
  return result;
}