Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Batch Changing font style
#1
Hello!
I have managed to put together a Gimp plugin (attached) to change font styles
a. the font itself
b. increase/decrease: font size, letter spacing and line height (separately)
c. the font color to foreground color
to apply inside: active group, active group & subgroups, or whole image.

I find it especially useful for treatment of files with a lot of text layers (maps, diagrams)  after scaling the whole image. With a hitch: the plugin works only on text layers, and that property disappears on scaling, to be restored only by clicking on the layer with the text tool and accepting 'edit'--somewhat uphill when you have 20+ text layers.
Now, my question is: can there be some way to restore the text to editable from a plugin? (It will be on the wrong font size and requiring further adjustments, but one can always work on a copy.)
After much digging, I have found that those former text layers return on
Code:
pdb.gimp_item_get_parasite_list()

a 'tuple' containig "gimp-text-layer" (so, one can pick them out from the other layers), but I haven't found any way to restore them. Something like 'open as text layer' (with options) must exist in the Gimp internals...
So, please: any ideas?
Thanks!


Attached Files
.zip   group_stylefont_V3.zip (Size: 1.83 KB / Downloads: 12)
Reply
#2
Maybe it exists in the Gimp internals and maybe not . If it is not exposed you are a bit out of luck. Personally I think that Gimp just recreates a layer from the parasite info. The only advantage it has on you is that it can use a string with mixed formatting.

As a side note creating a text with size 10 and scaling it up 2x doesn't create the same shape as creating the text in size 20. In the picture below, the blue is a Roboto Heavy size 62 scaled up to match the red which is native size 124:

   
Reply
#3
(10-14-2019, 06:47 AM)Ofnuts Wrote: Maybe it exists in the Gimp internals and maybe not . If it is not exposed you are a bit out of luck. Personally I think that Gimp just recreates a layer from the parasite info. The only advantage it has on you is that it can use a string with mixed formatting.

OK--I shall try everything  at the gimpparasite page of GIMP Base Library Reference Manual--hopefully, some will rescue the data from the parasite and allow me to inset them back as a new text layer ... I was hoping for a pointer on which ones to try, being green as green...
Quote:As a side note creating a text with size 10 and scaling it up 2x doesn't create the same shape as creating the text in size 20. In the picture below, the blue is a Roboto Heavy size 62 scaled up to match the red which is native size 124:
Well--that ought to be expected, ought it not?
--Your own observations on 'bendiness' in the ofn-bend-path pluguin give some pointers in path deformation on transforms
--Latex goes to the trouble of creating lots of 'virtual fonts' for each of its fonts to address size change
--Some font packages come with different versions for size (Serif6Beta-Regular.otf, Serif12Beta-Regular.otf, Serif72Beta-Regular.otf)...
That just shows that if you have a file with lots of text, scale it and wish to continue editing by adding some more text, you ought to edit the scaled text layers also, to get a uniform look...
Reply
#4
In my own text-info script:

Code:
def text_info(img,layer):
    parasites=None
    try:
        parasites=layer.parasite_list()
    except Exception as e:
        pass;
    if parasites and 'gimp-text-layer' in parasites:
        data=layer.parasite_find('gimp-text-layer').data
        pdb.gimp_message('Text layer "%s": %s' % (layer.name,data))
    else:
        pdb.gimp_message('No text information found for layer "%s"' % layer.name)
With the caveat that the parasite doesn't exist until you save the file (so you won't find it on a freshly created text layer).
Reply
#5
(10-14-2019, 12:32 PM)Ofnuts Wrote: In my own text-info script:

Code:
def text_info(img,layer):
    parasites=None
    try:
        parasites=layer.parasite_list()
    except Exception as e:
        pass;
    if parasites and 'gimp-text-layer' in parasites:
        data=layer.parasite_find('gimp-text-layer').data
        pdb.gimp_message('Text layer "%s": %s' % (layer.name,data))
    else:
        pdb.gimp_message('No text information found for layer "%s"' % layer.name)
With the caveat that the parasite doesn't exist until you save the file (so you won't find it on a freshly created text layer).
Thanks a ton! As always ... the cat's pajamas! Smile
Reply


Forum Jump: