mirror of
https://gitlab.gnome.org/GNOME/gimp
synced 2024-10-20 19:43:01 +00:00
app: add gimp_item_replace_item() which is a bad hack and documented as such
in order to get rid of fiddling with GimpItem internals inside gimptextlayer-xcf.c
This commit is contained in:
parent
cfecdc8b70
commit
0428be2944
|
@ -1520,13 +1520,10 @@ gimp_item_set_image (GimpItem *item,
|
|||
{
|
||||
g_return_if_fail (GIMP_IS_ITEM (item));
|
||||
g_return_if_fail (! gimp_item_is_attached (item));
|
||||
g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
|
||||
g_return_if_fail (! gimp_item_is_removed (item));
|
||||
g_return_if_fail (GIMP_IS_IMAGE (image));
|
||||
|
||||
if (image == NULL)
|
||||
{
|
||||
item->tattoo = 0;
|
||||
}
|
||||
else if (item->tattoo == 0 || item->image != image)
|
||||
if (item->tattoo == 0 || item->image != image)
|
||||
{
|
||||
item->tattoo = gimp_image_get_new_tattoo (image);
|
||||
}
|
||||
|
@ -1534,6 +1531,69 @@ gimp_item_set_image (GimpItem *item,
|
|||
item->image = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_item_replace_item:
|
||||
* @item: a newly allocated #GimpItem
|
||||
* @replace: the #GimpItem to be replaced by @item
|
||||
*
|
||||
* This function shouly only be called right after @item has been
|
||||
* newly allocated.
|
||||
*
|
||||
* Replaces @replace by @item, as far as possible within the #GimpItem
|
||||
* class. The new @item takes over @replace's ID, tattoo, offset, size
|
||||
* etc. and all these properties are set to %NULL on @replace.
|
||||
*
|
||||
* This function *only* exists to allow subclasses to do evil hacks
|
||||
* like in XCF text layer loading. Don't ever use this function if you
|
||||
* are not sure.
|
||||
*
|
||||
* After this function returns, @replace has become completely
|
||||
* unusable, should only be used to steal everything it has (like its
|
||||
* drawable properties if it's a drawable), and then be destroyed.
|
||||
**/
|
||||
void
|
||||
gimp_item_replace_item (GimpItem *item,
|
||||
GimpItem *replace)
|
||||
{
|
||||
gint offset_x;
|
||||
gint offset_y;
|
||||
|
||||
g_return_if_fail (GIMP_IS_ITEM (item));
|
||||
g_return_if_fail (! gimp_item_is_attached (item));
|
||||
g_return_if_fail (! gimp_item_is_removed (item));
|
||||
g_return_if_fail (GIMP_IS_ITEM (replace));
|
||||
|
||||
gimp_object_set_name (GIMP_OBJECT (item), gimp_object_get_name (replace));
|
||||
|
||||
item->ID = gimp_item_get_ID (replace);
|
||||
g_hash_table_replace (gimp_item_get_image (item)->gimp->item_table,
|
||||
GINT_TO_POINTER (gimp_item_get_ID (item)),
|
||||
item);
|
||||
|
||||
/* Set image before tatoo so that the explicitly set tatoo overrides
|
||||
* the one implicitly set when setting the image
|
||||
*/
|
||||
gimp_item_set_image (item, gimp_item_get_image (replace));
|
||||
replace->image = NULL;
|
||||
|
||||
gimp_item_set_tattoo (item, gimp_item_get_tattoo (replace));
|
||||
gimp_item_set_tattoo (replace, 0);
|
||||
|
||||
item->parasites = replace->parasites;
|
||||
replace->parasites = NULL;
|
||||
|
||||
gimp_item_get_offset (replace, &offset_x, &offset_y);
|
||||
gimp_item_set_offset (item, offset_x, offset_y);
|
||||
|
||||
gimp_item_set_size (item,
|
||||
gimp_item_get_width (replace),
|
||||
gimp_item_get_height (replace));
|
||||
|
||||
gimp_item_set_visible (item, gimp_item_get_visible (replace), FALSE);
|
||||
gimp_item_set_linked (item, gimp_item_get_linked (replace), FALSE);
|
||||
gimp_item_set_lock_content (item, gimp_item_get_lock_content (replace), FALSE);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_item_parasite_attach (GimpItem *item,
|
||||
const GimpParasite *parasite)
|
||||
|
|
|
@ -286,6 +286,9 @@ GimpImage * gimp_item_get_image (const GimpItem *item);
|
|||
void gimp_item_set_image (GimpItem *item,
|
||||
GimpImage *image);
|
||||
|
||||
void gimp_item_replace_item (GimpItem *item,
|
||||
GimpItem *replace);
|
||||
|
||||
void gimp_item_parasite_attach (GimpItem *item,
|
||||
const GimpParasite *parasite);
|
||||
void gimp_item_parasite_detach (GimpItem *item,
|
||||
|
|
|
@ -175,49 +175,17 @@ gimp_text_layer_from_layer (GimpLayer *layer,
|
|||
GimpText *text)
|
||||
{
|
||||
GimpTextLayer *text_layer;
|
||||
GimpItem *item;
|
||||
GimpDrawable *drawable;
|
||||
gint offset_x;
|
||||
gint offset_y;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
|
||||
|
||||
text_layer = g_object_new (GIMP_TYPE_TEXT_LAYER, NULL);
|
||||
|
||||
item = GIMP_ITEM (text_layer);
|
||||
gimp_item_replace_item (GIMP_ITEM (text_layer), GIMP_ITEM (layer));
|
||||
|
||||
drawable = GIMP_DRAWABLE (text_layer);
|
||||
|
||||
gimp_object_set_name (GIMP_OBJECT (text_layer),
|
||||
gimp_object_get_name (layer));
|
||||
|
||||
item->ID = gimp_item_get_ID (GIMP_ITEM (layer));
|
||||
|
||||
/* Set image before tatoo so that the explicitly set tatoo overrides
|
||||
* the one implicitly set when setting the image
|
||||
*/
|
||||
gimp_item_set_image (item, gimp_item_get_image (GIMP_ITEM (layer)));
|
||||
gimp_item_set_tattoo (item, gimp_item_get_tattoo (GIMP_ITEM (layer)));
|
||||
|
||||
gimp_item_set_image (GIMP_ITEM (layer), NULL);
|
||||
g_hash_table_replace (gimp_item_get_image (item)->gimp->item_table,
|
||||
GINT_TO_POINTER (gimp_item_get_ID (item)),
|
||||
item);
|
||||
|
||||
item->parasites = GIMP_ITEM (layer)->parasites;
|
||||
GIMP_ITEM (layer)->parasites = NULL;
|
||||
|
||||
gimp_item_get_offset (GIMP_ITEM (layer), &offset_x, &offset_y);
|
||||
gimp_item_set_offset (item, offset_x, offset_y);
|
||||
|
||||
gimp_item_set_size (item,
|
||||
gimp_item_get_width (GIMP_ITEM (layer)),
|
||||
gimp_item_get_height (GIMP_ITEM (layer)));
|
||||
|
||||
gimp_item_set_visible (item, gimp_item_get_visible (GIMP_ITEM (layer)), FALSE);
|
||||
gimp_item_set_linked (item, gimp_item_get_linked (GIMP_ITEM (layer)), FALSE);
|
||||
gimp_item_set_lock_content (item, gimp_item_get_lock_content (GIMP_ITEM (layer)), FALSE);
|
||||
|
||||
drawable->private->tiles = gimp_drawable_get_tiles (GIMP_DRAWABLE (layer));
|
||||
GIMP_DRAWABLE (layer)->private->tiles = NULL;
|
||||
|
||||
|
|
Loading…
Reference in a new issue