2006-12-09 13:33:38 -08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-10-27 13:50:41 -08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
|
*
|
|
|
|
|
* GimpText
|
|
|
|
|
* Copyright (C) 2003 Sven Neumann <sven@gimp.org>
|
|
|
|
|
*
|
2009-01-17 14:28:01 -08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-10-27 13:50:41 -08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 14:28:01 -08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-10-27 13:50:41 -08:00
|
|
|
* (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
|
2018-07-11 14:47:19 -07:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-10-27 13:50:41 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2013-10-14 16:58:39 -07:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-09 13:24:04 -07:00
|
|
|
#include <gegl.h>
|
app: add gimp_drawable_{start,end,flush}_paint()
gimp_drawable_start/end_paint() are used to enter/exit paint mode
for a given drawable. While the drawable is in paint mode,
gimp_drawable_get_buffer() returns a copy of the real drawable's
buffer, referred to as the paint buffer, so that modifications to
the returned buffer don't immediately affect the projection, and
calls to gimp_drawable_update() queue the updated region, instead
of emitting an "update" signal.
gimp_drawable_flush_paint() can be called while the drawable is in
paint mode, in order to copy the updated region of the paint buffer
back to the drawable's real buffer, and to emit "update" signals
for the queued region.
We use these functions in the next commit, to move painting to a
separate thread in the paint tools.
2018-04-08 06:21:46 -07:00
|
|
|
#include <cairo.h>
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2012-02-07 05:06:12 -08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2004-09-27 05:30:04 -07:00
|
|
|
#include "text-types.h"
|
2003-10-27 13:50:41 -08:00
|
|
|
|
|
|
|
|
#include "core/gimp.h"
|
2009-02-03 15:57:11 -08:00
|
|
|
#include "core/gimpdrawable-private.h" /* eek */
|
2003-10-27 13:50:41 -08:00
|
|
|
#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"
|
|
|
|
|
|
|
|
|
|
|
2004-03-18 07:27:23 -08:00
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
TEXT_LAYER_XCF_NONE = 0,
|
|
|
|
|
TEXT_LAYER_XCF_DONT_AUTO_RENAME = 1 << 0,
|
|
|
|
|
TEXT_LAYER_XCF_MODIFIED = 1 << 1
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-10-27 13:50:41 -08:00
|
|
|
static GimpLayer * gimp_text_layer_from_layer (GimpLayer *layer,
|
|
|
|
|
GimpText *text);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
gimp_text_layer_xcf_load_hack (GimpLayer **layer)
|
|
|
|
|
{
|
2006-04-02 08:37:25 -07:00
|
|
|
const gchar *name;
|
|
|
|
|
GimpText *text = NULL;
|
|
|
|
|
const GimpParasite *parasite;
|
2003-10-27 13:50:41 -08:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2006-10-09 11:49:15 -07:00
|
|
|
gimp_message (gimp_item_get_image (GIMP_ITEM (*layer))->gimp, NULL,
|
|
|
|
|
GIMP_MESSAGE_ERROR,
|
|
|
|
|
_("Problems parsing the text parasite for layer '%s':\n"
|
|
|
|
|
"%s\n\n"
|
|
|
|
|
"Some text properties may be wrong. "
|
|
|
|
|
"Unless you want to edit the text layer, "
|
|
|
|
|
"you don't need to worry about this."),
|
2009-08-31 13:47:18 -07:00
|
|
|
gimp_object_get_name (*layer),
|
2006-10-09 11:49:15 -07:00
|
|
|
error->message);
|
|
|
|
|
g_clear_error (&error);
|
2003-10-27 13:50:41 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
2009-08-30 01:43:09 -07:00
|
|
|
/* let the text layer knows what parasite was used to create it */
|
2003-10-27 13:50:41 -08:00
|
|
|
GIMP_TEXT_LAYER (*layer)->text_parasite = name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (text != NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
gimp_text_layer_xcf_save_prepare (GimpTextLayer *layer)
|
|
|
|
|
{
|
2004-03-18 07:27:23 -08:00
|
|
|
GimpText *text;
|
2003-10-27 13:50:41 -08:00
|
|
|
|
|
|
|
|
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);
|
2004-03-18 07:27:23 -08:00
|
|
|
if (text)
|
|
|
|
|
{
|
|
|
|
|
GimpParasite *parasite = gimp_text_to_parasite (text);
|
|
|
|
|
|
2011-01-30 11:40:43 -08:00
|
|
|
/* Don't push an undo because the parasite only exists temporarily
|
|
|
|
|
* while the text layer is saved to XCF.
|
|
|
|
|
*/
|
|
|
|
|
gimp_item_parasite_attach (GIMP_ITEM (layer), parasite, FALSE);
|
2012-02-07 05:06:12 -08:00
|
|
|
|
|
|
|
|
gimp_parasite_free (parasite);
|
2004-03-18 07:27:23 -08:00
|
|
|
}
|
|
|
|
|
}
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2004-03-18 07:27:23 -08:00
|
|
|
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));
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2004-03-18 07:27:23 -08:00
|
|
|
g_object_set (text_layer,
|
|
|
|
|
"auto-rename", (flags & TEXT_LAYER_XCF_DONT_AUTO_RENAME) == 0,
|
|
|
|
|
"modified", (flags & TEXT_LAYER_XCF_MODIFIED) != 0,
|
|
|
|
|
NULL);
|
2003-10-27 13:50:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
GimpDrawable *drawable;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_LAYER (layer), NULL);
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
|
|
|
|
|
|
2011-02-01 05:15:46 -08:00
|
|
|
text_layer = g_object_new (GIMP_TYPE_TEXT_LAYER,
|
|
|
|
|
"image", gimp_item_get_image (GIMP_ITEM (layer)),
|
|
|
|
|
NULL);
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2011-01-30 10:26:32 -08:00
|
|
|
gimp_item_replace_item (GIMP_ITEM (text_layer), GIMP_ITEM (layer));
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2011-01-30 10:26:32 -08:00
|
|
|
drawable = GIMP_DRAWABLE (text_layer);
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2018-02-13 10:22:08 -08:00
|
|
|
gimp_drawable_steal_buffer (drawable, GIMP_DRAWABLE (layer));
|
2003-10-27 13:50:41 -08:00
|
|
|
|
2017-02-21 15:58:44 -08:00
|
|
|
gimp_layer_set_opacity (GIMP_LAYER (text_layer),
|
|
|
|
|
gimp_layer_get_opacity (layer), FALSE);
|
|
|
|
|
gimp_layer_set_mode (GIMP_LAYER (text_layer),
|
|
|
|
|
gimp_layer_get_mode (layer), FALSE);
|
|
|
|
|
gimp_layer_set_blend_space (GIMP_LAYER (text_layer),
|
|
|
|
|
gimp_layer_get_blend_space (layer), FALSE);
|
|
|
|
|
gimp_layer_set_composite_space (GIMP_LAYER (text_layer),
|
|
|
|
|
gimp_layer_get_composite_space (layer), FALSE);
|
|
|
|
|
gimp_layer_set_composite_mode (GIMP_LAYER (text_layer),
|
|
|
|
|
gimp_layer_get_composite_mode (layer), FALSE);
|
|
|
|
|
gimp_layer_set_lock_alpha (GIMP_LAYER (text_layer),
|
|
|
|
|
gimp_layer_get_lock_alpha (layer), FALSE);
|
2003-10-27 13:50:41 -08:00
|
|
|
|
|
|
|
|
gimp_text_layer_set_text (text_layer, text);
|
|
|
|
|
|
|
|
|
|
g_object_unref (text);
|
|
|
|
|
g_object_unref (layer);
|
|
|
|
|
|
|
|
|
|
return GIMP_LAYER (text_layer);
|
|
|
|
|
}
|