delki8 wrote:
I'm writing a python plugin that writes some text into my layer and I would really like to select a portion of that text and apply a different formatting to it, like changing the font-size and its color.
I heard a little bit about the concept of parasites, which from my understanding is the metadata associated with my .xcf. When I do this formatting manually I can see this parasite attached to the text as a markup, but I can't find the right way to create a parasite and attach it to my text layer. I've been browsing the "Python Procedure Browser" but this part is a little blurred.
To add a parasite:
p=gimp.Parasite('some_name',0,some_data)
textLayer.parasite_attach(p)
However the parasite is ignored by Gimp, which only looks at it when loading the file. And when the file is saved, it generates a new parasite from the actual layer contents.
It may be easier for you to format several individual text layers side-by-side. To align them to the same baseline: if you use "pdb.gimp_text_get_extents_fontname()" with a character that has a flat bottom (I typically use "X") the "ascent" is the distance of the baseline from the top of the layer (round character such as "O" can extent slightly under the baseline).