2003-07-21 05:23:01 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* GimpText
|
|
|
|
* Copyright (C) 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>
|
2003-07-24 21:10:27 +08:00
|
|
|
#include <freetype/ftglyph.h>
|
2003-07-21 05:58:27 +08:00
|
|
|
#include <freetype/ftoutln.h>
|
2003-07-21 05:23:01 +08:00
|
|
|
|
|
|
|
#include "text/text-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpimage.h"
|
2003-07-24 21:10:27 +08:00
|
|
|
|
|
|
|
#include "vectors/gimpbezierstroke.h"
|
2003-07-21 05:23:01 +08:00
|
|
|
#include "vectors/gimpvectors.h"
|
2003-08-29 08:48:44 +08:00
|
|
|
#include "vectors/gimpanchor.h"
|
2003-07-21 05:23:01 +08:00
|
|
|
|
|
|
|
#include "gimptext.h"
|
|
|
|
#include "gimptext-private.h"
|
|
|
|
#include "gimptext-vectors.h"
|
|
|
|
#include "gimptextlayout.h"
|
|
|
|
#include "gimptextlayout-render.h"
|
|
|
|
|
|
|
|
|
2003-07-28 20:51:51 +08:00
|
|
|
/* for compatibility with older freetype versions */
|
|
|
|
#ifndef FT_GLYPH_FORMAT_OUTLINE
|
|
|
|
#define FT_GLYPH_FORMAT_OUTLINE ft_glyph_format_outline
|
|
|
|
#endif
|
|
|
|
|
2003-07-21 05:58:27 +08:00
|
|
|
typedef struct _RenderContext RenderContext;
|
|
|
|
|
|
|
|
struct _RenderContext
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
2003-07-24 21:10:27 +08:00
|
|
|
GimpStroke *stroke;
|
|
|
|
GimpAnchor *anchor;
|
2003-08-16 03:45:41 +08:00
|
|
|
gdouble offset_x;
|
|
|
|
gdouble offset_y;
|
2003-07-21 05:58:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_text_render_vectors (PangoFont *font,
|
2003-09-01 02:10:15 +08:00
|
|
|
PangoGlyph glyph,
|
2003-08-16 03:45:41 +08:00
|
|
|
FT_Int32 flags,
|
|
|
|
FT_Matrix *matrix,
|
2003-07-21 05:58:27 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
RenderContext *context);
|
2003-07-21 05:23:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
GimpVectors *
|
|
|
|
gimp_text_vectors_new (GimpImage *image,
|
|
|
|
GimpText *text)
|
|
|
|
{
|
|
|
|
GimpVectors *vectors;
|
|
|
|
GimpTextLayout *layout;
|
2003-07-21 05:58:27 +08:00
|
|
|
RenderContext context = { 0, };
|
2003-07-21 05:23:01 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
|
|
|
|
|
|
|
|
vectors = gimp_vectors_new (image, NULL);
|
|
|
|
|
|
|
|
if (text->text)
|
|
|
|
{
|
|
|
|
gimp_object_set_name_safe (GIMP_OBJECT (vectors), text->text);
|
|
|
|
|
|
|
|
layout = gimp_text_layout_new (text, image);
|
|
|
|
|
2003-07-21 05:58:27 +08:00
|
|
|
context.vectors = vectors;
|
|
|
|
|
2003-07-21 05:23:01 +08:00
|
|
|
gimp_text_layout_render (layout,
|
|
|
|
(GimpTextRenderFunc) gimp_text_render_vectors,
|
2003-07-21 05:58:27 +08:00
|
|
|
&context);
|
2003-07-21 05:23:01 +08:00
|
|
|
|
|
|
|
g_object_unref (layout);
|
2003-09-01 07:46:05 +08:00
|
|
|
|
|
|
|
if (context.stroke)
|
|
|
|
gimp_stroke_close (context.stroke);
|
2003-07-21 05:23:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return vectors;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
static inline void
|
2003-07-24 21:10:27 +08:00
|
|
|
gimp_text_vector_coords (RenderContext *context,
|
|
|
|
const FT_Vector *vector,
|
|
|
|
GimpCoords *coords)
|
|
|
|
{
|
|
|
|
coords->x = context->offset_x + (gdouble) vector->x / 64.0;
|
|
|
|
coords->y = context->offset_y - (gdouble) vector->y / 64.0;
|
|
|
|
coords->pressure = 1.0;
|
|
|
|
coords->xtilt = 0.5;
|
|
|
|
coords->ytilt = 0.5;
|
|
|
|
coords->wheel = 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2003-07-21 05:58:27 +08:00
|
|
|
moveto (FT_Vector *to,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
RenderContext *context = (RenderContext *) data;
|
2003-09-01 06:33:50 +08:00
|
|
|
GimpCoords start;
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-07-25 00:40:22 +08:00
|
|
|
#if TEXT_DEBUG
|
2003-07-24 21:10:27 +08:00
|
|
|
g_printerr ("moveto %f, %f\n", to->x / 64.0, to->y / 64.0);
|
2003-07-25 00:40:22 +08:00
|
|
|
#endif
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_text_vector_coords (context, to, &start);
|
|
|
|
|
2003-09-01 07:46:05 +08:00
|
|
|
if (context->stroke)
|
|
|
|
gimp_stroke_close (context->stroke);
|
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
context->stroke = gimp_bezier_stroke_new_moveto (&start);
|
2003-07-24 21:10:27 +08:00
|
|
|
|
|
|
|
gimp_vectors_stroke_add (context->vectors, context->stroke);
|
2003-07-24 21:25:31 +08:00
|
|
|
g_object_unref (context->stroke);
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-07-21 05:58:27 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-24 21:10:27 +08:00
|
|
|
static gint
|
2003-07-21 05:58:27 +08:00
|
|
|
lineto (FT_Vector *to,
|
2003-07-24 21:10:27 +08:00
|
|
|
gpointer data)
|
2003-07-21 05:58:27 +08:00
|
|
|
{
|
|
|
|
RenderContext *context = (RenderContext *) data;
|
2003-09-01 06:33:50 +08:00
|
|
|
GimpCoords end;
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-07-25 00:40:22 +08:00
|
|
|
#if TEXT_DEBUG
|
2003-07-24 21:10:27 +08:00
|
|
|
g_printerr ("lineto %f, %f\n", to->x / 64.0, to->y / 64.0);
|
2003-07-25 00:40:22 +08:00
|
|
|
#endif
|
2003-07-24 21:10:27 +08:00
|
|
|
|
|
|
|
if (! context->stroke)
|
|
|
|
return 0;
|
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_text_vector_coords (context, to, &end);
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_bezier_stroke_lineto (context->stroke, &end);
|
2003-07-21 05:58:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-24 21:10:27 +08:00
|
|
|
static gint
|
2003-08-29 08:48:44 +08:00
|
|
|
conicto (FT_Vector *ftcontrol,
|
2003-07-21 05:58:27 +08:00
|
|
|
FT_Vector *to,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
RenderContext *context = (RenderContext *) data;
|
2003-08-29 08:48:44 +08:00
|
|
|
GimpCoords control;
|
2003-09-01 06:33:50 +08:00
|
|
|
GimpCoords end;
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-07-25 00:40:22 +08:00
|
|
|
#if TEXT_DEBUG
|
2003-07-24 21:10:27 +08:00
|
|
|
g_printerr ("conicto %f, %f\n", to->x / 64.0, to->y / 64.0);
|
2003-07-25 00:40:22 +08:00
|
|
|
#endif
|
2003-07-24 21:10:27 +08:00
|
|
|
|
|
|
|
if (! context->stroke)
|
|
|
|
return 0;
|
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_text_vector_coords (context, ftcontrol, &control);
|
|
|
|
gimp_text_vector_coords (context, to, &end);
|
2003-07-24 21:25:31 +08:00
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_bezier_stroke_conicto (context->stroke, &control, &end);
|
2003-07-21 05:58:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-24 21:10:27 +08:00
|
|
|
static gint
|
2003-09-01 06:33:50 +08:00
|
|
|
cubicto (FT_Vector *ftcontrol1,
|
|
|
|
FT_Vector *ftcontrol2,
|
2003-07-21 05:58:27 +08:00
|
|
|
FT_Vector *to,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
RenderContext *context = (RenderContext *) data;
|
2003-09-01 06:33:50 +08:00
|
|
|
GimpCoords control1;
|
|
|
|
GimpCoords control2;
|
|
|
|
GimpCoords end;
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-07-25 00:40:22 +08:00
|
|
|
#if TEXT_DEBUG
|
2003-07-24 21:10:27 +08:00
|
|
|
g_printerr ("cubicto %f, %f\n", to->x / 64.0, to->y / 64.0);
|
2003-07-25 00:40:22 +08:00
|
|
|
#endif
|
2003-07-24 21:10:27 +08:00
|
|
|
|
|
|
|
if (! context->stroke)
|
|
|
|
return 0;
|
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_text_vector_coords (context, ftcontrol1, &control1);
|
|
|
|
gimp_text_vector_coords (context, ftcontrol2, &control2);
|
|
|
|
gimp_text_vector_coords (context, to, &end);
|
2003-07-24 21:10:27 +08:00
|
|
|
|
2003-09-01 06:33:50 +08:00
|
|
|
gimp_bezier_stroke_cubicto (context->stroke, &control1, &control2, &end);
|
2003-07-21 05:58:27 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-21 05:23:01 +08:00
|
|
|
static void
|
2003-07-21 05:58:27 +08:00
|
|
|
gimp_text_render_vectors (PangoFont *font,
|
2003-09-01 02:10:15 +08:00
|
|
|
PangoGlyph pango_glyph,
|
2003-08-16 03:45:41 +08:00
|
|
|
FT_Int32 flags,
|
|
|
|
FT_Matrix *trafo,
|
2003-07-21 05:58:27 +08:00
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
RenderContext *context)
|
2003-07-21 05:23:01 +08:00
|
|
|
{
|
2003-07-24 21:10:27 +08:00
|
|
|
const FT_Outline_Funcs outline_funcs =
|
2003-07-21 05:58:27 +08:00
|
|
|
{
|
|
|
|
moveto,
|
|
|
|
lineto,
|
|
|
|
conicto,
|
2003-07-24 21:10:27 +08:00
|
|
|
cubicto,
|
|
|
|
0,
|
|
|
|
0
|
2003-07-21 05:58:27 +08:00
|
|
|
};
|
|
|
|
|
2003-07-24 21:10:27 +08:00
|
|
|
FT_Face face;
|
|
|
|
FT_Glyph glyph;
|
|
|
|
|
2003-07-21 05:58:27 +08:00
|
|
|
face = pango_ft2_font_get_face (font);
|
|
|
|
|
2003-07-24 21:10:27 +08:00
|
|
|
FT_Load_Glyph (face, (FT_UInt) pango_glyph, flags);
|
|
|
|
|
|
|
|
FT_Get_Glyph (face->glyph, &glyph);
|
|
|
|
|
|
|
|
if (face->glyph->format == FT_GLYPH_FORMAT_OUTLINE)
|
|
|
|
{
|
|
|
|
FT_OutlineGlyph outline_glyph = (FT_OutlineGlyph) glyph;
|
|
|
|
|
2003-08-16 03:45:41 +08:00
|
|
|
context->offset_x = (gdouble) x / PANGO_SCALE;
|
|
|
|
context->offset_y = (gdouble) y / PANGO_SCALE;
|
2003-07-24 21:10:27 +08:00
|
|
|
|
|
|
|
FT_Outline_Decompose (&outline_glyph->outline, &outline_funcs, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
FT_Done_Glyph (glyph);
|
2003-07-21 05:23:01 +08:00
|
|
|
}
|