It is currently Fri Jun 21, 2024 3:16 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: manipulate a portion of text inside a text layer using python-fu
PostPosted: Mon Dec 12, 2022 8:12 pm  (#1) 
Offline
New Member

Joined: Dec 12, 2022
Posts: 2
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 2233 times ]
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: manipulate a portion of text inside a text layer using python-fu
PostPosted: Tue Dec 13, 2022 3:54 am  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4750
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).

_________________
Image


Top
 Post subject: Re: manipulate a portion of text inside a text layer using python-fu
PostPosted: Thu Dec 15, 2022 5:17 am  (#3) 
Offline
New Member

Joined: Dec 12, 2022
Posts: 2
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.


Top
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts script to load text file and create text layer

6

No new posts How to make a python or scrip fue from text

2

No new posts Eager to learn to input text in python script (Solved)

2

No new posts Cannot edit text in a layer from a PSD file

1

No new posts Attachment(s) Creating text (layer?) presets/profile?

15



* Login  



Powered by phpBB3 © phpBB Group