Skip to content

Commit

Permalink
Do not transform the edges
Browse files Browse the repository at this point in the history
  • Loading branch information
msft-Jeyaram committed Mar 22, 2017
1 parent a043ea2 commit 859f25f
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 30 deletions.
23 changes: 14 additions & 9 deletions Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,21 @@

// Strokes
ComPtr<ID2D1Brush> strokeBrush{ nullptr };
D2D1_STROKE_STYLE_PROPERTIES strokeProperties{
D2D1_STROKE_STYLE_PROPERTIES1 strokeProperties{
D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT,
D2D1_CAP_STYLE_FLAT,
D2D1_LINE_JOIN_MITER,
10.f, // Default from Reference Docs
D2D1_DASH_STYLE_SOLID,
0.f,
D2D1_STROKE_TRANSFORM_TYPE_FIXED,
};
std::vector<CGFloat> dashes{};
CGFloat lineWidth = 1.0f;

// Computed from the above at draw time
ComPtr<ID2D1StrokeStyle> strokeStyle{ nullptr };
ComPtr<ID2D1StrokeStyle1> strokeStyle{ nullptr };

CGFloat flatness = 0.0f;

Expand Down Expand Up @@ -132,9 +133,7 @@
__CGTrinary shouldSmoothFonts = _kCGTrinaryDefault;

inline void ComputeStrokeStyle(ID2D1DeviceContext* deviceContext) {
if (strokeStyle) {
return;
}
RETURN_IF(!deviceContext);

if (std::fpclassify(lineWidth) == FP_ZERO) {
// Set no stroke style.
Expand All @@ -144,15 +143,23 @@ inline void ComputeStrokeStyle(ID2D1DeviceContext* deviceContext) {
ComPtr<ID2D1Factory> factory;
deviceContext->GetFactory(&factory);

ComPtr<ID2D1Factory1> factory1;
FAIL_FAST_IF_FAILED(factory->QueryInterface(__uuidof(ID2D1Factory1), &factory1));

std::vector<float> adjustedDashes(dashes.size());
std::transform(dashes.cbegin(), dashes.cend(), adjustedDashes.begin(), [this](const CGFloat& f) -> float { return f / lineWidth; });
FAIL_FAST_IF_FAILED(factory->CreateStrokeStyle(strokeProperties, adjustedDashes.data(), adjustedDashes.size(), &strokeStyle));
FAIL_FAST_IF_FAILED(factory1->CreateStrokeStyle(strokeProperties, adjustedDashes.data(), adjustedDashes.size(), &strokeStyle));
}

inline void ClearStrokeStyle() {
strokeStyle.Reset();
}

inline void SetLineWidth(CGFloat width) {
ClearStrokeStyle();
lineWidth = width;
}

inline bool HasShadow() {
return std::fpclassify(shadowColor.w) != FP_ZERO;
}
Expand Down Expand Up @@ -1638,9 +1645,7 @@ void CGContextSetLineCap(CGContextRef context, CGLineCap lineCap) {
*/
void CGContextSetLineWidth(CGContextRef context, CGFloat width) {
NOISY_RETURN_IF_NULL(context);
auto& state = context->CurrentGState();
state.ClearStrokeStyle();
state.lineWidth = width;
context->CurrentGState().SetLineWidth(width);
}
#pragma endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ DISABLED_DRAW_TEST_F(CGPatternTests, PatternFillWindowsLogoPath, UIKitMimicTest<
CGPathRelease(thepath);
}

DRAW_TEST_F(CGPatternTests, PatternDrawPath, UIKitMimicTest<>) {
DRAW_TEST_F(CGPatternTests, PatternDrawPath, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand Down Expand Up @@ -475,4 +475,16 @@ DRAW_TEST_F(CGPatternTests, PatternFillTransformationWindowsLogoScale, UIKitMimi
CGContextFillRect(context, bounds);
}

DRAW_TEST_F(CGPatternTests, CGPatternColoredRectBasedStrokeTransform, WhiteBackgroundTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

CGContextRotateCTM(context, 0.5);
CGContextTranslateCTM(context, 0, -3);
CGContextScaleCTM(context, 2, 2);
_SetPatternForStroke(context, CGRectMake(0, 0, 100, 100), 100, 100, drawCoolStar, 1);
CGRect borderRect = CGRectInset(bounds, 30, 50);
CGContextStrokeRect(context, borderRect);
}

#pragma endregion Colored Pattern
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 8 additions & 4 deletions tests/unittests/CoreGraphics.Drawing/CGPathDrawingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ DRAW_TEST_F(CGPath, CloseSubpath, UIKitMimicTest<>) {
CGPathRelease(thePath);
}

DRAW_TEST_F(CGPath, GetBoundingBox, UIKitMimicTest<>) {
// TODO : Enable this test when #2301 is fixed
DISABLED_DRAW_TEST_F(CGPath, GetBoundingBox, UIKitMimicTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();

Expand Down Expand Up @@ -465,7 +466,8 @@ static void CGPathControlPointCallback(void* context, const CGPathElement* eleme
}
}

DRAW_TEST_F(CGPath, PathApplyControlPointsQuadCurve, UIKitMimicTest<>) {
// TODO : Enable this test when #2301 is fixed
DISABLED_DRAW_TEST_F(CGPath, PathApplyControlPointsQuadCurve, UIKitMimicTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
CGFloat width = bounds.size.width;
Expand All @@ -491,7 +493,8 @@ DRAW_TEST_F(CGPath, PathApplyControlPointsQuadCurve, UIKitMimicTest<>) {
CGPathRelease(thepath);
}

DRAW_TEST_F(CGPath, PathApplyControlPointsArcs, UIKitMimicTest<>) {
// TODO : Enable this test when #2301 is fixed
DISABLED_DRAW_TEST_F(CGPath, PathApplyControlPointsArcs, UIKitMimicTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
CGFloat width = bounds.size.width;
Expand Down Expand Up @@ -527,7 +530,8 @@ DRAW_TEST_F(CGPath, PathApplyControlPointsArcs, UIKitMimicTest<>) {
CGPathRelease(thepath);
}

DRAW_TEST_F(CGPath, PathApplyControlPointsArcsSimple, UIKitMimicTest<>) {
// TODO : Enable this test when #2301 is fixed
DISABLED_DRAW_TEST_F(CGPath, PathApplyControlPointsArcsSimple, UIKitMimicTest<>) {
CGContextRef context = GetDrawingContext();
CGRect bounds = GetDrawingBounds();
CGFloat width = bounds.size.width;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit 859f25f

Please sign in to comment.