forked from microsoft/WinObjC
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for ClearRect with clipping geometry (microsoft#2053)
* Adding support for ClearRect with clipping geometry
- Loading branch information
1 parent
c4a2e35
commit e7edfdf
Showing
22 changed files
with
301 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
172 changes: 172 additions & 0 deletions
172
tests/UnitTests/CoreGraphics.drawing/CGContextDrawing_ClearRectTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
//****************************************************************************** | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// | ||
// This code is licensed under the MIT License (MIT). | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
// | ||
//****************************************************************************** | ||
|
||
#include "DrawingTest.h" | ||
|
||
#pragma region ClearRect | ||
|
||
class CGClearRect : public WhiteBackgroundTest<>, public ::testing::WithParamInterface<::testing::tuple<CGRect, CGAffineTransform>> { | ||
CFStringRef CreateOutputFilename() { | ||
CGRect rect = ::testing::get<0>(GetParam()); | ||
CGAffineTransform transformation = ::testing::get<1>(GetParam()); | ||
|
||
return CFStringCreateWithFormat(nullptr, | ||
nullptr, | ||
CFSTR("TestImage.CGContext.ClearRect.(%0.0f.%0.0f)%0.0fx%0.0f.[%0.1f,%0." | ||
"1f,%0.1f,%0.1f,%0.1f,%0.1f].png"), | ||
rect.origin.x, | ||
rect.origin.y, | ||
rect.size.width, | ||
rect.size.height, | ||
transformation.a, | ||
transformation.b, | ||
transformation.c, | ||
transformation.d, | ||
transformation.tx, | ||
transformation.ty); | ||
} | ||
}; | ||
|
||
DRAW_TEST_P(CGClearRect, Transformed) { | ||
CGRect rect = ::testing::get<0>(GetParam()); | ||
CGAffineTransform transformation = ::testing::get<1>(GetParam()); | ||
|
||
CGContextRef context = GetDrawingContext(); | ||
|
||
CGContextAddRect(context, CGRectMake(100, 50, 50, 50)); | ||
CGContextConcatCTM(context, transformation); | ||
CGContextClip(context); | ||
|
||
CGContextSetRGBFillColor(context, 0.48, 0.73, 0, 1); | ||
CGContextClearRect(context, rect); | ||
} | ||
|
||
DRAW_TEST_P(CGClearRect, Transformed2) { | ||
CGRect rect = ::testing::get<0>(GetParam()); | ||
CGAffineTransform transformation = ::testing::get<1>(GetParam()); | ||
|
||
CGContextRef context = GetDrawingContext(); | ||
CGRect bounds = GetDrawingBounds(); | ||
|
||
CGContextAddRect(context, CGRectMake(0, 0, 250, 250)); | ||
CGContextConcatCTM(context, transformation); | ||
CGContextClip(context); | ||
|
||
CGContextSetRGBFillColor(context, 0.48, 0.73, 0, 1); | ||
CGContextClearRect(context, rect); | ||
} | ||
|
||
static CGRect rects[] = { CGRectMake(0, 0, 100, 100), CGRectMake(0, 0, 50, 250), CGRectMake(100, 100, 125, 250) }; | ||
static CGAffineTransform transformation[] = { CGAffineTransformMakeRotation(0.4), | ||
CGAffineTransformMakeTranslation(3, 6), | ||
CGAffineTransformMakeScale(0.25, 0.75), | ||
CGAffineTransformMake(1.f, 0.f, 0.3f, 1.f, 0.f, 0.f), | ||
CGAffineTransformIdentity }; | ||
|
||
INSTANTIATE_TEST_CASE_P(CGContextTests, CGClearRect, ::testing::Combine(::testing::ValuesIn(rects), ::testing::ValuesIn(transformation))); | ||
|
||
DRAW_TEST_F(CGContext, ClearRect, WhiteBackgroundTest<>) { | ||
CGContextRef context = GetDrawingContext(); | ||
CGRect bounds = GetDrawingBounds(); | ||
|
||
CGContextSetRGBFillColor(context, 1.0, 0.0, 0.0, 1); | ||
CGContextFillRect(context, bounds); | ||
|
||
CGRect borderRect = CGRectInset(bounds, 30, 50); | ||
CGContextClearRect(context, borderRect); | ||
} | ||
|
||
// Failure to fill in an Arc geometry - #2059 | ||
// Note add a test for CGContextFill of an Arc that spans from 0-2*PI | ||
DISABLED_DRAW_TEST_F(CGContext, ClearRectArc, WhiteBackgroundTest<>) { | ||
CGContextRef context = GetDrawingContext(); | ||
CGRect bounds = GetDrawingBounds(); | ||
|
||
CGRect cirleRect = CGRectMake(0, 0, 100, 100); | ||
CGContextAddArc(context, 50, 50, 50, 0.0, 2 * M_PI, 0); | ||
CGContextClip(context); | ||
CGContextClearRect(context, cirleRect); | ||
} | ||
|
||
DRAW_TEST_F(CGContext, ClearRectTransparencyLayer, WhiteBackgroundTest<>) { | ||
CGContextRef context = GetDrawingContext(); | ||
CGRect bounds = GetDrawingBounds(); | ||
|
||
CGContextSetRGBFillColor(context, 1, 0, 0, 1); | ||
CGContextFillRect(context, bounds); | ||
|
||
CGContextBeginTransparencyLayer(context, nullptr); | ||
CGContextSetRGBFillColor(context, 0, 0, 1, 1); | ||
CGContextFillRect(context, bounds); | ||
|
||
CGContextClearRect(context, CGRectMake(0, 0, 100, 100)); | ||
|
||
CGContextEndTransparencyLayer(context); | ||
} | ||
|
||
class CGClearRectArc : public WhiteBackgroundTest<>, public ::testing::WithParamInterface<::testing::tuple<CGRect, CGPoint>> { | ||
CFStringRef CreateOutputFilename() { | ||
CGRect rect = ::testing::get<0>(GetParam()); | ||
CGPoint sweep = ::testing::get<1>(GetParam()); | ||
|
||
return CFStringCreateWithFormat(nullptr, | ||
nullptr, | ||
CFSTR("TestImage.CGContext.CGClearRectArc.(%0.0f.%0.0f)%0.0fx%0.0f.sweep(%0.0f--%0.0f).png"), | ||
rect.origin.x, | ||
rect.origin.y, | ||
rect.size.width, | ||
rect.size.height, | ||
sweep.x, | ||
sweep.y); | ||
} | ||
}; | ||
|
||
DRAW_TEST_P(CGClearRectArc, ClearArc) { | ||
CGContextRef context = GetDrawingContext(); | ||
CGRect rect = ::testing::get<0>(GetParam()); | ||
CGPoint sweep = ::testing::get<1>(GetParam()); | ||
|
||
CGContextAddArc(context, 50, 50, 50, sweep.x, sweep.y, 0); | ||
CGContextClip(context); | ||
CGContextClearRect(context, rect); | ||
} | ||
|
||
static CGPoint sweep[] = { CGPointMake(0, M_PI), CGPointMake(M_PI, 0), CGPointMake(0.3 * M_PI, 0.6 * M_PI), CGPointMake(0, 1.9 * M_PI) }; | ||
// TODO: enable when #2062 is fixed. | ||
INSTANTIATE_TEST_CASE_P(DISABLED_CGContextTests, | ||
CGClearRectArc, | ||
::testing::Combine(::testing::ValuesIn(rects), ::testing::ValuesIn(sweep))); | ||
|
||
DRAW_TEST_F(CGContext, CustomPathClearRect, WhiteBackgroundTest<>) { | ||
CGContextRef context = GetDrawingContext(); | ||
CGRect bounds = GetDrawingBounds(); | ||
|
||
CGMutablePathRef thepath = CGPathCreateMutable(); | ||
CGPathMoveToPoint(thepath, NULL, 30, 100); | ||
CGPathAddCurveToPoint(thepath, NULL, 47.0f, 67.0f, 50.0f, 55.0f, 45.0f, 50.0f); | ||
CGPathAddCurveToPoint(thepath, NULL, 42.0f, 47.0f, 37.0f, 46.0f, 30.0f, 55.0f); | ||
|
||
CGPathAddCurveToPoint(thepath, NULL, 23.0f, 46.0f, 18.0f, 47.0f, 15.0f, 50.0f); | ||
CGPathAddCurveToPoint(thepath, NULL, 10.0f, 55.0f, 13.0f, 67.0f, 30.0f, 100.0f); | ||
|
||
CGPathCloseSubpath(thepath); | ||
CGContextAddPath(context, thepath); | ||
|
||
CGContextClip(context); | ||
CGContextClearRect(context, CGRectMake(0, 0, 50, 70)); | ||
CGPathRelease(thepath); | ||
} | ||
#pragma endregion ClearRect |
3 changes: 3 additions & 0 deletions
3
...erence/TestImage.CGContext.ClearRect.(0.0)100x100.[0.3,0.0,0.0,0.8,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...rence/TestImage.CGContext.ClearRect.(0.0)100x100.[0.9,0.4,-0.4,0.9,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...erence/TestImage.CGContext.ClearRect.(0.0)100x100.[1.0,0.0,0.0,1.0,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...erence/TestImage.CGContext.ClearRect.(0.0)100x100.[1.0,0.0,0.0,1.0,3.0,6.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...erence/TestImage.CGContext.ClearRect.(0.0)100x100.[1.0,0.0,0.3,1.0,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ference/TestImage.CGContext.ClearRect.(0.0)50x250.[0.3,0.0,0.0,0.8,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...erence/TestImage.CGContext.ClearRect.(0.0)50x250.[0.9,0.4,-0.4,0.9,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ference/TestImage.CGContext.ClearRect.(0.0)50x250.[1.0,0.0,0.0,1.0,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ference/TestImage.CGContext.ClearRect.(0.0)50x250.[1.0,0.0,0.0,1.0,3.0,6.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ference/TestImage.CGContext.ClearRect.(0.0)50x250.[1.0,0.0,0.3,1.0,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ce/TestImage.CGContext.ClearRect.(100.100)125x250.[0.3,0.0,0.0,0.8,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...e/TestImage.CGContext.ClearRect.(100.100)125x250.[0.9,0.4,-0.4,0.9,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ce/TestImage.CGContext.ClearRect.(100.100)125x250.[1.0,0.0,0.0,1.0,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ce/TestImage.CGContext.ClearRect.(100.100)125x250.[1.0,0.0,0.0,1.0,3.0,6.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...ce/TestImage.CGContext.ClearRect.(100.100)125x250.[1.0,0.0,0.3,1.0,0.0,0.0].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
3 changes: 3 additions & 0 deletions
3
...phics.drawing/data/reference/TestImage.CGContext.ClearRectTransparencyLayer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
...CoreGraphics.drawing/data/reference/TestImage.CGContext.CustomPathClearRect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters