gimp/app/text/gimptextlayer-xcf.c

229 lines
6.5 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <glib-object.h>
#include "text/text-types.h"
#include "core/gimp.h"
#include "core/gimpimage.h"
#include "core/gimpparasitelist.h"
#include "gimptext.h"
#include "gimptext-parasite.h"
#include "gimptextlayer.h"
#include "gimptextlayer-xcf.h"
#include "gimp-intl.h"
enum
{
TEXT_LAYER_XCF_NONE = 0,
TEXT_LAYER_XCF_DONT_AUTO_RENAME = 1 << 0,
TEXT_LAYER_XCF_MODIFIED = 1 << 1
};
static GimpLayer * gimp_text_layer_from_layer (GimpLayer *layer,
GimpText *text);
gboolean
gimp_text_layer_xcf_load_hack (GimpLayer **layer)
{
const gchar *name;
GimpText *text = NULL;
GimpParasite *parasite;
g_return_val_if_fail (layer != NULL, FALSE);
g_return_val_if_fail (GIMP_IS_LAYER (*layer), FALSE);
name = gimp_text_parasite_name ();
parasite = gimp_item_parasite_find (GIMP_ITEM (*layer), name);
if (parasite)
{
GError *error = NULL;
text = gimp_text_from_parasite (parasite, &error);
if (error)
{
libgimpwidgets/gimpquerybox.c configure the labels in the message dialog 2003-11-14 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpquerybox.c * app/widgets/gimpwidgets-utils.c: configure the labels in the message dialog and the query boxes to do automatic word wrapping to be HIG compliant. * app/app_procs.c * app/batch.c * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-path.c * app/config/gimpconfig-utils.c * app/config/gimpconfigwriter.c * app/config/gimpscanner.c * app/core/gimpbrush.c * app/core/gimpbrushgenerated.c * app/core/gimpbrushpipe.c * app/core/gimpdatafactory.c * app/core/gimpgradient.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpselection.c * app/display/gimpdisplayshell.c * app/file/file-utils.c * app/gui/brush-select.c * app/gui/dialogs-commands.c * app/gui/drawable-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-select.c * app/gui/gui.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/palette-select.c * app/gui/palettes-commands.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/select-commands.c * app/gui/stroke-dialog.c * app/gui/tool-options-menu.c * app/gui/vectors-commands.c * app/gui/view-commands.c * app/plug-in/plug-in-message.c * app/plug-in/plug-in.c * app/plug-in/plug-ins.c * app/text/gimptextlayer-xcf.c * app/text/gimptextlayer.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimptransformtool.c * app/vectors/gimpvectors-export.c * app/widgets/gimpdatafactoryview.c * app/widgets/gimphelp.c * app/widgets/gimptemplateview.c * app/widgets/gimptooloptionseditor.c * app/xcf/xcf.c * tools/pdbgen/pdb/image.pdb: removed explicit newlines from messages. Reduced number of translatable strings by making many file error messages the same. Quote single words and filenames with 'foo', not "foo". Replaced some more "drawable" by "layer". General message cleanup and consistency check. * app/pdb/image_cmds.c: regenerated.
2003-11-14 23:33:40 +08:00
g_message (_("Problems parsing the text parasite for layer '%s':\n"
"%s\n\n"
libgimpwidgets/gimpquerybox.c configure the labels in the message dialog 2003-11-14 Michael Natterer <mitch@gimp.org> * libgimpwidgets/gimpquerybox.c * app/widgets/gimpwidgets-utils.c: configure the labels in the message dialog and the query boxes to do automatic word wrapping to be HIG compliant. * app/app_procs.c * app/batch.c * app/config/gimpconfig-deserialize.c * app/config/gimpconfig-path.c * app/config/gimpconfig-utils.c * app/config/gimpconfigwriter.c * app/config/gimpscanner.c * app/core/gimpbrush.c * app/core/gimpbrushgenerated.c * app/core/gimpbrushpipe.c * app/core/gimpdatafactory.c * app/core/gimpgradient.c * app/core/gimpimage-merge.c * app/core/gimpimage.c * app/core/gimpimagefile.c * app/core/gimplayer-floating-sel.c * app/core/gimppalette.c * app/core/gimppattern.c * app/core/gimpselection.c * app/display/gimpdisplayshell.c * app/file/file-utils.c * app/gui/brush-select.c * app/gui/dialogs-commands.c * app/gui/drawable-commands.c * app/gui/edit-commands.c * app/gui/file-commands.c * app/gui/file-new-dialog.c * app/gui/font-select.c * app/gui/gradient-select.c * app/gui/gui.c * app/gui/image-commands.c * app/gui/layers-commands.c * app/gui/palette-select.c * app/gui/palettes-commands.c * app/gui/pattern-select.c * app/gui/preferences-dialog.c * app/gui/select-commands.c * app/gui/stroke-dialog.c * app/gui/tool-options-menu.c * app/gui/vectors-commands.c * app/gui/view-commands.c * app/plug-in/plug-in-message.c * app/plug-in/plug-in.c * app/plug-in/plug-ins.c * app/text/gimptextlayer-xcf.c * app/text/gimptextlayer.c * app/tools/gimpcurvestool.c * app/tools/gimphuesaturationtool.c * app/tools/gimplevelstool.c * app/tools/gimptransformtool.c * app/vectors/gimpvectors-export.c * app/widgets/gimpdatafactoryview.c * app/widgets/gimphelp.c * app/widgets/gimptemplateview.c * app/widgets/gimptooloptionseditor.c * app/xcf/xcf.c * tools/pdbgen/pdb/image.pdb: removed explicit newlines from messages. Reduced number of translatable strings by making many file error messages the same. Quote single words and filenames with 'foo', not "foo". Replaced some more "drawable" by "layer". General message cleanup and consistency check. * app/pdb/image_cmds.c: regenerated.
2003-11-14 23:33:40 +08:00
"Some text properties may be wrong. "
"Unless you want to edit the text layer, "
"you don't need to worry about this."),
gimp_object_get_name (GIMP_OBJECT (*layer)),
error->message);
g_error_free (error);
}
}
else
{
name = gimp_text_gdyntext_parasite_name ();
parasite = gimp_item_parasite_find (GIMP_ITEM (*layer), name);
if (parasite)
text = gimp_text_from_gdyntext_parasite (parasite);
}
if (text)
{
*layer = gimp_text_layer_from_layer (*layer, text);
/* let the text layer know what parasite was used to create it */
GIMP_TEXT_LAYER (*layer)->text_parasite = name;
}
return (text != NULL);
}
void
gimp_text_layer_xcf_save_prepare (GimpTextLayer *layer)
{
GimpText *text;
g_return_if_fail (GIMP_IS_TEXT_LAYER (layer));
/* If the layer has a text parasite already, it wasn't changed and we
* can simply save the original parasite back which is still attached.
*/
if (layer->text_parasite)
return;
text = gimp_text_layer_get_text (layer);
if (text)
{
GimpParasite *parasite = gimp_text_to_parasite (text);
gimp_parasite_list_add (GIMP_ITEM (layer)->parasites, parasite);
}
}
guint32
gimp_text_layer_get_xcf_flags (GimpTextLayer *text_layer)
{
guint flags = 0;
g_return_val_if_fail (GIMP_IS_TEXT_LAYER (text_layer), 0);
if (! text_layer->auto_rename)
flags |= TEXT_LAYER_XCF_DONT_AUTO_RENAME;
if (text_layer->modified)
flags |= TEXT_LAYER_XCF_MODIFIED;
return flags;
}
void
gimp_text_layer_set_xcf_flags (GimpTextLayer *text_layer,
guint32 flags)
{
g_return_if_fail (GIMP_IS_TEXT_LAYER (text_layer));
g_object_set (text_layer,
"auto-rename", (flags & TEXT_LAYER_XCF_DONT_AUTO_RENAME) == 0,
"modified", (flags & TEXT_LAYER_XCF_MODIFIED) != 0,
NULL);
}
/**
* gimp_text_layer_from_layer:
* @layer: a #GimpLayer object
* @text: a #GimpText object
*
* Converts a standard #GimpLayer and a #GimpText object into a
* #GimpTextLayer. The new text layer takes ownership of the @text and
* @layer objects. The @layer object is rendered unusable by this
* function. Don't even try to use if afterwards!
*
* This is a gross hack that is needed in order to load text layers
* from XCF files in a backwards-compatible way. Please don't use it
* for anything else!
*
* Return value: a newly allocated #GimpTextLayer object
**/
static GimpLayer *
gimp_text_layer_from_layer (GimpLayer *layer,
GimpText *text)
{
GimpTextLayer *text_layer;
GimpItem *item;
GimpDrawable *drawable;
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);
drawable = GIMP_DRAWABLE (text_layer);
gimp_object_set_name (GIMP_OBJECT (text_layer),
gimp_object_get_name (GIMP_OBJECT (layer)));
item->ID = gimp_item_get_ID (GIMP_ITEM (layer));
item->tattoo = gimp_item_get_tattoo (GIMP_ITEM (layer));
item->gimage = gimp_item_get_image (GIMP_ITEM (layer));
gimp_item_set_image (GIMP_ITEM (layer), NULL);
g_hash_table_replace (item->gimage->gimp->item_table,
GINT_TO_POINTER (item->ID),
item);
item->parasites = GIMP_ITEM (layer)->parasites;
GIMP_ITEM (layer)->parasites = NULL;
item->width = gimp_item_width (GIMP_ITEM (layer));
item->height = gimp_item_height (GIMP_ITEM (layer));
gimp_item_offsets (GIMP_ITEM (layer), &item->offset_x, &item->offset_y);
item->visible = gimp_item_get_visible (GIMP_ITEM (layer));
item->linked = gimp_item_get_linked (GIMP_ITEM (layer));
drawable->tiles = GIMP_DRAWABLE (layer)->tiles;
GIMP_DRAWABLE (layer)->tiles = NULL;
drawable->bytes = gimp_drawable_bytes (GIMP_DRAWABLE (layer));
drawable->type = gimp_drawable_type (GIMP_DRAWABLE (layer));
drawable->has_alpha = gimp_drawable_has_alpha (GIMP_DRAWABLE (layer));
GIMP_LAYER (text_layer)->opacity = gimp_layer_get_opacity (layer);
GIMP_LAYER (text_layer)->mode = gimp_layer_get_mode (layer);
GIMP_LAYER (text_layer)->preserve_trans = gimp_layer_get_preserve_trans (layer);
gimp_text_layer_set_text (text_layer, text);
g_object_unref (text);
g_object_unref (layer);
return GIMP_LAYER (text_layer);
}