Getting Images onto a Cairo Surface.
Introduction.This article is a classic example of me not being able to RTFM. I had got focused onto Cairo Surface, but there's a perfectly good method in gdk.Cairo - setSourcePixbuf() - to set a Pixbuf as source in a Cairo context. My apologies to the GTK developers. So you can basically forget what follows ;=(
You used to be able to create a gdk.Drawable, load an image into it, and then plaster that onto a Cairo Surface. You could then paint a target DrawingArea with the result.
Now there is only provision for directly loading a PNG file into a Cairo Surface, and the documentation in fact classifies that as a 'toy interface'. In 3.10 there is apparently a facility within Gdk to load a Pixmap into a Cairo Surface, thus putting us back close to square one but without the now abandoned Drawable. However, for some time into the future, many systems will not have GTK3.10. This can be detected via gtk.Version, and when it is not detected, if you want to load a .jpg file you will be SOL.
This article presents a way that can be used within the pre 3.10 limitations of Gdc and Cairo.
The Proposition.I shall continue to talk about this in a somewhat neutral way language-wise. We can load any reasonable image file into a Gdk.Pixbuf, and there we can scale it and such. At the same time we can create a Cairo.ImageSurface of some specified size with bits set to unspecified values. We therefore are left with the remaining problem of transferring the bits from one to the other. Here's how it can be done. I'm not saying it is robust or portable - time will tell:
You should be able to get the idea from that which can then be converted to the language of your choice. But, you might ask, what is the strange language here. Well, it is D. Many of D'd proponents would say no, but I've deliberately written it so as to be C or C++ like.
It seems from the appearance of the code above that highlightjs does not know about D either ;=(
D is a cool language that has absorbed an enormous amount of effort and thought from its community, and in particular from Walter Bright.