Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Affine Transform in CGPath #1550

Merged
merged 5 commits into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Frameworks/CoreGraphics/CGContext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -827,14 +827,15 @@ void CGContextAddPath(CGContextRef context, CGPathRef path) {
return;
}

CGAffineTransform userToDeviceTransform = CGContextGetUserSpaceToDeviceSpaceTransform(context);

if (!context->HasPath()) {
// If we don't curerntly have a path, take this one in as our own.
woc::unique_cf<CGMutablePathRef> copiedPath{ CGPathCreateMutableCopy(path) };
woc::unique_cf<CGMutablePathRef> copiedPath{ CGPathCreateMutableCopyByTransformingPath(path, &userToDeviceTransform) };
context->SetPath(copiedPath.get());
return;
}

CGAffineTransform userToDeviceTransform = CGContextGetUserSpaceToDeviceSpaceTransform(context);
CGPathAddPath(context->Path(), &userToDeviceTransform, path);
}

Expand Down
31 changes: 22 additions & 9 deletions Frameworks/CoreGraphics/CGPath.mm
Original file line number Diff line number Diff line change
Expand Up @@ -754,21 +754,34 @@ CGPathRef CGPathCreateCopyByStrokingPath(
}

/**
@Status Stub
@Notes
@Status Caveat
Copy link
Contributor

@rajsesh rajsesh Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be interoperable. It would be a caveat if ref plat created mutable copy and we didn't. #Resolved

@Notes Creates a mutable copy
*/
CGPathRef CGPathCreateCopyByTransformingPath(CGPathRef path, const CGAffineTransform* transform) {
UNIMPLEMENTED();
return StubReturn();
return CGPathCreateMutableCopyByTransformingPath(path, transform);
}

/**
@Status Stub
@Notes
@Status Interoperable
*/
CGMutablePathRef CGPathCreateMutableCopyByTransformingPath(CGPathRef path, const CGAffineTransform* transform) {
UNIMPLEMENTED();
return StubReturn();
RETURN_NULL_IF(!path);

if (transform) {
Copy link

@DHowett-MSFT DHowett-MSFT Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fold these together? if (transform && !CGAffine... #Resolved

if (CGAffineTransformEqualToTransform(*transform, CGAffineTransformIdentity)) {
return CGPathCreateMutableCopy(path);
}

CGMutablePathRef transformedPath = CGPathCreateMutable();
path->ClosePath();

FAIL_FAST_IF_FAILED(transformedPath->AddGeometryToPathWithTransformation(path->GetPathGeometry().Get(), transform));
Copy link

@DHowett-MSFT DHowett-MSFT Dec 15, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It bothers me a bit that GetPathGeometry returns a ComPtr<ID2D1Geometry>; it's an unnecessary +1/-1/+1 for this case (and an unnecessary +1/-1 for every other case where you call it (!) #Resolved

transformedPath->SetCurrentPoint(CGPointApplyAffineTransform(path->GetCurrentPoint(), *transform));
transformedPath->SetStartingPoint(CGPointApplyAffineTransform(path->GetStartingPoint(), *transform));
transformedPath->SetLastTransform(transform);
return transformedPath;
}
return CGPathCreateMutableCopy(path);
}

/**
Expand All @@ -782,7 +795,7 @@ CGPathRef CGPathCreateWithRoundedRect(CGRect rect, CGFloat cornerWidth, CGFloat
}

/**
@Status Stub
@Status Interoperable
*/
bool CGPathEqualToPath(CGPathRef path1, CGPathRef path2) {
return __CGPathEqual(path1, path2);
Expand Down
9 changes: 4 additions & 5 deletions include/CoreGraphics/CGPath.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ COREGRAPHICS_EXPORT CGPathRef CGPathCreateWithRect(CGRect rect, const CGAffineTr
COREGRAPHICS_EXPORT CGPathRef CGPathCreateWithRoundedRect(CGRect rect,
CGFloat cornerWidth,
CGFloat cornerHeight,
const CGAffineTransform* transform) STUB_METHOD;
const CGAffineTransform* transform);

COREGRAPHICS_EXPORT CGPathRef CGPathCreateCopy(CGPathRef path);

COREGRAPHICS_EXPORT CGPathRef CGPathCreateCopyByTransformingPath(CGPathRef path, const CGAffineTransform* transform) STUB_METHOD;
COREGRAPHICS_EXPORT CGPathRef CGPathCreateCopyByTransformingPath(CGPathRef path, const CGAffineTransform* transform);

COREGRAPHICS_EXPORT CGPathRef CGPathCreateCopyByDashingPath(
CGPathRef path, const CGAffineTransform* transform, CGFloat phase, const CGFloat* lengths, size_t count) STUB_METHOD;
Expand All @@ -74,8 +74,7 @@ COREGRAPHICS_EXPORT CGPathRef CGPathCreateCopyByStrokingPath(CGPathRef path,

COREGRAPHICS_EXPORT CGMutablePathRef CGPathCreateMutableCopy(CGPathRef path);

COREGRAPHICS_EXPORT CGMutablePathRef CGPathCreateMutableCopyByTransformingPath(CGPathRef path,
const CGAffineTransform* transform) STUB_METHOD;
COREGRAPHICS_EXPORT CGMutablePathRef CGPathCreateMutableCopyByTransformingPath(CGPathRef path, const CGAffineTransform* transform);

COREGRAPHICS_EXPORT void CGPathRelease(CGPathRef path);
COREGRAPHICS_EXPORT CGPathRef CGPathRetain(CGPathRef path);
Expand Down Expand Up @@ -110,7 +109,7 @@ COREGRAPHICS_EXPORT void CGPathAddRect(CGMutablePathRef path, const CGAffineTran

COREGRAPHICS_EXPORT void CGPathAddRects(CGMutablePathRef path, const CGAffineTransform* m, const CGRect* rects, size_t count) STUB_METHOD;
COREGRAPHICS_EXPORT void CGPathAddRoundedRect(
CGMutablePathRef path, const CGAffineTransform* transform, CGRect rect, CGFloat cornerWidth, CGFloat cornerHeight) STUB_METHOD;
CGMutablePathRef path, const CGAffineTransform* transform, CGRect rect, CGFloat cornerWidth, CGFloat cornerHeight);
COREGRAPHICS_EXPORT void CGPathApply(CGPathRef path, void* info, CGPathApplierFunction function);

COREGRAPHICS_EXPORT void CGPathMoveToPoint(CGMutablePathRef path, const CGAffineTransform* m, CGFloat x, CGFloat y);
Expand Down