Gimp Plug-in for Retrieving Text Layers
This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.
This is a read-only list on gimpusers.com so this discussion thread is read-only, too.
Gimp Plug-in for Retrieving Text Layers | BillC@sptech.com | 02 Dec 07:18 |
Gimp Plug-in for Retrieving Text Layers | Sven Neumann | 02 Dec 10:13 |
Gimp Plug-in for Retrieving Text Layers | David Neary | 02 Dec 11:00 |
Gimp Plug-in for Retrieving Text Layers | Sven Neumann | 02 Dec 12:50 |
Gimp Plug-in for Retrieving Text Layers | David Neary | 02 Dec 16:26 |
Gimp Plug-in for Retrieving Text Layers | Joao S. O. Bueno Calligaris | 02 Dec 16:39 |
Gimp Plug-in for Retrieving Text Layers | Sven Neumann | 05 Dec 04:00 |
Gimp Plug-in for Retrieving Text Layers | Joao S. O. Bueno Calligaris | 05 Dec 16:55 |
Gimp Plug-in for Retrieving Text Layers | BillC@sptech.com | 03 Dec 00:01 |
Gimp Plug-in for Retrieving Text Layers | William Skaggs | 05 Dec 18:44 |
Gimp Plug-in for Retrieving Text Layers | Sven Neumann | 05 Dec 22:44 |
Gimp Plug-in for Retrieving Text Layers
I am having difficulties enumerating, and identifying layers in a Gimp
Plug-in. Is there
a good source for code that shows how to do this?
My need is to save the text information found in a Gimp document/image
into another
file. To do this, I need to iterate through all of the layers, find the
text ones, get the text
and save it to a file.
My end goal is to make a new Plug-in Filter for an archaic file type that
many people
would like to have.
Any code would be appreciated, I am just having a problem getting started
with
Gimp development.
I am using the Plug-in Template, Linux (Fedora Core 2), Developer and Base
RPM's.
I have compiled the sample plugin, and got it to list the layers, but I
cannot identify
the contents of the layer or the simply the layer type.
Thanks in advance
Bill
Gimp Plug-in for Retrieving Text Layers
Hi,
BillC@sptech.com writes:
I am having difficulties enumerating, and identifying layers in a Gimp Plug-in. Is there a good source for code that shows how to do this? My need is to save the text information found in a Gimp document/image into another file. To do this, I need to iterate through all of the layers, find the text ones, get the text and save it to a file. My end goal is to make a new Plug-in Filter for an archaic file type that many people would like to have. Any code would be appreciated, I am just having a problem getting started with Gimp development. I am using the Plug-in Template, Linux (Fedora Core 2), Developer and Base RPM's. I have compiled the sample plugin, and got it to list the layers, but I cannot identify the contents of the layer or the simply the layer type.
I am afraid there is no way for a plug-in to find out if a layer is a text layer or even to access the text properties. You could perhaps implement what you are trying to do using some internal knowledge about text layer. Basically I could tell you how to do it but I'd have to kill you afterwards ;)
If you could outline what information you need exactly, we could try to come up with an API that allows you to do this in a proper way. Having access to the text layers has been requested before so I think we should add this for GIMP 2.4.
Sven
Gimp Plug-in for Retrieving Text Layers
Hi Bill,
BillC@sptech.com wrote:
I am having difficulties enumerating, and identifying layers in a Gimp Plug-in. Is there
a good source for code that shows how to do this?
Not really - the usual way is to do something like this:
gint nlayers, i; gint *layers = gimp_image_get_layers(image_id, &nlayers); /* layers[0] is the top layer */
for (i = 0; i < nlayers; i++)
{
/* Do stuff with layers[i] */
/* layer is a text layer if the parasite "gimp-text-layer" has been
* set */
GimpDrawable *layer = gimp_drawable_get (layers[i]);
GimpParasite *text_parasite = gimp_drawable_parasite_find
(layers[i], "gimp-text-layer");
if (text_parasite != NULL)
/* We have a text layer */
}
All the standard GIMP parasites are listed in the gimp sources, in devel-docs/parasites.txt. There are also docs for things like debugging plug-ins, overviews of many of the GIMP's internal formats including xcf, and some documentation for important subsystems like undo, as well as gtkdocs for the libgimp API.
To do this, I need to iterate through all of the layers, find the text ones, get the text
and save it to a file.
I'm not sure how the text is stores in a gimp-text-layer parasite. It is a GimpText object serialised to a string, if that helps any. UTSL (Use the Source, Luke) or ask Sven :)
Hope this helps,
Cheers, Dave.
Gimp Plug-in for Retrieving Text Layers
Hi,
David Neary writes:
Not really - the usual way is to do something like this:
gint nlayers, i; gint *layers = gimp_image_get_layers(image_id, &nlayers); /* layers[0] is the top layer */
for (i = 0; i < nlayers; i++) {
/* Do stuff with layers[i] */
/* layer is a text layer if the parasite "gimp-text-layer" has been * set */
GimpDrawable *layer = gimp_drawable_get (layers[i]); GimpParasite *text_parasite = gimp_drawable_parasite_find (layers[i], "gimp-text-layer"); if (text_parasite != NULL)
/* We have a text layer */
}
OK, now I will have to kill you both. Well, perhaps not but I can only strongly discourage to do it this way. You must not rely on the text parasite and it's content. Doing this might to some extent work on XCF files that have been freshly loaded but it will fail as soon as a text layer is modified. There is also no guarantee that this behaviour won't change in future versions of GIMP. I might even decide to change it in the middle of a stable release cycle. Perhaps even for the only reason to break your code that should not be doing this.
Sven
Gimp Plug-in for Retrieving Text Layers
Hi,
Sven Neumann wrote:
OK, now I will have to kill you both. Well, perhaps not but I can only strongly discourage to do it this way. You must not rely on the text parasite and it's content.
Sorry - wrote that before I got your reply :)
I know you were hoping to implement text transforms this week before 2.2, aside from that, is there any (good) reason why the parasite's format would change?
Cheers, Dave.
Gimp Plug-in for Retrieving Text Layers
On Thursday 02 December 2004 09:50, Sven Neumann wrote:
Hi,
David Neary writes:
Not really - the usual way is to do something like this:
gint nlayers, i; gint *layers = gimp_image_get_layers(image_id, &nlayers); /* layers[0] is the top layer */
for (i = 0; i < nlayers; i++) {
/* Do stuff with layers[i] */
/* layer is a text layer if the parasite "gimp-text-layer" has been * set */
GimpDrawable *layer = gimp_drawable_get (layers[i]); GimpParasite *text_parasite = gimp_drawable_parasite_find (layers[i], "gimp-text-layer"); if (text_parasite != NULL)
/* We have a text layer */}
OK, now I will have to kill you both. Well, perhaps not but I can only strongly discourage to do it this way. You must not rely on the text parasite and it's content. Doing this might to some extent work on XCF files that have been freshly loaded but it will fail as soon as a text layer is modified. There is also no guarantee that this behaviour won't change in future versions of GIMP. I might even decide to change it in the middle of a stable release cycle. Perhaps even for the only reason to break your code that should not be doing this.
Actually, it doesn't even work on a newly created text layer. No parasites in there, checking interactively.
There is one thing to do - The plug-in have to manage text layers on it's side, creating itsef the parasites it need to store the information. - Just like the old Dyn text. Then, the standard text-tool api can be used. The plug-in won't know about any other text layers but the ones it creates, thought.
Sven
Gimp Plug-in for Retrieving Text Layers
This is a response to the "Why would you need to have the text?"
Well, when writing a filter to save a file, or generate a file set. Some
old IBM
file formats allow you to optimize your image with text objects and
"rules"
(horizontal or vertical lines). If I could determine the text content, I
could
generate a very small and optimized file.
Also, file formats such as wmf, postscript, pdf and such benefit from vector based information and text information.
I guess, my thought would be for widget implementers, to abide by certain rules, with the raster based image being the common denominator. So, "Text" tools, should implement the "GimpText" object. "Curve Editors" should implement their counterpart. This way, enumeration of layers and content would yield good information (not great) for exporting in specific file formats.
Gimp is great tool, could be a start to more than photo's and images, a whole world of "document management" could be assisted by this :)
This is all just my opinion.
Thanks
Bill
Sven Neumann wrote on 12/02/2004 05:50:58 AM:
Hi,
David Neary writes:
Not really - the usual way is to do something like this:
gint nlayers, i; gint *layers = gimp_image_get_layers(image_id, &nlayers); /* layers[0] is the top layer */
for (i = 0; i < nlayers; i++) {
/* Do stuff with layers[i] */
/* layer is a text layer if the parasite "gimp-text-layer" has been * set */
GimpDrawable *layer = gimp_drawable_get (layers[i]); GimpParasite *text_parasite = gimp_drawable_parasite_find (layers[i], "gimp-text-layer"); if (text_parasite != NULL)
/* We have a text layer */}
OK, now I will have to kill you both. Well, perhaps not but I can only strongly discourage to do it this way. You must not rely on the text parasite and it's content. Doing this might to some extent work on XCF files that have been freshly loaded but it will fail as soon as a text layer is modified. There is also no guarantee that this behaviour won't change in future versions of GIMP. I might even decide to change it in the middle of a stable release cycle. Perhaps even for the only reason to break your code that should not be doing this.
Sven
Gimp Plug-in for Retrieving Text Layers
Hi,
"Joao S. O. Bueno Calligaris" writes:
Actually, it doesn't even work on a newly created text layer. No parasites in there, checking interactively.
Correct. It would only work in freshly loaded XCF files.
There is one thing to do - The plug-in have to manage text layers on it's side, creating itsef the parasites it need to store the information. - Just like the old Dyn text. Then, the standard text-tool api can be used. The plug-in won't know about any other text layers but the ones it creates, thought.
Why should a plug-in do this? Plug-ins shouldn't have to deal with the hacks that GIMP uses to extend the XCF file format. These hacks might change at anytime and should become part of the API.
Sven
Gimp Plug-in for Retrieving Text Layers
On Sunday 05 December 2004 01:00, Sven Neumann wrote:
Hi,
"Joao S. O. Bueno Calligaris" writes:
.
There is one thing to do - The plug-in have to manage text layers on it's side, creating itsef the parasites it need to store the information. - Just like the old Dyn text. Then, the standard text-tool api can be used. The plug-in won't know about any other text layers but the ones it creates, thought.
Why should a plug-in do this? Plug-ins shouldn't have to deal with the hacks that GIMP uses to extend the XCF file format. These hacks might change at anytime and should become part of the API.
Sorry Sven, I am afraid I was broadly misunderstood here. When I speak of parasites above, I am talking of parasites as they intend to be used: extra data that can be used by the plug-in. My idea above is that the plug-in stores the information it needs about which text layers exist on the image, and their content, on it's onw - on a parasite it creates for its own use. When a text changes - on the plug-in interface, it just deletes the text layer and create a new one.
I cannot figure out any other way of a plug-in managing text layers right now.
Sven
Gimp Plug-in for Retrieving Text Layers
If people need to work with text layers in plugins, then clearly the right approach is to add new functions gimp_layer_is_text(), gimp_layer_get_text(), and gimp_layer_set_text() to libgimp. I expect this wouldn't even be very difficult.
Best,
-- Bill
______________ ______________ ______________ ______________
Sent via the KillerWebMail system at primate.ucdavis.edu
Gimp Plug-in for Retrieving Text Layers
Hi,
"William Skaggs" writes:
If people need to work with text layers in plugins, then clearly the right approach is to add new functions gimp_layer_is_text(), gimp_layer_get_text(), and gimp_layer_set_text() to libgimp.
Yes, something along these lines. It would probably be a little more complex than get_text() and set_text() but I think we should try to come up with such an API for GIMP 2.4.
I expect this wouldn't even be very difficult.
Implementation-wise I expect this to be simple. Getting the APIs right could turn out difficult.
Sven