2002-10-10 22:30:01 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-01-31 17:22:42 +08:00
|
|
|
* GimpText
|
|
|
|
* Copyright (C) 2002-2003 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2002-10-10 22:30:01 +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"
|
|
|
|
|
|
|
|
#include <glib-object.h>
|
|
|
|
|
2003-01-31 21:36:27 +08:00
|
|
|
#include "libgimpbase/gimplimits.h"
|
2003-01-31 17:22:42 +08:00
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
|
|
|
|
2003-01-30 06:20:09 +08:00
|
|
|
#include "text/text-types.h"
|
2002-10-10 22:30:01 +08:00
|
|
|
|
2003-02-02 05:50:21 +08:00
|
|
|
#include "config/gimpconfig.h"
|
2002-10-10 22:30:01 +08:00
|
|
|
#include "config/gimpconfig-params.h"
|
|
|
|
|
|
|
|
#include "gimptext.h"
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_TEXT,
|
|
|
|
PROP_FONT,
|
2003-01-31 21:36:27 +08:00
|
|
|
PROP_FONT_SIZE,
|
|
|
|
PROP_FONT_SIZE_UNIT,
|
2003-01-31 17:22:42 +08:00
|
|
|
PROP_COLOR,
|
2003-02-05 17:51:26 +08:00
|
|
|
PROP_JUSTIFICATION,
|
|
|
|
PROP_INDENTATION,
|
2003-01-31 21:36:27 +08:00
|
|
|
PROP_LINE_SPACING,
|
2003-02-05 17:51:26 +08:00
|
|
|
PROP_LETTER_SPACING,
|
2003-01-31 21:36:27 +08:00
|
|
|
PROP_FIXED_WIDTH,
|
|
|
|
PROP_FIXED_HEIGHT,
|
|
|
|
PROP_GRAVITY,
|
|
|
|
PROP_BORDER
|
2002-10-10 22:30:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static void gimp_text_class_init (GimpTextClass *klass);
|
|
|
|
static void gimp_text_finalize (GObject *object);
|
2003-01-31 17:22:42 +08:00
|
|
|
static void gimp_text_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_text_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
static GObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
GType
|
|
|
|
gimp_text_get_type (void)
|
|
|
|
{
|
|
|
|
static GType text_type = 0;
|
|
|
|
|
|
|
|
if (! text_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo text_info =
|
|
|
|
{
|
|
|
|
sizeof (GimpTextClass),
|
|
|
|
(GBaseInitFunc) NULL,
|
|
|
|
(GBaseFinalizeFunc) NULL,
|
|
|
|
(GClassInitFunc) gimp_text_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GimpText),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
NULL /* instance_init */
|
|
|
|
};
|
2003-02-02 05:50:21 +08:00
|
|
|
static const GInterfaceInfo text_iface_info =
|
|
|
|
{
|
|
|
|
NULL, /* iface_init */
|
|
|
|
NULL, /* iface_finalize */
|
|
|
|
NULL /* iface_data */
|
|
|
|
};
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
text_type = g_type_register_static (G_TYPE_OBJECT,
|
|
|
|
"GimpText", &text_info, 0);
|
2003-02-02 05:50:21 +08:00
|
|
|
|
|
|
|
g_type_add_interface_static (text_type,
|
|
|
|
GIMP_TYPE_CONFIG_INTERFACE,
|
|
|
|
&text_iface_info);
|
2002-10-10 22:30:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return text_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_class_init (GimpTextClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
GParamSpec *param_spec;
|
2003-01-31 17:22:42 +08:00
|
|
|
GimpRGB black;
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gimp_text_finalize;
|
2003-01-31 17:22:42 +08:00
|
|
|
object_class->get_property = gimp_text_get_property;
|
2002-10-10 22:30:01 +08:00
|
|
|
object_class->set_property = gimp_text_set_property;
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
|
|
|
|
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_TEXT,
|
|
|
|
"text", NULL,
|
2003-02-02 05:50:21 +08:00
|
|
|
"GIMP",
|
2003-01-31 17:22:42 +08:00
|
|
|
0);
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_FONT,
|
|
|
|
"font", NULL,
|
|
|
|
"Sans",
|
|
|
|
0);
|
2003-01-31 21:36:27 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_FONT_SIZE,
|
|
|
|
"font-size", NULL,
|
2003-02-04 07:54:19 +08:00
|
|
|
0.0, 8192.0, 18.0,
|
2003-01-31 17:22:42 +08:00
|
|
|
0);
|
2003-01-31 21:36:27 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_FONT_SIZE_UNIT,
|
|
|
|
"font-size-unit", NULL,
|
2003-01-31 17:22:42 +08:00
|
|
|
TRUE, GIMP_UNIT_PIXEL,
|
|
|
|
0);
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_COLOR (object_class, PROP_COLOR,
|
|
|
|
"color", NULL,
|
|
|
|
&black,
|
|
|
|
0);
|
2003-02-05 17:51:26 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_JUSTIFICATION,
|
|
|
|
"justify", NULL,
|
|
|
|
GIMP_TYPE_TEXT_JUSTIFICATION,
|
|
|
|
GIMP_TEXT_JUSTIFY_LEFT,
|
2003-02-05 16:29:12 +08:00
|
|
|
0);
|
2003-02-05 17:51:26 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_INDENTATION,
|
|
|
|
"indent", NULL,
|
|
|
|
-8192.0, 8192.0, 0.0,
|
|
|
|
0);
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LINE_SPACING,
|
|
|
|
"line-spacing", NULL,
|
|
|
|
-8192.0, 8192.0, 0.0,
|
|
|
|
0);
|
2003-01-31 17:22:42 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LETTER_SPACING,
|
|
|
|
"letter-spacing", NULL,
|
|
|
|
0.0, 64.0, 1.0,
|
|
|
|
0);
|
2003-01-31 21:36:27 +08:00
|
|
|
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_FIXED_WIDTH,
|
|
|
|
"fixed-width", NULL,
|
|
|
|
0, GIMP_MAX_IMAGE_SIZE, 0,
|
|
|
|
0);
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_FIXED_HEIGHT,
|
|
|
|
"fixed-height", NULL,
|
|
|
|
0, GIMP_MAX_IMAGE_SIZE, 0,
|
|
|
|
0);
|
|
|
|
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_GRAVITY,
|
|
|
|
"gravity", NULL,
|
|
|
|
GIMP_TYPE_GRAVITY_TYPE, GIMP_GRAVITY_CENTER,
|
|
|
|
0);
|
|
|
|
|
|
|
|
/* border does only exist to implement the old text API */
|
|
|
|
param_spec = g_param_spec_int ("border", NULL, NULL,
|
|
|
|
0, GIMP_MAX_IMAGE_SIZE, 0,
|
|
|
|
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
|
2002-10-11 01:07:46 +08:00
|
|
|
g_object_class_install_property (object_class, PROP_BORDER, param_spec);
|
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_text_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpText *text = GIMP_TEXT (object);
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
if (text->text)
|
2002-10-10 22:30:01 +08:00
|
|
|
{
|
2003-01-31 17:22:42 +08:00
|
|
|
g_free (text->text);
|
|
|
|
text->text = NULL;
|
2002-10-10 22:30:01 +08:00
|
|
|
}
|
|
|
|
if (text->font)
|
|
|
|
{
|
|
|
|
g_free (text->font);
|
|
|
|
text->font = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2003-01-31 17:22:42 +08:00
|
|
|
static void
|
|
|
|
gimp_text_get_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpText *text = GIMP_TEXT (object);
|
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TEXT:
|
|
|
|
g_value_set_string (value, text->text);
|
|
|
|
break;
|
|
|
|
case PROP_FONT:
|
|
|
|
g_value_set_string (value, text->font);
|
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FONT_SIZE:
|
|
|
|
g_value_set_double (value, text->font_size);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FONT_SIZE_UNIT:
|
|
|
|
g_value_set_int (value, text->font_size_unit);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
|
|
|
case PROP_COLOR:
|
|
|
|
g_value_set_boxed (value, &text->color);
|
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_JUSTIFICATION:
|
|
|
|
g_value_set_enum (value, text->justify);
|
2003-02-05 16:29:12 +08:00
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_INDENTATION:
|
|
|
|
g_value_set_double (value, text->indent);
|
2003-01-31 17:22:42 +08:00
|
|
|
break;
|
|
|
|
case PROP_LINE_SPACING:
|
|
|
|
g_value_set_double (value, text->line_spacing);
|
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_LETTER_SPACING:
|
|
|
|
g_value_set_double (value, text->letter_spacing);
|
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FIXED_WIDTH:
|
|
|
|
g_value_set_int (value, text->fixed_width);
|
|
|
|
break;
|
|
|
|
case PROP_FIXED_HEIGHT:
|
|
|
|
g_value_set_int (value, text->fixed_height);
|
|
|
|
break;
|
|
|
|
case PROP_GRAVITY:
|
|
|
|
g_value_set_enum (value, text->gravity);
|
|
|
|
break;
|
2003-01-31 17:22:42 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-10 22:30:01 +08:00
|
|
|
static void
|
|
|
|
gimp_text_set_property (GObject *object,
|
|
|
|
guint property_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpText *text = GIMP_TEXT (object);
|
2003-01-31 17:22:42 +08:00
|
|
|
GimpRGB *color;
|
2002-10-10 22:30:01 +08:00
|
|
|
|
|
|
|
switch (property_id)
|
|
|
|
{
|
|
|
|
case PROP_TEXT:
|
2003-01-31 17:22:42 +08:00
|
|
|
g_free (text->text);
|
|
|
|
text->text = g_value_dup_string (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
|
|
|
case PROP_FONT:
|
|
|
|
g_free (text->font);
|
|
|
|
text->font = g_value_dup_string (value);
|
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FONT_SIZE:
|
|
|
|
text->font_size = g_value_get_double (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FONT_SIZE_UNIT:
|
|
|
|
text->font_size_unit = g_value_get_int (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
2003-01-31 17:22:42 +08:00
|
|
|
case PROP_COLOR:
|
|
|
|
color = g_value_get_boxed (value);
|
|
|
|
text->color = *color;
|
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_JUSTIFICATION:
|
|
|
|
text->justify = g_value_get_enum (value);
|
2003-02-05 16:29:12 +08:00
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_INDENTATION:
|
|
|
|
text->indent = g_value_get_double (value);
|
2002-10-10 22:30:01 +08:00
|
|
|
break;
|
|
|
|
case PROP_LINE_SPACING:
|
|
|
|
text->line_spacing = g_value_get_double (value);
|
|
|
|
break;
|
2003-02-05 17:51:26 +08:00
|
|
|
case PROP_LETTER_SPACING:
|
|
|
|
text->letter_spacing = g_value_get_double (value);
|
|
|
|
break;
|
2003-01-31 21:36:27 +08:00
|
|
|
case PROP_FIXED_WIDTH:
|
|
|
|
text->fixed_width = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_FIXED_HEIGHT:
|
|
|
|
text->fixed_height = g_value_get_int (value);
|
|
|
|
break;
|
|
|
|
case PROP_GRAVITY:
|
|
|
|
text->gravity = g_value_get_enum (value);
|
|
|
|
break;
|
|
|
|
case PROP_BORDER:
|
|
|
|
text->border = g_value_get_int (value);
|
|
|
|
if (text->border > 0)
|
|
|
|
text->gravity = GIMP_GRAVITY_CENTER;
|
|
|
|
break;
|
2002-10-10 22:30:01 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|