Example #1
0
    def testContextManager10_5(self):
        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        try:
            Quartz.CGContextBeginPage(context, objc.NULL)

            # XXX: This need actual tests, this at least tests that
            # the contextmanagers can be used
            with Quartz.CGTransparencyLayer(context, None):
                pass

            with Quartz.CGTransparencyLayer(context, None,
                                            ((10, 10), (200, 200))):
                pass

        finally:
            Quartz.CGContextEndPage(context)
            if hasattr(Quartz, "CGPDFContextClose"):
                Quartz.CGPDFContextClose(context)
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")
Example #2
0
    def testFunctions(self):
        self.assertIsInstance(Quartz.CGPatternGetTypeID(), int)

        myInfo = object()
        cnt = [0]

        def drawPattern(info, context):
            self.assertTrue(info is myInfo)
            self.assertIsInstance(context, Quartz.CGContextRef)
            cnt[0] += 1

        pattern = Quartz.CGPatternCreate(
            myInfo,
            Quartz.CGRectMake(0, 0, 10, 10),
            Quartz.CGAffineTransformIdentity,
            10.0,
            10.0,
            Quartz.kCGPatternTilingConstantSpacing,
            True,
            drawPattern,
        )
        self.assertIsInstance(pattern, Quartz.CGPatternRef)

        v = Quartz.CGPatternRetain(pattern)
        self.assertTrue(v is pattern)
        Quartz.CGPatternRelease(pattern)

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        Quartz.CGContextBeginPage(context, objc.NULL)
        try:
            color = Quartz.CGColorCreateWithPattern(
                Quartz.CGColorSpaceCreatePattern(None), pattern,
                (0.5, 0.5, 0.5, 0.5))
            self.assertIsInstance(color, Quartz.CGColorRef)

            v = Quartz.CGColorGetPattern(color)
            self.assertTrue(v is pattern)

            # Now draw something with the pattern color to ensure that the callback
            # is actually called at least once.
            Quartz.CGContextSetFillColorWithColor(context, color)
            Quartz.CGContextSetStrokeColorWithColor(context, color)
            Quartz.CGContextFillRect(context, ((0, 0), (50, 50)))

        finally:
            Quartz.CGContextEndPage(context)
            if hasattr(Quartz, "CGPDFContextClose"):
                Quartz.CGPDFContextClose(context)
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")

        self.assertNotEqual(cnt[0], 0)
    def testFunctions(self):
        self.assertIsInstance(Quartz.CGDataConsumerGetTypeID(), int)

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        try:
            consumer = Quartz.CGDataConsumerCreateWithURL(url)
            self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

            data = NSMutableData.data()
            self.assertIsInstance(data, Quartz.CFMutableDataRef)

            consumer = Quartz.CGDataConsumerCreateWithCFData(data)
            self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

            v = Quartz.CGDataConsumerRetain(consumer)
            self.assertTrue(v is consumer)
            Quartz.CGDataConsumerRelease(consumer)

        finally:
            del url
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")

        def putBytes(info, a_buffer, bufsize):
            self.assertIsInstance(a_buffer, bytes)
            self.assertEqual(len(a_buffer), bufsize)
            info.append(a_buffer)
            return bufsize

        def release(info):
            released.append(info)

        output = []
        released = []
        consumer = Quartz.CGDataConsumerCreate(output, (putBytes, release))
        self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

        ctx = Quartz.CGPDFContextCreate(consumer,
                                        Quartz.CGRectMake(0, 0, 500, 500),
                                        None)
        self.assertIsInstance(ctx, Quartz.CGContextRef)
        Quartz.CGContextBeginPage(ctx, None)
        Quartz.CGContextFillRect(ctx, ((10, 10), (50, 30)))
        Quartz.CGContextEndPage(ctx)
        Quartz.CGContextFlush(ctx)
        if hasattr(Quartz, "CGPDFContextClose"):
            Quartz.CGPDFContextClose(ctx)

        del ctx
        del consumer

        self.assertNotEqual(len(output), 0)
        self.assertNotEqual(len(released), 0)
Example #4
0
    def testFunctions(self):
        values = []

        def evaluate(info, input_value, output_value):
            values.append(input_value)
            return input_value * 4

        self.assertIsInstance(Quartz.CGFunctionGetTypeID(), int)

        myInfo = object()
        func = Quartz.CGFunctionCreate(myInfo, 1, [0, 1], 4,
                                       [0, 1, 0, 1, 0, 1, 0, 1], evaluate)
        self.assertIsInstance(func, Quartz.CGFunctionRef)

        v = Quartz.CGFunctionRetain(func)
        self.assertTrue(v is func)
        Quartz.CGFunctionRelease(func)

        # It is not possible to "call" a Quartz.CGFunction object directly, use a
        # shading object to check that the function is actually called.

        shading = Quartz.CGShadingCreateAxial(
            Quartz.CGColorSpaceCreateDeviceRGB(), (0, 0), (50, 50), func, True,
            True)
        self.assertIsInstance(shading, Quartz.CGShadingRef)

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        try:
            Quartz.CGContextBeginPage(context, objc.NULL)

            Quartz.CGContextDrawShading(context, shading)
        finally:
            Quartz.CGContextEndPage(context)
            if hasattr(Quartz, "CGPDFContextClose"):
                Quartz.CGPDFContextClose(context)
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")

        # Drawing is done, check that the shading function is actually used
        self.assertNotEqual(len(values), 0)
        for item in values:
            self.assertIsInstance(item, tuple)
            self.assertEqual(len(item), 1)
            self.assertIsInstance(item[0], float)

        del func
Example #5
0
    def setUp(self):
        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        Quartz.CGContextBeginPage(context, objc.NULL)

        self.context = context
Example #6
0
    def testFunctions(self):
        self.assertIsInstance(Quartz.CGDataProviderGetTypeID(), int)

        provider = Quartz.CGDataProviderCreateWithCFData(b"data")
        self.assertIsInstance(provider, Quartz.CGDataProviderRef)

        fn = "/Library/Documentation/Acknowledgements.rtf"
        if not os.path.exists(fn):
            fn = "/Library/Documentation/Airport Acknowledgements.rtf"
        if not os.path.exists(fn):
            fn = "/Library/Documentation//MacOSXServer/Server Acknowledgments.pdf"

        if not os.path.exists(fn):
            self.fail("Cannot find test file")

        url = Quartz.CFURLCreateWithFileSystemPath(None, fn,
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)

        provider = Quartz.CGDataProviderCreateWithURL(url)
        self.assertIsInstance(provider, Quartz.CGDataProviderRef)

        provider = Quartz.CGDataProviderCreateWithFilename(fn.encode("ascii"))
        self.assertIsInstance(provider, Quartz.CGDataProviderRef)

        v = Quartz.CGDataProviderRetain(provider)
        self.assertTrue(v is provider)
        Quartz.CGDataProviderRelease(provider)

        data = Quartz.CGDataProviderCopyData(provider)
        self.assertIsInstance(data, Quartz.CFDataRef)

        info = [b"hello world", False]

        def release(info):
            info[-1] = True

        provider = Quartz.CGDataProviderCreateWithData(info, info[0],
                                                       len(info[0]), release)
        self.assertIsInstance(provider, Quartz.CGDataProviderRef)
        del provider

        self.assertTrue(info[-1])
    def testFunctions(self):
        if os.path.exists(
                "/Library/Documentation//Applications/iWeb/Acknowledgements.pdf"
        ):
            pdf_path = "/Library/Documentation//Applications/iWeb/Acknowledgements.pdf"
        elif os.path.exists(
                "/Library/Documentation/Applications/iMovie/Acknowledgements.pdf"
        ):
            pdf_path = "/Library/Documentation/Applications/iMovie/Acknowledgements.pdf"
        elif os.path.exists(
                "/Library/Documentation/WebObjects/Acknowlegdements.pdf"):
            pdf_path = "/Library/Documentation/WebObjects/Acknowlegdements.pdf"
        elif os.path.exists(
                "/Library/Documentation/License.lpdf/Contents/Resources/English.lproj/License.pdf"
        ):
            pdf_path = "/Library/Documentation/License.lpdf/Contents/Resources/English.lproj/License.pdf"
        elif os.path.exists(
                "/Library/Documentation//MacOSXServer/Server Acknowledgments.pdf"
        ):
            pdf_path = "/Library/Documentation//MacOSXServer/Server Acknowledgments.pdf"
        else:
            self.fail("No test PDF file found")

        doc = Quartz.CGPDFDocumentCreateWithURL(
            Quartz.CFURLCreateWithFileSystemPath(None, pdf_path,
                                                 Quartz.kCFURLPOSIXPathStyle,
                                                 False))
        self.assertIsInstance(doc, Quartz.CGPDFDocumentRef)

        page = Quartz.CGPDFDocumentGetPage(doc, 1)
        self.assertIsInstance(page, Quartz.CGPDFPageRef)

        stream = Quartz.CGPDFContentStreamCreateWithPage(page)
        self.assertIsInstance(stream, Quartz.CGPDFContentStreamRef)

        v = Quartz.CGPDFContentStreamRetain(stream)
        self.assertEqual(v.__pointer__, stream.__pointer__)

        Quartz.CGPDFContentStreamRelease(v)

        v = Quartz.CGPDFContentStreamGetResource(stream, b"ColorSpace", b"Cs1")
        self.assertIsInstance(v, Quartz.CGPDFObject)
Example #8
0
    def testContextManager(self):
        """
        Tests for some additional functionality
        """
        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        try:
            Quartz.CGContextBeginPage(context, objc.NULL)
            transform = Quartz.CGContextGetCTM(context)
            newTransform = Quartz.CGAffineTransformMake(
                1.5, 2.5, 3.5, 4.5, 5.5, 6.5)

            with Quartz.CGSavedGState(context):
                Quartz.CGContextConcatCTM(context, newTransform)
                tf = Quartz.CGContextGetCTM(context)
                self.assertNotEqual(tf, transform)

            tf = Quartz.CGContextGetCTM(context)
            self.assertEqual(tf, transform)

            Quartz.CGContextEndPage(context)
            with Quartz.CGContextPage(context):
                pass

            with Quartz.CGContextPage(context,
                                      Quartz.CGRectMake(0, 0, 500, 500)):
                pass

            Quartz.CGContextBeginPage(context, None)

        finally:
            Quartz.CGContextEndPage(context)
            if hasattr(Quartz, "CGPDFContextClose"):
                Quartz.CGPDFContextClose(context)
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")
    def testFunctions(self):
        data = NSMutableData.data()
        self.assertIsInstance(data, Quartz.CFMutableDataRef)

        consumer = Quartz.CGDataConsumerCreateWithCFData(data)
        self.assertIsInstance(consumer, Quartz.CGDataConsumerRef)

        self.assertArgIsIn(Quartz.CGPDFContextCreate, 1)
        self.assertResultIsCFRetained(Quartz.CGPDFContextCreate)
        context = Quartz.CGPDFContextCreate(consumer, None, None)
        self.assertIsInstance(context, Quartz.CGContextRef)

        if hasattr(Quartz, "CGPDFContextClose"):
            Quartz.CGPDFContextClose(context)

        self.assertResultIsCFRetained(Quartz.CGPDFContextCreateWithURL)
        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertArgIsIn(Quartz.CGPDFContextCreateWithURL, 1)
        context = Quartz.CGPDFContextCreateWithURL(url, None, None)
        self.assertIsInstance(context, Quartz.CGContextRef)

        Quartz.CGPDFContextBeginPage(context, None)

        Quartz.CGPDFContextSetURLForRect(context, url, ((0, 0), (10, 10)))
        Quartz.CGPDFContextAddDestinationAtPoint(context, "target", (50, 50))

        Quartz.CGPDFContextSetDestinationForRect(context, "target",
                                                 ((100, 120), (50, 60)))

        Quartz.CGPDFContextEndPage(context)

        if hasattr(Quartz, "CGPDFContextClose"):
            Quartz.CGPDFContextClose(context)
    def testFunctions(self):
        self.assertIsInstance(Quartz.CGImageDestinationGetTypeID(), int)

        self.assertResultIsCFRetained(
            Quartz.CGImageDestinationCopyTypeIdentifiers)
        v = Quartz.CGImageDestinationCopyTypeIdentifiers()
        self.assertIsInstance(v, Quartz.CFArrayRef)
        if v:
            self.assertIsInstance(v[0], str)

        data = NSMutableData.dataWithCapacity_(1024 * 1024 * 50)
        self.assertResultIsCFRetained(Quartz.CGImageDestinationCreateWithData)
        dest = Quartz.CGImageDestinationCreateWithData(data, v[0], 1, None)
        self.assertIsInstance(dest, Quartz.CGImageDestinationRef)

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertResultIsCFRetained(Quartz.CGImageDestinationCreateWithURL)
        dest = Quartz.CGImageDestinationCreateWithURL(url, "public.tiff", 2,
                                                      None)
        self.assertIsInstance(dest, Quartz.CGImageDestinationRef)

        Quartz.CGImageDestinationSetProperties(dest, {"key": "value"})

        provider = Quartz.CGDataProviderCreateWithCFData(
            buffer("1" * 4 * 100 * 80))
        img = Quartz.CGImageCreate(
            100,
            80,
            8,
            32,
            400,
            Quartz.CGColorSpaceCreateDeviceRGB(),
            Quartz.kCGImageAlphaPremultipliedLast,
            provider,
            None,
            False,
            Quartz.kCGRenderingIntentDefault,
        )
        self.assertIsInstance(img, Quartz.CGImageRef)

        Quartz.CGImageDestinationAddImage(dest, img, None)

        image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif"
        if not os.path.exists(image_path):
            image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png"
        if not os.path.exists(image_path):
            image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff"

        self.assertTrue(os.path.exists(image_path))

        url = Quartz.CFURLCreateWithFileSystemPath(None, image_path,
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)

        isrc = Quartz.CGImageSourceCreateWithURL(url, None)
        Quartz.CGImageDestinationAddImageFromSource(dest, isrc, 0, None)

        self.assertResultHasType(Quartz.CGImageDestinationFinalize,
                                 objc._C_BOOL)
        v = Quartz.CGImageDestinationFinalize(dest)
        self.assertIsInstance(v, bool)
        self.assertIs(v, True)

        dta = NSMutableData.alloc().init()
        cons = Quartz.CGDataConsumerCreateWithCFData(dta)

        self.assertResultIsCFRetained(
            Quartz.CGImageDestinationCreateWithDataConsumer)
        c = Quartz.CGImageDestinationCreateWithDataConsumer(
            cons, "public.tiff", 1, None)
        self.assertIsInstance(c, Quartz.CGImageDestinationRef)
Example #11
0
    def testFunctions10_5(self):

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        Quartz.CGContextBeginPage(context, objc.NULL)
        try:
            fn = "/System/Library/CoreServices/DefaultDesktop.jpg"
            if not os.path.exists(fn):
                fn = "/System/Library/Automator/Apply ColorSync Profile to Images.action/Contents/Resources/A-1075-normal.jpg"
                if not os.path.exists(fn):
                    fn = "/System/Library/CoreServices//RemoteManagement/ARDAgent.app/Contents/Resources/Lock.jpg"

            with open(fn, "rb") as fp:
                data = fp.read()

            provider = Quartz.CGDataProviderCreateWithCFData(data)
            image = Quartz.CGImageCreateWithJPEGDataProvider(
                provider, None, True, Quartz.kCGRenderingIntentDefault)
            self.assertIsInstance(image, Quartz.CGImageRef)

            Quartz.CGContextDrawTiledImage(context, ((0, 0), (10, 10)), image)

            font = Quartz.CGFontCreateWithFontName("Helvetica")
            self.assertIsInstance(font, Quartz.CGFontRef)
            Quartz.CGContextSetFont(context, font)

            Quartz.CGContextBeginTransparencyLayerWithRect(
                context, ((10, 10), (500, 100)), None)
            Quartz.CGContextEndTransparencyLayer(context)

            color = Quartz.CGColorCreateGenericRGB(1.0, 0.5, 0.5, 1.0)
            self.assertIsInstance(color, Quartz.CGColorRef)
            Quartz.CGContextSetFillColorWithColor(context, color)
            Quartz.CGContextSetStrokeColorWithColor(context, color)

            gradient = Quartz.CGGradientCreateWithColorComponents(
                Quartz.CGColorSpaceCreateDeviceGray(), (0.25, 0.8),
                (0.95, 0.99), 2)
            self.assertIsInstance(gradient, Quartz.CGGradientRef)

            Quartz.CGContextDrawRadialGradient(
                context,
                gradient,
                (10, 15),
                30,
                (50, 70),
                99.5,
                Quartz.kCGGradientDrawsAfterEndLocation,
            )

            Quartz.CGContextDrawShading

            def evaluate(info, input_value, output_value):
                return input_value * 4

            func = Quartz.CGFunctionCreate(None, 1, (0, 1), 2, (0, 1, 0, 1),
                                           evaluate)
            self.assertIsInstance(func, Quartz.CGFunctionRef)
            shading = Quartz.CGShadingCreateAxial(
                Quartz.CGColorSpaceCreateDeviceGray(),
                (0, 0),
                (30, 90),
                func,
                False,
                False,
            )
            self.assertIsInstance(shading, Quartz.CGShadingRef)

            self.assertArgHasType(
                Quartz.CGContextSetShouldSubpixelPositionFonts, 1,
                objc._C_BOOL)
            self.assertArgHasType(
                Quartz.CGContextSetAllowsFontSubpixelPositioning, 1,
                objc._C_BOOL)
            self.assertArgHasType(
                Quartz.CGContextSetShouldSubpixelQuantizeFonts, 1,
                objc._C_BOOL)

            gradient = Quartz.CGGradientCreateWithColorComponents(
                Quartz.CGColorSpaceCreateDeviceGray(), (0.25, 0.8),
                (0.95, 0.99), 2)
            self.assertIsInstance(gradient, Quartz.CGGradientRef)

            Quartz.CGContextDrawLinearGradient(
                context,
                gradient,
                (0, 10),
                (50, 60),
                Quartz.kCGGradientDrawsAfterEndLocation,
            )

        finally:
            Quartz.CGContextEndPage(context)
            if hasattr(Quartz, "CGPDFContextClose"):
                Quartz.CGPDFContextClose(context)
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")
Example #12
0
    def testFunctions(self):
        self.assertIsInstance(Quartz.CGContextGetTypeID(), int)

        url = Quartz.CFURLCreateWithFileSystemPath(None,
                                                   "/tmp/pyobjc.test.pdf",
                                                   Quartz.kCFURLPOSIXPathStyle,
                                                   False)
        self.assertIsInstance(url, Quartz.CFURLRef)
        context = Quartz.CGPDFContextCreateWithURL(url, ((0, 0), (1000, 1000)),
                                                   None)
        self.assertIsInstance(context, Quartz.CGContextRef)
        Quartz.CGContextBeginPage(context, objc.NULL)

        self.assertTrue(Quartz.CGContextIsPathEmpty(context) is True)
        try:
            Quartz.CGContextBeginPath(context)
            Quartz.CGContextAddEllipseInRect(context, ((0, 10), (50, 30)))
            Quartz.CGContextDrawPath(context, Quartz.kCGPathStroke)

            Quartz.CGContextSaveGState(context)
            Quartz.CGContextRestoreGState(context)

            Quartz.CGContextScaleCTM(context, 5.5, 9.5)
            Quartz.CGContextTranslateCTM(context, 4.5, 3.5)
            Quartz.CGContextRotateCTM(context, 0.79)
            Quartz.CGContextConcatCTM(context,
                                      Quartz.CGAffineTransformIdentity)

            tf = Quartz.CGContextGetCTM(context)
            self.assertIsInstance(tf, Quartz.CGAffineTransform)

            Quartz.CGContextSetLineWidth(context, 2.5)
            Quartz.CGContextSetLineCap(context, Quartz.kCGLineCapRound)
            Quartz.CGContextSetLineJoin(context, Quartz.kCGLineJoinMiter)
            Quartz.CGContextSetMiterLimit(context, 9.5)

            Quartz.CGContextSetLineDash(context, 0.5, [0.4, 0.2, 0.8, 0.1], 4)

            self.assertRaises(
                ValueError,
                Quartz.CGContextSetLineDash,
                context,
                0.5,
                [0.4, 0.2, 0.8, 0.1],
                8,
            )

            Quartz.CGContextSetFlatness(context, 0.8)
            Quartz.CGContextSetAlpha(context, 0.5)
            Quartz.CGContextSetBlendMode(context, Quartz.kCGBlendModeLighten)

            Quartz.CGContextMoveToPoint(context, 10.5, 50.8)
            Quartz.CGContextAddLineToPoint(context, 0.5, 0.7)
            Quartz.CGContextAddCurveToPoint(context, 7.5, 8.7, 9.10, 9.10,
                                            99.5, 80.5)
            Quartz.CGContextAddQuadCurveToPoint(context, 50.5, 50.5, 75.9,
                                                78.4)
            Quartz.CGContextClosePath(context)

            Quartz.CGContextAddRect(
                context,
                Quartz.CGRect(Quartz.CGPoint(10, 10), Quartz.CGSize(50, 50)))
            Quartz.CGContextAddRects(context, [((8, 8), (7, 7)),
                                               ((90, 80), (6, 6)),
                                               ((50, 80), (60, 6))], 3)
            self.assertRaises(
                ValueError,
                Quartz.CGContextAddRects,
                context,
                [((8, 8), (7, 7)), ((90, 80), (6, 6)), ((50, 80), (60, 6))],
                8,
            )

            Quartz.CGContextAddLines(context, [(0, 10), (50, 7), (50, 90),
                                               (90.5, 8)], 4)
            self.assertRaises(
                ValueError,
                Quartz.CGContextAddLines,
                context,
                [(0, 10), (50, 7), (50, 90), (90.5, 8)],
                7,
            )

            Quartz.CGContextAddEllipseInRect(context, ((0, 10), (50, 30)))

            Quartz.CGContextAddArc(context, 50, 50, 70.5, 0.5, 1.3, 0)

            Quartz.CGContextAddArcToPoint(context, 20, 30, 70, 20, 55)

            path = Quartz.CGPathCreateMutable()
            Quartz.CGPathAddEllipseInRect(path, None, ((10, 50), (33, 33)))
            self.assertIsInstance(path, Quartz.CGPathRef)
            Quartz.CGContextAddPath(context, path)

            Quartz.CGContextReplacePathWithStrokedPath(context)

            self.assertResultHasType(Quartz.CGContextIsPathEmpty, objc._C_BOOL)
            self.assertTrue(Quartz.CGContextIsPathEmpty(context) is False)

            pt = Quartz.CGContextGetPathCurrentPoint(context)
            self.assertIsInstance(pt, Quartz.CGPoint)

            box = Quartz.CGContextGetPathBoundingBox(context)
            self.assertIsInstance(box, Quartz.CGRect)

            p = Quartz.CGContextCopyPath(context)
            self.assertIsInstance(p, Quartz.CGPathRef)

            self.assertResultHasType(Quartz.CGContextPathContainsPoint,
                                     objc._C_BOOL)
            self.assertIsInstance(
                Quartz.CGContextPathContainsPoint(context, pt,
                                                  Quartz.kCGPathStroke),
                bool,
            )

            Quartz.CGContextFillPath(context)
            Quartz.CGContextEOFillPath(context)
            Quartz.CGContextStrokePath(context)
            Quartz.CGContextFillRect(context, ((10, 10), (50, 30)))

            Quartz.CGContextFillRects(
                context,
                [((10, 10), (50, 30)), ((90, 10), (50, 30)),
                 ((30, 50), (50, 30))],
                3,
            )
            self.assertRaises(
                ValueError,
                Quartz.CGContextFillRects,
                context,
                [((10, 10), (50, 30)), ((90, 10), (50, 30)),
                 ((30, 50), (50, 30))],
                6,
            )

            Quartz.CGContextStrokeRect(context, ((10, 10), (50, 30)))
            Quartz.CGContextStrokeRectWithWidth(context, ((10, 10), (50, 30)),
                                                8.0)
            Quartz.CGContextClearRect(context, ((10, 10), (50, 30)))

            Quartz.CGContextFillEllipseInRect(context, ((10, 10), (50, 30)))
            Quartz.CGContextStrokeEllipseInRect(context, ((10, 10), (50, 30)))

            Quartz.CGContextStrokeLineSegments(context, [(0, 0), (10, 15),
                                                         (15, 10), (0, 0)], 4)
            self.assertRaises(
                ValueError,
                Quartz.CGContextStrokeLineSegments,
                context,
                [(0, 0), (10, 15), (15, 10)],
                4,
            )

            Quartz.CGContextAddRect(
                context,
                Quartz.CGRect(Quartz.CGPoint(10, 10), Quartz.CGSize(50, 50)))
            Quartz.CGContextClip(context)

            Quartz.CGContextAddRect(
                context,
                Quartz.CGRect(Quartz.CGPoint(10, 10), Quartz.CGSize(50, 50)))
            Quartz.CGContextEOClip(context)

            box = Quartz.CGContextGetClipBoundingBox(context)
            self.assertIsInstance(box, Quartz.CGRect)

            Quartz.CGContextClipToRect(context, ((0, 0), (40, 50)))
            Quartz.CGContextClipToRects(context, [((0, 0), (40, 50)),
                                                  ((60, 50), (90, 100))], 2)
            self.assertRaises(
                ValueError,
                Quartz.CGContextClipToRects,
                context,
                [((0, 0), (40, 50)), ((60, 50), (90, 100))],
                3,
            )

            Quartz.CGContextSetFillColorSpace(
                context, Quartz.CGColorSpaceCreateDeviceGray())
            Quartz.CGContextSetStrokeColorSpace(
                context, Quartz.CGColorSpaceCreateDeviceGray())

            Quartz.CGContextSetFillColor(context, [0.5, 1.0])
            Quartz.CGContextSetStrokeColor(context, [0.5, 1.0])

            Quartz.CGContextSetPatternPhase(context, Quartz.CGSize(10.0, 50.0))

            Quartz.CGContextSetGrayFillColor(context, 0.8, 1.0)
            Quartz.CGContextSetGrayStrokeColor(context, 0.8, 1.0)

            Quartz.CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0)
            Quartz.CGContextSetRGBStrokeColor(context, 1.0, 1.0, 1.0, 1.0)

            Quartz.CGContextSetCMYKFillColor(context, 1.0, 1.0, 1.0, 0.5, 0.8)
            Quartz.CGContextSetCMYKStrokeColor(context, 1.0, 1.0, 1.0, 0.5,
                                               0.8)

            Quartz.CGContextSetRenderingIntent(
                context, Quartz.kCGRenderingIntentPerceptual)

            v = Quartz.CGContextGetInterpolationQuality(context)
            self.assertIsInstance(v, int)

            Quartz.CGContextSetInterpolationQuality(
                context, Quartz.kCGInterpolationHigh)

            color = Quartz.CGColorCreate(Quartz.CGColorSpaceCreateDeviceRGB(),
                                         (1, 1, 1, 1))

            Quartz.CGContextSetShadowWithColor(context, (2, 3), 0.5, color)
            Quartz.CGContextSetShadow(context, (5, 6), 0.6)

            Quartz.CGContextSetCharacterSpacing(context, 0.1)
            Quartz.CGContextSetTextPosition(context, 10, 50)
            p = Quartz.CGContextGetTextPosition(context)
            self.assertIsInstance(pt, Quartz.CGPoint)

            Quartz.CGContextSetTextMatrix(context,
                                          Quartz.CGAffineTransformIdentity)

            tr = Quartz.CGContextGetTextMatrix(context)
            self.assertIsInstance(tr, Quartz.CGAffineTransform)

            Quartz.CGContextSetTextDrawingMode(context, Quartz.kCGTextStroke)

            Quartz.CGContextSetFontSize(context, 11.5)

            Quartz.CGContextSelectFont(context, b"Helvetica", 10.5,
                                       Quartz.kCGEncodingMacRoman)

            Quartz.CGContextShowText(context, b"value", 5)
            Quartz.CGContextShowTextAtPoint(context, 50, 60, b"value", 5)

            v = Quartz.CGContextRetain(context)
            self.assertTrue(v is context)
            Quartz.CGContextRelease(context)

            Quartz.CGContextFlush(context)
            Quartz.CGContextSynchronize(context)

            self.assertArgHasType(Quartz.CGContextSetShouldAntialias, 1,
                                  objc._C_BOOL)
            Quartz.CGContextSetShouldAntialias(context, True)

            self.assertArgHasType(Quartz.CGContextSetAllowsAntialiasing, 1,
                                  objc._C_BOOL)
            Quartz.CGContextSetAllowsAntialiasing(context, True)

            self.assertArgHasType(Quartz.CGContextSetShouldSmoothFonts, 1,
                                  objc._C_BOOL)
            Quartz.CGContextSetShouldSmoothFonts(context, True)

            self.assertArgHasType(Quartz.CGContextSetAllowsFontSmoothing, 1,
                                  objc._C_BOOL)
            Quartz.CGContextSetAllowsFontSmoothing(context, True)

            self.assertArgHasType(
                Quartz.CGContextSetAllowsFontSubpixelQuantization, 1,
                objc._C_BOOL)
            Quartz.CGContextSetAllowsFontSubpixelQuantization(context, True)

            Quartz.CGContextBeginTransparencyLayer(context, None)
            Quartz.CGContextEndTransparencyLayer(context)

            tf = Quartz.CGContextGetUserSpaceToDeviceSpaceTransform(context)
            self.assertIsInstance(tf, Quartz.CGAffineTransform)

            pt = Quartz.CGContextConvertPointToDeviceSpace(
                context, (10.5, 11.9))
            self.assertIsInstance(pt, Quartz.CGPoint)

            pt = Quartz.CGContextConvertPointToUserSpace(context, (10.5, 11.9))
            self.assertIsInstance(pt, Quartz.CGPoint)

            sz = Quartz.CGContextConvertSizeToDeviceSpace(
                context, (10.5, 11.9))
            self.assertIsInstance(sz, Quartz.CGSize)

            sz = Quartz.CGContextConvertSizeToUserSpace(context, (10.5, 11.9))
            self.assertIsInstance(sz, Quartz.CGSize)

            box = Quartz.CGContextConvertRectToDeviceSpace(
                context, ((10.5, 11.9), (55.6, 39.3)))
            self.assertIsInstance(box, Quartz.CGRect)
            box = Quartz.CGContextConvertRectToUserSpace(
                context, ((10.5, 11.9), (55.6, 39.3)))
            self.assertIsInstance(box, Quartz.CGRect)

            myInfo = object()

            def drawPattern(info, context):
                pass

            pattern = Quartz.CGPatternCreate(
                myInfo,
                Quartz.CGRectMake(0, 0, 10, 10),
                Quartz.CGAffineTransformIdentity,
                10.0,
                10.0,
                Quartz.kCGPatternTilingConstantSpacing,
                True,
                drawPattern,
            )
            self.assertIsInstance(pattern, Quartz.CGPatternRef)

            Quartz.CGContextSetFillColorSpace(
                context, Quartz.CGColorSpaceCreatePattern(None))
            Quartz.CGContextSetStrokeColorSpace(
                context, Quartz.CGColorSpaceCreatePattern(None))
            Quartz.CGContextSetFillPattern(context, pattern,
                                           (1.0, 1.0, 1.0, 1.0))
            Quartz.CGContextSetStrokePattern(context, pattern,
                                             (1.0, 1.0, 1.0, 1.0))

            fn = "/System/Library/CoreServices/DefaultDesktop.jpg"
            if not os.path.exists(fn):
                fn = "/System/Library/Automator/Apply ColorSync Profile to Images.action/Contents/Resources/A-1075-normal.jpg"
                if not os.path.exists(fn):
                    fn = "/System/Library/CoreServices//RemoteManagement/ARDAgent.app/Contents/Resources/Lock.jpg"

            with open(fn, "rb") as fp:
                data = fp.read()
            provider = Quartz.CGDataProviderCreateWithCFData(data)
            image = Quartz.CGImageCreateWithJPEGDataProvider(
                provider, None, True, Quartz.kCGRenderingIntentDefault)
            self.assertIsInstance(image, Quartz.CGImageRef)

            Quartz.CGContextDrawImage(context, ((0, 0), (70, 50)), image)

            provider = Quartz.CGDataProviderCreateWithCFData(b"1" * 4 * 20 *
                                                             10)
            mask = Quartz.CGImageMaskCreate(20, 10, 8, 32, 80, provider, None,
                                            True)
            self.assertIsInstance(mask, Quartz.CGImageRef)

            Quartz.CGContextClipToMask(context,
                                       Quartz.CGRectMake(0, 0, 50, 90), mask)

        finally:
            Quartz.CGContextEndPage(context)
            if hasattr(Quartz, "CGPDFContextClose"):
                Quartz.CGPDFContextClose(context)
            if os.path.exists("/tmp/pyobjc.test.pdf"):
                os.unlink("/tmp/pyobjc.test.pdf")