Вопрос

How is it possible to copy a path after a call to stroke() or fill() ? I've setup a caching mecanism which looks like that

high end visual object class:

override void DrawDirect(canvas aCanvas)
{
    aCanvas.Line(...)
    aCanvas.Rectangle(...)
    // etc. 
    MyCache = aCanvas.GetPath(); // = canvas.Context.copy_Path()
    IsCached = true;
}

override void DrawCache(canvas aCanvas)
{
    aCanvas.DrawPath(MyCache); // = canvas.Context.appendPath...
}

and the super class has this method:

voidDraw(canvas aCanvas)
{
    if(IsCached) DrawCache();
    else DrawDirect;
}

the canvas defines this kind of methods:

void Line(...)
{
    Context.moveTo(...)
    Context.lineTo(...)
    Context.stroke();
}

when I call GetPath, MyCache.numData is equal to 0 unless I comment the calls to stroke() and to fill(). But as a side effect the DrawDirect methods do (visually) nothing.

One other subsequent question would be: is calling appendPath (really) faster than calling the basic "direct" methods ? (you can comment about this, I'll only accept answers about the copy_Path stuff).

Это было полезно?

Решение

Cairo has stroke() which deletes the path after stroking and stroke_preserve() which does not touch the path and leaves it as-is.

I don't really know if appendPath() is faster than re-creating the path directly, but I really cannot imagine that something like this should be a performance issue. It likely depends on your paths anyway and you should just benchmark this yourself.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top