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"
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.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"
|
|
|
|
|
2001-05-10 06:34:59 +08:00
|
|
|
#include "tools-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
#include "paint-funcs/paint-funcs.h"
|
|
|
|
|
|
|
|
#include "base/base-types.h"
|
2001-05-15 19:25:25 +08:00
|
|
|
#include "base/pixel-region.h"
|
|
|
|
#include "base/tile-manager.h"
|
2001-04-07 23:58:26 +08:00
|
|
|
|
2001-05-09 10:32:03 +08:00
|
|
|
#include "core/gimpchannel.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimage-mask.h"
|
|
|
|
#include "core/gimplayer.h"
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
#include "widgets/gimpfontselection.h"
|
2001-05-26 00:04:54 +08:00
|
|
|
|
2001-03-08 09:07:03 +08:00
|
|
|
#include "gimptexttool.h"
|
|
|
|
#include "gimptool.h"
|
2001-02-25 05:06:48 +08:00
|
|
|
#include "tool_manager.h"
|
2001-01-23 21:01:48 +08:00
|
|
|
#include "tool_options.h"
|
|
|
|
|
2001-07-08 01:36:00 +08:00
|
|
|
#include "app_procs.h"
|
|
|
|
#include "gdisplay.h"
|
2001-08-11 23:35:16 +08:00
|
|
|
#include "floating_sel.h"
|
|
|
|
#include "undo_types.h"
|
2001-07-08 01:36:00 +08:00
|
|
|
#include "undo.h"
|
|
|
|
|
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-11 23:35:16 +08:00
|
|
|
#define DEFAULT_FONT "sans Normal"
|
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-11 23:35:16 +08:00
|
|
|
GtkWidget *font_selection;
|
1999-04-09 06:25:54 +08:00
|
|
|
};
|
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
static void gimp_text_tool_class_init (GimpTextToolClass *klass);
|
|
|
|
static void gimp_text_tool_init (GimpTextTool *tool);
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
static void gimp_text_tool_finalize (GObject *object);
|
2001-07-18 04:50:01 +08:00
|
|
|
|
|
|
|
static void text_tool_control (GimpTool *tool,
|
|
|
|
ToolAction tool_action,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void text_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void text_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp);
|
|
|
|
static void text_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp);
|
2001-08-11 23:35:16 +08:00
|
|
|
static void text_tool_render (GimpTextTool *text_tool);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
static TextOptions * text_tool_options_new (GimpTextTool *text_tool);
|
2001-07-18 04:50:01 +08:00
|
|
|
static void text_tool_options_reset (GimpToolOptions *tool_options);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
|
|
|
|
/* local variables */
|
2001-02-25 05:06:48 +08:00
|
|
|
|
|
|
|
static TextOptions *text_tool_options = NULL;
|
|
|
|
static GimpToolClass *parent_class = NULL;
|
1998-10-07 16:59:11 +08:00
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-04-13 01:55:06 +08:00
|
|
|
/* functions */
|
1999-04-09 06:25:54 +08:00
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
void
|
2001-07-07 20:17:23 +08:00
|
|
|
gimp_text_tool_register (Gimp *gimp)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2001-07-07 20:17:23 +08:00
|
|
|
tool_manager_register_tool (gimp,
|
|
|
|
GIMP_TYPE_TEXT_TOOL,
|
2001-02-28 07:20:51 +08:00
|
|
|
FALSE,
|
2001-02-25 05:06:48 +08:00
|
|
|
"gimp:text_tool",
|
|
|
|
_("Text Tool"),
|
|
|
|
_("Add text to the image"),
|
|
|
|
N_("/Tools/Text"), "T",
|
|
|
|
NULL, "tools/text.html",
|
2001-08-06 00:08:19 +08:00
|
|
|
GIMP_STOCK_TOOL_TEXT);
|
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,
|
|
|
|
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-11 23:35:16 +08:00
|
|
|
tool_type = g_type_register_static (GIMP_TYPE_TOOL, "GimpTextTool",
|
|
|
|
&tool_info, 0);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return tool_type;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
parent_class = gtk_type_class (GIMP_TYPE_TOOL);
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GimpTool *tool;
|
|
|
|
|
|
|
|
tool = GIMP_TOOL (text_tool);
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
text_tool->pango_context = pango_ft2_get_context ();
|
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
/* The tool options */
|
|
|
|
if (! text_tool_options)
|
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
text_tool_options = text_tool_options_new (text_tool);
|
2001-02-25 05:06:48 +08:00
|
|
|
|
|
|
|
tool_manager_register_tool_options (GIMP_TYPE_TEXT_TOOL,
|
2001-07-18 04:50:01 +08:00
|
|
|
(GimpToolOptions *) text_tool_options);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
2001-04-01 01:08:55 +08:00
|
|
|
tool->tool_cursor = GIMP_TEXT_TOOL_CURSOR;
|
2001-02-25 05:06:48 +08:00
|
|
|
tool->scroll_lock = TRUE; /* Disallow scrolling */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-08-11 23:35:16 +08:00
|
|
|
gimp_text_tool_finalize (GObject *object)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
GimpTextTool *text_tool;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_OBJECT_CLASS (parent_class)->finalize)
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
2001-02-25 05:06:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-07-18 04:50:01 +08:00
|
|
|
text_tool_options_reset (GimpToolOptions *tool_options)
|
2001-02-25 05:06:48 +08:00
|
|
|
{
|
2001-04-01 04:41:39 +08:00
|
|
|
TextOptions *options;
|
|
|
|
|
|
|
|
options = (TextOptions *) tool_options;
|
1999-04-09 06:25:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static TextOptions *
|
2001-08-11 23:35:16 +08:00
|
|
|
text_tool_options_new (GimpTextTool *text_tool)
|
1999-04-09 06:25:54 +08:00
|
|
|
{
|
|
|
|
TextOptions *options;
|
2001-04-01 04:41:39 +08:00
|
|
|
GtkWidget *vbox;
|
1999-04-13 01:55:06 +08:00
|
|
|
|
2001-02-25 05:06:48 +08:00
|
|
|
options = g_new0 (TextOptions, 1);
|
2001-08-11 23:35:16 +08:00
|
|
|
tool_options_init ((GimpToolOptions *) options, text_tool_options_reset);
|
1998-10-07 16:59:11 +08:00
|
|
|
|
|
|
|
/* the main vbox */
|
1999-04-13 01:55:06 +08:00
|
|
|
vbox = options->tool_options.main_vbox;
|
1998-10-07 16:59:11 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
options->font_selection = gimp_font_selection_new (text_tool->pango_context);
|
|
|
|
gimp_font_selection_set_fontname (GIMP_FONT_SELECTION (options->font_selection), DEFAULT_FONT);
|
|
|
|
gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (options->font_selection),
|
|
|
|
FALSE, FALSE, 0);
|
|
|
|
gtk_widget_show (options->font_selection);
|
|
|
|
|
1999-04-09 06:25:54 +08:00
|
|
|
return options;
|
1998-10-07 16:59:11 +08:00
|
|
|
}
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
static void
|
2001-02-25 05:06:48 +08:00
|
|
|
text_tool_control (GimpTool *tool,
|
|
|
|
ToolAction action,
|
|
|
|
GDisplay *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:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_tool_button_press (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
|
|
|
{
|
|
|
|
GimpTextTool *text_tool;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
tool->state = ACTIVE;
|
2000-12-31 12:07:42 +08:00
|
|
|
tool->gdisp = gdisp;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y,
|
|
|
|
&text_tool->click_x, &text_tool->click_y,
|
|
|
|
TRUE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-25 05:06:48 +08:00
|
|
|
text_tool_button_release (GimpTool *tool,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
text_tool_render (GIMP_TEXT_TOOL (tool));
|
|
|
|
|
1997-11-25 06:05:25 +08:00
|
|
|
tool->state = INACTIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-02-25 05:06:48 +08:00
|
|
|
text_tool_cursor_update (GimpTool *tool,
|
|
|
|
GdkEventMotion *mevent,
|
|
|
|
GDisplay *gdisp)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-02-25 03:29:47 +08:00
|
|
|
gdisplay_install_tool_cursor (gdisp,
|
|
|
|
GDK_XTERM,
|
|
|
|
GIMP_TEXT_TOOL_CURSOR,
|
|
|
|
GIMP_CURSOR_MODIFIER_NONE);
|
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
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
GDisplay *gdisp;
|
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
gchar *fontname;
|
|
|
|
gchar *text;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-31 12:07:42 +08:00
|
|
|
gdisp = text_tool->gdisp;
|
2001-08-11 23:35:16 +08:00
|
|
|
|
|
|
|
font_desc = gimp_font_selection_get_font_desc (GIMP_FONT_SELECTION (text_tool_options->font_selection));
|
|
|
|
|
|
|
|
font_desc->size = PANGO_SCALE * 60; /* FIXME */
|
|
|
|
fontname = pango_font_description_to_string (font_desc);
|
|
|
|
pango_font_description_free (font_desc);
|
1998-02-22 18:45:12 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
text = "gimp"; /* FIXME */
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2000-12-29 23:22:01 +08:00
|
|
|
text_render (gdisp->gimage, gimp_image_active_drawable (gdisp->gimage),
|
1998-10-07 16:59:11 +08:00
|
|
|
text_tool->click_x, text_tool->click_y,
|
2001-08-11 23:35:16 +08:00
|
|
|
fontname, text, 0 /*border*/, TRUE /* antialias */);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
1999-12-18 00:37:50 +08:00
|
|
|
g_free (fontname);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
gdisplays_flush ();
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
1999-04-10 12:54:34 +08:00
|
|
|
GimpLayer *
|
1999-12-18 00:37:50 +08:00
|
|
|
text_render (GimpImage *gimage,
|
1998-01-22 15:02:57 +08:00
|
|
|
GimpDrawable *drawable,
|
2000-04-06 06:59:44 +08:00
|
|
|
gint text_x,
|
|
|
|
gint text_y,
|
2001-08-11 23:35:16 +08:00
|
|
|
const gchar *fontname,
|
|
|
|
const gchar *text,
|
2000-04-06 06:59:44 +08:00
|
|
|
gint border,
|
|
|
|
gint antialias)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
PangoContext *context;
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle rect;
|
|
|
|
GimpImageType layer_type;
|
|
|
|
GimpLayer *layer;
|
|
|
|
|
|
|
|
g_return_val_if_fail (fontname != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (text != NULL, FALSE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* determine the layer type */
|
1998-04-24 10:18:52 +08:00
|
|
|
if (drawable)
|
2001-01-15 05:11:52 +08:00
|
|
|
layer_type = gimp_drawable_type_with_alpha (drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
else
|
2000-12-29 23:22:01 +08:00
|
|
|
layer_type = gimp_image_base_type_with_alpha (gimage);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
font_desc = pango_font_description_from_string (fontname);
|
|
|
|
g_return_val_if_fail (font_desc != NULL, NULL);
|
|
|
|
if (!font_desc)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
context = pango_ft2_get_context ();
|
|
|
|
layout = pango_layout_new (context);
|
|
|
|
pango_layout_set_font_description (layout, font_desc);
|
|
|
|
pango_font_description_free (font_desc);
|
|
|
|
pango_layout_set_text (layout, text, -1);
|
2000-11-08 02:37:28 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
pango_layout_get_pixel_extents (layout, &rect, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
if (rect.width > 0 && rect.height > 0)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
TileManager *mask;
|
|
|
|
PixelRegion textPR, maskPR;
|
|
|
|
FT_Bitmap bitmap;
|
|
|
|
guchar color[MAX_CHANNELS];
|
|
|
|
gint y;
|
|
|
|
|
|
|
|
bitmap.width = rect.width;
|
|
|
|
bitmap.rows = rect.height;
|
|
|
|
bitmap.pitch = rect.width;
|
|
|
|
if (bitmap.pitch & 3)
|
|
|
|
bitmap.pitch += 4 - (bitmap.pitch & 3);
|
|
|
|
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
|
|
|
|
bitmap.num_grays = 256;
|
|
|
|
bitmap.pixel_mode = ft_pixel_mode_grays;
|
|
|
|
|
|
|
|
pango_ft2_render_layout (&bitmap, layout, 0, 0);
|
|
|
|
|
|
|
|
mask = tile_manager_new (rect.width, rect.height, 1);
|
|
|
|
pixel_region_init (&maskPR, mask, 0, 0, rect.width, rect.height, TRUE);
|
|
|
|
|
|
|
|
for (y = 0; y < bitmap.rows; y++)
|
|
|
|
pixel_region_set_row (&maskPR, 0, y, bitmap.width,
|
|
|
|
bitmap.buffer + y * bitmap.pitch);
|
|
|
|
|
|
|
|
g_free (bitmap.buffer);
|
|
|
|
|
|
|
|
layer = gimp_layer_new (gimage, rect.width, rect.height, layer_type,
|
|
|
|
_("Text Layer"), OPAQUE_OPACITY, NORMAL_MODE);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* color the layer buffer */
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_get_foreground (gimage, drawable, color);
|
1999-12-18 00:37:50 +08:00
|
|
|
color[GIMP_DRAWABLE (layer)->bytes - 1] = OPAQUE_OPACITY;
|
|
|
|
pixel_region_init (&textPR, GIMP_DRAWABLE (layer)->tiles,
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height, TRUE);
|
1997-11-25 06:05:25 +08:00
|
|
|
color_region (&textPR, color);
|
|
|
|
|
|
|
|
/* apply the text mask */
|
1999-12-18 00:37:50 +08:00
|
|
|
pixel_region_init (&textPR, GIMP_DRAWABLE (layer)->tiles,
|
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height, TRUE);
|
2001-08-11 23:35:16 +08:00
|
|
|
pixel_region_init (&maskPR, mask,
|
1999-12-18 00:37:50 +08:00
|
|
|
0, 0,
|
|
|
|
GIMP_DRAWABLE (layer)->width,
|
|
|
|
GIMP_DRAWABLE (layer)->height, FALSE);
|
1998-01-25 09:24:46 +08:00
|
|
|
apply_mask_to_region (&textPR, &maskPR, OPAQUE_OPACITY);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Start a group undo */
|
1999-11-04 06:34:32 +08:00
|
|
|
undo_push_group_start (gimage, TEXT_UNDO);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* Set the layer offsets */
|
2001-08-11 23:35:16 +08:00
|
|
|
GIMP_DRAWABLE (layer)->offset_x = text_x + rect.x;
|
|
|
|
GIMP_DRAWABLE (layer)->offset_y = text_y + rect.y;
|
1997-11-25 06:05:25 +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 (! gimage_mask_is_empty (gimage))
|
2001-01-29 10:45:02 +08:00
|
|
|
gimp_channel_clear (gimp_image_get_mask (gimage));
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* If the drawable id is invalid, create a new layer */
|
1998-01-22 15:02:57 +08:00
|
|
|
if (drawable == NULL)
|
2000-12-29 23:22:01 +08:00
|
|
|
gimp_image_add_layer (gimage, layer, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
/* Otherwise, instantiate the text as the new floating selection */
|
|
|
|
else
|
1998-01-22 15:02:57 +08:00
|
|
|
floating_sel_attach (layer, drawable);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
|
|
|
/* end the group undo */
|
|
|
|
undo_push_group_end (gimage);
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
tile_manager_destroy (mask);
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
g_object_unref (layout);
|
|
|
|
g_object_unref (context);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
return NULL;
|
1997-11-25 06:05:25 +08:00
|
|
|
}
|
|
|
|
|
2000-04-06 06:59:44 +08:00
|
|
|
gboolean
|
2001-08-11 23:35:16 +08:00
|
|
|
text_get_extents (const gchar *fontname,
|
|
|
|
const gchar *text,
|
|
|
|
gint *width,
|
|
|
|
gint *height,
|
|
|
|
gint *ascent,
|
|
|
|
gint *descent)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
2001-08-11 23:35:16 +08:00
|
|
|
PangoFontDescription *font_desc;
|
|
|
|
PangoContext *context;
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle rect;
|
2000-11-08 02:37:28 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
g_return_val_if_fail (fontname != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (text != NULL, FALSE);
|
2000-11-08 02:37:28 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
font_desc = pango_font_description_from_string (fontname);
|
|
|
|
if (!font_desc)
|
1997-11-25 06:05:25 +08:00
|
|
|
return FALSE;
|
2001-08-11 23:35:16 +08:00
|
|
|
|
|
|
|
context = pango_ft2_get_context ();
|
|
|
|
layout = pango_layout_new (context);
|
|
|
|
pango_layout_set_font_description (layout, font_desc);
|
|
|
|
pango_font_description_free (font_desc);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
pango_layout_set_text (layout, text, -1);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
pango_layout_get_pixel_extents (layout, &rect, NULL);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
if (width)
|
|
|
|
*width = rect.width;
|
|
|
|
if (height)
|
|
|
|
*height = rect.height;
|
|
|
|
if (ascent)
|
|
|
|
*ascent = -rect.y;
|
|
|
|
if (descent)
|
|
|
|
*descent = rect.height + rect.y;
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
g_object_unref (layout);
|
|
|
|
g_object_unref (context);
|
1997-11-25 06:05:25 +08:00
|
|
|
|
2001-08-11 23:35:16 +08:00
|
|
|
return TRUE;
|
1999-04-25 23:53:30 +08:00
|
|
|
}
|