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

opaque gradients #355

Open
typemytype opened this issue Jan 27, 2020 · 0 comments
Open

opaque gradients #355

typemytype opened this issue Jan 27, 2020 · 0 comments

Comments

@typemytype
Copy link
Owner

@typemytype typemytype commented Jan 27, 2020

this does not work...
and I dont know what or where to change anything, is this even possible...

a pure quartz example:

import AppKit
import Quartz


mediaBox = Quartz.CGRectMake(0, 0, 100, 100)

pdfData = Quartz.CFDataCreateMutable(None, 0)

dataConsumer = Quartz.CGDataConsumerCreateWithCFData(pdfData)
pdfContext = Quartz.CGPDFContextCreate(dataConsumer, mediaBox, None)
Quartz.CGContextBeginPage(pdfContext, mediaBox)

Quartz.CGContextSaveGState(pdfContext)

Quartz.CGContextMoveToPoint(pdfContext, 10, 10)
Quartz.CGContextAddLineToPoint(pdfContext, 90, 10)
Quartz.CGContextAddLineToPoint(pdfContext, 90, 90)
Quartz.CGContextAddLineToPoint(pdfContext, 10, 90)
Quartz.CGContextClosePath(pdfContext)

Quartz.CGContextClip(pdfContext)

cgGradient = Quartz.CGGradientCreateWithColors(
    AppKit.NSColorSpace.genericRGBColorSpace().CGColorSpace(),
    [
        Quartz.CGColorCreateGenericRGB(1, 0, 0, .3),
        Quartz.CGColorCreateGenericRGB(1, 1, 0, 0),    
    ],
    None
)
print(cgGradient)

Quartz.CGContextDrawLinearGradient(pdfContext, cgGradient, (10, 10), (90, 90), Quartz.kCGGradientDrawsBeforeStartLocation | Quartz.kCGGradientDrawsAfterEndLocation)
Quartz.CGContextRestoreGState(pdfContext)

Quartz.CGContextEndPage(pdfContext)
Quartz.CGPDFContextClose(pdfContext)

path = 'test.pdf'
pdfData.writeToFile_atomically_(path, True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.