Commit 27698a2b authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

app/config/gimpconfig-params.h

2003-01-31  Sven Neumann  <sven@gimp.org>

	* app/config/gimpconfig-params.h

	* app/config/gimpcoreconfig.c: added a pixels parameter to the
	GIMP_CONFIG_INSTALL_PROP_UNIT() macro.

	* app/core/Makefile.am
	* app/core/gimpimage-text.[ch]: removed these two files.

	* app/text/Makefile.am
	* app/text/gimptext-compat.[ch]: new files with compatibility
	routines that provide the old text API (solely for PDB calls).

	* app/text/gimptext-render.[ch]: new files with text rendering
	routines (not much yet).

	* app/text/text-types.h
	* app/text/gimptextlayer.[ch]: new object derived from GimpLayer.

	* app/text/gimptext.[ch]: prepared for future improvements.

	* app/pdb/text_tool_cmds.c
	* app/tools/gimptexttool.c
	* tools/pdbgen/pdb/text_tool.pdb: changed accordingly.
parent 1305d37c
2003-01-31 Sven Neumann <sven@gimp.org>
* app/config/gimpconfig-params.h
* app/config/gimpcoreconfig.c: added a pixels parameter to the
GIMP_CONFIG_INSTALL_PROP_UNIT() macro.
* app/core/Makefile.am
* app/core/gimpimage-text.[ch]: removed these two files.
* app/text/Makefile.am
* app/text/gimptext-compat.[ch]: new files with compatibility
routines that provide the old text API (solely for PDB calls).
* app/text/gimptext-render.[ch]: new files with text rendering
routines (not much yet).
* app/text/text-types.h
* app/text/gimptextlayer.[ch]: new object derived from GimpLayer.
* app/text/gimptext.[ch]: prepared for future improvements.
* app/pdb/text_tool_cmds.c
* app/tools/gimptexttool.c
* tools/pdbgen/pdb/text_tool.pdb: changed accordingly.
2003-01-30 Manish Singh <yosh@gimp.org>
 
* app/undo_history.c
......@@ -34,7 +60,7 @@
2003-01-30 Sven Neumann <sven@gimp.org>
 
* libgimp/gimpcompat.h: removed GIMP_ENABLE_COMPAT_CRUFT guards.
The file needs to included explicitely anyway.
The file needs to be included explicitely anyway.
 
2003-01-30 Michael Natterer <mitch@gimp.org>
 
......
......@@ -174,10 +174,10 @@ GParamSpec * gimp_param_spec_unit (const gchar *name,
min, max, default,\
flags | GIMP_CONFIG_PARAM_FLAGS))
#define GIMP_CONFIG_INSTALL_PROP_UNIT(class, id,\
name, blurb, default, flags)\
name, blurb, pixels, default, flags)\
g_object_class_install_property (class, id,\
gimp_param_spec_unit (name, NULL, blurb,\
FALSE, default,\
pixels, default,\
flags | GIMP_CONFIG_PARAM_FLAGS))
......
......@@ -216,7 +216,7 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
0);
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_DEFAULT_UNIT,
"default-unit", DEFAULT_UNIT_BLURB,
GIMP_UNIT_INCH,
FALSE, GIMP_UNIT_INCH,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_DEFAULT_XRESOLUTION,
"default-xresolution",
......@@ -233,7 +233,7 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_DEFAULT_RESOLUTION_UNIT,
"default-resolution-unit",
DEFAULT_RESOLUTION_UNIT_BLURB,
GIMP_UNIT_INCH,
FALSE, GIMP_UNIT_INCH,
0);
GIMP_CONFIG_INSTALL_PROP_INT (object_class, PROP_UNDO_LEVELS,
"undo-levels", UNDO_LEVELS_BLURB,
......
......@@ -11,7 +11,6 @@ INCLUDES = \
-I$(top_srcdir)/app \
$(GTK_CFLAGS) \
$(LIBART_CFLAGS) \
$(PANGOFT2_CFLAGS) \
-I$(includedir)
noinst_LIBRARIES = libappcore.a
......@@ -114,8 +113,6 @@ libappcore_a_sources = \
gimpimage-resize.h \
gimpimage-scale.c \
gimpimage-scale.h \
gimpimage-text.c \
gimpimage-text.h \
gimpimage-undo.c \
gimpimage-undo.h \
gimpimagefile.c \
......
......@@ -32,9 +32,9 @@
#include "core/core-types.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage-text.h"
#include "core/gimpimage.h"
#include "core/gimplayer.h"
#include "text/gimptext-compat.h"
#include "libgimpbase/gimpbase.h"
......
......@@ -9,13 +9,20 @@ INCLUDES = \
-I$(top_srcdir) \
-I$(top_srcdir)/app \
$(GTK_CFLAGS) \
$(PANGOFT2_CFLAGS) \
-I$(includedir)
noinst_LIBRARIES = libapptext.a
libapptext_a_SOURCES = \
text-types.h \
gimptext.c \
gimptext.h
text-types.h \
gimptext.c \
gimptext.h \
gimptext-compat.c \
gimptext-compat.h \
gimptext-render.c \
gimptext-render.h \
gimptextlayer.c \
gimptextlayer.h
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2002-2003 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
......@@ -21,174 +24,25 @@
#include <glib-object.h>
#include <pango/pangoft2.h>
#include "libgimpbase/gimpbase.h"
#include "core-types.h"
#include "libgimpcolor/gimpcolor.h"
#include "base/pixel-region.h"
#include "base/tile-manager.h"
#include "text-types.h"
#include "paint-funcs/paint-funcs.h"
#include "text/gimptext.h"
#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimplayer-floating-sel.h"
#include "gimpdrawable.h"
#include "gimpimage.h"
#include "gimpimage-mask.h"
#include "gimpimage-text.h"
#include "gimplayer.h"
#include "gimplayer-floating-sel.h"
#include "gimptext.h"
#include "gimptext-compat.h"
#include "gimptextlayer.h"
#include "undo.h"
#include "libgimp/gimpintl.h"
GimpLayer *
gimp_image_text_render (GimpImage *gimage,
GimpText *text)
{
PangoFontDescription *font_desc;
PangoContext *context;
PangoLayout *layout;
PangoRectangle ink;
PangoRectangle logical;
GimpLayer *layer = NULL;
gdouble factor;
gdouble xres;
gdouble yres;
gint size;
gint border;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
if (!text->str)
return NULL;
gimp_image_get_resolution (gimage, &xres, &yres);
switch (text->unit)
{
case GIMP_UNIT_PIXEL:
size = PANGO_SCALE * text->size;
border = text->border;
break;
default:
factor = gimp_unit_get_factor (text->unit);
g_return_val_if_fail (factor > 0.0, NULL);
size = (gdouble) PANGO_SCALE * text->size * yres / factor;
border = text->border * yres / factor;
break;
}
font_desc = pango_font_description_from_string (text->font);
g_return_val_if_fail (font_desc != NULL, NULL);
if (!font_desc)
return NULL;
if (size > 1)
pango_font_description_set_size (font_desc, size);
context = pango_ft2_get_context (xres, yres);
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->str, -1);
pango_layout_get_pixel_extents (layout, &ink, &logical);
g_print ("ink rect: %d x %d @ %d, %d\n",
ink.width, ink.height, ink.x, ink.y);
g_print ("logical rect: %d x %d @ %d, %d\n",
logical.width, logical.height, logical.x, logical.y);
if (ink.width > 8192 || ink.height > 8192)
{
g_message ("Uh, oh, insane text size.");
return NULL;
}
if (ink.width > 0 && ink.height > 0)
{
TileManager *mask;
PixelRegion textPR;
PixelRegion maskPR;
FT_Bitmap bitmap;
guchar *black = NULL;
guchar color[MAX_CHANNELS];
gint width;
gint height;
gint y;
bitmap.width = ink.width;
bitmap.rows = ink.height;
bitmap.pitch = ink.width;
if (bitmap.pitch & 3)
bitmap.pitch += 4 - (bitmap.pitch & 3);
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
pango_ft2_render_layout (&bitmap, layout, - ink.x, - ink.y);
width = ink.width + 2 * border;
height = ink.height + 2 * border;
mask = tile_manager_new (width, height, 1);
pixel_region_init (&maskPR, mask, 0, 0, width, height, TRUE);
if (border)
black = g_malloc0 (width);
for (y = 0; y < border; y++)
pixel_region_set_row (&maskPR, 0, y, width, black);
for (; y < height - border; y++)
{
if (border)
{
pixel_region_set_row (&maskPR, 0, y, border, black);
pixel_region_set_row (&maskPR, width - border, y, border, black);
}
pixel_region_set_row (&maskPR, border, y, bitmap.width,
bitmap.buffer + (y - border) * bitmap.pitch);
}
for (; y < height; y++)
pixel_region_set_row (&maskPR, 0, y, width, black);
g_free (black);
g_free (bitmap.buffer);
layer = gimp_layer_new (gimage,
width, height,
gimp_image_base_type_with_alpha (gimage),
_("Text Layer"),
GIMP_OPACITY_OPAQUE, GIMP_NORMAL_MODE);
/* color the layer buffer */
gimp_image_get_foreground (gimage, GIMP_DRAWABLE (layer), color);
color[GIMP_DRAWABLE (layer)->bytes - 1] = OPAQUE_OPACITY;
pixel_region_init (&textPR, GIMP_DRAWABLE (layer)->tiles,
0, 0, width, height, TRUE);
color_region (&textPR, color);
/* apply the text mask */
pixel_region_init (&textPR, GIMP_DRAWABLE (layer)->tiles,
0, 0, width, height, TRUE);
pixel_region_init (&maskPR, mask,
0, 0, width, height, FALSE);
apply_mask_to_region (&textPR, &maskPR, OPAQUE_OPACITY);
tile_manager_destroy (mask);
}
g_object_unref (layout);
g_object_unref (context);
return layer;
}
GimpLayer *
text_render (GimpImage *gimage,
......@@ -202,6 +56,7 @@ text_render (GimpImage *gimage,
{
GimpText *gtext;
GimpLayer *layer;
GimpRGB color;
g_return_val_if_fail (fontname != NULL, FALSE);
g_return_val_if_fail (text != NULL, FALSE);
......@@ -209,15 +64,18 @@ text_render (GimpImage *gimage,
if (border < 0)
border = 0;
gimp_context_get_foreground (gimp_get_current_context (gimage->gimp), &color);
gtext = GIMP_TEXT (g_object_new (GIMP_TYPE_TEXT,
"text", text,
"font", fontname,
"border", border,
"unit", GIMP_UNIT_PIXEL,
"color", &color,
NULL));
gtext->size = -1;
layer = gimp_image_text_render (gimage, gtext);
layer = gimp_text_layer_new (gimage, gtext);
g_object_unref (gtext);
......
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattisbvf
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2002-2003 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
......@@ -16,14 +19,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __GIMP_IMAGE_TEXT_H__
#define __GIMP_IMAGE_TEXT_H__
GimpLayer * gimp_image_text_render (GimpImage *image,
GimpText *text);
#ifndef __GIMP_TEXT_COMPAT_H__
#define __GIMP_TEXT_COMPAT_H__
/* convenience functions using the old API */
/* convenience functions that provide the 1.2 API, only used by the PDB */
GimpLayer * text_render (GimpImage *gimage,
GimpDrawable *drawable,
......@@ -40,4 +40,5 @@ gboolean text_get_extents (const gchar *fontname,
gint *ascent,
gint *descent);
#endif /* __GIMP_IMAGE_TEXT_H__ */
#endif /* __GIMP_TEXT_COMPAT_H__ */
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2002-2003 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 <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 "gimptext-render.h"
TileManager *
gimp_text_render_layout (PangoLayout *layout,
gint x,
gint y,
gint width,
gint height)
{
TileManager *mask;
FT_Bitmap bitmap;
PixelRegion maskPR;
gint i;
g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL);
g_return_val_if_fail (width > 0 && height > 0, NULL);
bitmap.width = width;
bitmap.rows = height;
bitmap.pitch = width;
if (bitmap.pitch & 3)
bitmap.pitch += 4 - (bitmap.pitch & 3);
bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
pango_ft2_render_layout (&bitmap, layout, x, y);
mask = tile_manager_new (width, height, 1);
pixel_region_init (&maskPR, mask, 0, 0, width, height, TRUE);
for (i = 0; i < height; i++)
pixel_region_set_row (&maskPR,
0, i, width, bitmap.buffer + i * bitmap.pitch);
g_free (bitmap.buffer);
return mask;
}
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2002-2003 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.
*/
#ifndef __GIMP_TEXT_RENDER_H__
#define __GIMP_TEXT_RENDER_H__
TileManager * gimp_text_render_layout (PangoLayout *layout,
gint x,
gint y,
gint width,
gint height);
GimpLayer * gimp_image_text_render (GimpImage *gimage,
GimpText *text);
#endif /* __GIMP_TEXT_RENDER_H__ */
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* Copyright (C) 2002-2003 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
......@@ -20,6 +23,8 @@
#include <glib-object.h>
#include "libgimpcolor/gimpcolor.h"
#include "text/text-types.h"
#include "config/gimpconfig-params.h"
......@@ -34,16 +39,21 @@ enum
PROP_SIZE,
PROP_BORDER,
PROP_UNIT,
PROP_COLOR,
PROP_LETTER_SPACING,
PROP_LINE_SPACING
};
static void gimp_text_class_init (GimpTextClass *klass);
static void gimp_text_finalize (GObject *object);
static void gimp_text_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
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);
static GObjectClass *parent_class = NULL;
......@@ -80,50 +90,52 @@ gimp_text_class_init (GimpTextClass *klass)
{
GObjectClass *object_class;
GParamSpec *param_spec;
GimpRGB black;
object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gimp_text_finalize;
object_class->get_property = gimp_text_get_property;
object_class->set_property = gimp_text_set_property;
param_spec = g_param_spec_string ("text", NULL, NULL,
NULL,
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class, PROP_TEXT, param_spec);
param_spec = g_param_spec_string ("font", NULL, NULL,
"Sans",
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class, PROP_FONT, param_spec);
param_spec = g_param_spec_double ("size", NULL, NULL,
0.0, G_MAXFLOAT, 18.0,
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class, PROP_SIZE, param_spec);
gimp_rgba_set (&black, 0.0, 0.0, 0.0, GIMP_OPACITY_OPAQUE);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_TEXT,
"text", NULL,
NULL,
0);
GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_FONT,
"font", NULL,
"Sans",
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_SIZE,
"size", NULL,
0.0, G_MAXFLOAT, 18.0,
0);
GIMP_CONFIG_INSTALL_PROP_UNIT (object_class, PROP_UNIT,
"unit", NULL,
TRUE, GIMP_UNIT_PIXEL,
0);
GIMP_CONFIG_INSTALL_PROP_COLOR (object_class, PROP_COLOR,
"color", NULL,
&black,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LETTER_SPACING,
"letter-spacing", NULL,
0.0, 64.0, 1.0,
0);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LINE_SPACING,
"line-spacing", NULL,
0.0, 64.0, 1.0,
0);
/* border is supposed to die */
param_spec = g_param_spec_double ("border", NULL, NULL,
0.0, G_MAXFLOAT, 0.0,
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
G_PARAM_CONSTRUCT | G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_BORDER, param_spec);
param_spec = gimp_param_spec_unit ("unit", NULL, NULL,
TRUE, GIMP_UNIT_PIXEL,
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class, PROP_UNIT, param_spec);
param_spec = g_param_spec_double ("letter-spacing", NULL, NULL,
0.0, 64.0, 1.0,
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class,
PROP_LETTER_SPACING, param_spec);
param_spec = g_param_spec_double ("line-spacing", NULL, NULL,
0.0, 64.0, 1.0,
G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
g_object_class_install_property (object_class,
PROP_LINE_SPACING, param_spec);