1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
/* GIMP - The GNU 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 3 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, see <https://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gegl.h>
#include "libgimpmath/gimpmath.h"
#include "text-types.h"
#include "core/gimp-transform-utils.h"
#include "core/gimpimage-undo.h"
#include "gimptext.h"
#include "gimptextlayer.h"
#include "gimptextlayer-transform.h"
static GimpItemClass * gimp_text_layer_parent_class (void) G_GNUC_CONST;
static gboolean gimp_text_layer_get_transformation (GimpTextLayer *layer,
GimpMatrix3 *matrix);
static gboolean gimp_text_layer_set_transformation (GimpTextLayer *layer,
GimpMatrix3 *matrix);
void
gimp_text_layer_scale (GimpItem *item,
gint new_width,
gint new_height,
gint new_offset_x,
gint new_offset_y,
GimpInterpolationType interpolation_type,
GimpProgress *progress)
{
/* 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;
gimp_transform_matrix_flip (&matrix, flip_type, axis);
return gimp_text_layer_set_transformation (layer, &matrix);
}
void
gimp_text_layer_flip (GimpItem *item,
GimpContext *context,
GimpOrientationType flip_type,
gdouble axis,
gboolean clip_result)
{
GimpTextLayer *layer = GIMP_TEXT_LAYER (item);
if (gimp_text_layer_transform_flip (layer, flip_type, axis))
{
GimpLayerMask *mask = gimp_layer_get_mask (GIMP_LAYER (layer));
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);
}
}
static gboolean
gimp_text_layer_transform_rotate (GimpTextLayer *layer,
GimpRotationType rotate_type,
gdouble center_x,
gdouble center_y)
{
GimpMatrix3 matrix;
if (! gimp_text_layer_get_transformation (layer, &matrix))
return FALSE;
gimp_transform_matrix_rotate (&matrix, rotate_type, center_x, center_y);
return gimp_text_layer_set_transformation (layer, &matrix);
}
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));
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);
}
}
void
gimp_text_layer_transform (GimpItem *item,
GimpContext *context,
const GimpMatrix3 *matrix,
GimpTransformDirection direction,
GimpInterpolationType interpolation_type,
gboolean supersample,
GimpTransformResize clip_result,
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)
{
if (! layer->text || layer->modified)
return FALSE;
gimp_text_get_transformation (layer->text, matrix);
return TRUE;
}
static gboolean
gimp_text_layer_set_transformation (GimpTextLayer *layer,
GimpMatrix3 *matrix)
{
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;
}
|