gimp/app/text/gimptextlayer.c

666 lines
21 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextLayer
* Copyright (C) 2002-2004 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 <string.h>
#include <glib-object.h>
#include <pango/pangoft2.h>
#include "text-types.h"
#include "base/pixel-region.h"
#include "base/tile-manager.h"
#include "paint-funcs/paint-funcs.h"
#include "config/gimpconfig.h"
#include "config/gimpconfig-params.h"
#include "config/gimpconfig-utils.h"
#include "core/gimp.h"
#include "core/gimpcontainer.h"
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "core/gimpimage-undo-push.h"
#include "core/gimpparasitelist.h"
#include "gimptext.h"
#include "gimptext-bitmap.h"
#include "gimptext-private.h"
#include "gimptextlayer.h"
#include "gimptextlayer-transform.h"
#include "gimptextlayout.h"
#include "gimptextlayout-render.h"
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_TEXT,
PROP_AUTO_RENAME,
PROP_MODIFIED
};
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);
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);
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_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
const gchar *undo_desc,
gdouble opacity,
GimpLayerModeEffects mode,
TileManager *src1_tiles,
gint x,
gint y);
static void gimp_text_layer_replace_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
const gchar *undo_desc,
gdouble opacity,
PixelRegion *maskPR,
gint x,
gint y);
static void gimp_text_layer_set_tiles (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
TileManager *tiles,
GimpImageType type,
gint offset_x,
gint offset_y);
static void gimp_text_layer_swap_pixels (GimpDrawable *drawable,
TileManager *tiles,
gboolean sparse,
gint x,
gint y,
gint width,
gint height);
static void gimp_text_layer_text_notify (GimpTextLayer *layer);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
GimpTextLayout *layout);
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)
{
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);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_text_layer_finalize;
object_class->get_property = gimp_text_layer_get_property;
object_class->set_property = gimp_text_layer_set_property;
gimp_object_class->get_memsize = gimp_text_layer_get_memsize;
More great icons from Jimmac: 2003-03-27 Michael Natterer <mitch@gimp.org> More great icons from Jimmac: * themes/Default/images/stock-channel-16.png * themes/Default/images/stock-channel-24.png * themes/Default/images/stock-channel-blue-16.png * themes/Default/images/stock-channel-blue-24.png * themes/Default/images/stock-channel-gray-16.png * themes/Default/images/stock-channel-gray-24.png * themes/Default/images/stock-channel-green-16.png * themes/Default/images/stock-channel-green-24.png * themes/Default/images/stock-channel-red-16.png * themes/Default/images/stock-channel-red-24.png: updated. * themes/Default/images/stock-channel-32.png * themes/Default/images/stock-channel-48.png * themes/Default/images/stock-channel-blue-32.png * themes/Default/images/stock-channel-blue-48.png * themes/Default/images/stock-channel-gray-32.png * themes/Default/images/stock-channel-gray-48.png * themes/Default/images/stock-channel-green-32.png * themes/Default/images/stock-channel-green-48.png * themes/Default/images/stock-channel-red-32.png * themes/Default/images/stock-channel-red-48.png * themes/Default/images/stock-grid-16.png * themes/Default/images/stock-image-32.png * themes/Default/images/stock-image-48.png * themes/Default/images/stock-layer-32.png * themes/Default/images/stock-layer-48.png * themes/Default/images/stock-list-16.png * themes/Default/images/stock-text-layer-16.png * themes/Default/images/stock-text-layer-24.png * themes/Default/images/stock-text-layer-32.png * themes/Default/images/stock-text-layer-48.png: new ones. * themes/Default/images/Makefile.am * libgimpwidgets/gimpstock.[ch]: added them to the stock system. * app/text/gimptextlayer.c: use GIMP_STOCK_TEXT_LAYER.
2003-03-27 12:29:54 +00:00
viewable_class->default_stock_id = "gimp-text-layer";
item_class->default_name = _("Text Layer");
item_class->duplicate = gimp_text_layer_duplicate;
item_class->rename = gimp_text_layer_rename;
#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
drawable_class->apply_region = gimp_text_layer_apply_region;
drawable_class->replace_region = gimp_text_layer_replace_region;
drawable_class->set_tiles = gimp_text_layer_set_tiles;
drawable_class->swap_pixels = gimp_text_layer_swap_pixels;
GIMP_CONFIG_INSTALL_PROP_OBJECT (object_class, PROP_TEXT,
"text", NULL,
GIMP_TYPE_TEXT,
0);
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);
}
static void
gimp_text_layer_init (GimpTextLayer *layer)
{
layer->text = NULL;
layer->text_parasite = NULL;
}
static void
gimp_text_layer_finalize (GObject *object)
{
GimpTextLayer *layer = GIMP_TEXT_LAYER (object);
if (layer->text)
{
g_object_unref (layer->text);
layer->text = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
}
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_TEXT:
g_value_set_object (value, text_layer->text);
break;
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_TEXT:
gimp_text_layer_set_text (text_layer, g_value_get_object (value));
break;
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;
}
}
static gint64
2003-08-25 10:45:16 +00:00
gimp_text_layer_get_memsize (GimpObject *object,
gint64 *gui_size)
{
GimpTextLayer *text_layer;
gint64 memsize = 0;
text_layer = GIMP_TEXT_LAYER (object);
if (text_layer->text)
2003-08-25 10:45:16 +00:00
memsize += gimp_object_get_memsize (GIMP_OBJECT (text_layer->text),
gui_size);
2003-08-25 10:45:16 +00:00
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object,
gui_size);
}
static GimpItem *
gimp_text_layer_duplicate (GimpItem *item,
GType new_type,
gboolean add_alpha)
{
GimpItem *new_item;
g_return_val_if_fail (g_type_is_a (new_type, GIMP_TYPE_DRAWABLE), NULL);
new_item = GIMP_ITEM_CLASS (parent_class)->duplicate (item, new_type,
add_alpha);
if (! GIMP_IS_TEXT_LAYER (new_item))
return new_item;
gimp_config_sync (GIMP_CONFIG (item), GIMP_CONFIG (new_item), 0);
return new_item;
}
Disallow to rename the layer mask. Instead, always name the mask "<layer 2004-02-01 Michael Natterer <mitch@gimp.org> Disallow to rename the layer mask. Instead, always name the mask "<layer name> mask". Fixes bug #133112 along with some other unreported ones. * app/core/gimpitem.[ch]: added a boolean return value indicating success to GimpItem::rename(). (gimp_item_real_rename): push an undo step only if the item is attached. * app/core/gimplayer.c (gimp_layer_rename): refuse renaming if the layer is a floating selection floated from a channel (renaming a layer's floating selection makes a new layer out of the floating selection). (gimp_layer_duplicate): use gimp_layer_add_mask() to attach the mask's duplicate. Fixes mask refcount brokenness for duplicated layer masks. (gimp_layer_name_changed): new function. Automatically renames the layer mask when the layer's name changes. * app/core/gimplayermask.c (gimp_layer_mask_rename): new function which refuses renaming. (gimp_layer_mask_name_changed): skip the unique name voodoo GimpItem does by not chaining up. (gimp_layer_mask_set_layer): change the mask's name whenever it is attached to a layer. * app/text/gimptextlayer.c (gimp_text_layer_rename): fiddle with text_layer->auto_rename only if renaming was successful. * app/widgets/gimpitemtreeview.c (gimp_item_tree_view_name_edited): restore the old name if renaming failed. * tools/pdbgen/pdb/drawable.pdb (set_name): return an execution error if renaming failed. * app/pdb/drawable_cmds.c: regenerated.
2004-02-01 20:38:26 +00:00
static gboolean
gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc)
{
Disallow to rename the layer mask. Instead, always name the mask "<layer 2004-02-01 Michael Natterer <mitch@gimp.org> Disallow to rename the layer mask. Instead, always name the mask "<layer name> mask". Fixes bug #133112 along with some other unreported ones. * app/core/gimpitem.[ch]: added a boolean return value indicating success to GimpItem::rename(). (gimp_item_real_rename): push an undo step only if the item is attached. * app/core/gimplayer.c (gimp_layer_rename): refuse renaming if the layer is a floating selection floated from a channel (renaming a layer's floating selection makes a new layer out of the floating selection). (gimp_layer_duplicate): use gimp_layer_add_mask() to attach the mask's duplicate. Fixes mask refcount brokenness for duplicated layer masks. (gimp_layer_name_changed): new function. Automatically renames the layer mask when the layer's name changes. * app/core/gimplayermask.c (gimp_layer_mask_rename): new function which refuses renaming. (gimp_layer_mask_name_changed): skip the unique name voodoo GimpItem does by not chaining up. (gimp_layer_mask_set_layer): change the mask's name whenever it is attached to a layer. * app/text/gimptextlayer.c (gimp_text_layer_rename): fiddle with text_layer->auto_rename only if renaming was successful. * app/widgets/gimpitemtreeview.c (gimp_item_tree_view_name_edited): restore the old name if renaming failed. * tools/pdbgen/pdb/drawable.pdb (set_name): return an execution error if renaming failed. * app/pdb/drawable_cmds.c: regenerated.
2004-02-01 20:38:26 +00:00
if (GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc))
{
g_object_set (item, "auto-rename", FALSE, NULL);
Disallow to rename the layer mask. Instead, always name the mask "<layer 2004-02-01 Michael Natterer <mitch@gimp.org> Disallow to rename the layer mask. Instead, always name the mask "<layer name> mask". Fixes bug #133112 along with some other unreported ones. * app/core/gimpitem.[ch]: added a boolean return value indicating success to GimpItem::rename(). (gimp_item_real_rename): push an undo step only if the item is attached. * app/core/gimplayer.c (gimp_layer_rename): refuse renaming if the layer is a floating selection floated from a channel (renaming a layer's floating selection makes a new layer out of the floating selection). (gimp_layer_duplicate): use gimp_layer_add_mask() to attach the mask's duplicate. Fixes mask refcount brokenness for duplicated layer masks. (gimp_layer_name_changed): new function. Automatically renames the layer mask when the layer's name changes. * app/core/gimplayermask.c (gimp_layer_mask_rename): new function which refuses renaming. (gimp_layer_mask_name_changed): skip the unique name voodoo GimpItem does by not chaining up. (gimp_layer_mask_set_layer): change the mask's name whenever it is attached to a layer. * app/text/gimptextlayer.c (gimp_text_layer_rename): fiddle with text_layer->auto_rename only if renaming was successful. * app/widgets/gimpitemtreeview.c (gimp_item_tree_view_name_edited): restore the old name if renaming failed. * tools/pdbgen/pdb/drawable.pdb (set_name): return an execution error if renaming failed. * app/pdb/drawable_cmds.c: regenerated.
2004-02-01 20:38:26 +00:00
return TRUE;
}
Disallow to rename the layer mask. Instead, always name the mask "<layer 2004-02-01 Michael Natterer <mitch@gimp.org> Disallow to rename the layer mask. Instead, always name the mask "<layer name> mask". Fixes bug #133112 along with some other unreported ones. * app/core/gimpitem.[ch]: added a boolean return value indicating success to GimpItem::rename(). (gimp_item_real_rename): push an undo step only if the item is attached. * app/core/gimplayer.c (gimp_layer_rename): refuse renaming if the layer is a floating selection floated from a channel (renaming a layer's floating selection makes a new layer out of the floating selection). (gimp_layer_duplicate): use gimp_layer_add_mask() to attach the mask's duplicate. Fixes mask refcount brokenness for duplicated layer masks. (gimp_layer_name_changed): new function. Automatically renames the layer mask when the layer's name changes. * app/core/gimplayermask.c (gimp_layer_mask_rename): new function which refuses renaming. (gimp_layer_mask_name_changed): skip the unique name voodoo GimpItem does by not chaining up. (gimp_layer_mask_set_layer): change the mask's name whenever it is attached to a layer. * app/text/gimptextlayer.c (gimp_text_layer_rename): fiddle with text_layer->auto_rename only if renaming was successful. * app/widgets/gimpitemtreeview.c (gimp_item_tree_view_name_edited): restore the old name if renaming failed. * tools/pdbgen/pdb/drawable.pdb (set_name): return an execution error if renaming failed. * app/pdb/drawable_cmds.c: regenerated.
2004-02-01 20:38:26 +00:00
return FALSE;
}
static void
gimp_text_layer_apply_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
const gchar *undo_desc,
gdouble opacity,
GimpLayerModeEffects mode,
TileManager *src1_tiles,
gint x,
gint y)
{
GIMP_DRAWABLE_CLASS (parent_class)->apply_region (drawable, src2PR,
push_undo, undo_desc,
opacity, mode,
src1_tiles, x, y);
g_object_set (drawable, "modified", TRUE, NULL);
}
static void
gimp_text_layer_replace_region (GimpDrawable *drawable,
PixelRegion *src2PR,
gboolean push_undo,
const gchar *undo_desc,
gdouble opacity,
PixelRegion *maskPR,
gint x,
gint y)
{
GIMP_DRAWABLE_CLASS (parent_class)->replace_region (drawable, src2PR,
push_undo, undo_desc,
opacity,
maskPR, x, y);
g_object_set (drawable, "modified", TRUE, NULL);
}
static void
gimp_text_layer_set_tiles (GimpDrawable *drawable,
gboolean push_undo,
const gchar *undo_desc,
TileManager *tiles,
GimpImageType type,
gint offset_x,
gint offset_y)
{
GIMP_DRAWABLE_CLASS (parent_class)->set_tiles (drawable,
push_undo, undo_desc,
tiles, type,
offset_x, offset_y);
g_object_set (drawable, "modified", TRUE, NULL);
}
static void
gimp_text_layer_swap_pixels (GimpDrawable *drawable,
TileManager *tiles,
gboolean sparse,
gint x,
gint y,
gint width,
gint height)
{
GIMP_DRAWABLE_CLASS (parent_class)->swap_pixels (drawable, tiles, sparse,
x, y, width, height);
g_object_set (drawable, "modified", TRUE, NULL);
}
/**
* 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
**/
GimpLayer *
gimp_text_layer_new (GimpImage *image,
GimpText *text)
{
GimpTextLayer *layer;
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
if (! text->text)
return NULL;
layer = g_object_new (GIMP_TYPE_TEXT_LAYER, NULL);
gimp_drawable_configure (GIMP_DRAWABLE (layer),
image,
0, 0, 0, 0,
gimp_image_base_type_with_alpha (image),
NULL);
gimp_text_layer_set_text (layer, text);
if (! gimp_text_layer_render (layer))
{
g_object_unref (layer);
return NULL;
}
return GIMP_LAYER (layer);
}
void
gimp_text_layer_set_text (GimpTextLayer *layer,
GimpText *text)
{
g_return_if_fail (GIMP_IS_TEXT_LAYER (layer));
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);
}
g_object_notify (G_OBJECT (layer), "text");
gimp_viewable_invalidate_preview (GIMP_VIEWABLE (layer));
}
GimpText *
gimp_text_layer_get_text (GimpTextLayer *layer)
{
g_return_val_if_fail (GIMP_IS_TEXT_LAYER (layer), NULL);
return layer->text;
}
void
gimp_text_layer_set (GimpTextLayer *layer,
const gchar *undo_desc,
const gchar *first_property_name,
...)
{
GimpImage *image;
GimpText *text;
va_list var_args;
g_return_if_fail (gimp_drawable_is_text_layer ((GimpDrawable *) layer));
text = gimp_text_layer_get_text (layer);
if (! text)
return;
image = gimp_item_get_image (GIMP_ITEM (layer));
/* If the layer contains a mask,
* gimp_text_layer_render() might have to resize it.
*/
if (GIMP_LAYER (layer)->mask)
gimp_image_undo_group_start (image, GIMP_UNDO_GROUP_TEXT, NULL);
gimp_image_undo_push_text_layer (image, undo_desc, layer);
va_start (var_args, first_property_name);
g_object_set_valist (G_OBJECT (text), first_property_name, var_args);
va_end (var_args);
if (GIMP_LAYER (layer)->mask)
gimp_image_undo_group_end (image);
}
/**
* gimp_text_layer_discard:
* @layer: a #GimpTextLayer
*
* Discards the text information. This makes @layer behave like a
* normal layer.
*/
void
gimp_text_layer_discard (GimpTextLayer *layer)
{
g_return_if_fail (GIMP_IS_TEXT_LAYER (layer));
if (! layer->text)
return;
gimp_image_undo_push_text_layer (gimp_item_get_image (GIMP_ITEM (layer)),
_("Discard Text Information"),
layer);
gimp_text_layer_set_text (layer, NULL);
}
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);
}
static void
gimp_text_layer_text_notify (GimpTextLayer *layer)
{
/* 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;
}
gimp_text_layer_render (layer);
}
static gboolean
gimp_text_layer_render (GimpTextLayer *layer)
{
GimpDrawable *drawable;
removed gimp_drawable_width,height(). 2003-05-08 Michael Natterer <mitch@gimp.org> * app/core/gimpdrawable.[ch]: removed gimp_drawable_width,height(). * app/core/gimpitem.[ch]: added gimp_item_width,height(). * app/core/gimpchannel.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-preview.c * app/core/gimpdrawable-transform.c * app/core/gimpimage-contiguous-region.c * app/core/gimpimage-crop.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-preview.c * app/core/gimpimage-projection.c * app/core/gimpimage-undo-push.c * app/core/gimpimage.c * app/core/gimpimagemap.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimplayermask.c * app/core/gimpscanconvert.c * app/display/gimpdisplay.c * app/display/gimpdisplayshell-dnd.c * app/display/gimpdisplayshell.c * app/gui/channels-commands.c * app/gui/layers-commands.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimppaintcore.c * app/paint/gimpsmudge.c * app/text/gimptextlayer.c * app/tools/gimpbezierselecttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcroptool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpfliptool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimphistogramtool.c * app/tools/gimpinktool.c * app/tools/gimprectselecttool.c * app/tools/gimptransformtool.c * app/widgets/gimpselectioneditor.c * app/widgets/gimptoolbox.c * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/selection.pdb: changed accordingly. * app/pdb/drawable_cmds.c * app/pdb/selection_cmds.c: regenerated.
2003-05-08 13:12:46 +00:00
GimpItem *item;
GimpImage *image;
GimpTextLayout *layout;
gint width;
gint height;
if (! layer->text)
return FALSE;
drawable = GIMP_DRAWABLE (layer);
removed gimp_drawable_width,height(). 2003-05-08 Michael Natterer <mitch@gimp.org> * app/core/gimpdrawable.[ch]: removed gimp_drawable_width,height(). * app/core/gimpitem.[ch]: added gimp_item_width,height(). * app/core/gimpchannel.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-preview.c * app/core/gimpdrawable-transform.c * app/core/gimpimage-contiguous-region.c * app/core/gimpimage-crop.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-preview.c * app/core/gimpimage-projection.c * app/core/gimpimage-undo-push.c * app/core/gimpimage.c * app/core/gimpimagemap.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimplayermask.c * app/core/gimpscanconvert.c * app/display/gimpdisplay.c * app/display/gimpdisplayshell-dnd.c * app/display/gimpdisplayshell.c * app/gui/channels-commands.c * app/gui/layers-commands.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimppaintcore.c * app/paint/gimpsmudge.c * app/text/gimptextlayer.c * app/tools/gimpbezierselecttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcroptool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpfliptool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimphistogramtool.c * app/tools/gimpinktool.c * app/tools/gimprectselecttool.c * app/tools/gimptransformtool.c * app/widgets/gimpselectioneditor.c * app/widgets/gimptoolbox.c * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/selection.pdb: changed accordingly. * app/pdb/drawable_cmds.c * app/pdb/selection_cmds.c: regenerated.
2003-05-08 13:12:46 +00:00
item = GIMP_ITEM (layer);
image = gimp_item_get_image (item);
if (gimp_container_num_children (image->gimp->fonts) == 0)
{
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 15:33:40 +00:00
g_message (_("Due to lack of any fonts, "
"text functionality is not available."));
return FALSE;
}
layout = gimp_text_layout_new (layer->text, image);
if (gimp_text_layout_get_size (layout, &width, &height) &&
(width != gimp_item_width (item) ||
height != gimp_item_height (item)))
{
TileManager *new_tiles;
item->width = width;
item->height = height;
new_tiles = tile_manager_new (width, height, drawable->bytes);
gimp_drawable_set_tiles (drawable, FALSE, NULL, new_tiles);
tile_manager_unref (new_tiles);
if (GIMP_LAYER (layer)->mask)
gimp_item_resize (GIMP_ITEM (GIMP_LAYER (layer)->mask),
width, height, 0, 0);
}
if (layer->auto_rename)
gimp_object_set_name_safe (GIMP_OBJECT (layer),
layer->text->text ?
layer->text->text : _("Empty Text Layer"));
gimp_text_layer_render_layout (layer, layout);
g_object_unref (layout);
g_object_set (drawable, "modified", FALSE, NULL);
return (width > 0 && height > 0);
}
static void
gimp_text_layer_render_layout (GimpTextLayer *layer,
GimpTextLayout *layout)
{
GimpDrawable *drawable = GIMP_DRAWABLE (layer);
GimpItem *item = GIMP_ITEM (layer);
TileManager *mask;
FT_Bitmap bitmap;
PixelRegion textPR;
PixelRegion maskPR;
gint i;
removed gimp_drawable_width,height(). 2003-05-08 Michael Natterer <mitch@gimp.org> * app/core/gimpdrawable.[ch]: removed gimp_drawable_width,height(). * app/core/gimpitem.[ch]: added gimp_item_width,height(). * app/core/gimpchannel.c * app/core/gimpdrawable-bucket-fill.c * app/core/gimpdrawable-offset.c * app/core/gimpdrawable-preview.c * app/core/gimpdrawable-transform.c * app/core/gimpimage-contiguous-region.c * app/core/gimpimage-crop.c * app/core/gimpimage-mask.c * app/core/gimpimage-merge.c * app/core/gimpimage-preview.c * app/core/gimpimage-projection.c * app/core/gimpimage-undo-push.c * app/core/gimpimage.c * app/core/gimpimagemap.c * app/core/gimplayer-floating-sel.c * app/core/gimplayer.c * app/core/gimplayermask.c * app/core/gimpscanconvert.c * app/display/gimpdisplay.c * app/display/gimpdisplayshell-dnd.c * app/display/gimpdisplayshell.c * app/gui/channels-commands.c * app/gui/layers-commands.c * app/paint/gimpclone.c * app/paint/gimpconvolve.c * app/paint/gimpdodgeburn.c * app/paint/gimppaintcore.c * app/paint/gimpsmudge.c * app/text/gimptextlayer.c * app/tools/gimpbezierselecttool.c * app/tools/gimpbucketfilltool.c * app/tools/gimpbycolorselecttool.c * app/tools/gimpclonetool.c * app/tools/gimpcroptool.c * app/tools/gimpeditselectiontool.c * app/tools/gimpfliptool.c * app/tools/gimpfuzzyselecttool.c * app/tools/gimphistogramtool.c * app/tools/gimpinktool.c * app/tools/gimprectselecttool.c * app/tools/gimptransformtool.c * app/widgets/gimpselectioneditor.c * app/widgets/gimptoolbox.c * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/selection.pdb: changed accordingly. * app/pdb/drawable_cmds.c * app/pdb/selection_cmds.c: regenerated.
2003-05-08 13:12:46 +00:00
Enabled skipping enum values for either the PDB or GType registration 2004-01-06 Michael Natterer <mitch@gimp.org> Enabled skipping enum values for either the PDB or GType registration (don't always skip both targets): * tools/gimp-mkenums: skip enum values only if there is a literal "skip" (don't match "pdb-skip"). * tools/pdbgen/enumgen.pl: skip only "pdb-skip" values, not "skip" ones. * app/base/base-enums.h * app/core/core-enums.h * app/paint/paint-enums.h * libgimpbase/gimpbaseenums.h: use the right "pdb-skip"/"skip" combination to skip enum values. Changed comments accordingly. Cleaned up the fill functions: * app/core/core-enums.[ch]: added GIMP_PATTERN_FILL enum value to the GimpFillType enum. Don't export GIMP_NO_FILL to the PDB because it's completely useless to export a NOP. * app/core/gimp-edit.c (gimp_edit_fill, gimp_edit_fill_internal): handle pattern fill requests. * app/core/gimpdrawable.[ch] (gimp_drawable_fill): added GimpPattern parameter and fill with it if it's non-NULL. (gimp_drawable_fill_by_type): handle pattern fill and pass the current pattern to gimp_drawable_fill(). * app/text/gimptextlayer.c: changed accordingly. * app/gui/edit-commands.c * app/gui/image-menu.c: use gimp_edit_fill() instead of gimp_drawable_bucket_fill() for FG, BG and pattern filling. * libgimp/gimpcompat.h * plug-ins/script-fu/siod-wrapper.c: removed NO_IMAGE_FILL compat enum value. It should have never been exported to the PDB. * app/pdb/drawable_cmds.c * app/pdb/edit_cmds.c * libgimp/gimpenums.h * plug-ins/pygimp/gimpenums.py * plug-ins/script-fu/script-fu-constants.c * tools/pdbgen/enums.pl: regenerated.
2004-01-06 14:02:08 +00:00
gimp_drawable_fill (drawable, &layer->text->color, NULL);
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);
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
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);
apply_mask_to_region (&textPR, &maskPR, OPAQUE_OPACITY);
2003-05-26 17:02:06 +00:00
tile_manager_unref (mask);
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-06 20:06:53 +00:00
/* no need to gimp_drawable_update() since gimp_drawable_fill()
* did that for us.
*/
}