Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This repository was archived by the owner on May 28, 2025. It is now read-only.

CoreGraphics Gradient Clipping Issue #599

Closed

Description

@s5msft

Gradient clipping of non-rectangular clipping paths does not work correctly:

iOS:
ios

Windows:
windows

Repro:

-(void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextSaveGState(ctx);

    CGContextTranslateCTM(ctx, 40, 40);
    CGContextScaleCTM(ctx, 1, 1);

    // set an initial rect clip path
    //
    CGContextClearRect(ctx, CGRectMake(0, 0, 80, 80));
    CGContextAddRect(ctx, CGRectMake(0, 0, 80, 80));
    CGContextClip(ctx);

    // fill the rect
    //
    CGContextAddRect(ctx, CGRectMake(0, 0, 80, 80));
    CGContextSetRGBFillColor(ctx, 1, 0, 0, 1);
    CGContextFillPath(ctx);

    // adding a second non-rectangular clipping path
    //
    CGContextSetRGBFillColor(ctx, 0, 0, 1, 1);
    CGContextAddEllipseInRect(ctx, CGRectMake(-10, 20, 100, 100));
    CGContextClip(ctx);

    // draw a gradient
    //
    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
    CGFloat locations[] = { 0.0, 1.0 };
    NSArray *colors = @[(id)[[UIColor blueColor] CGColor], (id)[[UIColor yellowColor] CGColor]];

    CGGradientRef gradient = CGGradientCreateWithColors(colorSpace, (CFArrayRef)colors, locations);

    CGContextDrawLinearGradient(ctx, gradient, CGPointMake(0, 40), CGPointMake(0, 160), (kCGGradientDrawsBeforeStartLocation | kCGGradientDrawsAfterEndLocation));

    CGContextRestoreGState(ctx);
}

Activity

  1. rajsesh commented on Oct 1, 2016

    @rajsesh
    Contributor

    This seems like a bug in cairo. This won't be an issue when we move to D2D.

  2. rajsesh commented on Nov 18, 2016

    @rajsesh
    Contributor

    closing this will cover this in #1416

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions