Commit 4f22db21 authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

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.
parent 62304b0f
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):
......
## 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
......@@ -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;
......
......@@ -34,26 +34,27 @@ typedef struct _GimpTextClass GimpTextClass;
struct _GimpText
{
GObject parent_instance;
gchar *text;
gchar *font;
gdouble font_size;
GimpUnit font_size_unit;
GimpRGB color;
gdouble letter_spacing;
gdouble line_spacing;
gint fixed_width;
gint fixed_height;
GimpGravityType gravity;
GObject parent_instance;
gchar *text;
gchar *font;
gdouble font_size;
GimpUnit font_size_unit;
GimpRGB color;
GimpTextAlignment alignment;
gdouble letter_spacing;
gdouble line_spacing;
gint fixed_width;
gint fixed_height;
GimpGravityType gravity;
/* for historical reasons, don't use */
gint border;
gint border;
};
struct _GimpTextClass
{
GObjectClass parent_class;
GObjectClass parent_class;
};
......
......@@ -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);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
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)
gimp_text_layer_render_layout (GimpTextLayer *layer,
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);
}
/* 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;