Cairo talk feedback from DPC10

I noted a couple of comments after my talk on Cairo at DPC 10 yesterday, so I thought I'd respond to them here to clear up what's going on. It's always good to get some feedback about something I've been working on so I'd like to reply and keep the conversation going if I can.

First off, someone mentioned that the wrapper seems a bit beta and incomplete - and yes, that is true. The 0.2.0 release, which is the latest as I wrote this, is still marked as beta. The aim of me coming and talking about it is to try and get some more people interested in using it, so we can get some more information from real users about what works and what doesn't. I probably didn't help by mentioning that there are some features that we intend to implement that aren't there yet, which I'll list:

  • Support for reading and writing images that aren't PNGs The developers of the core Cairo API are not really interested in handling all the various graphics formats that exist, so they decided to implement one and one only which is useful for getting data in and out. This is the functionality that we use at present. We (the developers of the wrapper) would like to fix that and handle JPEG, GIF, TIFF, and whatever new format is cool this week, but we're not quite sure how to go about that yet. We could recycle the code used by GD or use ImageMagick or GraphicsMagick, but those would introduce dependencies that people might not have available. Once we work out a decent solution here, it will be put in.
  • Support for hyperlinks in PDFs and SVGs Again, this is something we'd quite like but it's not supported in the underlying library yet. There have been rumours about adding an API to do this, but there hasn't been a concensus about what's a good way to go about it. It's something I'd quite like to help fix, so I've been learning how Cairo itself is put together with the intention to add the support.

The other comments I saw suggested that the API is a bit fiddly, which I can't deny. It's not quite as simple to set up and get running as some of the other libraries in PHP already. This is nearly intentional - we're wrapping the underlying Cairo API as closely as we can, because we don't want to diverge too far from how other languages with Cairo wrappers work, so that developers who may be familiar with those already know roughly what is going on. It's for this reason that, for example, the API uses floating-point values from 0 to 1 to define the intensity of colours, rather than an integer value from 0-255 which most people are probably used to. This is because Cairo is designed not to make any assumptions about the surface you're going to be drawing to - some day we might get 16-bits-per-channel surfaces, and using float values means that we don't need to change the API or the values we're passing in to allow us to write to them. It'll just carry on working as it did before, just with better colour resolution.

However, if anyone has any ideas for how we could make things simpler, then we'd love to hear about it &emdash; drop us a line on the PECL developers mailing list (which you can find on the PECL mailing lists page), or find us on IRC on #php.pecl on EFnet.

There are a couple of things that I have worked on which sit on top of the Cairo extension, which can do some interesting things. If you're still at DPC I'll be demoing a couple of them on the uncon track at 2pm. It's only a 15 minute talk, so it shouldn't be too boring...!

Ubuntu Accessibility team

Recently I've become involved in a move to resurrect the Ubuntu Accessibility team, which seemed to have stagnated until quite recently when Penelope Stowe got involved and suggested I joined too. She arranged a session at the Ubuntu Developer Summit for the next Ubuntu release, Maverick Meerkat, which seems to have gone quite well. The main focus for the team right now is getting organised, and to this end we're aiming to create a set of personas, which are representations of hypothetical users with various accessibility requirements which developers and testers can keep in mind when working on the next Ubuntu release. These personas are going to be developed by a survey which will be dispatched to a host of groups who may have accessibility requirements to get an idea of what the main factors that affect their experience with Ubuntu are, so we can get an idea of the main areas to improve. Hopefully then the work which will take place as a result of these can be sent upstream to the original projects.

My own role in the team isn't quite clear yet, but I intend to help on the development side, if I can, once more work starts in this area. If you would like to help, the team hangs out on #ubuntu-accessibility on Freenode IRC, and there is a mailing list. You can also check out the wiki page which we're working on improving.

Handling fonts in PECL/Cairo

(This is just a quick note to get some information out there for reference, I am adding it to the PHP manual as well!)

Currently, in PECL/Cairo the only way to draw text is the referred to as the "toy" text API, which is a very basic way of handling text compared to the facilities available in the Cairo library itself. However, it's sufficient for most purposes that I've come across so far. In version 0.1.0 of PECL/Cairo, there was only one way to choose what font you wished to use, which was the CairoContext::selectFontFace() method. You pass a string to this method with the name of the font you want, along with the optional slant and weight parameters. This then invokes your system's font handling to find the font you're after, or an alternative if it's not available, so you need to have the font you want installed into your system's font library.This is occasionally not handy.

In version 0.2.0 FreeType support was added. It allows you to choose any font file you'd like, as long as PHP's streams API can find it. Yes, this means 'http://' streams, but I wouldn't recommend it.

  1.  
  2. <?php
  3. /* Set up the surface, and make the background white */
  4. $s = new CairoImageSurface(CairoFormat::ARGB32, 300, 100);
  5. $c = new CairoContext($s);
  6. $c->setSourceRgb(1, 1, 1);
  7. $c->paint();
  8.  
  9. /* Draw the text using the Vollkorn font, from
  10.   http://friedrichalthausen.de/2006/01/01/vollkorn/ */
  11. $c->setSourceRGB(0, 0, 0);
  12. $c->moveTo(10, 60);
  13. $f = new CairoFtFontFace(dirname(__FILE__) . "/vollkorn.otf");
  14. $c->setFontFace($f);
  15. $c->setFontSize(50);
  16. $c->showText("Hello world");
  17.  
  18. /* Send the image to the browser */
  19. header("Content-type: image/png");
  20. $s->writeToPng("php://output");
  21. ?>
  22.  

The output image should hopefully look like this:

Script output

(For those who are familiar with the Cairo library, this function maps to the cairo_ft_font_face_create_for_ft_face function in its API.)

There is still some work to be done in this area, notably to support the Windows and Mac OS X font systems, but they'll be coming in a future release, we hope. If anyone would like to help us with that, or any other aspect of it (including documentation!), you can get in touch on the PECL dev mailing list, or if you're on IRC, drop in to #php.pecl on EFnet. All contributions are welcome!

Speaking at DPC10

DPC10 speaker badge

I'm happy to say that I'll be speaking at the Dutch PHP Conference in June in Amsterdam, on the subject of the PECL/Cairo extension I've been helping out by working on for the past few months. This will be my first appearance as a speaker at a technical conference so I'm a little nervous, but I've no doubt I'll be practicing a bit before it happens. Apologies in advance to anyone I inflict the talk on before the event.

PECL/Cairo 0.2.0 released

The first beta version of the PECL/Cairo extension has just been released. This version includes support for loading arbitrary fonts via Freetype, cloning matrices, and has a rather large set of bug fixes. If you've been using 0.1.0 for anything at all I'd really recommend an upgrade. Windows builds will appear soon over at perisama.net for all the major PHP variants courtesy of Elizabeth M. Smith. Many thanks to Mark Skilbeck for helping get this release working on Windows!

 1 2 Next →

About

User