[cairo] cairo + os X + xcode / please help

Jjgod Jiang gzjjgod at gmail.com
Thu Apr 2 10:13:30 PDT 2009

Hi Anton,

On Fri, Apr 3, 2009 at 12:43 AM, Anton Mezhiborskiy
<Anton.Mezhiborskiy at htw-berlin.de> wrote:
> I've decided to post this qurstion, because i cannot find the solution
> on my own. I've read manuals and googled, but... i need help.
> I want like to learn/use cairo, it's great. I'm trying to write a simple
> code and render it under macosx. But i don't understand how should i do
> it. I'm lost in Carbon / Cocoa / Quartz Surfaces / cairo_surface_t*.
> I just need a workflow, how should i write Cairo code and render it then
> under osx.

First you'll need to create a custom view (which is inherited directly or
indirectly from NSView) which you have access to the -drawRect: method
of it.

In this -drawRect: method, you can retrieve Core Graphics (Quartz) context
and create a cairo quartz surface from it, like this:

- (void) drawRect: (NSRect) rect
    CGContext *context = [[NSGraphicsContext currentContext] graphicsPort];

    cairo_surface_t *surface =
cairo_quartz_surface_create_for_cg_context(context, (int)
rect.size.width, (int) rect.size.height);
    cairo_t *cr = cairo_create(surface);

    // do your drawings with cairo here



- Jiang

More information about the cairo mailing list