From 0ad581ba4f4a68ed4ccdad22996301ffde891b2f Mon Sep 17 00:00:00 2001 From: Richard Robinson Date: Mon, 10 Apr 2023 12:13:14 -0700 Subject: [PATCH] REGRESSION: Thumbnail turns blank after choose A3/Tabloid paper size in Print Screen https://bugs.webkit.org/show_bug.cgi?id=255210 rdar://107503946 Reviewed by Wenson Hsieh. iOS print preview thumbnail generation uses `CGBitmapContextCreateImage` to create the bitmap image. However, with some combinations of page scale size with paper size, the resulting image dimension becomes too large, resulting in the function returning null and no thumbnail being generated. This PR fixes this by scaling down the dimensions before the image is created to ensure the maximum possible size of the image is constrained. This limit is the size at which the thumbnail itself is rendered, so the scaling is safe to do. * Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm: (WebKit::WebPage::drawToImage): Canonical link: https://commits.webkit.org/262780@main --- Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm index e8b772589f06..8a52a2c49f6d 100644 --- a/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm +++ b/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm @@ -4503,6 +4503,17 @@ static bool selectionIsInsideFixedPositionContainer(LocalFrame& frame) Checked pageWidth = pageRects[0].width(); Checked pageHeight = pageRects[0].height(); + // The thumbnail images are always a maximum of 500 x 500. + static constexpr float maximumPrintPreviewDimensionSize = 500.0; + + // If the sizes are too large, the bitmap will not be able to be created, + // so scale them down. + float scaleFactor = maximumPrintPreviewDimensionSize / static_cast(std::max(pageWidth, pageHeight)); + if (scaleFactor < 1.0) { + pageWidth = static_cast(std::floorf(static_cast(pageWidth) * scaleFactor)); + pageHeight = static_cast(std::floorf(static_cast(pageHeight) * scaleFactor)); + } + int imageHeight; if (!WTF::safeMultiply(pageHeight.value(), pageCount, imageHeight)) { reply({ });