tags:

views:

125

answers:

2

I'm doing some work on a potentially cross-platform C++ application and for Windows and OS X it seems that Cairo will meet most of my needs for 2D graphics and allow me to share a lot of code between platforms. In an ideal world I'd really like to be able to use the same (or very similar) drawing code in iPhone/iPad apps.

I realise that this means that I'll need to compile Cairo for iPhone before I try to use it, but I've got no real idea on how to go about this.

If anyone can point me in the right direction I'd be very grateful.

A: 

I recommend against using Cairo on the iPhone. It's not a bad library, but it's not optimized for iPhone, which is a device with limited processing power. In contrast, Quartz, the native graphics engine of the iPhone, is highly optimized for the iPhone.

So you better design a common API, that you implement using Quartz for the iPhone and using Cairo for the other platforms your aiming at. Since Quartz and Cairo share a similar drawing model and comparable functionality, this shouldn't be utterly difficult.

Codo
Doesn't Cairo use Quartz on iPhone/MacOS? Just like Cairo uses GDI and Direct2D on Windows. That's what I understand after a quick glance at http://cairographics.org/manual/
Cristian Adam
Yes, it does. That's one of the main appeals of Cairo - it takes advantage of the native APIs so I don't have to rewrite the code for Quartz specifically. Which brings me back to my problem of compiling Cairo for the iPhone...
Redeye
A: 

On Windows I've compiled Cairo using Visual Studio like this:

  • libpng-1.2.40
  • zlib-1.2.3
  • pixman-0.16.2
  • cairo-1.8.8

Since Cairo will be using Quartz for font and text handling you will not have to compile Pango (which has Glib as dependency) and FreeType. I assume the setup for iPhone should be similar.

This entry from Vladimir Vukićević's blog shows that Cairo runs on iPhone since 2008 :)

Cristian Adam