[cairo] Observations from a newb
dirk.schoenberger at sz-online.de
Fri Nov 9 00:01:42 PST 2007
> Sorry if I ask silly questions, but I do not savvy the "source" concept
> yet. I
> can see that it's a place where data comes from, but not how the flavours,
> what a source can be, work.
> I sort of picture a source as being an array of rgba values that have
> preset in memory from some other place (the source of the source). So it's
> hard to picture how a source can said to be SVG or PDF, given my oddball
> angle on it.
You have to separate between image and meta surfaces. An image surface
works as you described, it is an array of RGBA values (and some other
A meta surface stores basically the "service level primitives" and can
play these back. So if you use such a surface as a source, you can e.g.
fill areas with scalable patterns.
Problem is that these meta surfaces don't exist as a public API, but are
"hidden" behind other surfaces (PS and PDF I think). So in order to use
them, you have to create a PDF surface and use that as source in your
"real" context. This is a little non-obvious.
> For example, I assume one would use librsvg to open an SVG file and then
> some cairo footwork would turn that into a source; after that it can be
> stamped around as per the clever cairo idiom. But how does this source
> from a bitmap? I mean, what are it's properties that differentiate it?
Can it be
> smoothly scaled for example (i.e. redrawn as a vector and then updated
> across the cairo surface wherever it has been used).
I am not sure, but I have not yet seen a usebale SVG (or PDF) renderer
which targets cairo directly. All I have seen are modules which render to
image buffers, which in turn can be used as a image surface. In using this
approach, all vector possibilities are lost.
What I would like to see would be a "real" metafile system for cairo.
Basically a way to store a sequence of cairo calls (high level, not
service level) and be able to replay this later. I envision some kind of
string format using reverse polish notation operands for storing the
commands. Basically this is how the Adobe family of graphics formats work
(PS, EPS, AI, PDF).
M is moveto, C is curveto, L is lineto, Z is closepath, f is fill, s is
stroke, r is set_source_rgb etc
a metadata file would look something like
10 10 M 100 0 L 100 100 L 0 0 L 1 0 0 r f
Maybe I will give this idea a try.
More information about the cairo