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

CGPattern does not tile/repeat #578

Closed
adein opened this issue Jun 23, 2016 · 1 comment
Closed

CGPattern does not tile/repeat #578

adein opened this issue Jun 23, 2016 · 1 comment

Comments

@adein
Copy link
Collaborator

adein commented Jun 23, 2016

Issue Description

Filling with a CGPattern does not result in the pattern being repeated through the filled area.

Reproduction Steps
  1. Create a CGPattern that is smaller than the area to be filled.
  2. Set the pattern as the fill pattern using CGContextSetFillPattern.
  3. Fill an area using CGContextFillRect.
Expected Behavior

If a CGPattern is less than the size of the area to be filled, the pattern should be tiled in the filled space.

Observed Behavior

The pattern is only drawn once in the filled area.

Pull Request, Test Case, or Sample Code
    // White background
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, maxWidth, maxHeight));

    // Create a base pattern color space
    CGContextSaveGState(context);
    CGColorSpaceRef colorSpace = CGColorSpaceCreatePattern(NULL);
    CGContextSetFillColorSpace(context, colorSpace);
    CGColorSpaceRelease(colorSpace);

    // Create the pattern
    static const CGPatternCallbacks callbacks = { 0, &_DrawCustomPattern, NULL };
    CGFloat alpha = 1;
    CGPatternRef pattern = CGPatternCreate(
        NULL, rect, CGAffineTransformIdentity, c_PatternSize, c_PatternSize, kCGPatternTilingConstantSpacing, true, &callbacks);
    CGContextSetFillPattern(context, pattern, &alpha);
    CGPatternRelease(pattern);

    // Fill using the pattern
    CGContextFillRect(context, rect);
    CGContextRestoreGState(context);
void _DrawCustomPattern(void* info, CGContextRef context) {
    // Draw a circle inset from the pattern size
    CGRect circleRect = CGRectMake(0, 0, c_PatternSize, c_PatternSize);
    circleRect = CGRectInset(circleRect, 4, 4);
    CGContextFillEllipseInRect(context, circleRect);
    CGContextStrokeEllipseInRect(context, circleRect);
}
@adein
Copy link
Collaborator Author

adein commented Jun 23, 2016

I believe I have found the fix for this issue, and will submit a pull request for it after some more testing.

adein pushed a commit to vectorform/WinObjC that referenced this issue Jun 23, 2016
Changed CGPattern getPatternImage to set height and width variables based
on the xStep and yStep variables instead of bounds.size.  The bounds.size
variable contains the size of the entire pattern area being filled, where
the xStep and yStep variables contain the size of the pattern itself.

Fixes microsoft#578
jaredhms pushed a commit that referenced this issue Jun 23, 2016
Changed CGPattern getPatternImage to set height and width variables based
on the xStep and yStep variables instead of bounds.size.  The bounds.size
variable contains the size of the entire pattern area being filled, where
the xStep and yStep variables contain the size of the pattern itself.

Fixes #578
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant