Hi!

Tavmjonh Bah has suggested me to contact you and consult SPPaintServer class refactoring I would like to do.

Currently SPPaintServer contains pattern_new method. Since it directly handles rendering and uses cairo, I think it could be moved outside of SP tree.

My idea is to implement paint server drawing routines in a parallel hierarchy of classes belonging to New Renderer. Image [1] contains the class diagram. Common base for them would be NRPaintServer, containing pure virtual method pattern_new. Concrete NRPaintServer derivatives would contain a reference to corresponding SPTree items and use it while rendering.

To choose an appropriate NRPaintServer for given SPPaintServer I thought about a factory method in NRPaintServer class. Example interfaces and their usage are shown at [2]

The tricky part can be the implementation of NRPaintServer::create method. I have thought about two solutions:
a) using a battery of dynamic_cast if statements like this:
NRPaintServer* NRPaintServer::create(SPPaintServer* ps) {
    SPPattern* pattern = dynamic_cast<SPPattern*>ps;
    if (pattern != 0) {
        return new NRPattern(&pattern);
    }
    //and so on for gradients
}

b) using double-dispatch strategy. There would be an .cpp file internal class NRPaintServerFactory.
class NRPaintServerFactory {
    public:
        virtual NRPaintServer* create(SPPaintServer*);
        virtual NRPaintServer* create(SPLinearGradient*);
        virtual NRPaintServer* create(SPRadialGradient*);
        //and so on
}

And NRPaintServer::create implementation would look like this:
NRPaintServer* NRPaintServer::create(SPPaintServer* ps) {
    static NRPaintServerFactory *factory = new NRPaintServerFactory;
    return factory->create(ps);
}

What are your thoughts about this solution?

[1]https://www.dropbox.com/s/bz83xd0ks378qys/NRPaintServer.svg
[2]http://pastebin.com/h9AcrusW

Regards,
  Tomasz