Skip to content

Commit

Permalink
REGRESSION: Thumbnail turns blank after choose A3/Tabloid paper size …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rr-codes committed Apr 10, 2023
1 parent 1cc30ed commit 0ad581b
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Expand Up @@ -4503,6 +4503,17 @@ static bool selectionIsInsideFixedPositionContainer(LocalFrame& frame)
Checked<int> pageWidth = pageRects[0].width();
Checked<int> 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<int>(std::max(pageWidth, pageHeight));
if (scaleFactor < 1.0) {
pageWidth = static_cast<int>(std::floorf(static_cast<int>(pageWidth) * scaleFactor));
pageHeight = static_cast<int>(std::floorf(static_cast<int>(pageHeight) * scaleFactor));
}

int imageHeight;
if (!WTF::safeMultiply(pageHeight.value<size_t>(), pageCount, imageHeight)) {
reply({ });
Expand Down

0 comments on commit 0ad581b

Please sign in to comment.