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

Anton Mezhiborskiy Anton.Mezhiborskiy at htw-berlin.de
Mon Apr 6 07:23:09 PDT 2009


Hi Jiang!

Thank you for your answer! It's exactly what i need!

Unfortunatelly I can't build/run my code, because i haven't 
cairo-quartz.h (or something like that) inside the cairo's include 
folder. I've installed cairo via MacPorts. And included "cairo.h" in the 
code, but the Xcode can't find cairo_quartz_surface_create_for_cg_context().

Then i've tried to configure the port with "sudo port edit cairo" and 
put there --enable-quartz. No results.

How should i correctly install/configure cairo+quartz+xcode?

Sorry if my questions are studid.

p.s. i've added "header search paths" and "library search path" to the 
Xcode project. So the xcode sees cairo_surface_t and so on correctly, 
but not the cairo_quartz_surface_create_for_cg_context().

Thank you for Your help.


Anton



Jjgod Jiang wrote:
> 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
> 
>     cairo_destroy(cr);
>     cairo_surface_destroy(surface);
> }
> 
> HTH.
> 
> - Jiang


More information about the cairo mailing list