mirror of https://github.com/GNOME/gimp.git
fixed rules for generated sources.
2003-02-05 Sven Neumann <sven@gimp.org> * app/paint/Makefile.am: fixed rules for generated sources. * app/text/Makefile.am * app/text/text-enums.[ch]: added new files with text-related enums. * app/text/gimptext.[ch]: added text alignment property. * app/text/gimptext-render.[ch]: removed * app/text/text-types.h * app/text/gimptextlayout.[ch]: added new files that define GimpTextLayout, a wrapper around PangoLayout. Moved render code to this file. * app/text/gimptextlayer.c: changed accordingly.
This commit is contained in:
parent
62304b0fb5
commit
4f22db2174
18
ChangeLog
18
ChangeLog
|
@ -1,3 +1,21 @@
|
|||
2003-02-05 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/paint/Makefile.am: fixed rules for generated sources.
|
||||
|
||||
* app/text/Makefile.am
|
||||
* app/text/text-enums.[ch]: added new files with text-related enums.
|
||||
|
||||
* app/text/gimptext.[ch]: added text alignment property.
|
||||
|
||||
* app/text/gimptext-render.[ch]: removed
|
||||
|
||||
* app/text/text-types.h
|
||||
* app/text/gimptextlayout.[ch]: added new files that define
|
||||
GimpTextLayout, a wrapper around PangoLayout. Moved render code to
|
||||
this file.
|
||||
|
||||
* app/text/gimptextlayer.c: changed accordingly.
|
||||
|
||||
2003-02-04 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/widgets/gimpitemfactory.c (gimp_item_factory_item_key_press):
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DG_LOG_DOMAIN=\"Gimp-Paint\" \
|
||||
@GIMP_THREAD_FLAGS@ \
|
||||
@GIMP_MP_FLAGS@
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_builddir) \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_builddir)/app \
|
||||
-I$(top_srcdir)/app \
|
||||
$(GTK_CFLAGS) \
|
||||
-I$(includedir)
|
||||
|
||||
noinst_LIBRARIES = libapppaint.a
|
||||
|
||||
libapppaint_a_SOURCES = \
|
||||
libapppaint_a_sources = \
|
||||
paint-enums.h \
|
||||
paint-enums.c \
|
||||
paint-types.h \
|
||||
paint.c \
|
||||
paint.h \
|
||||
|
@ -32,18 +44,9 @@ libapppaint_a_SOURCES = \
|
|||
gimpsmudge.c \
|
||||
gimpsmudge.h
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-DG_LOG_DOMAIN=\"Gimp-Paint\" \
|
||||
@GIMP_THREAD_FLAGS@ \
|
||||
@GIMP_MP_FLAGS@
|
||||
libapppaint_a_built_sources = paint-enums.c
|
||||
|
||||
INCLUDES = \
|
||||
-I$(top_builddir) \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_builddir)/app \
|
||||
-I$(top_srcdir)/app \
|
||||
$(GTK_CFLAGS) \
|
||||
-I$(includedir)
|
||||
libapppaint_a_SOURCES = $(libapppaint_a_built_sources) $(libapppaint_a_sources)
|
||||
|
||||
#
|
||||
# rules to generate built sources
|
||||
|
|
|
@ -14,15 +14,36 @@ INCLUDES = \
|
|||
|
||||
noinst_LIBRARIES = libapptext.a
|
||||
|
||||
libapptext_a_SOURCES = \
|
||||
libapptext_a_sources = \
|
||||
text-types.h \
|
||||
text-enums.h \
|
||||
gimptext.c \
|
||||
gimptext.h \
|
||||
gimptext-compat.c \
|
||||
gimptext-compat.h \
|
||||
gimptext-render.c \
|
||||
gimptext-render.h \
|
||||
gimptextlayer.c \
|
||||
gimptextlayer.h
|
||||
gimptextlayer.h \
|
||||
gimptextlayout.c \
|
||||
gimptextlayout.h
|
||||
|
||||
libapptext_a_built_sources = text-enums.c
|
||||
|
||||
libapptext_a_SOURCES = $(libapptext_a_built_sources) $(libapptext_a_sources)
|
||||
|
||||
#
|
||||
# rules to generate built sources
|
||||
#
|
||||
# setup autogeneration dependencies
|
||||
gen_sources = xgen-tec
|
||||
CLEANFILES = $(gen_sources)
|
||||
|
||||
$(srcdir)/text-enums.c: $(srcdir)/text-enums.h $(GIMP_MKENUMS)
|
||||
$(GIMP_MKENUMS) \
|
||||
--fhead "#include \"config.h\"\n#include <glib-object.h>\n#include \"text-enums.h\"\n#include \"libgimp/gimpintl.h\"" \
|
||||
--fprod "\n/* enumerations from \"@filename@\" */" \
|
||||
--vhead "\nstatic const GEnumValue @enum_name@_enum_values[] =\n{" \
|
||||
--vprod " { @VALUENAME@, @valuedesc@, \"@valuenick@\" }," \
|
||||
--vtail " { 0, NULL, NULL }\n};\n\nGType\n@enum_name@_get_type (void)\n{\n static GType enum_type = 0;\n\n if (!enum_type)\n enum_type = g_enum_register_static (\"@EnumName@\", @enum_name@_enum_values);\n\n return enum_type;\n}\n" \
|
||||
$(srcdir)/text-enums.h > xgen-tec \
|
||||
&& cp xgen-tec $(@F) \
|
||||
&& rm -f xgen-tec
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
/* 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;
|
||||
}
|
|
@ -41,6 +41,7 @@ enum
|
|||
PROP_FONT_SIZE,
|
||||
PROP_FONT_SIZE_UNIT,
|
||||
PROP_COLOR,
|
||||
PROP_ALIGNMENT,
|
||||
PROP_LETTER_SPACING,
|
||||
PROP_LINE_SPACING,
|
||||
PROP_FIXED_WIDTH,
|
||||
|
@ -137,6 +138,11 @@ gimp_text_class_init (GimpTextClass *klass)
|
|||
"color", NULL,
|
||||
&black,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_ALIGNMENT,
|
||||
"alignment", NULL,
|
||||
GIMP_TYPE_TEXT_ALIGNMENT,
|
||||
GIMP_TEXT_ALIGNMENT_LEFT,
|
||||
0);
|
||||
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_LETTER_SPACING,
|
||||
"letter-spacing", NULL,
|
||||
0.0, 64.0, 1.0,
|
||||
|
@ -210,6 +216,9 @@ gimp_text_get_property (GObject *object,
|
|||
case PROP_COLOR:
|
||||
g_value_set_boxed (value, &text->color);
|
||||
break;
|
||||
case PROP_ALIGNMENT:
|
||||
g_value_set_enum (value, text->alignment);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
g_value_set_double (value, text->letter_spacing);
|
||||
break;
|
||||
|
@ -260,6 +269,9 @@ gimp_text_set_property (GObject *object,
|
|||
color = g_value_get_boxed (value);
|
||||
text->color = *color;
|
||||
break;
|
||||
case PROP_ALIGNMENT:
|
||||
text->alignment = g_value_get_enum (value);
|
||||
break;
|
||||
case PROP_LETTER_SPACING:
|
||||
text->letter_spacing = g_value_get_double (value);
|
||||
break;
|
||||
|
|
|
@ -41,6 +41,7 @@ struct _GimpText
|
|||
gdouble font_size;
|
||||
GimpUnit font_size_unit;
|
||||
GimpRGB color;
|
||||
GimpTextAlignment alignment;
|
||||
gdouble letter_spacing;
|
||||
gdouble line_spacing;
|
||||
gint fixed_width;
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
#include <glib-object.h>
|
||||
#include <pango/pangoft2.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
|
||||
#include "text-types.h"
|
||||
|
||||
#include "base/pixel-region.h"
|
||||
|
@ -38,8 +36,8 @@
|
|||
#include "core/gimpimage.h"
|
||||
|
||||
#include "gimptext.h"
|
||||
#include "gimptext-render.h"
|
||||
#include "gimptextlayer.h"
|
||||
#include "gimptextlayout.h"
|
||||
|
||||
|
||||
static void gimp_text_layer_class_init (GimpTextLayerClass *klass);
|
||||
|
@ -47,26 +45,16 @@ 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 PangoLayout * gimp_text_layer_layout_new (GimpTextLayer *layer);
|
||||
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
|
||||
static gboolean gimp_text_layer_position_layout (GimpTextLayer *layer,
|
||||
PangoLayout *layout,
|
||||
PangoRectangle *pos);
|
||||
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
|
||||
PangoLayout *layout,
|
||||
gint x,
|
||||
gint y);
|
||||
|
||||
static PangoContext * gimp_image_get_pango_context (GimpImage *image);
|
||||
GimpTextLayout *layout);
|
||||
|
||||
|
||||
static GimpLayerClass *parent_class = NULL;
|
||||
static GQuark gimp_text_layer_context_quark;
|
||||
|
||||
|
||||
GType
|
||||
|
@ -115,8 +103,6 @@ gimp_text_layer_class_init (GimpTextLayerClass *klass)
|
|||
gimp_object_class->get_memsize = gimp_text_layer_get_memsize;
|
||||
|
||||
viewable_class->get_preview = gimp_text_layer_get_preview;
|
||||
|
||||
gimp_text_layer_context_quark = g_quark_from_static_string ("pango-context");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -217,24 +203,28 @@ gimp_text_layer_render (GimpTextLayer *layer)
|
|||
{
|
||||
GimpImage *image;
|
||||
GimpDrawable *drawable;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle pos;
|
||||
GimpTextLayout *layout;
|
||||
gint width;
|
||||
gint height;
|
||||
gchar *name;
|
||||
gchar *newline;
|
||||
|
||||
layout = gimp_text_layer_layout_new (layer);
|
||||
image = gimp_item_get_image (GIMP_ITEM (layer));
|
||||
|
||||
if (!gimp_text_layer_position_layout (layer, layout, &pos))
|
||||
layout = gimp_text_layout_new (layer->text, image);
|
||||
|
||||
gimp_text_layout_get_size (layout, &width, &height);
|
||||
|
||||
if (! gimp_text_layout_get_size (layout, &width, &height))
|
||||
{
|
||||
g_object_unref (layout);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
image = gimp_item_get_image (GIMP_ITEM (layer));
|
||||
drawable = GIMP_DRAWABLE (layer);
|
||||
|
||||
if (pos.width != gimp_drawable_width (drawable) ||
|
||||
pos.height != gimp_drawable_height (drawable))
|
||||
if (width != gimp_drawable_width (drawable) ||
|
||||
height != gimp_drawable_height (drawable))
|
||||
{
|
||||
gimp_drawable_update (GIMP_DRAWABLE (layer),
|
||||
0, 0,
|
||||
|
@ -242,15 +232,13 @@ gimp_text_layer_render (GimpTextLayer *layer)
|
|||
gimp_drawable_height (drawable));
|
||||
|
||||
|
||||
drawable->width = pos.width;
|
||||
drawable->height = pos.height;
|
||||
drawable->width = width;
|
||||
drawable->height = height;
|
||||
|
||||
if (drawable->tiles)
|
||||
tile_manager_destroy (drawable->tiles);
|
||||
|
||||
drawable->tiles = tile_manager_new (drawable->width,
|
||||
drawable->height,
|
||||
drawable->bytes);
|
||||
drawable->tiles = tile_manager_new (width, height, drawable->bytes);
|
||||
|
||||
gimp_viewable_size_changed (GIMP_VIEWABLE (layer));
|
||||
}
|
||||
|
@ -267,176 +255,18 @@ gimp_text_layer_render (GimpTextLayer *layer)
|
|||
gimp_object_set_name (GIMP_OBJECT (layer), layer->text->text);
|
||||
}
|
||||
|
||||
gimp_text_layer_render_layout (layer, layout, pos.x, pos.y);
|
||||
gimp_text_layer_render_layout (layer, layout);
|
||||
g_object_unref (layout);
|
||||
|
||||
gimp_drawable_update (drawable, 0, 0, pos.width, pos.height);
|
||||
gimp_drawable_update (drawable, 0, 0, width, height);
|
||||
gimp_image_flush (image);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static PangoLayout *
|
||||
gimp_text_layer_layout_new (GimpTextLayer *layer)
|
||||
{
|
||||
GimpText *text = layer->text;
|
||||
GimpImage *image;
|
||||
PangoContext *context;
|
||||
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;
|
||||
|
||||
image = gimp_item_get_image (GIMP_ITEM (layer));
|
||||
|
||||
switch (text->font_size_unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
size = PANGO_SCALE * text->font_size;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
gdouble xres, yres;
|
||||
gdouble factor;
|
||||
|
||||
factor = gimp_unit_get_factor (text->font_size_unit);
|
||||
g_return_val_if_fail (factor > 0.0, NULL);
|
||||
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
|
||||
size = (gdouble) PANGO_SCALE * text->font_size * yres / factor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (size > 1)
|
||||
pango_font_description_set_size (font_desc, size);
|
||||
|
||||
context = gimp_image_get_pango_context (image);
|
||||
|
||||
layout = pango_layout_new (context);
|
||||
g_object_unref (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 gboolean
|
||||
gimp_text_layer_position_layout (GimpTextLayer *layer,
|
||||
PangoLayout *layout,
|
||||
PangoRectangle *pos)
|
||||
{
|
||||
GimpText *text;
|
||||
PangoRectangle ink;
|
||||
PangoRectangle logical;
|
||||
gint x1, y1;
|
||||
gint x2, y2;
|
||||
gboolean fixed;
|
||||
|
||||
text = layer->text;
|
||||
fixed = (text->fixed_width > 1 && text->fixed_height > 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 (!fixed)
|
||||
{
|
||||
if (ink.width < 1 || ink.height < 1)
|
||||
return FALSE;
|
||||
|
||||
/* sanity checks for insane font sizes */
|
||||
if (ink.width > 8192) ink.width = 8192;
|
||||
if (ink.height > 8192) ink.height = 8192;
|
||||
}
|
||||
|
||||
x1 = MIN (0, logical.x);
|
||||
y1 = MIN (0, logical.y);
|
||||
x2 = MAX (ink.x + ink.width, logical.x + logical.width);
|
||||
y2 = MAX (ink.y + ink.height, logical.y + logical.height);
|
||||
|
||||
pos->width = fixed ? text->fixed_width : x2 - x1;
|
||||
pos->height = fixed ? text->fixed_height : y2 - y1;
|
||||
|
||||
/* border should only be used by the compatibility API;
|
||||
we assume that gravity is CENTER
|
||||
*/
|
||||
if (text->border)
|
||||
{
|
||||
fixed = TRUE;
|
||||
|
||||
pos->width += 2 * text->border;
|
||||
pos->height += 2 * text->border;
|
||||
}
|
||||
|
||||
pos->x = 0;
|
||||
pos->y = 0;
|
||||
|
||||
if (!fixed)
|
||||
return TRUE;
|
||||
|
||||
switch (text->gravity)
|
||||
{
|
||||
case GIMP_GRAVITY_NORTH_WEST:
|
||||
case GIMP_GRAVITY_SOUTH_WEST:
|
||||
case GIMP_GRAVITY_WEST:
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_NONE:
|
||||
case GIMP_GRAVITY_CENTER:
|
||||
case GIMP_GRAVITY_NORTH:
|
||||
case GIMP_GRAVITY_SOUTH:
|
||||
pos->x += (pos->width - logical.width) / 2;
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_NORTH_EAST:
|
||||
case GIMP_GRAVITY_SOUTH_EAST:
|
||||
case GIMP_GRAVITY_EAST:
|
||||
pos->x += (pos->width - logical.width);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (text->gravity)
|
||||
{
|
||||
case GIMP_GRAVITY_NORTH:
|
||||
case GIMP_GRAVITY_NORTH_WEST:
|
||||
case GIMP_GRAVITY_NORTH_EAST:
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_NONE:
|
||||
case GIMP_GRAVITY_CENTER:
|
||||
case GIMP_GRAVITY_WEST:
|
||||
case GIMP_GRAVITY_EAST:
|
||||
pos->y += (pos->height - logical.height) / 2;
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_SOUTH:
|
||||
case GIMP_GRAVITY_SOUTH_WEST:
|
||||
case GIMP_GRAVITY_SOUTH_EAST:
|
||||
pos->y += (pos->height - logical.height);
|
||||
break;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layer_render_layout (GimpTextLayer *layer,
|
||||
PangoLayout *layout,
|
||||
gint x,
|
||||
gint y)
|
||||
GimpTextLayout *layout)
|
||||
{
|
||||
GimpDrawable *drawable = GIMP_DRAWABLE (layer);
|
||||
TileManager *mask;
|
||||
|
@ -450,7 +280,7 @@ gimp_text_layer_render_layout (GimpTextLayer *layer,
|
|||
width = gimp_drawable_width (drawable);
|
||||
height = gimp_drawable_height (drawable);
|
||||
|
||||
mask = gimp_text_render_layout (layout, x, y, width, height);
|
||||
mask = gimp_text_layout_render (layout);
|
||||
|
||||
pixel_region_init (&textPR,
|
||||
GIMP_DRAWABLE (layer)->tiles, 0, 0, width, height, TRUE);
|
||||
|
@ -461,38 +291,3 @@ gimp_text_layer_render_layout (GimpTextLayer *layer,
|
|||
|
||||
tile_manager_destroy (mask);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
detach_pango_context (GObject *image)
|
||||
{
|
||||
g_object_set_qdata (image, gimp_text_layer_context_quark, NULL);
|
||||
}
|
||||
|
||||
static PangoContext *
|
||||
gimp_image_get_pango_context (GimpImage *image)
|
||||
{
|
||||
PangoContext *context;
|
||||
|
||||
context = (PangoContext *) g_object_get_qdata (G_OBJECT (image),
|
||||
gimp_text_layer_context_quark);
|
||||
|
||||
if (!context)
|
||||
{
|
||||
gdouble xres, yres;
|
||||
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
|
||||
context = pango_ft2_get_context (xres, yres);
|
||||
|
||||
g_signal_connect_object (image, "resolution_changed",
|
||||
G_CALLBACK (detach_pango_context),
|
||||
context, 0);
|
||||
|
||||
g_object_set_qdata_full (G_OBJECT (image),
|
||||
gimp_text_layer_context_quark, context,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
}
|
||||
|
||||
return g_object_ref (context);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,402 @@
|
|||
/* 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 "core/gimpimage.h"
|
||||
|
||||
#include "gimptext.h"
|
||||
#include "gimptextlayout.h"
|
||||
|
||||
|
||||
struct _GimpTextLayout
|
||||
{
|
||||
GObject object;
|
||||
|
||||
GimpText *text;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle extents;
|
||||
};
|
||||
|
||||
struct _GimpTextLayoutClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
static void gimp_text_layout_class_init (GimpTextLayoutClass *klass);
|
||||
static void gimp_text_layout_init (GimpTextLayout *layout);
|
||||
static void gimp_text_layout_finalize (GObject *object);
|
||||
|
||||
static void gimp_text_layout_position (GimpTextLayout *layout);
|
||||
|
||||
static PangoContext * gimp_image_get_pango_context (GimpImage *image);
|
||||
|
||||
|
||||
static GQuark gimp_text_context_quark = 0;
|
||||
static GObjectClass * parent_class = NULL;
|
||||
|
||||
|
||||
GType
|
||||
gimp_text_layout_get_type (void)
|
||||
{
|
||||
static GType layout_type = 0;
|
||||
|
||||
if (! layout_type)
|
||||
{
|
||||
static const GTypeInfo layout_info =
|
||||
{
|
||||
sizeof (GimpTextLayoutClass),
|
||||
(GBaseInitFunc) NULL,
|
||||
(GBaseFinalizeFunc) NULL,
|
||||
(GClassInitFunc) gimp_text_layout_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GimpTextLayout),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gimp_text_layout_init,
|
||||
};
|
||||
|
||||
layout_type = g_type_register_static (G_TYPE_OBJECT,
|
||||
"GimpTextLayout",
|
||||
&layout_info, 0);
|
||||
}
|
||||
|
||||
return layout_type;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layout_class_init (GimpTextLayoutClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_text_layout_finalize;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layout_init (GimpTextLayout *layout)
|
||||
{
|
||||
layout->text = NULL;
|
||||
layout->layout = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layout_finalize (GObject *object)
|
||||
{
|
||||
GimpTextLayout *layout;
|
||||
|
||||
layout = GIMP_TEXT_LAYOUT (object);
|
||||
|
||||
if (layout->text)
|
||||
{
|
||||
g_object_unref (layout->text);
|
||||
layout->text = NULL;
|
||||
}
|
||||
if (layout->layout)
|
||||
{
|
||||
g_object_unref (layout->layout);
|
||||
layout->layout = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
GimpTextLayout *
|
||||
gimp_text_layout_new (GimpText *text,
|
||||
GimpImage *image)
|
||||
{
|
||||
GimpTextLayout *layout;
|
||||
PangoContext *context;
|
||||
PangoFontDescription *font_desc;
|
||||
gint size;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
|
||||
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
||||
|
||||
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->font_size_unit)
|
||||
{
|
||||
case GIMP_UNIT_PIXEL:
|
||||
size = PANGO_SCALE * text->font_size;
|
||||
break;
|
||||
|
||||
default:
|
||||
{
|
||||
gdouble xres, yres;
|
||||
gdouble factor;
|
||||
|
||||
factor = gimp_unit_get_factor (text->font_size_unit);
|
||||
g_return_val_if_fail (factor > 0.0, NULL);
|
||||
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
|
||||
size = (gdouble) PANGO_SCALE * text->font_size * yres / factor;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (size > 1)
|
||||
pango_font_description_set_size (font_desc, size);
|
||||
|
||||
context = gimp_image_get_pango_context (image);
|
||||
|
||||
layout = g_object_new (GIMP_TYPE_TEXT_LAYOUT, NULL);
|
||||
layout->text = g_object_ref (text);
|
||||
layout->layout = pango_layout_new (context);
|
||||
|
||||
g_object_unref (context);
|
||||
|
||||
pango_layout_set_font_description (layout->layout, font_desc);
|
||||
pango_font_description_free (font_desc);
|
||||
|
||||
pango_layout_set_text (layout->layout, text->text, -1);
|
||||
pango_layout_set_alignment (layout->layout, text->alignment);
|
||||
|
||||
gimp_text_layout_position (layout);
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gimp_text_layout_get_size (GimpTextLayout *layout,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), FALSE);
|
||||
|
||||
if (width)
|
||||
*width = layout->extents.width;
|
||||
if (height)
|
||||
*height = layout->extents.height;
|
||||
|
||||
return (layout->extents.width > 0 && layout->extents.height > 0);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_text_layout_get_offsets (GimpTextLayout *layout,
|
||||
gint *x,
|
||||
gint *y)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_TEXT_LAYOUT (layout));
|
||||
|
||||
if (x)
|
||||
*x = layout->extents.x;
|
||||
if (y)
|
||||
*y = layout->extents.y;
|
||||
}
|
||||
|
||||
TileManager *
|
||||
gimp_text_layout_render (GimpTextLayout *layout)
|
||||
{
|
||||
TileManager *mask;
|
||||
FT_Bitmap bitmap;
|
||||
PixelRegion maskPR;
|
||||
gint i;
|
||||
gint x, y;
|
||||
gint width, height;
|
||||
|
||||
g_return_val_if_fail (GIMP_IS_TEXT_LAYOUT (layout), NULL);
|
||||
|
||||
gimp_text_layout_get_size (layout, &width, &height);
|
||||
gimp_text_layout_get_offsets (layout, &x, &y);
|
||||
|
||||
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->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;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_text_layout_position (GimpTextLayout *layout)
|
||||
{
|
||||
GimpText *text;
|
||||
PangoRectangle ink;
|
||||
PangoRectangle logical;
|
||||
gint x1, y1;
|
||||
gint x2, y2;
|
||||
gboolean fixed;
|
||||
|
||||
layout->extents.x = 0;
|
||||
layout->extents.x = 0;
|
||||
layout->extents.width = 0;
|
||||
layout->extents.height = 0;
|
||||
|
||||
text = layout->text;
|
||||
|
||||
fixed = (text->fixed_width > 1 && text->fixed_height > 1);
|
||||
|
||||
pango_layout_get_pixel_extents (layout->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 (!fixed)
|
||||
{
|
||||
if (ink.width < 1 || ink.height < 1)
|
||||
return;
|
||||
|
||||
/* sanity checks for insane font sizes */
|
||||
if (ink.width > 8192) ink.width = 8192;
|
||||
if (ink.height > 8192) ink.height = 8192;
|
||||
}
|
||||
|
||||
x1 = MIN (0, logical.x);
|
||||
y1 = MIN (0, logical.y);
|
||||
x2 = MAX (ink.x + ink.width, logical.x + logical.width);
|
||||
y2 = MAX (ink.y + ink.height, logical.y + logical.height);
|
||||
|
||||
layout->extents.width = fixed ? text->fixed_width : x2 - x1;
|
||||
layout->extents.height = fixed ? text->fixed_height : y2 - y1;
|
||||
|
||||
/* border should only be used by the compatibility API;
|
||||
we assume that gravity is CENTER
|
||||
*/
|
||||
if (text->border)
|
||||
{
|
||||
fixed = TRUE;
|
||||
|
||||
layout->extents.width += 2 * text->border;
|
||||
layout->extents.height += 2 * text->border;
|
||||
}
|
||||
|
||||
layout->extents.x = 0;
|
||||
layout->extents.y = 0;
|
||||
|
||||
if (!fixed)
|
||||
return;
|
||||
|
||||
switch (text->gravity)
|
||||
{
|
||||
case GIMP_GRAVITY_NORTH_WEST:
|
||||
case GIMP_GRAVITY_SOUTH_WEST:
|
||||
case GIMP_GRAVITY_WEST:
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_NONE:
|
||||
case GIMP_GRAVITY_CENTER:
|
||||
case GIMP_GRAVITY_NORTH:
|
||||
case GIMP_GRAVITY_SOUTH:
|
||||
layout->extents.x += (layout->extents.width - logical.width) / 2;
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_NORTH_EAST:
|
||||
case GIMP_GRAVITY_SOUTH_EAST:
|
||||
case GIMP_GRAVITY_EAST:
|
||||
layout->extents.x += (layout->extents.width - logical.width);
|
||||
break;
|
||||
}
|
||||
|
||||
switch (text->gravity)
|
||||
{
|
||||
case GIMP_GRAVITY_NORTH:
|
||||
case GIMP_GRAVITY_NORTH_WEST:
|
||||
case GIMP_GRAVITY_NORTH_EAST:
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_NONE:
|
||||
case GIMP_GRAVITY_CENTER:
|
||||
case GIMP_GRAVITY_WEST:
|
||||
case GIMP_GRAVITY_EAST:
|
||||
layout->extents.y += (layout->extents.height - logical.height) / 2;
|
||||
break;
|
||||
|
||||
case GIMP_GRAVITY_SOUTH:
|
||||
case GIMP_GRAVITY_SOUTH_WEST:
|
||||
case GIMP_GRAVITY_SOUTH_EAST:
|
||||
layout->extents.y += (layout->extents.height - logical.height);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
detach_pango_context (GObject *image)
|
||||
{
|
||||
g_object_set_qdata (image, gimp_text_context_quark, NULL);
|
||||
}
|
||||
|
||||
static PangoContext *
|
||||
gimp_image_get_pango_context (GimpImage *image)
|
||||
{
|
||||
PangoContext *context;
|
||||
|
||||
if (!gimp_text_context_quark)
|
||||
gimp_text_context_quark = g_quark_from_static_string ("pango-context");
|
||||
|
||||
context = (PangoContext *) g_object_get_qdata (G_OBJECT (image),
|
||||
gimp_text_context_quark);
|
||||
|
||||
if (!context)
|
||||
{
|
||||
gdouble xres, yres;
|
||||
|
||||
gimp_image_get_resolution (image, &xres, &yres);
|
||||
|
||||
context = pango_ft2_get_context (xres, yres);
|
||||
|
||||
g_signal_connect_object (image, "resolution_changed",
|
||||
G_CALLBACK (detach_pango_context),
|
||||
context, 0);
|
||||
|
||||
g_object_set_qdata_full (G_OBJECT (image),
|
||||
gimp_text_context_quark, context,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
}
|
||||
|
||||
return g_object_ref (context);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/* 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_LAYOUT_H__
|
||||
#define __GIMP_TEXT_LAYOUT_H__
|
||||
|
||||
|
||||
#define GIMP_TYPE_TEXT_LAYOUT (gimp_text_layout_get_type ())
|
||||
#define GIMP_TEXT_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_TEXT_LAYOUT, GimpTextLayout))
|
||||
#define GIMP_IS_TEXT_LAYOUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_TEXT_LAYOUT))
|
||||
|
||||
|
||||
typedef struct _GimpTextLayoutClass GimpTextLayoutClass;
|
||||
|
||||
|
||||
GType gimp_text_layout_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GimpTextLayout * gimp_text_layout_new (GimpText *text,
|
||||
GimpImage *image);
|
||||
gboolean gimp_text_layout_get_size (GimpTextLayout *layout,
|
||||
gint *width,
|
||||
gint *heigth);
|
||||
void gimp_text_layout_get_offsets (GimpTextLayout *layout,
|
||||
gint *x,
|
||||
gint *y);
|
||||
TileManager * gimp_text_layout_render (GimpTextLayout *layout);
|
||||
|
||||
|
||||
#endif /* __GIMP_TEXT_LAYOUT_H__ */
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
/* Generated data (by gimp-mkenums) */
|
||||
|
||||
#include "config.h"
|
||||
#include <glib-object.h>
|
||||
#include "text-enums.h"
|
||||
#include "libgimp/gimpintl.h"
|
||||
|
||||
/* enumerations from "./text-enums.h" */
|
||||
|
||||
static const GEnumValue gimp_text_alignment_enum_values[] =
|
||||
{
|
||||
{ GIMP_TEXT_ALIGNMENT_LEFT, N_("Left Aligned"), "left" },
|
||||
{ GIMP_TEXT_ALIGNMENT_CENTER, N_("Centered"), "center" },
|
||||
{ GIMP_TEXT_ALIGNMENT_RIGHT, N_("Right Aligned"), "right" },
|
||||
{ 0, NULL, NULL }
|
||||
};
|
||||
|
||||
GType
|
||||
gimp_text_alignment_get_type (void)
|
||||
{
|
||||
static GType enum_type = 0;
|
||||
|
||||
if (!enum_type)
|
||||
enum_type = g_enum_register_static ("GimpTextAlignment", gimp_text_alignment_enum_values);
|
||||
|
||||
return enum_type;
|
||||
}
|
||||
|
||||
|
||||
/* Generated data ends here */
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
/* 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
|
||||
|
@ -19,17 +16,21 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GIMP_TEXT_RENDER_H__
|
||||
#define __GIMP_TEXT_RENDER_H__
|
||||
#ifndef __TEXT_ENUMS_H__
|
||||
#define __TEXT_ENUMS_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);
|
||||
#define GIMP_TYPE_TEXT_ALIGNMENT (gimp_text_alignment_get_type ())
|
||||
|
||||
GType gimp_text_alignment_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* this enum must match the values of the PangoAlignment enum */
|
||||
typedef enum
|
||||
{
|
||||
GIMP_TEXT_ALIGNMENT_LEFT, /*< desc="Left Aligned" >*/
|
||||
GIMP_TEXT_ALIGNMENT_CENTER, /*< desc="Centered" >*/
|
||||
GIMP_TEXT_ALIGNMENT_RIGHT /*< desc="Right Aligned" >*/
|
||||
} GimpTextAlignment;
|
||||
|
||||
|
||||
#endif /* __GIMP_TEXT_RENDER_H__ */
|
||||
#endif /* __TEXT_ENUMS_H__ */
|
|
@ -24,9 +24,12 @@
|
|||
|
||||
#include "core/core-types.h"
|
||||
|
||||
#include "text/text-enums.h"
|
||||
|
||||
|
||||
typedef struct _GimpText GimpText;
|
||||
typedef struct _GimpTextLayer GimpTextLayer;
|
||||
typedef struct _GimpTextLayout GimpTextLayout;
|
||||
|
||||
|
||||
#endif /* __TEXT_TYPES_H__ */
|
||||
|
|
|
@ -142,6 +142,8 @@ app/plug-in/plug-in.c
|
|||
app/plug-in/plug-in-rc.c
|
||||
app/plug-in/plug-ins.c
|
||||
|
||||
app/text/text-enums.c
|
||||
|
||||
app/tools/gimpairbrushtool.c
|
||||
app/tools/gimpbezierselecttool.c
|
||||
app/tools/gimpblendtool.c
|
||||
|
|
Loading…
Reference in New Issue