2003-01-31 17:22:42 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-08-14 23:39:30 +08:00
|
|
|
* GimpTextLayer
|
2004-01-05 08:28:12 +08:00
|
|
|
* Copyright (C) 2002-2004 Sven Neumann <sven@gimp.org>
|
2003-01-31 17:22:42 +08:00
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
|
2003-02-01 09:44:35 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
#include <glib-object.h>
|
2003-07-21 05:23:01 +08:00
|
|
|
#include <pango/pangoft2.h>
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "text-types.h"
|
|
|
|
|
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/tile-manager.h"
|
|
|
|
|
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
2003-07-08 19:44:12 +08:00
|
|
|
#include "core/gimp.h"
|
2004-04-15 07:37:34 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2003-11-05 07:59:58 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "core/gimpimage.h"
|
2004-03-20 07:08:24 +08:00
|
|
|
#include "core/gimpimage-undo.h"
|
2004-01-05 08:28:12 +08:00
|
|
|
#include "core/gimpimage-undo-push.h"
|
2003-10-28 05:50:41 +08:00
|
|
|
#include "core/gimpparasitelist.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
|
|
|
|
#include "gimptext.h"
|
2003-07-21 05:23:01 +08:00
|
|
|
#include "gimptext-bitmap.h"
|
|
|
|
#include "gimptext-private.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "gimptextlayer.h"
|
2003-08-16 03:45:41 +08:00
|
|
|
#include "gimptextlayer-transform.h"
|
2003-02-05 16:29:12 +08:00
|
|
|
#include "gimptextlayout.h"
|
2003-07-07 02:43:58 +08:00
|
|
|
#include "gimptextlayout-render.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2003-04-01 01:47:00 +08:00
|
|
|
#include "gimp-intl.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
|
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_AUTO_RENAME,
|
|
|
|
PROP_MODIFIED
|
|
|
|
};
|
|
|
|
|
2004-03-13 23:07:33 +08:00
|
|
|
static void gimp_text_layer_class_init (GimpTextLayerClass *klass);
|
|
|
|
static void gimp_text_layer_init (GimpTextLayer *layer);
|
|
|
|
static void gimp_text_layer_finalize (GObject *object);
|
2004-03-18 23:27:23 +08:00
|
|
|
static void gimp_text_layer_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_text_layer_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2004-03-13 23:07:33 +08:00
|
|
|
|
|
|
|
static gint64 gimp_text_layer_get_memsize (GimpObject *object,
|
|
|
|
gint64 *gui_size);
|
|
|
|
|
|
|
|
static GimpItem * gimp_text_layer_duplicate (GimpItem *item,
|
|
|
|
GType new_type,
|
|
|
|
gboolean add_alpha);
|
|
|
|
static gboolean gimp_text_layer_rename (GimpItem *item,
|
|
|
|
const gchar *new_name,
|
|
|
|
const gchar *undo_desc);
|
|
|
|
|
|
|
|
static void gimp_text_layer_set_tiles (GimpDrawable *drawable,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
TileManager *tiles,
|
2004-03-16 03:34:35 +08:00
|
|
|
GimpImageType type,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y);
|
2004-04-01 22:51:58 +08:00
|
|
|
static void gimp_text_layer_push_undo (GimpDrawable *drawable,
|
|
|
|
const gchar *undo_desc,
|
2004-03-15 23:18:25 +08:00
|
|
|
TileManager *tiles,
|
|
|
|
gboolean sparse,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height);
|
2004-03-13 23:07:33 +08:00
|
|
|
|
|
|
|
static void gimp_text_layer_text_notify (GimpTextLayer *layer);
|
2004-03-15 02:48:00 +08:00
|
|
|
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
|
2004-03-13 23:07:33 +08:00
|
|
|
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
|
|
|
|
GimpTextLayout *layout);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
|
|
|
|
|
|
|
static GimpLayerClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_text_layer_get_type (void)
|
|
|
|
{
|
|
|
|
static GType layer_type = 0;
|
|
|
|
|
|
|
|
if (! layer_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo layer_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpTextLayerClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_text_layer_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpTextLayer),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_text_layer_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
layer_type = g_type_register_static (GIMP_TYPE_LAYER,
|
|
|
|
"GimpTextLayer",
|
|
|
|
&layer_info, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return layer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_layer_class_init (GimpTextLayerClass *klass)
|
|
|
|
{
|
2004-03-13 23:07:33 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpObjectClass *gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
|
|
|
GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
|
|
|
GimpItemClass *item_class = GIMP_ITEM_CLASS (klass);
|
|
|
|
GimpDrawableClass *drawable_class = GIMP_DRAWABLE_CLASS (klass);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2003-10-28 05:50:41 +08:00
|
|
|
object_class->finalize = gimp_text_layer_finalize;
|
2004-03-18 23:27:23 +08:00
|
|
|
object_class->get_property = gimp_text_layer_get_property;
|
|
|
|
object_class->set_property = gimp_text_layer_set_property;
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2003-02-27 02:08:26 +08:00
|
|
|
gimp_object_class->get_memsize = gimp_text_layer_get_memsize;
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2003-03-27 20:29:54 +08:00
|
|
|
viewable_class->default_stock_id = "gimp-text-layer";
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2003-02-27 02:08:26 +08:00
|
|
|
item_class->duplicate = gimp_text_layer_duplicate;
|
2003-04-01 01:47:00 +08:00
|
|
|
item_class->rename = gimp_text_layer_rename;
|
2003-08-16 03:45:41 +08:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
item_class->scale = gimp_text_layer_scale;
|
|
|
|
item_class->flip = gimp_text_layer_flip;
|
|
|
|
item_class->rotate = gimp_text_layer_rotate;
|
|
|
|
item_class->transform = gimp_text_layer_transform;
|
|
|
|
#endif
|
2004-03-13 23:07:33 +08:00
|
|
|
|
2004-04-15 22:41:36 +08:00
|
|
|
item_class->default_name = _("Text Layer");
|
|
|
|
item_class->rename_desc = _("Rename Text Layer");
|
|
|
|
item_class->translate_desc = _("Move Text Layer");
|
|
|
|
item_class->scale_desc = _("Scale Text Layer");
|
|
|
|
item_class->resize_desc = _("Resize Text Layer");
|
|
|
|
item_class->flip_desc = _("Flip Text Layer");
|
|
|
|
item_class->rotate_desc = _("Rotate Text Layer");
|
|
|
|
item_class->transform_desc = _("Transform Text Layer");
|
|
|
|
|
2004-03-13 23:07:33 +08:00
|
|
|
drawable_class->set_tiles = gimp_text_layer_set_tiles;
|
2004-04-01 22:51:58 +08:00
|
|
|
drawable_class->push_undo = gimp_text_layer_push_undo;
|
2004-03-18 23:27:23 +08:00
|
|
|
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_AUTO_RENAME,
|
|
|
|
"auto-rename", NULL,
|
|
|
|
TRUE,
|
|
|
|
0);
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_MODIFIED,
|
|
|
|
"modified", NULL,
|
|
|
|
FALSE,
|
|
|
|
0);
|
2003-01-31 17:22:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_layer_init (GimpTextLayer *layer)
|
|
|
|
{
|
2004-03-15 02:48:00 +08:00
|
|
|
layer->text = NULL;
|
|
|
|
layer->text_parasite = NULL;
|
2003-10-28 05:50:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_layer_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpTextLayer *layer = GIMP_TEXT_LAYER (object);
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
if (layer->text)
|
|
|
|
{
|
|
|
|
g_object_unref (layer->text);
|
|
|
|
layer->text = NULL;
|
|
|
|
}
|
|
|
|
|
2003-10-28 05:50:41 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2003-01-31 17:22:42 +08:00
|
|
|
}
|
|
|
|
|
2004-03-18 23:27:23 +08:00
|
|
|
static void
|
|
|
|
gimp_text_layer_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpTextLayer *text_layer = GIMP_TEXT_LAYER (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_AUTO_RENAME:
|
|
|
|
g_value_set_boolean (value, text_layer->auto_rename);
|
|
|
|
break;
|
|
|
|
case PROP_MODIFIED:
|
|
|
|
g_value_set_boolean (value, text_layer->modified);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_layer_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpTextLayer *text_layer = GIMP_TEXT_LAYER (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_AUTO_RENAME:
|
|
|
|
text_layer->auto_rename = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case PROP_MODIFIED:
|
|
|
|
text_layer->modified = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-11-17 01:51:36 +08:00
|
|
|
static gint64
|
2003-08-25 18:45:16 +08:00
|
|
|
gimp_text_layer_get_memsize (GimpObject *object,
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 *gui_size)
|
2003-02-11 21:52:47 +08:00
|
|
|
{
|
|
|
|
GimpTextLayer *text_layer;
|
2003-11-17 01:51:36 +08:00
|
|
|
gint64 memsize = 0;
|
2003-02-11 21:52:47 +08:00
|
|
|
|
|
|
|
text_layer = GIMP_TEXT_LAYER (object);
|
|
|
|
|
|
|
|
if (text_layer->text)
|
2003-08-25 18:45:16 +08:00
|
|
|
memsize += gimp_object_get_memsize (GIMP_OBJECT (text_layer->text),
|
|
|
|
gui_size);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2003-08-25 18:45:16 +08:00
|
|
|
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
|
|
|
|
gui_size);
|
2003-02-11 21:52:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static GimpItem *
|
|
|
|
gimp_text_layer_duplicate (GimpItem *item,
|
|
|
|
GType new_type,
|
|
|
|
gboolean add_alpha)
|
|
|
|
{
|
2004-03-21 04:18:57 +08:00
|
|
|
GimpTextLayer *layer;
|
2004-03-22 20:05:43 +08:00
|
|
|
GimpTextLayer *new_layer;
|
2004-03-21 04:18:57 +08:00
|
|
|
GimpItem *new_item;
|
2003-02-11 21:52:47 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
|
|
|
|
|
2004-03-21 04:18:57 +08:00
|
|
|
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item,
|
|
|
|
new_type,
|
2003-02-11 21:52:47 +08:00
|
|
|
add_alpha);
|
|
|
|
|
|
|
|
if (! GIMP_IS_TEXT_LAYER (new_item))
|
|
|
|
return new_item;
|
|
|
|
|
2004-03-22 20:05:43 +08:00
|
|
|
layer = GIMP_TEXT_LAYER (item);
|
|
|
|
new_layer = GIMP_TEXT_LAYER (new_item);
|
2004-03-21 04:18:57 +08:00
|
|
|
|
2005-04-07 18:05:54 +08:00
|
|
|
gimp_config_sync (G_OBJECT (layer), G_OBJECT (new_layer), 0);
|
2003-02-11 21:52:47 +08:00
|
|
|
|
2004-03-21 04:18:57 +08:00
|
|
|
if (layer->text)
|
|
|
|
{
|
|
|
|
GimpText *text = gimp_config_duplicate (GIMP_CONFIG (layer->text));
|
|
|
|
|
2004-03-22 20:05:43 +08:00
|
|
|
gimp_text_layer_set_text (new_layer, text);
|
2004-03-21 04:18:57 +08:00
|
|
|
|
|
|
|
g_object_unref (text);
|
|
|
|
}
|
|
|
|
|
2004-03-22 20:05:43 +08:00
|
|
|
/* this is just the parasite name, not a pointer to the parasite */
|
|
|
|
if (layer->text_parasite)
|
|
|
|
new_layer->text_parasite = layer->text_parasite;
|
|
|
|
|
2003-02-11 21:52:47 +08:00
|
|
|
return new_item;
|
|
|
|
}
|
|
|
|
|
2004-02-02 04:38:26 +08:00
|
|
|
static gboolean
|
2003-04-01 01:47:00 +08:00
|
|
|
gimp_text_layer_rename (GimpItem *item,
|
|
|
|
const gchar *new_name,
|
|
|
|
const gchar *undo_desc)
|
|
|
|
{
|
2004-02-02 04:38:26 +08:00
|
|
|
if (GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc))
|
|
|
|
{
|
2004-03-19 02:00:38 +08:00
|
|
|
g_object_set (item, "auto-rename", FALSE, NULL);
|
2004-02-02 04:38:26 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-08-14 23:39:30 +08:00
|
|
|
|
2004-02-02 04:38:26 +08:00
|
|
|
return FALSE;
|
2003-04-01 01:47:00 +08:00
|
|
|
}
|
|
|
|
|
2004-03-13 23:07:33 +08:00
|
|
|
static void
|
|
|
|
gimp_text_layer_set_tiles (GimpDrawable *drawable,
|
|
|
|
gboolean push_undo,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
TileManager *tiles,
|
2004-03-16 03:34:35 +08:00
|
|
|
GimpImageType type,
|
|
|
|
gint offset_x,
|
|
|
|
gint offset_y)
|
2004-03-13 23:07:33 +08:00
|
|
|
{
|
2004-04-01 22:51:58 +08:00
|
|
|
GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
|
|
|
|
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
if (push_undo && ! layer->modified)
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_DRAWABLE_MOD,
|
|
|
|
undo_desc);
|
|
|
|
|
2004-03-13 23:07:33 +08:00
|
|
|
GIMP_DRAWABLE_CLASS (parent_class)->set_tiles (drawable,
|
|
|
|
push_undo, undo_desc,
|
2004-03-16 03:34:35 +08:00
|
|
|
tiles, type,
|
|
|
|
offset_x, offset_y);
|
2004-04-01 22:51:58 +08:00
|
|
|
|
|
|
|
if (push_undo && ! layer->modified)
|
|
|
|
{
|
|
|
|
gimp_image_undo_push_text_layer_modified (gimage, NULL, layer);
|
|
|
|
|
|
|
|
g_object_set (drawable, "modified", TRUE, NULL);
|
|
|
|
|
|
|
|
gimp_image_undo_group_end (gimage);
|
|
|
|
}
|
2004-03-13 23:07:33 +08:00
|
|
|
}
|
|
|
|
|
2004-03-15 23:18:25 +08:00
|
|
|
static void
|
2004-04-01 22:51:58 +08:00
|
|
|
gimp_text_layer_push_undo (GimpDrawable *drawable,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
TileManager *tiles,
|
|
|
|
gboolean sparse,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gint width,
|
|
|
|
gint height)
|
2004-03-15 23:18:25 +08:00
|
|
|
{
|
2004-04-01 22:51:58 +08:00
|
|
|
GimpTextLayer *layer = GIMP_TEXT_LAYER (drawable);
|
|
|
|
GimpImage *gimage = gimp_item_get_image (GIMP_ITEM (layer));
|
|
|
|
|
|
|
|
if (! layer->modified)
|
|
|
|
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_DRAWABLE, undo_desc);
|
|
|
|
|
|
|
|
GIMP_DRAWABLE_CLASS (parent_class)->push_undo (drawable, undo_desc,
|
|
|
|
tiles, sparse,
|
|
|
|
x, y, width, height);
|
|
|
|
|
|
|
|
if (! layer->modified)
|
|
|
|
{
|
|
|
|
gimp_image_undo_push_text_layer_modified (gimage, NULL, layer);
|
|
|
|
|
|
|
|
g_object_set (drawable, "modified", TRUE, NULL);
|
|
|
|
|
|
|
|
gimp_image_undo_group_end (gimage);
|
|
|
|
}
|
2004-03-15 23:18:25 +08:00
|
|
|
}
|
|
|
|
|
2004-03-13 23:07:33 +08:00
|
|
|
|
2003-08-16 03:45:41 +08:00
|
|
|
/**
|
|
|
|
* gimp_text_layer_new:
|
|
|
|
* @image: the #GimpImage the layer should belong to
|
|
|
|
* @text: a #GimpText object
|
|
|
|
*
|
|
|
|
* Creates a new text layer.
|
|
|
|
*
|
|
|
|
* Return value: a new #GimpTextLayer or %NULL in case of a problem
|
|
|
|
**/
|
2003-01-31 17:22:42 +08:00
|
|
|
GimpLayer *
|
2003-01-31 21:36:27 +08:00
|
|
|
gimp_text_layer_new (GimpImage *image,
|
2003-08-16 03:45:41 +08:00
|
|
|
GimpText *text)
|
2003-01-31 17:22:42 +08:00
|
|
|
{
|
2003-06-24 21:58:34 +08:00
|
|
|
GimpTextLayer *layer;
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-01-31 21:36:27 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
2003-01-31 17:22:42 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-10-28 05:50:41 +08:00
|
|
|
if (! text->text)
|
2003-01-31 17:22:42 +08:00
|
|
|
return NULL;
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
layer = g_object_new (GIMP_TYPE_TEXT_LAYER, NULL);
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-02-01 02:57:10 +08:00
|
|
|
gimp_drawable_configure (GIMP_DRAWABLE (layer),
|
|
|
|
image,
|
2004-04-03 20:03:27 +08:00
|
|
|
0, 0, 1, 1,
|
2003-02-01 02:57:10 +08:00
|
|
|
gimp_image_base_type_with_alpha (image),
|
|
|
|
NULL);
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-06-24 21:58:34 +08:00
|
|
|
gimp_text_layer_set_text (layer, text);
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
if (! gimp_text_layer_render (layer))
|
2003-01-31 17:22:42 +08:00
|
|
|
{
|
|
|
|
g_object_unref (layer);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-06-24 21:58:34 +08:00
|
|
|
return GIMP_LAYER (layer);
|
|
|
|
}
|
2003-09-12 03:52:29 +08:00
|
|
|
|
2003-10-28 05:50:41 +08:00
|
|
|
void
|
2003-06-24 21:58:34 +08:00
|
|
|
gimp_text_layer_set_text (GimpTextLayer *layer,
|
|
|
|
GimpText *text)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_TEXT_LAYER (layer));
|
2004-01-05 08:28:12 +08:00
|
|
|
g_return_if_fail (text == NULL || GIMP_IS_TEXT (text));
|
|
|
|
|
|
|
|
if (layer->text == text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (layer->text)
|
|
|
|
{
|
|
|
|
g_signal_handlers_disconnect_by_func (layer->text,
|
|
|
|
G_CALLBACK (gimp_text_layer_text_notify),
|
|
|
|
layer);
|
|
|
|
|
|
|
|
g_object_unref (layer->text);
|
|
|
|
layer->text = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (text)
|
|
|
|
{
|
|
|
|
layer->text = g_object_ref (text);
|
|
|
|
|
|
|
|
g_signal_connect_object (text, "notify",
|
|
|
|
G_CALLBACK (gimp_text_layer_text_notify),
|
|
|
|
layer, G_CONNECT_SWAPPED);
|
|
|
|
}
|
2003-06-24 21:58:34 +08:00
|
|
|
|
2004-01-05 08:28:12 +08:00
|
|
|
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer));
|
2003-01-31 17:22:42 +08:00
|
|
|
}
|
|
|
|
|
2003-02-01 00:37:03 +08:00
|
|
|
GimpText *
|
|
|
|
gimp_text_layer_get_text (GimpTextLayer *layer)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_TEXT_LAYER (layer), NULL);
|
2003-08-14 23:39:30 +08:00
|
|
|
|
2003-02-01 00:37:03 +08:00
|
|
|
return layer->text;
|
|
|
|
}
|
|
|
|
|
2004-03-20 06:12:18 +08:00
|
|
|
void
|
|
|
|
gimp_text_layer_set (GimpTextLayer *layer,
|
|
|
|
const gchar *undo_desc,
|
|
|
|
const gchar *first_property_name,
|
|
|
|
...)
|
2004-03-13 23:07:33 +08:00
|
|
|
{
|
2004-03-20 07:08:24 +08:00
|
|
|
GimpImage *image;
|
|
|
|
GimpText *text;
|
|
|
|
va_list var_args;
|
2004-03-20 06:12:18 +08:00
|
|
|
|
|
|
|
g_return_if_fail (gimp_drawable_is_text_layer ((GimpDrawable *) layer));
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)));
|
2004-03-20 06:12:18 +08:00
|
|
|
|
|
|
|
text = gimp_text_layer_get_text (layer);
|
|
|
|
if (! text)
|
|
|
|
return;
|
|
|
|
|
2004-03-20 07:08:24 +08:00
|
|
|
image = gimp_item_get_image (GIMP_ITEM (layer));
|
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TEXT, undo_desc);
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (layer));
|
|
|
|
|
|
|
|
if (layer->modified)
|
|
|
|
{
|
|
|
|
gimp_image_undo_push_text_layer_modified (image, NULL, layer);
|
|
|
|
gimp_image_undo_push_drawable_mod (image, NULL, GIMP_DRAWABLE (layer));
|
|
|
|
}
|
2004-03-20 07:08:24 +08:00
|
|
|
|
2004-03-21 01:21:48 +08:00
|
|
|
gimp_image_undo_push_text_layer (image, undo_desc, layer, NULL);
|
2004-03-13 23:07:33 +08:00
|
|
|
|
2004-03-20 06:12:18 +08:00
|
|
|
va_start (var_args, first_property_name);
|
|
|
|
|
|
|
|
g_object_set_valist (G_OBJECT (text), first_property_name, var_args);
|
|
|
|
|
|
|
|
va_end (var_args);
|
2004-03-20 07:08:24 +08:00
|
|
|
|
2004-04-01 22:51:58 +08:00
|
|
|
g_object_set (layer, "modified", FALSE, NULL);
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (layer));
|
|
|
|
|
|
|
|
gimp_image_undo_group_end (image);
|
2004-03-20 06:12:18 +08:00
|
|
|
}
|
2004-03-13 23:07:33 +08:00
|
|
|
|
2004-01-05 08:28:12 +08:00
|
|
|
/**
|
|
|
|
* gimp_text_layer_discard:
|
|
|
|
* @layer: a #GimpTextLayer
|
|
|
|
*
|
|
|
|
* Discards the text information. This makes @layer behave like a
|
|
|
|
* normal layer.
|
|
|
|
*/
|
2003-08-16 03:45:41 +08:00
|
|
|
void
|
2004-01-05 08:28:12 +08:00
|
|
|
gimp_text_layer_discard (GimpTextLayer *layer)
|
2003-08-16 03:45:41 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_TEXT_LAYER (layer));
|
2004-11-16 21:41:55 +08:00
|
|
|
g_return_if_fail (gimp_item_is_attached (GIMP_ITEM (layer)));
|
2003-08-16 03:45:41 +08:00
|
|
|
|
2004-01-05 08:28:12 +08:00
|
|
|
if (! layer->text)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gimp_image_undo_push_text_layer (gimp_item_get_image (GIMP_ITEM (layer)),
|
|
|
|
_("Discard Text Information"),
|
2004-03-21 01:21:48 +08:00
|
|
|
layer, NULL);
|
2004-01-05 08:28:12 +08:00
|
|
|
|
|
|
|
gimp_text_layer_set_text (layer, NULL);
|
|
|
|
}
|
|
|
|
|
2004-03-20 06:12:18 +08:00
|
|
|
gboolean
|
|
|
|
gimp_drawable_is_text_layer (GimpDrawable *drawable)
|
|
|
|
{
|
|
|
|
return (GIMP_IS_TEXT_LAYER (drawable) &&
|
|
|
|
GIMP_TEXT_LAYER (drawable)->text &&
|
|
|
|
GIMP_TEXT_LAYER (drawable)->modified == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-06 02:23:58 +08:00
|
|
|
static void
|
2003-10-28 05:50:41 +08:00
|
|
|
gimp_text_layer_text_notify (GimpTextLayer *layer)
|
2003-02-06 02:23:58 +08:00
|
|
|
{
|
2003-10-28 05:50:41 +08:00
|
|
|
/* If the text layer was created from a parasite, it's time to
|
|
|
|
* remove that parasite now.
|
|
|
|
*/
|
|
|
|
if (layer->text_parasite)
|
|
|
|
{
|
|
|
|
gimp_parasite_list_remove (GIMP_ITEM (layer)->parasites,
|
|
|
|
layer->text_parasite);
|
|
|
|
layer->text_parasite = NULL;
|
|
|
|
}
|
|
|
|
|
2004-03-15 02:48:00 +08:00
|
|
|
gimp_text_layer_render (layer);
|
2003-02-06 02:23:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-15 02:48:00 +08:00
|
|
|
gimp_text_layer_render (GimpTextLayer *layer)
|
2003-01-31 17:22:42 +08:00
|
|
|
{
|
2003-02-01 02:57:10 +08:00
|
|
|
GimpDrawable *drawable;
|
2003-05-08 21:12:46 +08:00
|
|
|
GimpItem *item;
|
|
|
|
GimpImage *image;
|
2003-02-05 16:29:12 +08:00
|
|
|
GimpTextLayout *layout;
|
|
|
|
gint width;
|
|
|
|
gint height;
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2004-01-05 08:28:12 +08:00
|
|
|
if (! layer->text)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-02-08 01:01:38 +08:00
|
|
|
drawable = GIMP_DRAWABLE (layer);
|
2003-05-08 21:12:46 +08:00
|
|
|
item = GIMP_ITEM (layer);
|
|
|
|
image = gimp_item_get_image (item);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2005-04-13 05:36:54 +08:00
|
|
|
if (gimp_container_is_empty (image->gimp->fonts))
|
2003-11-05 07:59:58 +08:00
|
|
|
{
|
2003-11-14 23:33:40 +08:00
|
|
|
g_message (_("Due to lack of any fonts, "
|
2003-11-05 07:59:58 +08:00
|
|
|
"text functionality is not available."));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-05 16:29:12 +08:00
|
|
|
layout = gimp_text_layout_new (layer->text, image);
|
|
|
|
|
2004-03-22 20:05:43 +08:00
|
|
|
g_object_freeze_notify (G_OBJECT (drawable));
|
|
|
|
|
2004-03-16 04:05:31 +08:00
|
|
|
if (gimp_text_layout_get_size (layout, &width, &height) &&
|
|
|
|
(width != gimp_item_width (item) ||
|
|
|
|
height != gimp_item_height (item)))
|
2003-01-31 21:36:27 +08:00
|
|
|
{
|
2004-03-20 20:38:15 +08:00
|
|
|
TileManager *new_tiles = tile_manager_new (width, height,
|
|
|
|
drawable->bytes);
|
2004-03-15 23:18:25 +08:00
|
|
|
|
2004-03-16 04:05:31 +08:00
|
|
|
gimp_drawable_set_tiles (drawable, FALSE, NULL, new_tiles);
|
2004-03-20 20:38:15 +08:00
|
|
|
|
2004-03-16 04:05:31 +08:00
|
|
|
tile_manager_unref (new_tiles);
|
2004-03-20 03:26:18 +08:00
|
|
|
|
|
|
|
if (GIMP_LAYER (layer)->mask)
|
2004-04-15 07:37:34 +08:00
|
|
|
{
|
|
|
|
static GimpContext *unused_eek = NULL;
|
|
|
|
|
|
|
|
if (! unused_eek)
|
|
|
|
unused_eek = gimp_context_new (image->gimp, "eek", NULL);
|
|
|
|
|
|
|
|
gimp_item_resize (GIMP_ITEM (GIMP_LAYER (layer)->mask), unused_eek,
|
|
|
|
width, height, 0, 0);
|
|
|
|
}
|
2003-01-31 21:36:27 +08:00
|
|
|
}
|
2003-02-01 02:57:10 +08:00
|
|
|
|
2003-04-01 01:47:00 +08:00
|
|
|
if (layer->auto_rename)
|
|
|
|
gimp_object_set_name_safe (GIMP_OBJECT (layer),
|
|
|
|
layer->text->text ?
|
|
|
|
layer->text->text : _("Empty Text Layer"));
|
2003-01-31 21:36:27 +08:00
|
|
|
|
2003-02-05 16:29:12 +08:00
|
|
|
gimp_text_layer_render_layout (layer, layout);
|
2003-01-31 21:36:27 +08:00
|
|
|
g_object_unref (layout);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2004-03-22 20:05:43 +08:00
|
|
|
g_object_thaw_notify (G_OBJECT (drawable));
|
|
|
|
|
2003-02-08 01:01:38 +08:00
|
|
|
return (width > 0 && height > 0);
|
2003-01-31 17:22:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-02-05 16:29:12 +08:00
|
|
|
gimp_text_layer_render_layout (GimpTextLayer *layer,
|
|
|
|
GimpTextLayout *layout)
|
2003-01-31 17:22:42 +08:00
|
|
|
{
|
2004-03-15 23:18:25 +08:00
|
|
|
GimpDrawable *drawable = GIMP_DRAWABLE (layer);
|
|
|
|
GimpItem *item = GIMP_ITEM (layer);
|
2003-01-31 17:22:42 +08:00
|
|
|
TileManager *mask;
|
2003-07-21 05:23:01 +08:00
|
|
|
FT_Bitmap bitmap;
|
2003-01-31 17:22:42 +08:00
|
|
|
PixelRegion textPR;
|
|
|
|
PixelRegion maskPR;
|
2003-07-21 05:23:01 +08:00
|
|
|
gint i;
|
2003-05-08 21:12:46 +08:00
|
|
|
|
2004-01-06 22:02:08 +08:00
|
|
|
gimp_drawable_fill (drawable, &layer->text->color, NULL);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2003-07-21 05:23:01 +08:00
|
|
|
bitmap.width = gimp_item_width (item);
|
|
|
|
bitmap.rows = gimp_item_height (item);
|
|
|
|
bitmap.pitch = bitmap.width;
|
|
|
|
if (bitmap.pitch & 3)
|
|
|
|
bitmap.pitch += 4 - (bitmap.pitch & 3);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2003-07-21 05:23:01 +08:00
|
|
|
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
2003-07-21 05:23:01 +08:00
|
|
|
gimp_text_layout_render (layout,
|
|
|
|
(GimpTextRenderFunc) gimp_text_render_bitmap,
|
|
|
|
&bitmap);
|
|
|
|
|
|
|
|
mask = tile_manager_new (bitmap.width, bitmap.rows, 1);
|
|
|
|
pixel_region_init (&maskPR, mask, 0, 0, bitmap.width, bitmap.rows, TRUE);
|
|
|
|
|
|
|
|
for (i = 0; i < bitmap.rows; i++)
|
|
|
|
pixel_region_set_row (&maskPR,
|
|
|
|
0, i, bitmap.width,
|
|
|
|
bitmap.buffer + i * bitmap.pitch);
|
|
|
|
|
|
|
|
g_free (bitmap.buffer);
|
|
|
|
|
|
|
|
pixel_region_init (&textPR, drawable->tiles,
|
|
|
|
0, 0, bitmap.width, bitmap.rows, TRUE);
|
|
|
|
pixel_region_init (&maskPR, mask,
|
|
|
|
0, 0, bitmap.width, bitmap.rows, FALSE);
|
2003-01-31 17:22:42 +08:00
|
|
|
|
|
|
|
apply_mask_to_region (&textPR, &maskPR, OPAQUE_OPACITY);
|
2003-08-14 23:39:30 +08:00
|
|
|
|
2003-05-27 01:02:06 +08:00
|
|
|
tile_manager_unref (mask);
|
2003-02-08 01:01:38 +08:00
|
|
|
|
To optimize duplicate and/or wrong image updates away, introduced new
2003-09-06 Michael Natterer <mitch@gimp.org>
To optimize duplicate and/or wrong image updates away, introduced
new policy that a child object must never explicitly update or
invalidate its parent object (just like the GUI is not updated
explicitly by the core):
* app/core/gimpdrawable.[ch]: added new signal
GimpDrawable::update(). Never update or invalidate the image when
the drawable is updated or invalidated.
(gimp_drawable_set_visible): don't gimp_drawable_update() the
drawable since its pixels have not changed.
* app/core/gimpimage.[ch]: connect to the "add" and "remove"
signals of the layers and channels containers. Also connect to the
"update" and "visibility_changed" signals of all drawables in
these containers (optimizes away updates issued by drawables which
are not yet added to the image and updates of the selection
mask). Also, don't propagate updates to the image if the emitting
drawable is invisible (optimizes away updates issued by invisible
drawables).
(gimp_image_add_layer,channel)
(gimp_image_remove_layer,channel): don't update the image since
that's done by our "add" and "remove" handlers now.
(gimp_image_position_layer,channel): update just the image, not
the drawable since its pixels have not changed.
(gimp_image_real_colormap_changed)
(gimp_image_set_component_visible): always call
gimp_image_update() *and* gimp_viewable_invalidate_preview() to
get everything updated, since update and invalidate of images are
not connected.
* app/core/gimpimage-undo-push.c (undo_pop_layer,channel): don't
update the drawable since (a) its pixels don't change and (b) the
image updates itself upon adding/removing now.
(undo_pop_layer_mod): replaced gimp_image_update() by
gimp_drawable_update() (just for consistency with other similar
functions).
* app/core/gimplayer.c: connect to "update" of the layer mask and
issue updates on the layer if the mask update has any effect on
the projection.
(gimp_layer_create_mask): don't set the mask's offsets here since
they may be different when we later add the mask to the layer.
* app/core/gimplayermask.c (gimp_layer_mask_set_layer): set the
mask offsets here instead.
* app/core/gimpchannel.c (gimp_channel_translate): update the
channel even if push_undo == FALSE.
* app/paint/gimppaintcore.c (gimp_paint_core_finish)
* app/tools/gimpinktool.c (ink_finish): invalidate both the
drawable and the image preview since invalidating the drawable
doesn't invalidate the image any more.
* app/text/gimptextlayer.c (gimp_text_layer_render_now): also
update the new extents of the text layer, not only the old one.
(gimp_text_layer_render_layout): don't update the drawable since
gimp_drawable_fill() already updated it.
2003-09-07 04:06:53 +08:00
|
|
|
/* no need to gimp_drawable_update() since gimp_drawable_fill()
|
|
|
|
* did that for us.
|
|
|
|
*/
|
2003-01-31 17:22:42 +08:00
|
|
|
}
|