1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
2000-12-17 05:37:03 +08:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2002-10-13 16:45:00 +08:00
|
|
|
#include <stdio.h>
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
2002-10-15 06:07:39 +08:00
|
|
|
#include <string.h>
|
2002-10-12 01:42:26 +08:00
|
|
|
#include <errno.h>
|
1999-05-05 06:18:13 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
#include <gtk/gtk.h>
|
2001-08-11 23:35:16 +08:00
|
|
|
#include <pango/pangoft2.h>
|
2000-01-19 07:12:26 +08:00
|
|
|
|
2001-01-25 06:36:18 +08:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpimage.h"
|
2002-10-11 01:07:46 +08:00
|
|
|
#include "core/gimpimage-mask.h"
|
2002-10-09 22:00:26 +08:00
|
|
|
#include "core/gimpimage-text.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimplayer.h"
|
2002-10-11 01:07:46 +08:00
|
|
|
#include "core/gimplayer-floating-sel.h"
|
|
|
|
#include "core/gimptext.h"
|
2001-11-21 07:00:47 +08:00
|
|
|
#include "core/gimptoolinfo.h"
|
2001-05-09 10:32:03 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
#include "widgets/gimpfontselection.h"
|
2002-10-09 23:42:38 +08:00
|
|
|
#include "widgets/gimpwidgets-utils.h"
|
2001-05-26 00:04:54 +08:00
|
|
|
|
2001-09-26 07:23:09 +08:00
|
|
|
#include "display/gimpdisplay.h"
|
|
|
|
|
|
|
|
#include "gimpeditselectiontool.h"
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimptexttool.h"
|
2001-01-23 21:01:48 +08:00
|
|
|
#include "tool_options.h"
|
|
|
|
|
2001-11-23 07:46:13 +08:00
|
|
|
#include "gimprc.h"
|
2002-10-11 01:07:46 +08:00
|
|
|
#include "undo.h"
|
2001-11-23 07:46:13 +08:00
|
|
|
|
Lots of ii8n stuff here and some additions to the de.po. Applied
Wed Oct 14 17:46:15 EDT 1998 Adrian Likins <adrian@gimp.org>
* app/*, po/de.po, de/POTFILES.in, libgimp/gimpintl.h:
Lots of ii8n stuff here and some additions to the de.po.
Applied gimp-egger-981005-1 ,gimp-egger-981006-1,
gimp-egger-981007-1, gimp-egger-981008-1,
gimp-egger-981009-1.patch, gimp-egger-981010-1.patch
* plug-in/guillotine/guillotine.c: added the coordinates
of the split images from the original image to the title.
ie foo.jpg (0,0) for the image in the topleft.
* plug-in/script-fu/scripts/neon-logo.scm,
perspective-shadow.scm, predator.scm,rendermap.scm,
ripply-anim.scm, select_to_image.scm,swirltile.scm,
xach-effect.scm: updated scripts to use new script-fu stuff
wooo boy! a big un!
in testing this, it looks like some of the po files are busted.
but the code stuff seems okay.
-adrian
1998-10-15 07:23:52 +08:00
|
|
|
#include "libgimp/gimpintl.h"
|
|
|
|
|
2001-08-12 01:24:47 +08:00
|
|
|
|
|
|
|
#define DEFAULT_FONT "sans Normal"
|
2002-08-27 22:35:18 +08:00
|
|
|
#define DEFAULT_FONT_SIZE 18
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-08-06 00:08:19 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
/* the text tool structures */
|
|
|
|
|
|
|
|
typedef struct _TextOptions TextOptions;
|
1999-12-18 00:37:50 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
struct _TextOptions
|
|
|
|
{
|
2001-07-18 04:50:01 +08:00
|
|
|
GimpToolOptions tool_options;
|
2001-08-12 01:24:47 +08:00
|
|
|
|
2001-08-14 21:49:21 +08:00
|
|
|
gchar *fontname_d;
|
2001-08-11 23:35:16 +08:00
|
|
|
GtkWidget *font_selection;
|
2001-08-12 01:24:47 +08:00
|
|
|
|
|
|
|
gdouble size;
|
|
|
|
gdouble size_d;
|
|
|
|
GtkObject *size_w;
|
|
|
|
|
|
|
|
gdouble border;
|
|
|
|
gdouble border_d;
|
|
|
|
GtkObject *border_w;
|
|
|
|
|
|
|
|
GimpUnit unit;
|
|
|
|
GimpUnit unit_d;
|
|
|
|
GtkWidget *unit_w;
|
2002-10-09 23:42:38 +08:00
|
|
|
|
|
|
|
gdouble line_spacing;
|
|
|
|
gdouble line_spacing_d;
|
|
|
|
GtkObject *line_spacing_w;
|
|
|
|
|
|
|
|
gdouble letter_spacing;
|
|
|
|
gdouble letter_spacing_d;
|
|
|
|
GtkObject *letter_spacing_w;
|
1999-04-09 06:25:54 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2002-10-12 01:42:26 +08:00
|
|
|
static void gimp_text_tool_class_init (GimpTextToolClass *klass);
|
|
|
|
static void gimp_text_tool_init (GimpTextTool *tool);
|
|
|
|
|
|
|
|
static void gimp_text_tool_finalize (GObject *object);
|
|
|
|
|
|
|
|
static void text_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void text_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void text_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
static void text_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp);
|
|
|
|
|
|
|
|
static void text_tool_render (GimpTextTool *text_tool);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
static GimpToolOptions * text_tool_options_new (GimpToolInfo *tool_info);
|
|
|
|
static void text_tool_options_reset (GimpToolOptions *tool_options);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2002-10-12 01:42:26 +08:00
|
|
|
static void text_tool_editor (GimpTextTool *text_tool);
|
|
|
|
static void text_tool_editor_ok (GimpTextTool *text_tool);
|
|
|
|
static void text_tool_editor_load (GtkWidget *widget,
|
|
|
|
GimpTextTool *text_tool);
|
|
|
|
static void text_tool_editor_load_ok (GimpTextTool *text_tool);
|
|
|
|
static gboolean text_tool_load_file (GtkTextBuffer *buffer,
|
|
|
|
const gchar *filename);
|
|
|
|
static void text_tool_editor_clear (GtkWidget *widget,
|
|
|
|
GimpTextTool *text_tool);
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* local variables */
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
static GimpToolClass *parent_class = NULL;
|
1998-10-07 16:59:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
/* public functions */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
void
|
2002-03-29 11:50:29 +08:00
|
|
|
gimp_text_tool_register (GimpToolRegisterCallback callback,
|
2002-05-03 19:31:08 +08:00
|
|
|
gpointer data)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2002-03-29 11:50:29 +08:00
|
|
|
(* callback) (GIMP_TYPE_TEXT_TOOL,
|
2001-11-21 07:00:47 +08:00
|
|
|
text_tool_options_new,
|
|
|
|
FALSE,
|
2002-03-21 20:17:17 +08:00
|
|
|
"gimp-text-tool",
|
2002-11-01 07:06:09 +08:00
|
|
|
_("Text"),
|
2001-11-21 07:00:47 +08:00
|
|
|
_("Add text to the image"),
|
|
|
|
N_("/Tools/Text"), "T",
|
|
|
|
NULL, "tools/text.html",
|
2002-03-29 11:50:29 +08:00
|
|
|
GIMP_STOCK_TOOL_TEXT,
|
2002-05-03 19:31:08 +08:00
|
|
|
data);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
GType
|
2001-02-25 05:06:48 +08:00
|
|
|
gimp_text_tool_get_type (void)
|
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
static GType tool_type = 0;
|
2001-02-25 05:06:48 +08:00
|
|
|
|
|
|
|
if (! tool_type)
|
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
static const GTypeInfo tool_info =
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
sizeof (GimpTextToolClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_text_tool_class_init,
|
2001-08-14 22:53:55 +08:00
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2001-02-25 05:06:48 +08:00
|
|
|
sizeof (GimpTextTool),
|
2001-08-11 23:35:16 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gimp_text_tool_init,
|
2001-02-25 05:06:48 +08:00
|
|
|
};
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_TOOL,
|
|
|
|
"GimpTextTool",
|
2001-08-11 23:35:16 +08:00
|
|
|
&tool_info, 0);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
static void
|
2001-02-25 05:06:48 +08:00
|
|
|
gimp_text_tool_class_init (GimpTextToolClass *klass)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
GObjectClass *object_class;
|
|
|
|
GimpToolClass *tool_class;
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
tool_class = GIMP_TOOL_CLASS (klass);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
2001-08-14 22:53:55 +08:00
|
|
|
object_class->finalize = gimp_text_tool_finalize;
|
2001-02-25 05:06:48 +08:00
|
|
|
|
|
|
|
tool_class->control = text_tool_control;
|
|
|
|
tool_class->button_press = text_tool_button_press;
|
|
|
|
tool_class->button_release = text_tool_button_release;
|
|
|
|
tool_class->cursor_update = text_tool_cursor_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_tool_init (GimpTextTool *text_tool)
|
|
|
|
{
|
2002-10-11 02:37:12 +08:00
|
|
|
GimpTool *tool = GIMP_TOOL (text_tool);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-11-23 07:46:13 +08:00
|
|
|
text_tool->pango_context = pango_ft2_get_context (gimprc.monitor_xres,
|
|
|
|
gimprc.monitor_yres);
|
2001-08-11 23:35:16 +08:00
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
text_tool->buffer = gtk_text_buffer_new (NULL);
|
|
|
|
gtk_text_buffer_set_text (text_tool->buffer, "Eeek, it's The GIMP", -1);
|
|
|
|
|
2002-05-03 05:03:27 +08:00
|
|
|
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
|
|
|
|
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TEXT_TOOL_CURSOR);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 23:35:16 +08:00
|
|
|
gimp_text_tool_finalize (GObject *object)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2002-10-11 02:37:12 +08:00
|
|
|
GimpTextTool *text_tool = GIMP_TEXT_TOOL (object);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
if (text_tool->pango_context)
|
|
|
|
{
|
|
|
|
g_object_unref (text_tool->pango_context);
|
|
|
|
text_tool->pango_context = NULL;
|
|
|
|
}
|
2002-10-11 02:37:12 +08:00
|
|
|
if (text_tool->buffer)
|
|
|
|
{
|
|
|
|
g_object_unref (text_tool->buffer);
|
|
|
|
text_tool->buffer = NULL;
|
|
|
|
}
|
2001-08-11 23:35:16 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
1998-10-07 16:59:11 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2002-02-19 01:00:09 +08:00
|
|
|
text_tool_control (GimpTool *tool,
|
|
|
|
GimpToolAction action,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-25 05:06:48 +08:00
|
|
|
switch (action)
|
|
|
|
{
|
|
|
|
case PAUSE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RESUME:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HALT:
|
2002-10-12 01:42:26 +08:00
|
|
|
if (GIMP_TEXT_TOOL (tool)->editor)
|
|
|
|
gtk_widget_destroy (GIMP_TEXT_TOOL (tool)->editor);
|
2001-02-25 05:06:48 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->control (tool, action, gdisp);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
text_tool_button_press (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
|
|
|
GimpTextTool *text_tool;
|
2001-08-12 02:41:47 +08:00
|
|
|
GimpLayer *layer;
|
2001-02-25 05:06:48 +08:00
|
|
|
|
|
|
|
text_tool = GIMP_TEXT_TOOL (tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
text_tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-05-03 19:31:08 +08:00
|
|
|
gimp_tool_control_activate (tool->control);
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-09 03:14:51 +08:00
|
|
|
text_tool->click_x = coords->x;
|
|
|
|
text_tool->click_y = coords->y;
|
2001-08-12 02:41:47 +08:00
|
|
|
|
|
|
|
if ((layer = gimp_image_pick_correlate_layer (gdisp->gimage,
|
|
|
|
text_tool->click_x,
|
|
|
|
text_tool->click_y)))
|
2001-08-14 21:49:21 +08:00
|
|
|
/* if there is a floating selection, and this aint it, use the move tool */
|
2001-08-12 02:41:47 +08:00
|
|
|
if (gimp_layer_is_floating_sel (layer))
|
|
|
|
{
|
2001-11-09 03:14:51 +08:00
|
|
|
init_edit_selection (tool, gdisp, coords, EDIT_LAYER_TRANSLATE);
|
2001-08-12 02:41:47 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-10-12 01:42:26 +08:00
|
|
|
text_tool_editor (text_tool);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
text_tool_button_release (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
guint32 time,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-10-11 02:37:12 +08:00
|
|
|
/* sets paused_count to 0 -- is this ok? */
|
|
|
|
gimp_tool_control_halt (tool->control);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-11-09 03:14:51 +08:00
|
|
|
text_tool_cursor_update (GimpTool *tool,
|
|
|
|
GimpCoords *coords,
|
|
|
|
GdkModifierType state,
|
|
|
|
GimpDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-02-05 01:43:01 +08:00
|
|
|
GimpLayer *layer;
|
2001-08-12 02:41:47 +08:00
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
layer = gimp_image_pick_correlate_layer (gdisp->gimage,
|
|
|
|
coords->x, coords->y);
|
2001-08-12 02:41:47 +08:00
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
gimp_tool_control_set_cursor_modifier (tool->control,
|
|
|
|
(layer &&
|
|
|
|
gimp_layer_is_floating_sel (layer)) ?
|
|
|
|
GIMP_CURSOR_MODIFIER_MOVE :
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
2002-02-05 01:43:01 +08:00
|
|
|
|
|
|
|
GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, gdisp);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 23:35:16 +08:00
|
|
|
text_tool_render (GimpTextTool *text_tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2002-10-11 02:37:12 +08:00
|
|
|
TextOptions *options;
|
|
|
|
GimpImage *gimage;
|
|
|
|
GimpText *text;
|
|
|
|
GimpLayer *layer;
|
|
|
|
const gchar *font;
|
|
|
|
gchar *str;
|
|
|
|
GtkTextIter start_iter;
|
|
|
|
GtkTextIter end_iter;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
options = (TextOptions *) GIMP_TOOL (text_tool)->tool_info->tool_options;
|
2002-10-11 01:07:46 +08:00
|
|
|
gimage = text_tool->gdisp->gimage;
|
2001-11-21 07:00:47 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
font = gimp_font_selection_get_fontname (GIMP_FONT_SELECTION (options->font_selection));
|
2001-08-14 21:49:21 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
if (!font)
|
2001-08-14 21:49:21 +08:00
|
|
|
{
|
2002-09-11 22:21:30 +08:00
|
|
|
g_message (_("No font chosen or font invalid."));
|
2001-08-14 21:49:21 +08:00
|
|
|
return;
|
|
|
|
}
|
2002-10-11 01:07:46 +08:00
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
gtk_text_buffer_get_bounds (text_tool->buffer, &start_iter, &end_iter);
|
|
|
|
str = gtk_text_buffer_get_text (text_tool->buffer,
|
|
|
|
&start_iter, &end_iter, FALSE);
|
|
|
|
|
|
|
|
if (!str)
|
|
|
|
return;
|
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
text = GIMP_TEXT (g_object_new (GIMP_TYPE_TEXT,
|
2002-10-11 02:37:12 +08:00
|
|
|
"text", str,
|
2002-10-11 01:07:46 +08:00
|
|
|
"font", font,
|
|
|
|
"size", options->size,
|
|
|
|
"border", options->border,
|
|
|
|
"unit", options->unit,
|
|
|
|
"letter-spacing", options->letter_spacing,
|
|
|
|
"line-spacing", options->line_spacing,
|
|
|
|
NULL));
|
2002-10-11 02:37:12 +08:00
|
|
|
g_free (str);
|
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
layer = gimp_image_text_render (gimage, text);
|
2001-08-14 21:49:21 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
g_object_unref (text);
|
|
|
|
|
|
|
|
if (!layer)
|
|
|
|
return;
|
2001-08-14 21:49:21 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
undo_push_group_start (gimage, TEXT_UNDO_GROUP);
|
1998-02-22 18:45:12 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
GIMP_DRAWABLE (layer)->offset_x = text_tool->click_x;
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y = text_tool->click_y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
/* If there is a selection mask clear it--
|
|
|
|
* this might not always be desired, but in general,
|
|
|
|
* it seems like the correct behavior.
|
|
|
|
*/
|
|
|
|
if (! gimp_image_mask_is_empty (gimage))
|
|
|
|
gimp_image_mask_clear (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
floating_sel_attach (layer, gimp_image_active_drawable (gimage));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2002-10-11 01:07:46 +08:00
|
|
|
undo_push_group_end (gimage);
|
|
|
|
|
|
|
|
gimp_image_flush (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
/* tool options stuff */
|
|
|
|
|
|
|
|
static GimpToolOptions *
|
|
|
|
text_tool_options_new (GimpToolInfo *tool_info)
|
|
|
|
{
|
|
|
|
TextOptions *options;
|
|
|
|
PangoContext *pango_context;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *table;
|
|
|
|
GtkWidget *size_spinbutton;
|
|
|
|
GtkWidget *border_spinbutton;
|
2002-10-09 23:42:38 +08:00
|
|
|
GtkWidget *spin_button;
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
options = g_new0 (TextOptions, 1);
|
|
|
|
|
|
|
|
tool_options_init ((GimpToolOptions *) options, tool_info);
|
|
|
|
|
|
|
|
((GimpToolOptions *) options)->reset_func = text_tool_options_reset;
|
|
|
|
|
2002-10-09 23:42:38 +08:00
|
|
|
options->fontname_d = DEFAULT_FONT;
|
|
|
|
options->border = options->border_d = 0;
|
|
|
|
options->size = options->size_d = DEFAULT_FONT_SIZE;
|
|
|
|
options->unit = options->unit_d = GIMP_UNIT_PIXEL;
|
|
|
|
options->line_spacing = options->line_spacing_d = 1.0;
|
|
|
|
options->letter_spacing = options->letter_spacing_d = 1.0;
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
/* the main vbox */
|
|
|
|
vbox = options->tool_options.main_vbox;
|
|
|
|
|
2002-10-09 23:42:38 +08:00
|
|
|
table = gtk_table_new (4, 5, FALSE);
|
2002-03-11 02:31:42 +08:00
|
|
|
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
|
|
|
|
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
|
2002-10-09 23:42:38 +08:00
|
|
|
gtk_table_set_row_spacing (GTK_TABLE (table), 3, 12);
|
2002-03-11 02:31:42 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (table), FALSE, FALSE, 0);
|
2002-10-09 23:42:38 +08:00
|
|
|
gtk_widget_show (table);
|
2002-03-11 02:31:42 +08:00
|
|
|
|
2001-11-23 07:46:13 +08:00
|
|
|
pango_context = pango_ft2_get_context (gimprc.monitor_xres,
|
|
|
|
gimprc.monitor_yres);
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
options->font_selection = gimp_font_selection_new (pango_context);
|
|
|
|
|
|
|
|
g_object_unref (G_OBJECT (pango_context));
|
|
|
|
|
|
|
|
gimp_font_selection_set_fontname
|
|
|
|
(GIMP_FONT_SELECTION (options->font_selection), DEFAULT_FONT);
|
|
|
|
|
2002-03-11 02:31:42 +08:00
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
|
|
|
|
_("Font:"), 1.0, 0.5,
|
|
|
|
options->font_selection, 2, FALSE);
|
|
|
|
|
|
|
|
options->size_w = gimp_scale_entry_new (GTK_TABLE (table), 0, 1,
|
2002-10-09 23:42:38 +08:00
|
|
|
_("_Size:"), -1, 5,
|
2002-04-28 22:35:01 +08:00
|
|
|
options->size,
|
2002-03-11 02:31:42 +08:00
|
|
|
1.0, 256.0, 1.0, 50.0, 1,
|
|
|
|
FALSE, 1e-5, 32767.0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
size_spinbutton = GIMP_SCALE_ENTRY_SPINBUTTON (options->size_w);
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
g_signal_connect (G_OBJECT (options->size_w), "value_changed",
|
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&options->size);
|
2002-03-11 02:31:42 +08:00
|
|
|
|
|
|
|
options->border_w = gimp_scale_entry_new (GTK_TABLE (table), 0, 2,
|
2002-10-09 23:42:38 +08:00
|
|
|
_("_Border:"), -1, 5,
|
2002-04-28 22:35:01 +08:00
|
|
|
options->border,
|
2002-03-11 02:31:42 +08:00
|
|
|
0.0, 100.0, 1.0, 50.0, 1,
|
|
|
|
FALSE, 0.0, 32767.0,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
border_spinbutton = GIMP_SCALE_ENTRY_SPINBUTTON (options->border_w);
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
g_signal_connect (G_OBJECT (options->border_w), "value_changed",
|
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&options->border);
|
|
|
|
|
2002-04-28 22:35:01 +08:00
|
|
|
options->unit_w = gimp_unit_menu_new ("%a", options->unit,
|
|
|
|
TRUE, FALSE, TRUE);
|
2002-03-11 02:31:42 +08:00
|
|
|
|
|
|
|
gimp_table_attach_aligned (GTK_TABLE (table), 0, 3,
|
|
|
|
_("Unit:"), 1.0, 0.5,
|
|
|
|
options->unit_w, 2, TRUE);
|
|
|
|
|
2001-11-21 07:00:47 +08:00
|
|
|
g_object_set_data (G_OBJECT (options->unit_w), "set_digits",
|
|
|
|
size_spinbutton);
|
|
|
|
g_object_set_data (G_OBJECT (size_spinbutton), "set_digits",
|
|
|
|
border_spinbutton);
|
2002-03-11 02:31:42 +08:00
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (options->unit_w), "unit_changed",
|
|
|
|
G_CALLBACK (gimp_unit_menu_update),
|
|
|
|
&options->unit);
|
2001-11-21 07:00:47 +08:00
|
|
|
|
2002-10-09 23:42:38 +08:00
|
|
|
spin_button = gimp_spin_button_new (&options->letter_spacing_w,
|
|
|
|
options->letter_spacing,
|
|
|
|
0.0, 64.0, 0.1, 1.0, 0.0, 1.0, 2);
|
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (spin_button), 5);
|
|
|
|
gimp_table_attach_stock (GTK_TABLE (table), 0, 4,
|
|
|
|
GIMP_STOCK_LETTER_SPACING, spin_button);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (options->letter_spacing_w), "value_changed",
|
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&options->letter_spacing);
|
|
|
|
|
|
|
|
spin_button = gimp_spin_button_new (&options->line_spacing_w,
|
|
|
|
options->line_spacing,
|
|
|
|
0.0, 64.0, 0.1, 1.0, 0.0, 1.0, 2);
|
|
|
|
gtk_entry_set_width_chars (GTK_ENTRY (spin_button), 5);
|
|
|
|
gimp_table_attach_stock (GTK_TABLE (table), 0, 5,
|
|
|
|
GIMP_STOCK_LINE_SPACING, spin_button);
|
|
|
|
|
|
|
|
g_signal_connect (G_OBJECT (options->line_spacing_w), "value_changed",
|
|
|
|
G_CALLBACK (gimp_double_adjustment_update),
|
|
|
|
&options->line_spacing);
|
2001-11-21 07:00:47 +08:00
|
|
|
|
|
|
|
return (GimpToolOptions *) options;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_tool_options_reset (GimpToolOptions *tool_options)
|
|
|
|
{
|
|
|
|
TextOptions *options;
|
|
|
|
GtkWidget *spinbutton;
|
|
|
|
|
|
|
|
options = (TextOptions *) tool_options;
|
|
|
|
|
|
|
|
gimp_font_selection_set_fontname
|
|
|
|
(GIMP_FONT_SELECTION (options->font_selection), options->fontname_d);
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->size_w),
|
|
|
|
options->size_d);
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->border_w),
|
|
|
|
options->border_d);
|
|
|
|
|
|
|
|
/* resetting the unit menu is a bit tricky ... */
|
|
|
|
options->unit = options->unit_d;
|
|
|
|
gimp_unit_menu_set_unit (GIMP_UNIT_MENU (options->unit_w),
|
|
|
|
options->unit_d);
|
|
|
|
spinbutton =
|
|
|
|
g_object_get_data (G_OBJECT (options->unit_w), "set_digits");
|
|
|
|
while (spinbutton)
|
|
|
|
{
|
|
|
|
gtk_spin_button_set_digits (GTK_SPIN_BUTTON (spinbutton), 0);
|
|
|
|
spinbutton =
|
|
|
|
g_object_get_data (G_OBJECT (spinbutton), "set_digits");
|
|
|
|
}
|
2002-10-09 23:42:38 +08:00
|
|
|
|
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->letter_spacing_w),
|
|
|
|
options->letter_spacing_d);
|
2002-10-11 01:07:46 +08:00
|
|
|
gtk_adjustment_set_value (GTK_ADJUSTMENT (options->line_spacing_w),
|
|
|
|
options->line_spacing_d);
|
2001-11-21 07:00:47 +08:00
|
|
|
}
|
2002-10-11 02:37:12 +08:00
|
|
|
|
2002-10-12 01:42:26 +08:00
|
|
|
|
|
|
|
/* text editor */
|
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
static void
|
2002-10-12 01:42:26 +08:00
|
|
|
text_tool_editor (GimpTextTool *text_tool)
|
2002-10-11 02:37:12 +08:00
|
|
|
{
|
2002-10-12 01:42:26 +08:00
|
|
|
GtkWidget *toolbar;
|
2002-10-11 02:37:12 +08:00
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *text_view;
|
|
|
|
|
|
|
|
if (text_tool->editor)
|
|
|
|
{
|
2002-10-25 09:11:24 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (text_tool->editor));
|
2002-10-11 02:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
text_tool->editor = gimp_dialog_new (_("GIMP Text Editor"), "text_editor",
|
|
|
|
gimp_standard_help_func,
|
|
|
|
"dialogs/text_editor.html",
|
|
|
|
GTK_WIN_POS_NONE,
|
|
|
|
FALSE, TRUE, FALSE,
|
|
|
|
|
|
|
|
GTK_STOCK_CANCEL, gtk_widget_destroy,
|
|
|
|
NULL, 1, NULL, TRUE, TRUE,
|
|
|
|
|
|
|
|
GTK_STOCK_OK, text_tool_editor_ok,
|
|
|
|
NULL, text_tool, NULL, TRUE, TRUE,
|
|
|
|
|
|
|
|
NULL);
|
|
|
|
|
2002-10-12 01:42:26 +08:00
|
|
|
gtk_dialog_set_has_separator (GTK_DIALOG (text_tool->editor), FALSE);
|
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (text_tool->editor),
|
|
|
|
(gpointer) &text_tool->editor);
|
|
|
|
|
2002-10-12 01:42:26 +08:00
|
|
|
toolbar = gtk_toolbar_new ();
|
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (text_tool->editor)->vbox),
|
|
|
|
toolbar, FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (toolbar);
|
|
|
|
|
|
|
|
gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar), GTK_STOCK_OPEN,
|
|
|
|
_("Load Text from File"), NULL,
|
|
|
|
G_CALLBACK (text_tool_editor_load), text_tool,
|
|
|
|
0);
|
|
|
|
gtk_toolbar_insert_stock (GTK_TOOLBAR (toolbar), GTK_STOCK_CLEAR,
|
|
|
|
_("Clear all Text"), NULL,
|
|
|
|
G_CALLBACK (text_tool_editor_clear), text_tool,
|
|
|
|
1);
|
|
|
|
|
2002-10-11 02:37:12 +08:00
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 4);
|
2002-10-12 01:42:26 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (text_tool->editor)->vbox),
|
|
|
|
scrolled_window, TRUE, TRUE, 0);
|
2002-10-11 02:37:12 +08:00
|
|
|
gtk_widget_show (scrolled_window);
|
|
|
|
|
|
|
|
text_view = gtk_text_view_new_with_buffer (text_tool->buffer);
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
|
|
|
|
gtk_widget_show (text_view);
|
|
|
|
|
|
|
|
gtk_widget_show (text_tool->editor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_tool_editor_ok (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (text_tool->editor);
|
|
|
|
|
|
|
|
text_tool_render (text_tool);
|
|
|
|
}
|
2002-10-12 01:42:26 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
text_tool_editor_load (GtkWidget *widget,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
GtkFileSelection *filesel;
|
|
|
|
|
|
|
|
if (text_tool->filesel)
|
|
|
|
{
|
2002-10-25 09:11:24 +08:00
|
|
|
gtk_window_present (GTK_WINDOW (text_tool->filesel));
|
2002-10-12 01:42:26 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
filesel =
|
|
|
|
GTK_FILE_SELECTION (gtk_file_selection_new (_("Open Text File (UTF-8)")));
|
|
|
|
|
|
|
|
gtk_window_set_wmclass (GTK_WINDOW (filesel), "gimp-text-load-file", "Gimp");
|
|
|
|
gtk_window_set_position (GTK_WINDOW (filesel), GTK_WIN_POS_MOUSE);
|
|
|
|
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (filesel), 2);
|
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (filesel->button_area), 2);
|
|
|
|
|
|
|
|
gtk_window_set_transient_for (GTK_WINDOW (filesel),
|
|
|
|
GTK_WINDOW (text_tool->editor));
|
|
|
|
gtk_window_set_destroy_with_parent (GTK_WINDOW (filesel), TRUE);
|
|
|
|
|
|
|
|
g_signal_connect_swapped (G_OBJECT (filesel->ok_button), "clicked",
|
|
|
|
G_CALLBACK (text_tool_editor_load_ok),
|
|
|
|
text_tool);
|
|
|
|
g_signal_connect_swapped (G_OBJECT (filesel->cancel_button), "clicked",
|
|
|
|
G_CALLBACK (gtk_widget_destroy),
|
|
|
|
filesel);
|
|
|
|
|
|
|
|
gtk_widget_show (GTK_WIDGET (filesel));
|
|
|
|
|
|
|
|
text_tool->filesel = GTK_WIDGET (filesel);
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (filesel),
|
|
|
|
(gpointer) &text_tool->filesel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_tool_editor_load_ok (GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
const gchar *filename;
|
|
|
|
|
|
|
|
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (text_tool->filesel));
|
|
|
|
|
|
|
|
if (text_tool_load_file (text_tool->buffer, filename))
|
|
|
|
gtk_widget_destroy (text_tool->filesel);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
text_tool_load_file (GtkTextBuffer *buffer,
|
|
|
|
const gchar *filename)
|
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
gchar buf[2048];
|
|
|
|
gint remaining = 0;
|
|
|
|
GtkTextIter iter;
|
|
|
|
|
|
|
|
file = fopen (filename, "r");
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
g_message (_("Error opening file '%s': %s"),
|
|
|
|
filename, g_strerror (errno));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_buffer_set_text (buffer, "", 0);
|
|
|
|
gtk_text_buffer_get_iter_at_offset (buffer, &iter, 0);
|
|
|
|
|
|
|
|
while (!feof (file))
|
|
|
|
{
|
|
|
|
const char *leftover;
|
|
|
|
gint count;
|
|
|
|
gint to_read = sizeof (buf) - remaining - 1;
|
|
|
|
|
|
|
|
count = fread (buf + remaining, 1, to_read, file);
|
|
|
|
buf[count + remaining] = '\0';
|
|
|
|
|
|
|
|
g_utf8_validate (buf, count + remaining, &leftover);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert (buffer, &iter, buf, leftover - buf);
|
|
|
|
|
|
|
|
remaining = (buf + remaining + count) - leftover;
|
|
|
|
g_memmove (buf, leftover, remaining);
|
|
|
|
|
|
|
|
if (remaining > 6 || count < to_read)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (remaining)
|
|
|
|
g_message (_("Invalid UTF-8 data in file '%s'."), filename);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_tool_editor_clear (GtkWidget *widget,
|
|
|
|
GimpTextTool *text_tool)
|
|
|
|
{
|
|
|
|
gtk_text_buffer_set_text (text_tool->buffer, "", 0);
|
|
|
|
}
|