app/text/Makefile.am new files that hold yet unused GimpItem transform

2003-08-15  Sven Neumann  <sven@gimp.org>

	* app/text/Makefile.am
	* app/text/gimptextlayer-transform.[ch]: new files that hold yet
	unused GimpItem transform methods.

	* app/text/gimptextlayer.[ch]: export gimp_text_layer_render().

	* app/text/gimptext-bitmap.[ch]
	* app/text/gimptext-private.h
	* app/text/gimptext-vectors.c
	* app/text/gimptextlayout-render.c: use the transformation matrix.
	This doesn't change anything since it's still always the identity
	matrix.
This commit is contained in:
Sven Neumann 2003-08-15 19:45:41 +00:00 committed by Sven Neumann
parent 75f1f8161f
commit 5988e8967e
11 changed files with 363 additions and 60 deletions

View File

@ -1,3 +1,18 @@
2003-08-15 Sven Neumann <sven@gimp.org>
* app/text/Makefile.am
* app/text/gimptextlayer-transform.[ch]: new files that hold yet
unused GimpItem transform methods.
* app/text/gimptextlayer.[ch]: export gimp_text_layer_render().
* app/text/gimptext-bitmap.[ch]
* app/text/gimptext-private.h
* app/text/gimptext-vectors.c
* app/text/gimptextlayout-render.c: use the transformation matrix.
This doesn't change anything since it's still always the identity
matrix.
2003-08-15 Helvetix Victorinox <helvetix@gimp.org>
* app/composite/gimp-composite-vis.c
@ -22,7 +37,7 @@
"Tab Style" menu and grey them out if the dockable has no
get_preview_func.
2003-08-15 Sven Neumann <neo@bender>
2003-08-15 Sven Neumann <sven@gimp.org>
* LICENSE: cosmetics.
@ -35,7 +50,7 @@
* app/composite/make-installer.py: generate smaller tables and
less code. Now takes real command line options:
options:
--version show program's version number and exit
--version show program's version number
-h, --help show this help message and exit
-f FILE, --file=FILE the input object file
-t, --test generate regression testing code
@ -336,7 +351,7 @@
than 2.2.2. The next stable release will probably require 2.2.2
or later but for the moment we only issue a warning.
2003-08-09 Sven Neumann <neo@bender>
2003-08-09 Sven Neumann <sven@gimp.org>
* configure.in: added devel-docs/app.

View File

@ -15,30 +15,32 @@ INCLUDES = \
noinst_LIBRARIES = libapptext.a
libapptext_a_sources = \
text-types.h \
text-enums.h \
gimpfont.c \
gimpfont.h \
gimpfontlist.c \
gimpfontlist.h \
gimptext.c \
gimptext.h \
gimptext-bitmap.c \
gimptext-bitmap.h \
gimptext-compat.c \
gimptext-compat.h \
gimptext-parasite.c \
gimptext-parasite.h \
gimptext-private.h \
gimptext-vectors.c \
gimptext-vectors.h \
gimptext-xlfd.c \
gimptext-xlfd.h \
gimptextlayer.c \
gimptextlayer.h \
gimptextlayout.c \
gimptextlayout.h \
gimptextlayout-render.c \
text-types.h \
text-enums.h \
gimpfont.c \
gimpfont.h \
gimpfontlist.c \
gimpfontlist.h \
gimptext.c \
gimptext.h \
gimptext-bitmap.c \
gimptext-bitmap.h \
gimptext-compat.c \
gimptext-compat.h \
gimptext-parasite.c \
gimptext-parasite.h \
gimptext-private.h \
gimptext-vectors.c \
gimptext-vectors.h \
gimptext-xlfd.c \
gimptext-xlfd.h \
gimptextlayer.c \
gimptextlayer.h \
gimptextlayer-transform.c \
gimptextlayer-transform.h \
gimptextlayout.c \
gimptextlayout.h \
gimptextlayout-render.c \
gimptextlayout-render.h
libapptext_a_built_sources = text-enums.c

View File

@ -38,12 +38,14 @@
void
gimp_text_render_bitmap (PangoFont *font,
PangoGlyph glyph,
gint flags,
FT_Int32 flags,
FT_Matrix *trafo,
gint x,
gint y,
FT_Bitmap *bitmap)
{
FT_Face face;
FT_Vector pos;
gint y_start, y_limit, x_start, x_limit;
gint ix, iy;
const guchar *src;
@ -51,11 +53,21 @@ gimp_text_render_bitmap (PangoFont *font,
face = pango_ft2_font_get_face (font);
FT_Set_Transform (face, trafo, NULL);
FT_Load_Glyph (face, (FT_UInt) glyph, flags);
FT_Render_Glyph (face->glyph,
(flags & FT_LOAD_TARGET_MONO ?
ft_render_mode_mono : ft_render_mode_normal));
pos.x = x;
pos.y = y;
FT_Vector_Transform (&pos, trafo);
x = PANGO_PIXELS (pos.x);
y = PANGO_PIXELS (pos.y);
x_start = MAX (0, - (x + face->glyph->bitmap_left));
x_limit = MIN (face->glyph->bitmap.width,
bitmap->width - (x + face->glyph->bitmap_left));

View File

@ -25,7 +25,8 @@
void gimp_text_render_bitmap (PangoFont *font,
PangoGlyph glyph,
gint flags,
FT_Int32 flags,
FT_Matrix *trafo,
gint x,
gint y,
FT_Bitmap *bitmap);

View File

@ -44,7 +44,8 @@ struct _GimpTextLayoutClass
typedef void (* GimpTextRenderFunc) (PangoFont *font,
PangoGlyph glyph,
gint flags,
FT_Int32 load_flags,
FT_Matrix *tranform,
gint x,
gint y,
gpointer render_data);

View File

@ -53,14 +53,15 @@ struct _RenderContext
GimpVectors *vectors;
GimpStroke *stroke;
GimpAnchor *anchor;
gint offset_x;
gint offset_y;
gdouble offset_x;
gdouble offset_y;
};
static void gimp_text_render_vectors (PangoFont *font,
PangoGlyph *glyph,
gint flags,
FT_Int32 flags,
FT_Matrix *matrix,
gint x,
gint y,
RenderContext *context);
@ -244,7 +245,8 @@ cubicto (FT_Vector *control1,
static void
gimp_text_render_vectors (PangoFont *font,
PangoGlyph *pango_glyph,
gint flags,
FT_Int32 flags,
FT_Matrix *trafo,
gint x,
gint y,
RenderContext *context)
@ -272,8 +274,8 @@ gimp_text_render_vectors (PangoFont *font,
{
FT_OutlineGlyph outline_glyph = (FT_OutlineGlyph) glyph;
context->offset_x = x;
context->offset_y = y;
context->offset_x = (gdouble) x / PANGO_SCALE;
context->offset_y = (gdouble) y / PANGO_SCALE;
FT_Outline_Decompose (&outline_glyph->outline, &outline_funcs, context);
}

View File

@ -0,0 +1,162 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextLayer
* 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 "core/gimpimage-undo.h"
#include "gimptext.h"
#include "gimptextlayer.h"
#include "gimptextlayer-transform.h"
#include "gimp-intl.h"
void
gimp_text_layer_scale (GimpItem *item,
gint new_width,
gint new_height,
gint new_offset_x,
gint new_offset_y,
GimpInterpolationType interpolation_type)
{
}
void
gimp_text_layer_flip (GimpItem *item,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result)
{
GimpLayer *layer;
GimpImage *gimage;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
_("Flip Text Layer"));
{
GimpText *text = GIMP_TEXT_LAYER (item)->text;
GimpMatrix2 trafo = { { { 1.0, 0.0 }, { 0.0, 1.0 } } };
switch (flip_type)
{
case GIMP_ORIENTATION_HORIZONTAL:
trafo.coeff[0][0] = - 1.0;
break;
case GIMP_ORIENTATION_VERTICAL:
trafo.coeff[1][1] = - 1.0;
break;
case GIMP_ORIENTATION_UNKNOWN:
break;
}
gimp_matrix2_mult (&trafo, &text->transformation);
g_object_notify (G_OBJECT (text), "transformation");
gimp_text_layer_render (GIMP_TEXT_LAYER (item));
}
/* If there is a layer mask, make sure it gets flipped as well */
if (layer->mask)
gimp_item_flip (GIMP_ITEM (layer->mask),
flip_type, axis, clip_result);
gimp_image_undo_group_end (gimage);
/* Make sure we're not caching any old selection info */
gimp_layer_invalidate_boundary (layer);
}
void
gimp_text_layer_rotate (GimpItem *item,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result)
{
GimpLayer *layer;
GimpImage *gimage;
gdouble cos = 1.0;
gdouble sin = 0.0;
layer = GIMP_LAYER (item);
gimage = gimp_item_get_image (item);
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_TRANSFORM,
_("Rotate Text Layer"));
switch (rotate_type)
{
case GIMP_ROTATE_90:
cos = 0.0;
sin = - 1.0;
break;
case GIMP_ROTATE_180:
cos = - 1.0;
sin = 0.0;
break;
case GIMP_ROTATE_270:
cos = 0.0;
sin = 1.0;
break;
}
{
GimpText *text = GIMP_TEXT_LAYER (item)->text;
GimpMatrix2 trafo = { { { cos, - sin }, { sin, cos } } };
gimp_matrix2_mult (&trafo, &text->transformation);
g_object_notify (G_OBJECT (text), "transformation");
gimp_text_layer_render (GIMP_TEXT_LAYER (item));
}
/* If there is a layer mask, make sure it gets rotates as well */
if (layer->mask)
gimp_item_rotate (GIMP_ITEM (layer->mask),
rotate_type, center_x, center_y, clip_result);
gimp_image_undo_group_end (gimage);
/* Make sure we're not caching any old selection info */
gimp_layer_invalidate_boundary (layer);
}
void
gimp_text_layer_transform (GimpItem *item,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data)
{
}

View File

@ -0,0 +1,50 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpTextLayer
* 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_TRANSFORM_H__
#define __GIMP_TEXT_LAYER_TRANSFORM_H__
void gimp_text_layer_scale (GimpItem *item,
gint new_width,
gint new_height,
gint new_offset_x,
gint new_offset_y,
GimpInterpolationType interpolation_type);
void gimp_text_layer_flip (GimpItem *item,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result);
void gimp_text_layer_rotate (GimpItem *item,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y,
gboolean clip_result);
void gimp_text_layer_transform (GimpItem *item,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean clip_result,
GimpProgressFunc progress_callback,
gpointer progress_data);
#endif /* __GIMP_TEXT_LAYER_TRANSFORM_H__ */

View File

@ -42,6 +42,7 @@
#include "gimptext-bitmap.h"
#include "gimptext-private.h"
#include "gimptextlayer.h"
#include "gimptextlayer-transform.h"
#include "gimptextlayout.h"
#include "gimptextlayout-render.h"
@ -62,11 +63,12 @@ static GimpItem * gimp_text_layer_duplicate (GimpItem *item,
static void gimp_text_layer_rename (GimpItem *item,
const gchar *new_name,
const gchar *undo_desc);
static void gimp_text_layer_set_text (GimpTextLayer *layer,
GimpText *text);
static void gimp_text_layer_notify_text (GimpTextLayer *layer);
static gboolean gimp_text_layer_idle_render (GimpTextLayer *layer);
static gboolean gimp_text_layer_render (GimpTextLayer *layer);
static gboolean gimp_text_layer_render_now (GimpTextLayer *layer);
static void gimp_text_layer_render_layout (GimpTextLayer *layer,
GimpTextLayout *layout);
@ -124,9 +126,16 @@ gimp_text_layer_class_init (GimpTextLayerClass *klass)
viewable_class->default_stock_id = "gimp-text-layer";
viewable_class->get_preview = gimp_text_layer_get_preview;
item_class->default_name = _("Text Layer");
item_class->duplicate = gimp_text_layer_duplicate;
item_class->rename = gimp_text_layer_rename;
item_class->default_name = _("Text Layer");
#if 0
item_class->scale = gimp_text_layer_scale;
item_class->flip = gimp_text_layer_flip;
item_class->rotate = gimp_text_layer_rotate;
item_class->transform = gimp_text_layer_transform;
#endif
}
static void
@ -226,37 +235,46 @@ gimp_text_layer_rename (GimpItem *item,
GIMP_ITEM_CLASS (parent_class)->rename (item, new_name, undo_desc);
}
/**
* gimp_text_layer_new:
* @image: the #GimpImage the layer should belong to
* @text: a #GimpText object
*
* Creates a new text layer.
*
* Return value: a new #GimpTextLayer or %NULL in case of a problem
**/
GimpLayer *
gimp_text_layer_new (GimpImage *image,
GimpText *text)
GimpText *text)
{
GimpTextLayer *layer;
g_return_val_if_fail (GIMP_IS_IMAGE (image), 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);
gimp_drawable_configure (GIMP_DRAWABLE (layer),
image,
0, 0, 0, 0,
gimp_image_base_type_with_alpha (image),
NULL);
gimp_text_layer_set_text (layer, text);
if (! gimp_text_layer_render (layer))
if (! gimp_text_layer_render_now (layer))
{
g_object_unref (layer);
return NULL;
}
return GIMP_LAYER (layer);
}
/**
* gimp_text_layer_from_layer:
* @layer: a #GimpLayer object
@ -353,6 +371,20 @@ gimp_text_layer_get_text (GimpTextLayer *layer)
return layer->text;
}
void
gimp_text_layer_render (GimpTextLayer *layer)
{
g_return_if_fail (GIMP_IS_TEXT_LAYER (layer));
if (layer->idle_render_id)
{
g_source_remove (layer->idle_render_id);
layer->idle_render_id = 0;
}
gimp_text_layer_render_now (layer);
}
static void
gimp_text_layer_notify_text (GimpTextLayer *layer)
{
@ -370,13 +402,13 @@ gimp_text_layer_idle_render (GimpTextLayer *layer)
{
layer->idle_render_id = 0;
gimp_text_layer_render (layer);
gimp_text_layer_render_now (layer);
return FALSE;
}
static gboolean
gimp_text_layer_render (GimpTextLayer *layer)
gimp_text_layer_render_now (GimpTextLayer *layer)
{
GimpDrawable *drawable;
GimpItem *item;

View File

@ -1,7 +1,7 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* GimpText
* GimpTextLayer
* Copyright (C) 2002-2003 Sven Neumann <sven@gimp.org>
*
* This program is free software; you can redistribute it and/or modify
@ -60,6 +60,7 @@ GimpLayer * gimp_text_layer_new (GimpImage *image,
GimpLayer * gimp_text_layer_from_layer (GimpLayer *layer,
GimpText *text);
GimpText * gimp_text_layer_get_text (GimpTextLayer *layer);
void gimp_text_layer_render (GimpTextLayer *layer);
#endif /* __GIMP_TEXT_LAYER_H__ */

View File

@ -60,7 +60,8 @@ static void gimp_text_layout_render_glyphs (GimpTextLayout *layout,
gint x,
gint y,
gpointer render_data);
static gint gimp_text_layout_render_flags (GimpTextLayout *layout);
static FT_Int32 gimp_text_layout_render_flags (GimpTextLayout *layout);
static FT_Matrix gimp_text_layout_render_trafo (GimpTextLayout *layout);
@ -77,6 +78,9 @@ gimp_text_layout_render (GimpTextLayout *layout,
gimp_text_layout_get_offsets (layout, &x, &y);
x *= PANGO_SCALE;
y *= PANGO_SCALE;
iter = pango_layout_get_iter (layout->layout);
do
@ -92,8 +96,8 @@ gimp_text_layout_render (GimpTextLayout *layout,
gimp_text_layout_render_line (layout, line,
render_func,
x + PANGO_PIXELS (rect.x),
y + PANGO_PIXELS (baseline),
x + rect.x,
y + baseline,
render_data);
}
while (pango_layout_iter_next_line (iter));
@ -120,7 +124,7 @@ gimp_text_layout_render_line (GimpTextLayout *layout,
gimp_text_layout_render_glyphs (layout,
run->item->analysis.font, run->glyphs,
render_func,
x + PANGO_PIXELS (x_off), y,
x + x_off, y,
render_data);
x_off += rect.width;
@ -137,19 +141,26 @@ gimp_text_layout_render_glyphs (GimpTextLayout *layout,
gpointer render_data)
{
PangoGlyphInfo *gi;
gint flags;
FT_Int32 flags;
FT_Matrix trafo;
FT_Vector pos;
gint i;
gint x_position = 0;
flags = gimp_text_layout_render_flags (layout);
trafo = gimp_text_layout_render_trafo (layout);
for (i = 0, gi = glyphs->glyphs; i < glyphs->num_glyphs; i++, gi++)
{
if (gi->glyph)
{
render_func (font, gi->glyph, flags,
x + PANGO_PIXELS (x_position + gi->geometry.x_offset),
y + PANGO_PIXELS (gi->geometry.y_offset),
pos.x = x + x_position + gi->geometry.x_offset;
pos.y = y + gi->geometry.y_offset;
FT_Vector_Transform (&pos, &trafo);
render_func (font, gi->glyph, flags, &trafo,
pos.x, pos.y,
render_data);
}
@ -157,7 +168,7 @@ gimp_text_layout_render_glyphs (GimpTextLayout *layout,
}
}
static gint
static FT_Int32
gimp_text_layout_render_flags (GimpTextLayout *layout)
{
GimpText *text = layout->text;
@ -176,3 +187,17 @@ gimp_text_layout_render_flags (GimpTextLayout *layout)
return flags;
}
static FT_Matrix
gimp_text_layout_render_trafo (GimpTextLayout *layout)
{
GimpText *text = layout->text;
FT_Matrix trafo;
trafo.xx = text->transformation.coeff[0][0] * 65536.0;
trafo.xy = text->transformation.coeff[0][1] * 65536.0;
trafo.yx = text->transformation.coeff[1][0] * 65536.0;
trafo.yy = text->transformation.coeff[1][1] * 65536.0;
return trafo;
}