gimp r27542 - in trunk: . app/text
- From: neo svn gnome org
- To: svn-commits-list gnome org
- Subject: gimp r27542 - in trunk: . app/text
- Date: Mon, 3 Nov 2008 23:25:05 +0000 (UTC)
Author: neo
Date: Mon Nov 3 23:25:05 2008
New Revision: 27542
URL: http://svn.gnome.org/viewvc/gimp?rev=27542&view=rev
Log:
2008-11-04 Sven Neumann <sven gimp org>
* app/text/Makefile.am
* app/text/gimptext-bitmap.[ch]: removed.
* app/text/gimptext-private.h
* app/text/gimptext-vectors.c
* app/text/gimptextlayer.c
* app/text/gimptextlayout-render.[ch]
* app/text/gimptextlayout.c: removed text render abstraction as
this is now sufficiently provided by PangoCairo.
Removed:
trunk/app/text/gimptext-bitmap.c
trunk/app/text/gimptext-bitmap.h
Modified:
trunk/ChangeLog
trunk/app/text/Makefile.am
trunk/app/text/gimptext-private.h
trunk/app/text/gimptext-vectors.c
trunk/app/text/gimptextlayer.c
trunk/app/text/gimptextlayout-render.c
trunk/app/text/gimptextlayout-render.h
trunk/app/text/gimptextlayout.c
Modified: trunk/app/text/Makefile.am
==============================================================================
--- trunk/app/text/Makefile.am (original)
+++ trunk/app/text/Makefile.am Mon Nov 3 23:25:05 2008
@@ -28,8 +28,6 @@
gimpfontlist.h \
gimptext.c \
gimptext.h \
- gimptext-bitmap.c \
- gimptext-bitmap.h \
gimptext-compat.c \
gimptext-compat.h \
gimptext-parasite.c \
Modified: trunk/app/text/gimptext-private.h
==============================================================================
--- trunk/app/text/gimptext-private.h (original)
+++ trunk/app/text/gimptext-private.h Mon Nov 3 23:25:05 2008
@@ -27,7 +27,6 @@
* Cairo types from the rest of the gimp core.
*/
-
struct _GimpTextLayout
{
GObject object;
@@ -45,13 +44,4 @@
};
-typedef void (* GimpTextRenderFunc) (PangoFont *font,
- PangoGlyph glyph,
- cairo_font_options_t *options,
- cairo_matrix_t *tranform,
- gint x,
- gint y,
- gpointer render_data);
-
-
#endif /* __GIMP_TEXT_LAYOUT_PRIVATE_H__ */
Modified: trunk/app/text/gimptext-vectors.c
==============================================================================
--- trunk/app/text/gimptext-vectors.c (original)
+++ trunk/app/text/gimptext-vectors.c Mon Nov 3 23:25:05 2008
@@ -23,11 +23,8 @@
#include <gegl.h>
-#define PANGO_ENABLE_ENGINE
-#include <cairo.h>
#include <pango/pangocairo.h>
-
#include "text-types.h"
#include "core/gimpimage.h"
@@ -37,45 +34,29 @@
#include "vectors/gimpanchor.h"
#include "gimptext.h"
-#include "gimptext-private.h"
#include "gimptext-vectors.h"
#include "gimptextlayout.h"
#include "gimptextlayout-render.h"
-/* for compatibility with older freetype versions */
-#ifndef FT_GLYPH_FORMAT_OUTLINE
-#define FT_GLYPH_FORMAT_OUTLINE ft_glyph_format_outline
-#endif
-
-typedef struct _RenderContext RenderContext;
-
-struct _RenderContext
+typedef struct
{
- GimpVectors *vectors;
- GimpStroke *stroke;
- GimpAnchor *anchor;
- gdouble offset_x;
- gdouble offset_y;
-};
+ GimpVectors *vectors;
+ GimpStroke *stroke;
+ GimpAnchor *anchor;
+} RenderContext;
-static void gimp_text_render_vectors (PangoFont *font,
- PangoGlyph glyph,
- cairo_font_options_t *options,
- cairo_matrix_t *cmatrix,
- gint x,
- gint y,
- RenderContext *context);
+static void gimp_text_render_vectors (cairo_t *cr,
+ RenderContext *context);
GimpVectors *
gimp_text_vectors_new (GimpImage *image,
GimpText *text)
{
- GimpVectors *vectors;
- GimpTextLayout *layout;
- RenderContext context = { 0, };
+ GimpVectors *vectors;
+ RenderContext context = { NULL, };
g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
g_return_val_if_fail (GIMP_IS_TEXT (text), NULL);
@@ -84,18 +65,32 @@
if (text->text)
{
- gimp_object_set_name_safe (GIMP_OBJECT (vectors), text->text);
+ GimpTextLayout *layout;
+ cairo_surface_t *surface;
+ cairo_t *cr;
- layout = gimp_text_layout_new (text, image);
+ gimp_object_set_name_safe (GIMP_OBJECT (vectors), text->text);
context.vectors = vectors;
- gimp_text_layout_render (layout,
- (GimpTextRenderFunc) gimp_text_render_vectors,
- &context);
+ /* A cairo_t needs an image surface to function, so "surface" is
+ * created temporarily for this purpose. Nothing is drawn to
+ * "surface", but it is still needed to be connected to "cr" for
+ * "cr" to execute cr_glyph_path(). The size of surface is
+ * therefore irrelevant.
+ */
+ surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2);
+ cr = cairo_create (surface);
+ layout = gimp_text_layout_new (text, image);
+ gimp_text_layout_render (layout, cr, TRUE);
g_object_unref (layout);
+ gimp_text_render_vectors (cr, &context);
+
+ cairo_destroy (cr);
+ cairo_surface_destroy (surface);
+
if (context.stroke)
gimp_stroke_close (context.stroke);
}
@@ -105,13 +100,12 @@
static inline void
-gimp_text_vector_coords (RenderContext *context,
- const double x,
- const double y,
- GimpCoords *coords)
+gimp_text_vector_coords (const double x,
+ const double y,
+ GimpCoords *coords)
{
- coords->x = context->offset_x + (gdouble) x;
- coords->y = context->offset_y + (gdouble) y;
+ coords->x = x;
+ coords->y = y;
coords->pressure = GIMP_COORDS_DEFAULT_PRESSURE;
coords->xtilt = GIMP_COORDS_DEFAULT_TILT;
coords->ytilt = GIMP_COORDS_DEFAULT_TILT;
@@ -129,7 +123,7 @@
g_printerr ("moveto %f, %f\n", x, y);
#endif
- gimp_text_vector_coords (context, x, y, &start);
+ gimp_text_vector_coords (x, y, &start);
if (context->stroke)
gimp_stroke_close (context->stroke);
@@ -156,7 +150,7 @@
if (! context->stroke)
return 0;
- gimp_text_vector_coords (context, x, y, &end);
+ gimp_text_vector_coords (x, y, &end);
gimp_bezier_stroke_lineto (context->stroke, &end);
@@ -183,9 +177,9 @@
if (! context->stroke)
return 0;
- gimp_text_vector_coords (context, x1, y1, &control1);
- gimp_text_vector_coords (context, x2, y2, &control2);
- gimp_text_vector_coords (context, x3, y3, &end);
+ gimp_text_vector_coords (x1, y1, &control1);
+ gimp_text_vector_coords (x2, y2, &control2);
+ gimp_text_vector_coords (x3, y3, &end);
gimp_bezier_stroke_cubicto (context->stroke, &control1, &control2, &end);
@@ -199,7 +193,7 @@
g_printerr ("moveto\n");
#endif
- if (!context->stroke)
+ if (! context->stroke)
return 0;
gimp_stroke_close (context->stroke);
@@ -209,59 +203,24 @@
return 0;
}
-
static void
-gimp_text_render_vectors (PangoFont *font,
- PangoGlyph pango_glyph,
- cairo_font_options_t *options,
- cairo_matrix_t *matrix,
- gint x,
- gint y,
- RenderContext *context)
+gimp_text_render_vectors (cairo_t *cr,
+ RenderContext *context)
{
- cairo_surface_t *surface;
- cairo_t *cr;
- cairo_path_t *cpath;
- cairo_scaled_font_t *cfont;
- cairo_glyph_t cglyph;
- gint i;
-
- context->offset_x = (gdouble) x / PANGO_SCALE;
- context->offset_y = (gdouble) y / PANGO_SCALE;
-
- cglyph.x = 0;
- cglyph.y = 0;
- cglyph.index = pango_glyph;
-
- /* A cairo_t needs an image surface to function, so "surface" is created
- * temporarily for this purpose. Nothing is drawn to "surface", but it is
- * still needed to be connected to "cr" for "cr" to execute
- * cr_glyph_path(). The size of surface is therefore irrelevant.
- */
- surface = cairo_image_surface_create (CAIRO_FORMAT_A8, 2, 2);
- cr = cairo_create (surface);
-
- cfont = pango_cairo_font_get_scaled_font ((PangoCairoFont *) font);
+ cairo_path_t *path;
+ gint i;
- cairo_set_scaled_font (cr, cfont);
+ path = cairo_copy_path (cr);
- cairo_set_font_options (cr, options);
-
- cairo_transform (cr, matrix);
-
- cairo_glyph_path (cr, &cglyph, 1);
-
- cpath = cairo_copy_path (cr);
-
- for (i = 0; i < cpath->num_data; i += cpath->data[i].header.length)
+ for (i = 0; i < path->num_data; i += path->data[i].header.length)
{
- cairo_path_data_t *data = &cpath->data[i];
+ cairo_path_data_t *data = &path->data[i];
/* if the drawing operation is the final moveto of the glyph,
* break to avoid creating an empty point. This is because cairo
* always adds a moveto after each closepath.
*/
- if (i + data->header.length >= cpath->num_data)
+ if (i + data->header.length >= path->num_data)
break;
switch (data->header.type)
@@ -287,8 +246,5 @@
}
}
- cairo_path_destroy (cpath);
-
- cairo_destroy (cr);
- cairo_surface_destroy (surface);
+ cairo_path_destroy (path);
}
Modified: trunk/app/text/gimptextlayer.c
==============================================================================
--- trunk/app/text/gimptextlayer.c (original)
+++ trunk/app/text/gimptextlayer.c Mon Nov 3 23:25:05 2008
@@ -44,8 +44,6 @@
#include "core/gimpparasitelist.h"
#include "gimptext.h"
-#include "gimptext-bitmap.h"
-#include "gimptext-private.h"
#include "gimptextlayer.h"
#include "gimptextlayer-transform.h"
#include "gimptextlayout.h"
@@ -618,9 +616,7 @@
cr = cairo_create (surface);
- gimp_text_layout_render (layout,
- (GimpTextRenderFunc) gimp_text_render_bitmap,
- cr);
+ gimp_text_layout_render (layout, cr, FALSE);
mask = tile_manager_new ( width, height, 1);
pixel_region_init (&maskPR, mask, 0, 0, width, height, TRUE);
Modified: trunk/app/text/gimptextlayout-render.c
==============================================================================
--- trunk/app/text/gimptextlayout-render.c (original)
+++ trunk/app/text/gimptextlayout-render.c Mon Nov 3 23:25:05 2008
@@ -21,9 +21,7 @@
#include "config.h"
-#include <glib-object.h>
#include <pango/pangocairo.h>
-#include <pango/pango-font.h>
#include "text-types.h"
@@ -36,187 +34,60 @@
#include "gimptextlayout-render.h"
-static void gimp_text_layout_render_line (GimpTextLayout *layout,
- PangoLayoutLine *line,
- GimpTextRenderFunc render_func,
- gint x,
- gint y,
- gpointer render_data);
-static void gimp_text_layout_render_glyphs (GimpTextLayout *layout,
- PangoFont *font,
- PangoGlyphString *glyphs,
- GimpTextRenderFunc render_func,
- gint x,
- gint y,
- gpointer render_data);
-static cairo_font_options_t *
- gimp_text_layout_render_flags (GimpTextLayout *layout);
-static void gimp_text_layout_render_trafo (GimpTextLayout *layout,
- cairo_matrix_t *trafo);
-
+static void gimp_text_layout_render_trafo (GimpTextLayout *layout,
+ cairo_matrix_t *trafo);
void
-gimp_text_layout_render (GimpTextLayout *layout,
- GimpTextRenderFunc render_func,
- gpointer render_data)
+gimp_text_layout_render (GimpTextLayout *layout,
+ cairo_t *cr,
+ gboolean path)
{
- PangoLayoutIter *iter;
- PangoRectangle rect;
- gint x, y;
+ cairo_matrix_t trafo;
+ gint x, y;
g_return_if_fail (GIMP_IS_TEXT_LAYOUT (layout));
- g_return_if_fail (render_func != NULL);
+ g_return_if_fail (cr != NULL);
gimp_text_layout_get_offsets (layout, &x, &y);
- x *= PANGO_SCALE;
- y *= PANGO_SCALE;
-
- pango_layout_get_extents (layout->layout, NULL, &rect);
-
/* If the width of the layout is > 0, then the text-box is FIXED
* and the layout position should be offset if the alignment
* is centered or right-aligned*/
if (pango_layout_get_width (layout->layout) > 0)
- switch (pango_layout_get_alignment (layout->layout))
- {
- case PANGO_ALIGN_LEFT:
- break;
-
- case PANGO_ALIGN_RIGHT:
- x += pango_layout_get_width (layout->layout) - rect.width;
- break;
-
- case PANGO_ALIGN_CENTER:
- x += (pango_layout_get_width (layout->layout) - rect.width) / 2;
- break;
- }
-
- iter = pango_layout_get_iter (layout->layout);
-
- do
- {
- PangoLayoutLine *line;
- gint baseline;
-
- line = pango_layout_iter_get_line_readonly (iter);
-
- pango_layout_iter_get_line_extents (iter, NULL, &rect);
- baseline = pango_layout_iter_get_baseline (iter);
-
- gimp_text_layout_render_line (layout, line,
- render_func,
- x + rect.x,
- y + baseline,
- render_data);
- }
- while (pango_layout_iter_next_line (iter));
-
- pango_layout_iter_free (iter);
-}
-
-static void
-gimp_text_layout_render_line (GimpTextLayout *layout,
- PangoLayoutLine *line,
- GimpTextRenderFunc render_func,
- gint x,
- gint y,
- gpointer render_data)
-{
- PangoRectangle rect;
- GSList *list;
- gint x_off = 0;
-
- for (list = line->runs; list; list = list->next)
{
- PangoLayoutRun *run = list->data;
-
- pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
- NULL, &rect);
- gimp_text_layout_render_glyphs (layout,
- run->item->analysis.font, run->glyphs,
- render_func,
- x + x_off, y,
- render_data);
-
- x_off += rect.width;
- }
-}
+ gint width;
-static void
-gimp_text_layout_render_glyphs (GimpTextLayout *layout,
- PangoFont *font,
- PangoGlyphString *glyphs,
- GimpTextRenderFunc render_func,
- gint x,
- gint y,
- gpointer render_data)
-{
- PangoGlyphInfo *gi;
- cairo_font_options_t *flags;
- cairo_matrix_t trafo;
- double pos_x;
- double pos_y;
- gint i;
- gint x_position = 0;
+ pango_layout_get_pixel_size (layout->layout, &width, NULL);
- flags = gimp_text_layout_render_flags (layout);
- gimp_text_layout_render_trafo (layout, &trafo);
-
- for (i = 0, gi = glyphs->glyphs; i < glyphs->num_glyphs; i++, gi++)
- {
- if (gi->glyph != PANGO_GLYPH_EMPTY)
+ switch (pango_layout_get_alignment (layout->layout))
{
+ case PANGO_ALIGN_LEFT:
+ break;
- pos_x = x + x_position + gi->geometry.x_offset;
- pos_y = y + gi->geometry.y_offset;
-
- cairo_matrix_transform_point (&trafo, &pos_x, &pos_y);
-
- render_func (font, gi->glyph, flags, &trafo,
- pos_x, pos_y,
- render_data);
+ case PANGO_ALIGN_RIGHT:
+ x += PANGO_PIXELS (pango_layout_get_width (layout->layout)) - width;
+ break;
+
+ case PANGO_ALIGN_CENTER:
+ x += (PANGO_PIXELS (pango_layout_get_width (layout->layout))
+ - width) / 2;
+ break;
}
-
- x_position += glyphs->glyphs[i].geometry.width;
}
-}
-
-static cairo_font_options_t *
-gimp_text_layout_render_flags (GimpTextLayout *layout)
-{
- GimpText *text = layout->text;
- cairo_font_options_t *flags;
-
- flags = cairo_font_options_create ();
- cairo_font_options_set_antialias (flags, (text->antialias ?
- CAIRO_ANTIALIAS_DEFAULT :
- CAIRO_ANTIALIAS_NONE));
+ cairo_translate (cr, x, y);
- switch (text->hint_style)
- {
- case GIMP_TEXT_HINT_STYLE_NONE:
- cairo_font_options_set_hint_style (flags, CAIRO_HINT_STYLE_NONE);
- break;
-
- case GIMP_TEXT_HINT_STYLE_SLIGHT:
- cairo_font_options_set_hint_style (flags, CAIRO_HINT_STYLE_SLIGHT);
- break;
-
- case GIMP_TEXT_HINT_STYLE_MEDIUM:
- cairo_font_options_set_hint_style (flags, CAIRO_HINT_STYLE_MEDIUM);
- break;
-
- case GIMP_TEXT_HINT_STYLE_FULL:
- cairo_font_options_set_hint_style (flags, CAIRO_HINT_STYLE_FULL);
- break;
- }
+ gimp_text_layout_render_trafo (layout, &trafo);
+ cairo_transform (cr, &trafo);
- return flags;
+ if (path)
+ pango_cairo_layout_path (cr, layout->layout);
+ else
+ pango_cairo_show_layout (cr, layout->layout);
}
+
static void
gimp_text_layout_render_trafo (GimpTextLayout *layout,
cairo_matrix_t *trafo)
Modified: trunk/app/text/gimptextlayout-render.h
==============================================================================
--- trunk/app/text/gimptextlayout-render.h (original)
+++ trunk/app/text/gimptextlayout-render.h Mon Nov 3 23:25:05 2008
@@ -23,9 +23,9 @@
#define __GIMP_TEXT_LAYOUT_RENDER_H__
-void gimp_text_layout_render (GimpTextLayout *layout,
- GimpTextRenderFunc render_func,
- gpointer render_data);
+void gimp_text_layout_render (GimpTextLayout *layout,
+ cairo_t *cr,
+ gboolean path);
#endif /* __GIMP_TEXT_LAYOUT_RENDER_H__ */
Modified: trunk/app/text/gimptextlayout.c
==============================================================================
--- trunk/app/text/gimptextlayout.c (original)
+++ trunk/app/text/gimptextlayout.c Mon Nov 3 23:25:05 2008
@@ -302,13 +302,45 @@
#endif
}
+static cairo_font_options_t *
+gimp_text_get_font_options (GimpText *text)
+{
+ cairo_font_options_t *options = cairo_font_options_create ();
+
+ cairo_font_options_set_antialias (options, (text->antialias ?
+ CAIRO_ANTIALIAS_DEFAULT :
+ CAIRO_ANTIALIAS_NONE));
+
+ switch (text->hint_style)
+ {
+ case GIMP_TEXT_HINT_STYLE_NONE:
+ cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_NONE);
+ break;
+
+ case GIMP_TEXT_HINT_STYLE_SLIGHT:
+ cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_SLIGHT);
+ break;
+
+ case GIMP_TEXT_HINT_STYLE_MEDIUM:
+ cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_MEDIUM);
+ break;
+
+ case GIMP_TEXT_HINT_STYLE_FULL:
+ cairo_font_options_set_hint_style (options, CAIRO_HINT_STYLE_FULL);
+ break;
+ }
+
+ return options;
+}
+
static PangoContext *
gimp_text_get_pango_context (GimpText *text,
gdouble xres,
gdouble yres)
{
- PangoContext *context;
- PangoCairoFontMap *fontmap;
+ PangoContext *context;
+ PangoCairoFontMap *fontmap;
+ cairo_font_options_t *options;
fontmap = PANGO_CAIRO_FONT_MAP (pango_cairo_font_map_new ());
@@ -317,6 +349,10 @@
context = pango_cairo_font_map_create_context (fontmap);
g_object_unref (fontmap);
+ options = gimp_text_get_font_options (text);
+ pango_cairo_context_set_font_options (context, options);
+ cairo_font_options_destroy (options);
+
if (text->language)
pango_context_set_language (context,
pango_language_from_string (text->language));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]