GIMP Chat
http://gimpchat.com/

manipulate a portion of text inside a text layer using python-fu
http://gimpchat.com/viewtopic.php?f=4&t=20218
Page 1 of 1

Author:  delki8 [ Mon Dec 12, 2022 8:12 pm ]
Post subject:  manipulate a portion of text inside a text layer using python-fu

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.

Attachments:
File comment: What I want
SNi5u.gif
SNi5u.gif [ 51.92 KiB | Viewed 2241 times ]

Author:  ofnuts [ Tue Dec 13, 2022 3:54 am ]
Post subject:  Re: manipulate a portion of text inside a text layer using python-fu

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).

Author:  delki8 [ Thu Dec 15, 2022 5:17 am ]
Post subject:  Re: manipulate a portion of text inside a text layer using python-fu

Thank you ofnuts, I had thought about aligning them word by word but I thought this would be too tedious to implement consistently, so I left the part of increasing the font size to be run manually. The script I'm writing performs a few other tasks so this one in specific will be considered a trade-off to have the rest of it working automatically.

Thank you for the time you've put into your solution proposal.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/