Skip to content

Commit

Permalink
CreatePattern for zero height image should return null
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=250662
rdar://104285727

Reviewed by Tim Nguyen.

Use the same logic we use for createPattern when passed an
SVGImageElement for HTMLImageElement.

* LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.pattern.image.zeroheight-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/html/canvas/element/fill-and-stroke-styles/2d.pattern.image.zerowidth-expected.txt:
* LayoutTests/svg/as-image/resources/svg-with-feimage-with-link.svg:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::createPattern):

Canonical link: https://commits.webkit.org/267334@main
  • Loading branch information
annevk committed Aug 27, 2023
1 parent 77879c8 commit 94656d3
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
2d.pattern.image.zeroheight
Actual output:

FAIL Canvas test: 2d.pattern.image.zeroheight assert_equals: ctx.createPattern(img, 'repeat') === null (got [object CanvasPattern][object], expected [object]) expected null but got object "[object CanvasPattern]"
PASS Canvas test: 2d.pattern.image.zeroheight

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
2d.pattern.image.zerowidth
Actual output:

FAIL Canvas test: 2d.pattern.image.zerowidth assert_equals: ctx.createPattern(img, 'repeat') === null (got [object CanvasPattern][object], expected [object]) expected null but got object "[object CanvasPattern]"
PASS Canvas test: 2d.pattern.image.zerowidth

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,14 @@ ExceptionOr<RefPtr<CanvasPattern>> CanvasRenderingContext2DBase::createPattern(H
if (cachedImage->status() == CachedResource::LoadError)
return Exception { InvalidStateError };

// Image may have a zero-width or a zero-height.
Length intrinsicWidth;
Length intrinsicHeight;
FloatSize intrinsicRatio;
cachedImage->computeIntrinsicDimensions(intrinsicWidth, intrinsicHeight, intrinsicRatio);
if (intrinsicWidth.isZero() || intrinsicHeight.isZero())
return nullptr;

return createPattern(*cachedImage, imageElement.renderer(), repeatX, repeatY);
}

Expand Down

0 comments on commit 94656d3

Please sign in to comment.