[pango] Bug 594934 - pango_layout_copy



commit ce01a496c7dad90c672e673c0e7ba8c5de350137
Author: Behdad Esfahbod <behdad behdad org>
Date:   Fri Sep 11 16:51:34 2009 -0400

    Bug 594934 - pango_layout_copy
    
    Use memcpy() to copy value fields so we don't miss any.

 pango/pango-layout-private.h |   27 +++++++++++++++------------
 pango/pango-layout.c         |   27 +++++++--------------------
 2 files changed, 22 insertions(+), 32 deletions(-)
---
diff --git a/pango/pango-layout-private.h b/pango/pango-layout-private.h
index 99d0efb..dc4f3d4 100644
--- a/pango/pango-layout-private.h
+++ b/pango/pango-layout-private.h
@@ -30,48 +30,51 @@ struct _PangoLayout
 {
   GObject parent_instance;
 
-  /* If you add fields to PangoLayout, be sure to update both
-   * the _copy function
+  /* If you add fields to PangoLayout be sure to update _copy()
+   * unless you add a value between copy_begin and copy_end.
    */
 
+  /* Referenced items */
   PangoContext *context;
   PangoAttrList *attrs;
   PangoFontDescription *font_desc;
+  PangoTabArray *tabs;
 
+  /* Dupped */
   gchar *text;
+
+  /* Value fields.  These will be memcpy'd in _copy() */
+  int copy_begin;
+
   int length;			/* length of text in bytes */
+  int n_chars;		        /* number of characters in layout */
   int width;			/* wrap/ellipsize width, in device units, or -1 if not set */
   int height;			/* ellipsize width, in device units if positive, number of lines if negative */
   int indent;			/* amount by which first line should be shorter */
   int spacing;			/* spacing between lines */
 
-  int unknown_glyphs_count;	/* number of unknown glyphs */
-
   guint justify : 1;
   guint alignment : 2;
-
   guint single_paragraph : 1;
   guint auto_dir : 1;
-
   guint wrap : 2;		/* PangoWrapMode */
   guint is_wrapped : 1;		/* Whether the layout has any wrapped lines */
   guint ellipsize : 2;		/* PangoEllipsizeMode */
   guint is_ellipsized : 1;	/* Whether the layout has any ellipsized lines */
+  int unknown_glyphs_count;	/* number of unknown glyphs */
 
   /* some caching */
   guint logical_rect_cached : 1;
   guint ink_rect_cached : 1;
   PangoRectangle logical_rect;
   PangoRectangle ink_rect;
-
-
-  gint n_chars;		        /* Total number of characters in layout */
-  PangoLogAttr *log_attrs;	/* Logical attributes for layout's text */
-
   int tab_width;		/* Cached width of a tab. -1 == not yet calculated */
 
-  PangoTabArray *tabs;
+  int copy_end;
+
+  /* Not copied during _copy() */
 
+  PangoLogAttr *log_attrs;	/* Logical attributes for layout's text */
   GSList *lines;
   guint line_count;		/* Number of lines in @lines. 0 if lines is %NULL */
 };
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index fc166d4..537deee 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -293,35 +293,22 @@ pango_layout_copy (PangoLayout *src)
 
   g_return_val_if_fail (PANGO_IS_LAYOUT (src), NULL);
 
-  layout = pango_layout_new (src->context);
+  /* Copy referenced members */
 
+  layout = pango_layout_new (src->context);
   if (src->attrs)
     layout->attrs = pango_attr_list_copy (src->attrs);
-
   if (src->font_desc)
     layout->font_desc = pango_font_description_copy (src->font_desc);
-
-  layout->text = g_strdup (src->text);
-  layout->length = src->length;
-  layout->width = src->width;
-  layout->height = src->height;
-  layout->indent = src->indent;
-  layout->spacing = src->spacing;
-  layout->justify = src->justify;
-  layout->auto_dir = src->auto_dir;
-  layout->alignment = src->alignment;
-  layout->n_chars = src->n_chars;
-  layout->tab_width = src->tab_width;
-
   if (src->tabs)
     layout->tabs = pango_tab_array_copy (src->tabs);
-  layout->wrap = src->wrap;
-  layout->ellipsize = src->ellipsize;
 
-  layout->unknown_glyphs_count = -1;
+  /* Dupped */
+  layout->text = g_strdup (src->text);
 
-  /* unknown_glyphs_count, is_wrapped, is_ellipsized, log_attrs, lines
-   * fields are updated by check_lines */
+  /* Value fields */
+  memcpy (&layout->copy_begin, &src->copy_begin,
+	  G_STRUCT_OFFSET (PangoLayout, copy_end) - G_STRUCT_OFFSET (PangoLayout, copy_begin));
 
   return layout;
 }



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