rojas.run

Devops and dev stuff

GSOC Update 3

These last few weeks have been a good learning experience with Krita as I try to implement a node visitor and save context classes. First we want to create a saveContext class for svg called KisScalableVectorGraphicsSaveContext that will be used to save to the file when visiting all nodes. This class is fairly cookie cutter and takes a KoStore to use to write to a specified file. The real work will happen in our node visitor class KisScalableVectorGraphicsSaveVisitor. Most of this right now includes some template visit functions like visit(KisPaintLayer *layer) that just calls saveLayer(KisLayer *layer) to save the specific type of layer. One small quirk here was when trying to find out where vector layers are processed. After experimenting with the ora plugin I found out this would be visited under the group layer function visit(KisGroupLayer *layer) so I similar for the svg plugin.

What’s this extra text in my file

Now that we’ve implemented the node visitor and are using a save context we have some preliminary text in our saved file. But something in our file isn’t quite right in our file. We see some garbled text at the start of our file:

PK
�����ŽŽU_U0	���	������mimetypeimage/svg

I wasn’t sure where this garbled text was coming from but I can tell that the mimetypeimage/svg comes from my declaration in the KoStore where I specify image/svg. Starting from there, we can tell that something happens either in the creation of the KoStore object or when we start writing to it in the save context. At first I couldn’t find anything explicitly clear in the code for where this occurs. The save context declares some variables when an object is instantiated and just writes to disk when saving elements. But the KoStore has a little bit of a hint, it uses a zip or directory structure for use as its backend and I was using “Auto”. After checking the code comments and seeing that Auto defaults to Zip I was pretty sure that’s whats generating that garbled text.

But the next question is what should it be using instead? The node visitor requires a save Context to save elements. And the saveContext requires at something in order to actually to save to disk. Without a definitive answer I decided to look at some other export file code and what they do for their formats. I had been looking at ora/kra plugins but they are supposed to be a zip file so that’s not too helpful here. Instead the csv and tiff plugins show using the visitor with QIODevice a little more directly. Great that means we can go that route for the svg plugin.

Whats next

Right now I’m still figuring out how to integrate using the QIODevice with my node visitor. Hopefully that isn’t too difficult and I have some exciting news to share next week.