gimp r25973 - in branches/soc-2008-text: . app app/text



Author: danedde
Date: Sat Jun 21 15:58:31 2008
New Revision: 25973
URL: http://svn.gnome.org/viewvc/gimp?rev=25973&view=rev

Log:
2008-06-21  Daniel Eddeland <danedde svn gnome org>

    * app/text/gimptext-bitmap.c
    * app/text/gimptext-private.h
    * app/text/gimptext-bitmap.h
    * app/text/gimptextlayer.c
    * app/text/gimptextlayout.c
    * app/text/gimptext-vectors.c
    * app/text/gimptextlayout-render.c: replaced ft2 functions and
                                datatypes with cairo

    * app/text/Makefile.am
    * app/Makefile.am
    * configure.in: added pangocairo



Modified:
   branches/soc-2008-text/ChangeLog
   branches/soc-2008-text/app/Makefile.am
   branches/soc-2008-text/app/text/Makefile.am
   branches/soc-2008-text/app/text/gimptext-bitmap.c
   branches/soc-2008-text/app/text/gimptext-bitmap.h
   branches/soc-2008-text/app/text/gimptext-private.h
   branches/soc-2008-text/app/text/gimptext-vectors.c
   branches/soc-2008-text/app/text/gimptextlayer.c
   branches/soc-2008-text/app/text/gimptextlayout-render.c
   branches/soc-2008-text/app/text/gimptextlayout.c
   branches/soc-2008-text/configure.in

Modified: branches/soc-2008-text/app/Makefile.am
==============================================================================
--- branches/soc-2008-text/app/Makefile.am	(original)
+++ branches/soc-2008-text/app/Makefile.am	Sat Jun 21 15:58:31 2008
@@ -86,6 +86,7 @@
 	-I$(top_srcdir)		\
 	$(GTK_CFLAGS)		\
 	$(PANGOFT2_CFLAGS)	\
+	$(PANGOCAIRO_CFLAGS)	\
 	$(DBUS_GLIB_CFLAGS)	\
 	$(GEGL_CFLAGS)		\
 	-I$(includedir)
@@ -134,6 +135,7 @@
 	$(REGEXREPL)			\
 	$(GTK_LIBS)			\
 	$(PANGOFT2_LIBS)		\
+	$(PANGOCAIRO_LIBS)		\
 	$(FONTCONFIG_LIBS)		\
 	$(FREETYPE_LIBS)		\
 	$(DBUS_GLIB_LIBS)		\
@@ -179,6 +181,7 @@
 	$(GDK_PIXBUF_LIBS)		\
 	$(CAIRO_LIBS)			\
 	$(PANGOFT2_LIBS)		\
+	$(PANGOCAIRO_LIBS)		\
 	$(FONTCONFIG_LIBS)		\
 	$(FREETYPE_LIBS)		\
 	$(GEGL_LIBS)			\

Modified: branches/soc-2008-text/app/text/Makefile.am
==============================================================================
--- branches/soc-2008-text/app/text/Makefile.am	(original)
+++ branches/soc-2008-text/app/text/Makefile.am	Sat Jun 21 15:58:31 2008
@@ -10,6 +10,7 @@
 	-I$(top_srcdir)/app	\
 	$(GDK_PIXBUF_CFLAGS)	\
 	$(PANGOFT2_CFLAGS)	\
+	$(PANGOCAIRO_CFLAGS)	\
 	$(GLIB_CFLAGS)		\
 	-I$(includedir)
 

Modified: branches/soc-2008-text/app/text/gimptext-bitmap.c
==============================================================================
--- branches/soc-2008-text/app/text/gimptext-bitmap.c	(original)
+++ branches/soc-2008-text/app/text/gimptext-bitmap.c	Sat Jun 21 15:58:31 2008
@@ -24,7 +24,8 @@
 #include <glib-object.h>
 
 #define PANGO_ENABLE_ENGINE
-#include <pango/pangoft2.h>
+#include <cairo.h>
+#include <pango/pangocairo.h>
 
 #include "text-types.h"
 
@@ -36,104 +37,47 @@
 #define FT_LOAD_TARGET_MONO  FT_LOAD_MONOCHROME
 #endif
 
-
+/*
 void
 gimp_text_render_bitmap (PangoFont  *font,
                          PangoGlyph  glyph,
-                         FT_Int32    flags,
-                         FT_Matrix  *trafo,
+                         cairo_font_options_t *flags,
+                         cairo_matrix_t  *trafo,
+                         gint        x,
+                         gint        y,
+                         cairo_surface_t *surface)
+*/
+void
+gimp_text_render_bitmap (PangoFont  *font,
+                         PangoGlyph glyph,
+                         cairo_font_options_t *options,
+                         cairo_matrix_t  *trafo,
                          gint        x,
                          gint        y,
-                         FT_Bitmap  *bitmap)
+                         cairo_t *cr)
 {
-  FT_Face       face;
-  gint          y_start, y_limit, x_start, x_limit;
-  gint          ix, iy;
-  const guchar *src;
-  guchar       *dest;
-
-  face = pango_fc_font_lock_face (PANGO_FC_FONT (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));
+
+  cairo_scaled_font_t *cfont;
+  cairo_glyph_t cglyph;
+
+  cfont = pango_cairo_font_get_scaled_font ( (PangoCairoFont*) font);
+
 
   x = PANGO_PIXELS (x);
   y = PANGO_PIXELS (y);
 
-  x_start = MAX (0, - (x + face->glyph->bitmap_left));
-  x_limit = MIN (face->glyph->bitmap.width,
-                 bitmap->width - (x + face->glyph->bitmap_left));
-
-  y_start = MAX (0,  - (y - face->glyph->bitmap_top));
-  y_limit = MIN (face->glyph->bitmap.rows,
-                 bitmap->rows - (y - face->glyph->bitmap_top));
-
-  src = face->glyph->bitmap.buffer + y_start * face->glyph->bitmap.pitch;
-
-  dest = bitmap->buffer +
-    (y_start + y - face->glyph->bitmap_top) * bitmap->pitch +
-    x_start + x + face->glyph->bitmap_left;
-
-  switch (face->glyph->bitmap.pixel_mode)
-    {
-    case ft_pixel_mode_grays:
-      src += x_start;
-      for (iy = y_start; iy < y_limit; iy++)
-        {
-          const guchar *s = src;
-          guchar       *d = dest;
-
-          for (ix = x_start; ix < x_limit; ix++)
-            {
-              switch (*s)
-                {
-                case 0:
-                  break;
-                case 0xff:
-                  *d = 0xff;
-                default:
-                  *d = MIN ((gushort) *d + (const gushort) *s, 0xff);
-                  break;
-                }
-
-              s++;
-              d++;
-            }
-
-          dest += bitmap->pitch;
-          src  += face->glyph->bitmap.pitch;
-        }
-      break;
-
-    case ft_pixel_mode_mono:
-      src += x_start / 8;
-      for (iy = y_start; iy < y_limit; iy++)
-        {
-          const guchar *s = src;
-          guchar       *d = dest;
-
-          for (ix = x_start; ix < x_limit; ix++)
-            {
-              if ((*s) & (1 << (7 - (ix % 8))))
-                *d |= 0xff;
-
-              if ((ix % 8) == 7)
-                s++;
-              d++;
-            }
-
-          dest += bitmap->pitch;
-          src  += face->glyph->bitmap.pitch;
-        }
-      break;
-
-    default:
-      break;
-    }
+  cglyph.x = x;
+  cglyph.y = y;
+  cglyph.index = glyph;
+
+  cairo_set_scaled_font (cr, cfont);
+  cairo_set_font_options (cr, options);
+
+  cairo_transform (cr, trafo);
+  cairo_move_to (cr, x, y);
+
+  cairo_set_source_rgb (cr, 0.5, 0.5, 0.5);
+
+  cairo_show_glyphs (cr, &cglyph, 1);  
 
-  pango_fc_font_unlock_face (PANGO_FC_FONT (font));
 }

Modified: branches/soc-2008-text/app/text/gimptext-bitmap.h
==============================================================================
--- branches/soc-2008-text/app/text/gimptext-bitmap.h	(original)
+++ branches/soc-2008-text/app/text/gimptext-bitmap.h	Sat Jun 21 15:58:31 2008
@@ -24,12 +24,12 @@
 
 
 void  gimp_text_render_bitmap (PangoFont  *font,
-                               PangoGlyph  glyph,
-                               FT_Int32    flags,
-                               FT_Matrix  *trafo,
+                               PangoGlyph glyph,
+                               cairo_font_options_t *options,
+                               cairo_matrix_t  *trafo,
                                gint        x,
                                gint        y,
-                               FT_Bitmap  *bitmap);
+                               cairo_t *cr);
 
 
 #endif /* __GIMP_TEXT_BITMAP_H__ */

Modified: branches/soc-2008-text/app/text/gimptext-private.h
==============================================================================
--- branches/soc-2008-text/app/text/gimptext-private.h	(original)
+++ branches/soc-2008-text/app/text/gimptext-private.h	Sat Jun 21 15:58:31 2008
@@ -23,7 +23,7 @@
 #define __GIMP_TEXT_LAYOUT_PRIVATE_H__
 
 /*  The purpose of this extra header file is to hide any Pango or
- *  FreeType types from the rest of the gimp core.
+ *  Cairo types from the rest of the gimp core.
  */
 
 
@@ -46,8 +46,8 @@
 
 typedef  void (* GimpTextRenderFunc) (PangoFont  *font,
                                       PangoGlyph  glyph,
-                                      FT_Int32    load_flags,
-                                      FT_Matrix  *tranform,
+                                      cairo_font_options_t *options,
+                                      cairo_matrix_t  *tranform,
                                       gint        x,
                                       gint        y,
                                       gpointer    render_data);

Modified: branches/soc-2008-text/app/text/gimptext-vectors.c
==============================================================================
--- branches/soc-2008-text/app/text/gimptext-vectors.c	(original)
+++ branches/soc-2008-text/app/text/gimptext-vectors.c	Sat Jun 21 15:58:31 2008
@@ -24,6 +24,7 @@
 #include <glib-object.h>
 
 #define PANGO_ENABLE_ENGINE
+#include <cairo.h>
 #include <pango/pangoft2.h>
 
 #include <ft2build.h>

Modified: branches/soc-2008-text/app/text/gimptextlayer.c
==============================================================================
--- branches/soc-2008-text/app/text/gimptextlayer.c	(original)
+++ branches/soc-2008-text/app/text/gimptextlayer.c	Sat Jun 21 15:58:31 2008
@@ -24,7 +24,7 @@
 #include <string.h>
 
 #include <glib-object.h>
-#include <pango/pangoft2.h>
+#include <pango/pangocairo.h>
 
 #include "libgimpconfig/gimpconfig.h"
 
@@ -577,8 +577,9 @@
     gimp_object_set_name_safe (GIMP_OBJECT (layer),
                                layer->text->text ?
                                layer->text->text : _("Empty Text Layer"));
-
+  
   gimp_text_layer_render_layout (layer, layout);
+  
   g_object_unref (layout);
 
   g_object_thaw_notify (G_OBJECT (drawable));
@@ -593,39 +594,45 @@
   GimpDrawable *drawable = GIMP_DRAWABLE (layer);
   GimpItem     *item     = GIMP_ITEM (layer);
   TileManager  *mask;
-  FT_Bitmap     bitmap;
+  cairo_t *cr;
+  cairo_surface_t *surface;
   PixelRegion   textPR;
   PixelRegion   maskPR;
   gint          i;
+  gint  pitch;
 
   gimp_drawable_fill (drawable, &layer->text->color, NULL);
 
-  bitmap.width = gimp_item_width  (item);
-  bitmap.rows  = gimp_item_height (item);
-  bitmap.pitch = bitmap.width;
-  if (bitmap.pitch & 3)
-    bitmap.pitch += 4 - (bitmap.pitch & 3);
+  pitch = gimp_item_width (item);
+
+  if (pitch & 3)
+    pitch += 4 - (pitch & 3);
+
+
+  surface = cairo_image_surface_create ( CAIRO_FORMAT_A8,
+        pitch, gimp_item_height (item));
 
-  bitmap.buffer = g_malloc0 (bitmap.rows * bitmap.pitch);
+  cr = cairo_create (surface);
 
   gimp_text_layout_render (layout,
                            (GimpTextRenderFunc) gimp_text_render_bitmap,
-                           &bitmap);
+                           cr);
 
-  mask = tile_manager_new (bitmap.width, bitmap.rows, 1);
-  pixel_region_init (&maskPR, mask, 0, 0, bitmap.width, bitmap.rows, TRUE);
+  mask = tile_manager_new (cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface), 1);
+  pixel_region_init (&maskPR, mask, 0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface), TRUE);
 
-  for (i = 0; i < bitmap.rows; i++)
+  for (i = 0; i < cairo_image_surface_get_height (surface); i++)
     pixel_region_set_row (&maskPR,
-                          0, i, bitmap.width,
-                          bitmap.buffer + i * bitmap.pitch);
+                          0, i, cairo_image_surface_get_width (surface),
+                          cairo_image_surface_get_data (surface) + i * cairo_image_surface_get_stride (surface));
 
-  g_free (bitmap.buffer);
+  cairo_destroy (cr);
+  cairo_surface_destroy (surface);
 
   pixel_region_init (&textPR, gimp_drawable_get_tiles (drawable),
-                     0, 0, bitmap.width, bitmap.rows, TRUE);
+                     0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface), TRUE);
   pixel_region_init (&maskPR, mask,
-                     0, 0, bitmap.width, bitmap.rows, FALSE);
+                     0, 0, cairo_image_surface_get_width (surface), cairo_image_surface_get_height (surface), FALSE);
 
   apply_mask_to_region (&textPR, &maskPR, OPAQUE_OPACITY);
 

Modified: branches/soc-2008-text/app/text/gimptextlayout-render.c
==============================================================================
--- branches/soc-2008-text/app/text/gimptextlayout-render.c	(original)
+++ branches/soc-2008-text/app/text/gimptextlayout-render.c	Sat Jun 21 15:58:31 2008
@@ -24,7 +24,8 @@
 #include "config.h"
 
 #include <glib-object.h>
-#include <pango/pangoft2.h>
+#include <cairo.h>
+#include <pango/pangocairo.h>
 #include <pango/pango-font.h>
 
 #include "text-types.h"
@@ -37,7 +38,6 @@
 #include "gimptextlayout.h"
 #include "gimptextlayout-render.h"
 
-/* test comment for soc-2008-text project experimental svn commit */
 
 /* for compatibility with older freetype versions */
 #ifndef FT_LOAD_TARGET_MONO
@@ -62,9 +62,9 @@
                                               gint                x,
                                               gint                y,
                                               gpointer            render_data);
-static FT_Int32   gimp_text_layout_render_flags (GimpTextLayout  *layout);
+static cairo_font_options_t   *gimp_text_layout_render_flags (GimpTextLayout  *layout);
 static void       gimp_text_layout_render_trafo (GimpTextLayout  *layout,
-                                                 FT_Matrix       *trafo);
+                                                 cairo_matrix_t       *trafo);
 
 
 
@@ -146,9 +146,10 @@
                                 gpointer            render_data)
 {
   PangoGlyphInfo *gi;
-  FT_Int32        flags;
-  FT_Matrix       trafo;
-  FT_Vector       pos;
+  cairo_font_options_t *flags;
+  cairo_matrix_t trafo;
+  double pos_x;
+  double pos_y;
   gint            i;
   gint            x_position = 0;
 
@@ -159,13 +160,14 @@
     {
       if (gi->glyph != PANGO_GLYPH_EMPTY)
         {
-          pos.x = x + x_position + gi->geometry.x_offset;
-          pos.y = y + gi->geometry.y_offset;
 
-          FT_Vector_Transform (&pos, &trafo);
+          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,
+                       pos_x, pos_y,
                        render_data);
         }
 
@@ -173,12 +175,27 @@
     }
 }
 
-static FT_Int32
+static cairo_font_options_t *
 gimp_text_layout_render_flags (GimpTextLayout *layout)
 {
   GimpText *text  = layout->text;
-  gint      flags;
+  cairo_font_options_t *flags;
 
+  flags = cairo_font_options_create ();
+
+  if (text->antialias)
+    cairo_font_options_set_antialias (flags, CAIRO_ANTIALIAS_DEFAULT);
+  else
+    cairo_font_options_set_antialias (flags, CAIRO_ANTIALIAS_NONE);
+
+  if (!text->hinting)
+    cairo_font_options_set_hint_style (flags, CAIRO_HINT_STYLE_NONE);
+
+  if (text->autohint)
+    cairo_font_options_set_antialias (flags, CAIRO_HINT_STYLE_DEFAULT);
+
+
+/*
   if (text->antialias)
     flags = FT_LOAD_NO_BITMAP;
   else
@@ -189,18 +206,26 @@
 
   if (text->autohint)
     flags |= FT_LOAD_FORCE_AUTOHINT;
-
+*/
   return flags;
 }
 
 static void
 gimp_text_layout_render_trafo (GimpTextLayout *layout,
-                               FT_Matrix      *trafo)
+                               cairo_matrix_t *trafo)
 {
   GimpText *text = layout->text;
 
+/*
   trafo->xx = text->transformation.coeff[0][0] * 65536.0 / layout->yres * layout->xres;
   trafo->xy = text->transformation.coeff[0][1] * 65536.0;
   trafo->yx = text->transformation.coeff[1][0] * 65536.0 / layout->yres * layout->xres;
   trafo->yy = text->transformation.coeff[1][1] * 65536.0;
+  */
+  trafo->xx = text->transformation.coeff[0][0] * 1.0 / layout->yres * layout->xres;
+  trafo->xy = text->transformation.coeff[0][1] * 1.0;
+  trafo->yx = text->transformation.coeff[1][0] * 1.0 / layout->yres * layout->xres;
+  trafo->yy = text->transformation.coeff[1][1] * 1.0;
+  trafo->x0 = 0;
+  trafo->y0 = 0;
 }

Modified: branches/soc-2008-text/app/text/gimptextlayout.c
==============================================================================
--- branches/soc-2008-text/app/text/gimptextlayout.c	(original)
+++ branches/soc-2008-text/app/text/gimptextlayout.c	Sat Jun 21 15:58:31 2008
@@ -22,7 +22,8 @@
 #include "config.h"
 
 #include <glib-object.h>
-#include <pango/pangoft2.h>
+#include <cairo.h>
+#include <pango/pangocairo.h>
 
 #include "text-types.h"
 
@@ -302,9 +303,9 @@
 #endif
 }
 
-
+/*
 static void
-gimp_text_ft2_subst_func (FcPattern *pattern,
+gimp_text_cairo_subst_func (cairo_font_options_t *options,
                           gpointer   data)
 {
   GimpText *text = GIMP_TEXT (data);
@@ -313,25 +314,25 @@
   FcPatternAddBool (pattern, FC_AUTOHINT,  text->autohint);
   FcPatternAddBool (pattern, FC_ANTIALIAS, text->antialias);
 }
-
+*/
 static PangoContext *
 gimp_text_get_pango_context (GimpText *text,
                              gdouble   xres,
                              gdouble   yres)
 {
   PangoContext    *context;
-  PangoFT2FontMap *fontmap;
-
-  fontmap = PANGO_FT2_FONT_MAP (pango_ft2_font_map_new ());
+  PangoCairoFontMap *fontmap;
 
-  pango_ft2_font_map_set_resolution (fontmap, xres, yres);
+  fontmap = PANGO_CAIRO_FONT_MAP (pango_cairo_font_map_new ());
 
-  pango_ft2_font_map_set_default_substitute (fontmap,
-                                             gimp_text_ft2_subst_func,
+  pango_cairo_font_map_set_resolution (fontmap, xres);
+/*
+  pango_cairo_font_map_set_default_substitute (fontmap,
+                                             gimp_text_cairo_subst_func,
                                              g_object_ref (text),
                                              (GDestroyNotify) g_object_unref);
-
-  context = pango_ft2_font_map_create_context (fontmap);
+*/
+  context = pango_cairo_font_map_create_context (fontmap);
   g_object_unref (fontmap);
 
   /*  Workaround for bug #143542 (PangoFT2Fontmap leak),
@@ -341,9 +342,12 @@
    *  font_map cache to be flushed, thereby removing the circular
    *  reference that causes the leak.
    */
+
+  /*
   g_object_weak_ref (G_OBJECT (context),
-                     (GWeakNotify) pango_ft2_font_map_substitute_changed,
+                     (GWeakNotify) pango_cairo_font_map_substitute_changed,
                      fontmap);
+*/
 
   if (text->language)
     pango_context_set_language (context,

Modified: branches/soc-2008-text/configure.in
==============================================================================
--- branches/soc-2008-text/configure.in	(original)
+++ branches/soc-2008-text/configure.in	Sat Jun 21 15:58:31 2008
@@ -44,6 +44,7 @@
 m4_define([glib_required_version], [2.16.1])
 m4_define([gtk_required_version], [2.12.1])
 m4_define([gdk_pixbuf_required_version], [gtk_required_version])
+m4_define([pangocairo_required_version], [1.20.1])
 m4_define([pangoft2_required_version], [1.18.0])
 m4_define([fontconfig_required_version], [2.2.0])
 m4_define([cairo_required_version], [1.4.10])
@@ -483,6 +484,14 @@
 
 PKG_CHECK_MODULES(CAIRO, cairo >= cairo_required_version)
 
+PKG_CHECK_MODULES(PANGOCAIRO, pangocairo >= pangocairo_required_version, :,
+  AC_MSG_ERROR([Test for PangoCairo failed.
+*** We require Pango with the optional support for Cairo compiled in.
+*** See the file 'INSTALL' for more help.]))
+
+CFLAGS=$gimp_save_CFLAGS
+CFLAGS="$PANGOCAIRO_CFLAGS $CFLAGS"
+
 PKG_CHECK_MODULES(FONTCONFIG, fontconfig >= fontconfig_required_version)
 
 PKG_CHECK_MODULES(PANGOFT2, pangoft2 >= pangoft2_required_version, :,
@@ -523,6 +532,7 @@
 *** the same as the result here.])
 fi
 
+
 AC_PATH_PROG(FREETYPE_CONFIG, freetype-config, no)
 if test "x$FREETYPE_CONFIG" != "xno" ; then
   AC_MSG_CHECKING([for freetype libraries])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]