2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-08-15 19:45:41 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GimpTextLayer
|
|
|
|
* Copyright (C) 2002-2003 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-08-15 19:45:41 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-08-15 19:45:41 +00:00
|
|
|
* (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
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-08-15 19:45:41 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 01:58:39 +02:00
|
|
|
#include <gdk-pixbuf/gdk-pixbuf.h>
|
2008-10-09 20:24:04 +00:00
|
|
|
#include <gegl.h>
|
2003-08-15 19:45:41 +00:00
|
|
|
|
2011-04-28 14:23:33 +02:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
|
|
|
|
2003-08-15 19:45:41 +00:00
|
|
|
#include "text-types.h"
|
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
#include "core/gimp-transform-utils.h"
|
2003-08-15 19:45:41 +00:00
|
|
|
#include "core/gimpimage-undo.h"
|
|
|
|
|
|
|
|
#include "gimptext.h"
|
|
|
|
#include "gimptextlayer.h"
|
|
|
|
#include "gimptextlayer-transform.h"
|
|
|
|
|
2004-06-04 23:42:05 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
static GimpItemClass * gimp_text_layer_parent_class (void) G_GNUC_CONST;
|
2004-06-04 23:42:05 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
static gboolean gimp_text_layer_get_transformation (GimpTextLayer *layer,
|
|
|
|
GimpMatrix3 *matrix);
|
|
|
|
static gboolean gimp_text_layer_set_transformation (GimpTextLayer *layer,
|
|
|
|
GimpMatrix3 *matrix);
|
2003-08-15 19:45:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_layer_scale (GimpItem *item,
|
2004-06-04 23:42:05 +00:00
|
|
|
gint new_width,
|
|
|
|
gint new_height,
|
|
|
|
gint new_offset_x,
|
|
|
|
gint new_offset_y,
|
|
|
|
GimpInterpolationType interpolation_type,
|
2005-03-20 01:56:58 +00:00
|
|
|
GimpProgress *progress)
|
2003-08-15 19:45:41 +00:00
|
|
|
{
|
2005-03-20 01:56:58 +00:00
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_text_layer_transform_flip (GimpTextLayer *layer,
|
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis)
|
|
|
|
{
|
|
|
|
GimpMatrix3 matrix;
|
|
|
|
|
|
|
|
if (! gimp_text_layer_get_transformation (layer, &matrix))
|
|
|
|
return FALSE;
|
2003-08-15 19:45:41 +00:00
|
|
|
|
2005-03-21 19:10:11 +00:00
|
|
|
gimp_transform_matrix_flip (&matrix, flip_type, axis);
|
2005-03-20 01:56:58 +00:00
|
|
|
|
|
|
|
return gimp_text_layer_set_transformation (layer, &matrix);
|
2003-08-15 19:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_layer_flip (GimpItem *item,
|
2004-04-14 23:37:34 +00:00
|
|
|
GimpContext *context,
|
2004-06-04 23:42:05 +00:00
|
|
|
GimpOrientationType flip_type,
|
|
|
|
gdouble axis,
|
|
|
|
gboolean clip_result)
|
2003-08-15 19:45:41 +00:00
|
|
|
{
|
2005-03-20 01:56:58 +00:00
|
|
|
GimpTextLayer *layer = GIMP_TEXT_LAYER (item);
|
2003-08-15 19:45:41 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
if (gimp_text_layer_transform_flip (layer, flip_type, axis))
|
2004-06-04 23:42:05 +00:00
|
|
|
{
|
2005-03-20 01:56:58 +00:00
|
|
|
GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (layer));
|
2004-01-05 00:28:12 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
if (mask)
|
|
|
|
gimp_item_flip (GIMP_ITEM (mask), context,
|
|
|
|
flip_type, axis, clip_result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_text_layer_parent_class ()->flip (item, context,
|
|
|
|
flip_type, axis, clip_result);
|
2004-06-04 23:42:05 +00:00
|
|
|
}
|
2003-08-15 19:45:41 +00:00
|
|
|
}
|
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
static gboolean
|
|
|
|
gimp_text_layer_transform_rotate (GimpTextLayer *layer,
|
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y)
|
2003-08-15 19:45:41 +00:00
|
|
|
{
|
2005-03-20 01:56:58 +00:00
|
|
|
GimpMatrix3 matrix;
|
|
|
|
|
|
|
|
if (! gimp_text_layer_get_transformation (layer, &matrix))
|
|
|
|
return FALSE;
|
2003-08-15 19:45:41 +00:00
|
|
|
|
2005-03-21 19:10:11 +00:00
|
|
|
gimp_transform_matrix_rotate (&matrix, rotate_type, center_x, center_y);
|
2003-08-20 09:59:12 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
return gimp_text_layer_set_transformation (layer, &matrix);
|
|
|
|
}
|
2003-08-15 19:45:41 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
void
|
|
|
|
gimp_text_layer_rotate (GimpItem *item,
|
|
|
|
GimpContext *context,
|
|
|
|
GimpRotationType rotate_type,
|
|
|
|
gdouble center_x,
|
|
|
|
gdouble center_y,
|
|
|
|
gboolean clip_result)
|
|
|
|
{
|
|
|
|
GimpTextLayer *layer = GIMP_TEXT_LAYER (item);
|
|
|
|
|
|
|
|
if (! gimp_text_layer_transform_rotate (layer,
|
|
|
|
rotate_type, center_x, center_y))
|
|
|
|
{
|
|
|
|
GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (layer));
|
2003-08-15 19:45:41 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
if (mask)
|
|
|
|
gimp_item_rotate (GIMP_ITEM (mask), context,
|
|
|
|
rotate_type, center_x, center_y, clip_result);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_text_layer_parent_class ()->rotate (item, context,
|
|
|
|
rotate_type, center_x, center_y,
|
|
|
|
clip_result);
|
|
|
|
}
|
2003-08-15 19:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_text_layer_transform (GimpItem *item,
|
2004-04-14 23:37:34 +00:00
|
|
|
GimpContext *context,
|
2004-06-04 23:42:05 +00:00
|
|
|
const GimpMatrix3 *matrix,
|
|
|
|
GimpTransformDirection direction,
|
|
|
|
GimpInterpolationType interpolation_type,
|
|
|
|
gboolean supersample,
|
2006-12-24 16:48:08 +00:00
|
|
|
GimpTransformResize clip_result,
|
2005-03-20 01:56:58 +00:00
|
|
|
GimpProgress *progress)
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
}
|
|
|
|
|
|
|
|
static GimpItemClass *
|
|
|
|
gimp_text_layer_parent_class (void)
|
|
|
|
{
|
|
|
|
static GimpItemClass *parent_class = NULL;
|
|
|
|
|
|
|
|
if (! parent_class)
|
|
|
|
{
|
|
|
|
gpointer klass = g_type_class_peek (GIMP_TYPE_TEXT_LAYER);
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent_class;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_text_layer_get_transformation (GimpTextLayer *layer,
|
|
|
|
GimpMatrix3 *matrix)
|
2003-08-15 19:45:41 +00:00
|
|
|
{
|
2005-03-20 01:56:58 +00:00
|
|
|
if (! layer->text || layer->modified)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gimp_text_get_transformation (layer->text, matrix);
|
2004-01-05 00:28:12 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
return TRUE;
|
2003-08-15 19:45:41 +00:00
|
|
|
}
|
2004-06-04 23:42:05 +00:00
|
|
|
|
2005-03-20 01:56:58 +00:00
|
|
|
static gboolean
|
|
|
|
gimp_text_layer_set_transformation (GimpTextLayer *layer,
|
|
|
|
GimpMatrix3 *matrix)
|
2004-06-04 23:42:05 +00:00
|
|
|
{
|
2005-03-20 01:56:58 +00:00
|
|
|
GimpMatrix2 trafo;
|
|
|
|
|
|
|
|
if (! gimp_matrix3_is_affine (matrix))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
trafo.coeff[0][0] = matrix->coeff[0][0];
|
|
|
|
trafo.coeff[0][1] = matrix->coeff[0][1];
|
|
|
|
trafo.coeff[1][0] = matrix->coeff[1][0];
|
|
|
|
trafo.coeff[1][1] = matrix->coeff[1][1];
|
|
|
|
|
|
|
|
gimp_text_layer_set (GIMP_TEXT_LAYER (layer), NULL,
|
|
|
|
"transformation", &trafo,
|
|
|
|
"offset-x", matrix->coeff[0][2],
|
|
|
|
"offset-y", matrix->coeff[1][2],
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
2004-06-04 23:42:05 +00:00
|
|
|
}
|