mirror of https://github.com/GNOME/gimp.git
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.
This commit is contained in:
parent
1305d37cde
commit
27698a2b3f
28
ChangeLog
28
ChangeLog
|
@ -1,3 +1,29 @@
|
|||
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 \
|
||||
|
|
|
@ -1,298 +0,0 @@
|
|||
/* 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
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <pango/pangoft2.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "core-types.h"
|
||||
|
||||
#include "base/pixel-region.h"
|
||||
#include "base/tile-manager.h"
|
||||
|
||||
#include "paint-funcs/paint-funcs.h"
|
||||
#include "text/gimptext.h"
|
||||
|
||||
#include "gimpdrawable.h"
|
||||
#include "gimpimage.h"
|
||||
#include "gimpimage-mask.h"
|
||||
#include "gimpimage-text.h"
|
||||
#include "gimplayer.h"
|
||||
#include "gimplayer-floating-sel.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,
|
||||
GimpDrawable *drawable,
|
||||
gint text_x,
|
||||
gint text_y,
|
||||
const gchar *fontname,
|
||||
const gchar *text,
|
||||
gint border,
|
||||
gint antialias)
|
||||
{
|
||||
GimpText *gtext;
|
||||
GimpLayer *layer;
|
||||
|
||||
g_return_val_if_fail (fontname != NULL, FALSE);
|
||||
g_return_val_if_fail (text != NULL, FALSE);
|
||||
|
||||
if (border < 0)
|
||||
border = 0;
|
||||
|
||||
gtext = GIMP_TEXT (g_object_new (GIMP_TYPE_TEXT,
|
||||
"text", text,
|
||||
"font", fontname,
|
||||
"border", border,
|
||||
"unit", GIMP_UNIT_PIXEL,
|
||||
NULL));
|
||||
gtext->size = -1;
|
||||
|
||||
layer = gimp_image_text_render (gimage, gtext);
|
||||
|
||||
g_object_unref (gtext);
|
||||
|
||||
if (!layer)
|
||||
return NULL;
|
||||
|
||||
/* Start a group undo */
|
||||
undo_push_group_start (gimage, TEXT_UNDO_GROUP);
|
||||
|
||||
/* Set the layer offsets */
|
||||
GIMP_DRAWABLE (layer)->offset_x = text_x;
|
||||
GIMP_DRAWABLE (layer)->offset_y = text_y;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* If the drawable is NULL, create a new layer */
|
||||
if (drawable == NULL)
|
||||
gimp_image_add_layer (gimage, layer, -1);
|
||||
/* Otherwise, instantiate the text as the new floating selection */
|
||||
else
|
||||
floating_sel_attach (layer, drawable);
|
||||
|
||||
/* end the group undo */
|
||||
undo_push_group_end (gimage);
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
gboolean
|
||||
text_get_extents (const gchar *fontname,
|
||||
const gchar *text,
|
||||
gint *width,
|
||||
gint *height,
|
||||
gint *ascent,
|
||||
gint *descent)
|
||||
{
|
||||
PangoFontDescription *font_desc;
|
||||
PangoContext *context;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle rect;
|
||||
|
||||
g_return_val_if_fail (fontname != NULL, FALSE);
|
||||
g_return_val_if_fail (text != NULL, FALSE);
|
||||
|
||||
font_desc = pango_font_description_from_string (fontname);
|
||||
if (!font_desc)
|
||||
return FALSE;
|
||||
|
||||
/* FIXME: resolution */
|
||||
context = pango_ft2_get_context (72.0, 72.0);
|
||||
|
||||
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);
|
||||
|
||||
pango_layout_get_pixel_extents (layout, &rect, NULL);
|
||||
|
||||
if (width)
|
||||
*width = rect.width;
|
||||
if (height)
|
||||
*height = rect.height;
|
||||
if (ascent)
|
||||
*ascent = -rect.y;
|
||||
if (descent)
|
||||
*descent = rect.height + rect.y;
|
||||
|
||||
g_object_unref (layout);
|
||||
g_object_unref (context);
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,156 @@
|
|||
/* 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 "libgimpcolor/gimpcolor.h"
|
||||
|
||||
#include "text-types.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 "gimptext.h"
|
||||
#include "gimptext-compat.h"
|
||||
#include "gimptextlayer.h"
|
||||
|
||||
#include "undo.h"
|
||||
|
||||
|
||||
GimpLayer *
|
||||
text_render (GimpImage *gimage,
|
||||
GimpDrawable *drawable,
|
||||
gint text_x,
|
||||
gint text_y,
|
||||
const gchar *fontname,
|
||||
const gchar *text,
|
||||
gint border,
|
||||
gint antialias)
|
||||
{
|
||||
GimpText *gtext;
|
||||
GimpLayer *layer;
|
||||
GimpRGB color;
|
||||
|
||||
g_return_val_if_fail (fontname != NULL, FALSE);
|
||||
g_return_val_if_fail (text != NULL, FALSE);
|
||||
|
||||
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_text_layer_new (gimage, gtext);
|
||||
|
||||
g_object_unref (gtext);
|
||||
|
||||
if (!layer)
|
||||
return NULL;
|
||||
|
||||
/* Start a group undo */
|
||||
undo_push_group_start (gimage, TEXT_UNDO_GROUP);
|
||||
|
||||
/* Set the layer offsets */
|
||||
GIMP_DRAWABLE (layer)->offset_x = text_x;
|
||||
GIMP_DRAWABLE (layer)->offset_y = text_y;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* If the drawable is NULL, create a new layer */
|
||||
if (drawable == NULL)
|
||||
gimp_image_add_layer (gimage, layer, -1);
|
||||
/* Otherwise, instantiate the text as the new floating selection */
|
||||
else
|
||||
floating_sel_attach (layer, drawable);
|
||||
|
||||
/* end the group undo */
|
||||
undo_push_group_end (gimage);
|
||||
|
||||
return layer;
|
||||
}
|
||||
|
||||
gboolean
|
||||
text_get_extents (const gchar *fontname,
|
||||
const gchar *text,
|
||||
gint *width,
|
||||
gint *height,
|
||||
gint *ascent,
|
||||
gint *descent)
|
||||
{
|
||||
PangoFontDescription *font_desc;
|
||||
PangoContext *context;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle rect;
|
||||
|
||||
g_return_val_if_fail (fontname != NULL, FALSE);
|
||||
g_return_val_if_fail (text != NULL, FALSE);
|
||||
|
||||
font_desc = pango_font_description_from_string (fontname);
|
||||
if (!font_desc)
|
||||
return FALSE;
|
||||
|
||||
/* FIXME: resolution */
|
||||
context = pango_ft2_get_context (72.0, 72.0);
|
||||
|
||||
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);
|
||||
|
||||
pango_layout_get_pixel_extents (layout, &rect, NULL);
|
||||
|
||||
if (width)
|
||||
*width = rect.width;
|
||||
if (height)
|
||||
*height = rect.height;
|
||||
if (ascent)
|
||||
*ascent = -rect.y;
|
||||
if (descent)
|
||||
*descent = rect.height + rect.y;
|
||||
|
||||
g_object_unref (layout);
|
||||
g_object_unref (context);
|
||||
|
||||
return TRUE;
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
/* 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__ */
|
|
@ -0,0 +1,72 @@
|
|||
/* 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;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/* 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__ */
|
|
@ -1,6 +1,9 @@
|
|||
/* 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);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -131,10 +143,10 @@ gimp_text_finalize (GObject *object)
|
|||
{
|
||||
GimpText *text = GIMP_TEXT (object);
|
||||
|
||||
if (text->str)
|
||||
if (text->text)
|
||||
{
|
||||
g_free (text->str);
|
||||
text->str = NULL;
|
||||
g_free (text->text);
|
||||
text->text = NULL;
|
||||
}
|
||||
if (text->font)
|
||||
{
|
||||
|
@ -146,9 +158,9 @@ gimp_text_finalize (GObject *object)
|
|||
}
|
||||
|
||||
static void
|
||||
gimp_text_set_property (GObject *object,
|
||||
gimp_text_get_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpText *text = GIMP_TEXT (object);
|
||||
|
@ -156,8 +168,49 @@ gimp_text_set_property (GObject *object,
|
|||
switch (property_id)
|
||||
{
|
||||
case PROP_TEXT:
|
||||
g_free (text->str);
|
||||
text->str = g_value_dup_string (value);
|
||||
g_value_set_string (value, text->text);
|
||||
break;
|
||||
case PROP_FONT:
|
||||
g_value_set_string (value, text->font);
|
||||
break;
|
||||
case PROP_SIZE:
|
||||
g_value_set_double (value, text->size);
|
||||
break;
|
||||
case PROP_BORDER:
|
||||
g_value_set_double (value, text->border);
|
||||
break;
|
||||
case PROP_UNIT:
|
||||
g_value_set_int (value, text->unit);
|
||||
break;
|
||||
case PROP_COLOR:
|
||||
g_value_set_boxed (value, &text->color);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
g_value_set_double (value, text->letter_spacing);
|
||||
break;
|
||||
case PROP_LINE_SPACING:
|
||||
g_value_set_double (value, text->line_spacing);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GimpText *text = GIMP_TEXT (object);
|
||||
GimpRGB *color;
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_TEXT:
|
||||
g_free (text->text);
|
||||
text->text = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_FONT:
|
||||
g_free (text->font);
|
||||
|
@ -172,6 +225,10 @@ gimp_text_set_property (GObject *object,
|
|||
case PROP_UNIT:
|
||||
text->unit = g_value_get_int (value);
|
||||
break;
|
||||
case PROP_COLOR:
|
||||
color = g_value_get_boxed (value);
|
||||
text->color = *color;
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
text->letter_spacing = g_value_get_double (value);
|
||||
break;
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
/* 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
|
||||
|
@ -33,11 +36,12 @@ struct _GimpText
|
|||
{
|
||||
GObject parent_instance;
|
||||
|
||||
gchar *str;
|
||||
gchar *text;
|
||||
gchar *font;
|
||||
gdouble size;
|
||||
gdouble border;
|
||||
GimpUnit unit;
|
||||
GimpRGB color;
|
||||
gdouble letter_spacing;
|
||||
gdouble line_spacing;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,330 @@
|
|||
/* 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 "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "text-types.h"
|
||||
|
||||
#include "base/pixel-region.h"
|
||||
#include "base/tile-manager.h"
|
||||
|
||||
#include "paint-funcs/paint-funcs.h"
|
||||
|
||||
#include "core/gimpimage.h"
|
||||
|
||||
#include "gimptext.h"
|
||||
#include "gimptext-render.h"
|
||||
#include "gimptextlayer.h"
|
||||
|
||||
|
||||
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 gsize gimp_text_layer_get_memsize (GimpObject *object);
|
||||
|
||||
static TempBuf * gimp_text_layer_get_preview (GimpViewable *viewable,
|
||||
gint width,
|
||||
gint height);
|
||||
|
||||
static void gimp_text_layer_ensure_context (GimpTextLayer *layer);
|
||||
static PangoLayout * gimp_text_layer_layout_new (GimpTextLayer *layer,
|
||||
gint *border);
|
||||
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
|
||||
PangoLayout *layout,
|
||||
gint x,
|
||||
gint y);
|
||||
|
||||
|
||||
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;
|
||||
GimpObjectClass *gimp_object_class;
|
||||
GimpViewableClass *viewable_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
gimp_object_class = GIMP_OBJECT_CLASS (klass);
|
||||
viewable_class = GIMP_VIEWABLE_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_text_layer_finalize;
|
||||
|
||||
gimp_object_class->get_memsize = gimp_text_layer_get_memsize;
|
||||
|
||||
viewable_class->get_preview = gimp_text_layer_get_preview;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layer_init (GimpTextLayer *layer)
|
||||
{
|
||||
layer->text = NULL;
|
||||
layer->context = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layer_finalize (GObject *object)
|
||||
{
|
||||
GimpTextLayer *layer;
|
||||
|
||||
layer = GIMP_TEXT_LAYER (object);
|
||||
|
||||
if (layer->text)
|
||||
{
|
||||
g_object_unref (layer->text);
|
||||
layer->text = NULL;
|
||||
}
|
||||
if (layer->context)
|
||||
{
|
||||
g_object_unref (layer->context);
|
||||
layer->context = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
GimpLayer *
|
||||
gimp_text_layer_new (GimpImage *gimage,
|
||||
GimpText *text)
|
||||
{
|
||||
GimpTextLayer *layer;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle ink;
|
||||
PangoRectangle logical;
|
||||
gint border;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), 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);
|
||||
|
||||
layer->text = g_object_ref (text);
|
||||
gimp_item_set_image (GIMP_ITEM (layer), gimage);
|
||||
|
||||
layout = gimp_text_layer_layout_new (layer, &border);
|
||||
|
||||
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 < 1 || ink.height < 1)
|
||||
{
|
||||
g_object_unref (layout);
|
||||
g_object_unref (layer);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ink.width > 8192) ink.width = 8192;
|
||||
if (ink.height > 8192) ink.height = 8192;
|
||||
|
||||
gimp_drawable_configure (GIMP_DRAWABLE (layer),
|
||||
gimage,
|
||||
ink.width + 2 * border,
|
||||
ink.height + 2 * border,
|
||||
gimp_image_base_type_with_alpha (gimage),
|
||||
text->text /* name */);
|
||||
|
||||
gimp_text_layer_render_layout (layer, layout,
|
||||
border - ink.x, border - ink.y);
|
||||
g_object_unref (layout);
|
||||
|
||||
return GIMP_LAYER (layer);
|
||||
}
|
||||
|
||||
static gsize
|
||||
gimp_text_layer_get_memsize (GimpObject *object)
|
||||
{
|
||||
GimpTextLayer *text_layer;
|
||||
gsize memsize = 0;
|
||||
|
||||
text_layer = GIMP_TEXT_LAYER (object);
|
||||
|
||||
if (text_layer->text)
|
||||
{
|
||||
memsize += sizeof (GimpText);
|
||||
|
||||
if (text_layer->text->text)
|
||||
memsize += strlen (text_layer->text->text);
|
||||
}
|
||||
|
||||
return memsize + GIMP_OBJECT_CLASS (parent_class)->get_memsize (object);
|
||||
}
|
||||
|
||||
static TempBuf *
|
||||
gimp_text_layer_get_preview (GimpViewable *viewable,
|
||||
gint width,
|
||||
gint height)
|
||||
{
|
||||
return GIMP_VIEWABLE_CLASS (parent_class)->get_preview (viewable,
|
||||
width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layer_ensure_context (GimpTextLayer *layer)
|
||||
{
|
||||
GimpImage *image;
|
||||
gdouble xres, yres;
|
||||
|
||||
if (layer->context)
|
||||
return;
|
||||
|
||||
image = gimp_item_get_image (GIMP_ITEM (layer));
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
|
||||
layer->context = pango_ft2_get_context (xres, yres);
|
||||
|
||||
g_signal_connect_object (image, "resolution_changed",
|
||||
G_CALLBACK (g_object_unref),
|
||||
layer->context, G_CONNECT_SWAPPED);
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (layer->context),
|
||||
(gpointer *) &layer->context);
|
||||
}
|
||||
|
||||
static PangoLayout *
|
||||
gimp_text_layer_layout_new (GimpTextLayer *layer,
|
||||
gint *border)
|
||||
{
|
||||
GimpText *text = layer->text;
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *font_desc;
|
||||
gint size;
|
||||
|
||||
font_desc = pango_font_description_from_string (text->font);
|
||||
g_return_val_if_fail (font_desc != NULL, NULL);
|
||||
if (!font_desc)
|
||||
return NULL;
|
||||
|
||||
switch (text->unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
size = PANGO_SCALE * text->size;
|
||||
*border = text->border;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
GimpImage *image;
|
||||
gdouble xres, yres;
|
||||
gdouble factor;
|
||||
|
||||
factor = gimp_unit_get_factor (text->unit);
|
||||
g_return_val_if_fail (factor > 0.0, NULL);
|
||||
|
||||
image = gimp_item_get_image (GIMP_ITEM (layer));
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
|
||||
size = (gdouble) PANGO_SCALE * text->size * yres / factor;
|
||||
*border = text->border * yres / factor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (size > 1)
|
||||
pango_font_description_set_size (font_desc, size);
|
||||
|
||||
gimp_text_layer_ensure_context (layer);
|
||||
|
||||
layout = pango_layout_new (layer->context);
|
||||
|
||||
pango_layout_set_font_description (layout, font_desc);
|
||||
pango_font_description_free (font_desc);
|
||||
|
||||
pango_layout_set_text (layout, text->text, -1);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layer_render_layout (GimpTextLayer *layer,
|
||||
PangoLayout *layout,
|
||||
gint x,
|
||||
gint y)
|
||||
{
|
||||
GimpDrawable *drawable = GIMP_DRAWABLE (layer);
|
||||
TileManager *mask;
|
||||
PixelRegion textPR;
|
||||
PixelRegion maskPR;
|
||||
gint width;
|
||||
gint height;
|
||||
|
||||
gimp_drawable_fill (drawable, &layer->text->color);
|
||||
|
||||
width = gimp_drawable_width (drawable);
|
||||
height = gimp_drawable_height (drawable);
|
||||
|
||||
mask = gimp_text_render_layout (layout, x, y, width, height);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/* 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_LAYER_H__
|
||||
#define __GIMP_TEXT_LAYER_H__
|
||||
|
||||
|
||||
#include "core/gimplayer.h"
|
||||
|
||||
|
||||
#define GIMP_TYPE_TEXT_LAYER (gimp_text_layer_get_type ())
|
||||
#define GIMP_TEXT_LAYER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TEXT_LAYER, GimpTextLayer))
|
||||
#define GIMP_TEXT_LAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_TEXT_LAYER, GimpTextLayerClass))
|
||||
#define GIMP_IS_TEXT_LAYER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TEXT_LAYER))
|
||||
#define GIMP_IS_TEXT_LAYER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_TEXT_LAYER))
|
||||
#define GIMP_TEXT_LAYER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_TEXT_LAYER, GimpTextLayerClass))
|
||||
|
||||
|
||||
typedef struct _GimpTextLayerClass GimpTextLayerClass;
|
||||
|
||||
struct _GimpTextLayer
|
||||
{
|
||||
GimpLayer layer;
|
||||
|
||||
GimpText *text;
|
||||
PangoContext *context; /* should move to GimpImage ? */
|
||||
};
|
||||
|
||||
struct _GimpTextLayerClass
|
||||
{
|
||||
GimpLayerClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
/* function declarations */
|
||||
|
||||
GType gimp_text_layer_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GimpLayer * gimp_text_layer_new (GimpImage *gimage,
|
||||
GimpText *text);
|
||||
|
||||
|
||||
#endif /* __GIMP_TEXT_LAYER_H__ */
|
|
@ -1,6 +1,9 @@
|
|||
/* 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
|
||||
|
@ -22,7 +25,8 @@
|
|||
#include "core/core-types.h"
|
||||
|
||||
|
||||
typedef struct _GimpText GimpText;
|
||||
typedef struct _GimpText GimpText;
|
||||
typedef struct _GimpTextLayer GimpTextLayer;
|
||||
|
||||
|
||||
#endif /* __TEXT_TYPES_H__ */
|
||||
|
|
|
@ -33,14 +33,15 @@
|
|||
#include "config/gimpdisplayconfig.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpimage-mask.h"
|
||||
#include "core/gimpimage-text.h"
|
||||
#include "core/gimplayer.h"
|
||||
#include "core/gimplayer-floating-sel.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
|
||||
#include "text/gimptext.h"
|
||||
#include "text/gimptextlayer.h"
|
||||
|
||||
#include "widgets/gimpfontselection.h"
|
||||
#include "widgets/gimpwidgets-utils.h"
|
||||
|
@ -327,6 +328,7 @@ text_tool_render (GimpTextTool *text_tool)
|
|||
GimpImage *gimage;
|
||||
GimpText *text;
|
||||
GimpLayer *layer;
|
||||
GimpRGB color;
|
||||
const gchar *font;
|
||||
gchar *str;
|
||||
GtkTextIter start_iter;
|
||||
|
@ -350,18 +352,21 @@ text_tool_render (GimpTextTool *text_tool)
|
|||
if (!str)
|
||||
return;
|
||||
|
||||
gimp_context_get_foreground (gimp_get_current_context (gimage->gimp), &color);
|
||||
|
||||
text = GIMP_TEXT (g_object_new (GIMP_TYPE_TEXT,
|
||||
"text", str,
|
||||
"font", font,
|
||||
"size", options->size,
|
||||
"border", options->border,
|
||||
"unit", options->unit,
|
||||
"color", &color,
|
||||
"letter-spacing", options->letter_spacing,
|
||||
"line-spacing", options->line_spacing,
|
||||
NULL));
|
||||
g_free (str);
|
||||
|
||||
layer = gimp_image_text_render (gimage, text);
|
||||
layer = gimp_text_layer_new (gimage, text);
|
||||
|
||||
g_object_unref (text);
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
||||
|
||||
|
|
|
@ -245,8 +245,8 @@ HELP
|
|||
);
|
||||
}
|
||||
|
||||
@headers = qw("libgimpbase/gimpbase.h"
|
||||
"core/gimpimage-text.h" <stdio.h> <string.h>);
|
||||
@headers = qw("libgimpbase/gimpbase.h" "text/gimptext-compat.h"
|
||||
<stdio.h> <string.h>);
|
||||
|
||||
$extra{app}->{code} = <<'CODE';
|
||||
|
||||
|
|
Loading…
Reference in New Issue