Index: docs/pango-sections.txt
===================================================================
RCS file: /cvs/gnome/pango/docs/pango-sections.txt,v
retrieving revision 1.69
diff -u -p -d -r1.69 pango-sections.txt
--- docs/pango-sections.txt	31 Mar 2006 12:28:08 -0000	1.69
+++ docs/pango-sections.txt	29 Apr 2006 07:52:16 -0000
@@ -17,6 +17,8 @@ pango_item_split
 pango_reorder_items
 <SUBSECTION>
 pango_context_new
+pango_context_changed
+pango_context_get_serial
 pango_context_set_font_map
 pango_context_get_font_map
 pango_context_get_font_description
Index: pango/pango-context.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.c,v
retrieving revision 1.91
diff -u -p -d -r1.91 pango-context.c
--- pango/pango-context.c	31 Mar 2006 02:20:23 -0000	1.91
+++ pango/pango-context.c	29 Apr 2006 07:52:16 -0000
@@ -33,6 +33,7 @@
 struct _PangoContext
 {
   GObject parent_instance;
+  int serial;
 
   PangoLanguage *language;
   PangoDirection base_dir;
@@ -50,12 +51,15 @@ struct _PangoContextClass
 };
 
 static void pango_context_finalize    (GObject           *object);
+static void context_changed  (PangoContext                 *context);
 
 G_DEFINE_TYPE (PangoContext, pango_context, G_TYPE_OBJECT)
 
 static void
 pango_context_init (PangoContext *context)
 {
+  context->serial = 0;
+
   context->base_dir = PANGO_DIRECTION_WEAK_LTR;
   context->language = NULL;
   context->font_map = NULL;
@@ -94,7 +98,6 @@ pango_context_finalize (GObject *object)
   G_OBJECT_CLASS (pango_context_parent_class)->finalize (object);
 }
 
-
 /**
  * pango_context_new:
  * 
@@ -146,6 +149,9 @@ pango_context_set_matrix (PangoContext  
 {
   g_return_if_fail (PANGO_IS_CONTEXT (context));
 
+  if (context->matrix || matrix)
+    context_changed (context);
+
   if (context->matrix)
     pango_matrix_free (context->matrix);
   if (matrix)
@@ -192,6 +198,9 @@ pango_context_set_font_map (PangoContext
   g_return_if_fail (PANGO_IS_CONTEXT (context));
   g_return_if_fail (!font_map || PANGO_IS_FONT_MAP (font_map));
 
+  if (font_map != context->font_map)
+    context_changed (context);
+
   if (font_map)
     g_object_ref (font_map);
 
@@ -310,6 +319,8 @@ pango_context_set_font_description (Pang
   g_return_if_fail (context != NULL);
   g_return_if_fail (desc != NULL);
 
+  context_changed (context);
+
   pango_font_description_free (context->font_desc);
   context->font_desc = pango_font_description_copy (desc);
 }
@@ -344,6 +355,9 @@ pango_context_set_language (PangoContext
 {
   g_return_if_fail (context != NULL);
 
+  if (language != context->language)
+    context_changed (context);
+
   context->language = language;
 }
 
@@ -383,6 +397,9 @@ pango_context_set_base_dir (PangoContext
 {
   g_return_if_fail (context != NULL);
 
+  if (direction != context->base_dir)
+    context_changed (context);
+
   context->base_dir = direction;
 }
 
@@ -1400,4 +1417,51 @@ pango_context_get_metrics (PangoContext 
   g_object_unref (current_fonts);
 
   return metrics;
+}
+
+static void
+context_changed  (PangoContext                 *context)
+{
+  context->serial++;
+}
+
+/**
+ * pango_context_changed:
+ * @context: a #PangoContext
+ * 
+ * Creates a new #PangoContext initialized to default value.
+ *
+ * This function is only useful when implementing a new backend
+ * for Pango, something applications won't do. Backends should
+ * call this function if they have attached extra data to the context
+ * and such data is changed.
+ *
+ * Since: 1.14
+ **/
+void
+pango_context_changed  (PangoContext                 *context)
+{
+  context_changed (context);
+}
+
+/**
+ * pango_context_get_serial:
+ * @context: a #PangoContext
+ * 
+ * Returns the current serial number of @context.  The serial number is
+ * initialized to an small number not less than zero when a new context
+ * is created and is increased whenever the context is changed.
+ *
+ * This can be used to automatically detect changes to a #PangoContext, and
+ * is only useful when implementing objects that need update when their
+ * #PangoContext changes, like #PangoLayout.
+ * 
+ * Return value: The current serial number of @context.
+ *
+ * Since: 1.14
+ **/
+int
+pango_context_get_serial (PangoContext                 *context)
+{
+  return context->serial;
 }
Index: pango/pango-context.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.h,v
retrieving revision 1.20
diff -u -p -d -r1.20 pango-context.h
--- pango/pango-context.h	10 Jul 2004 21:41:37 -0000	1.20
+++ pango/pango-context.h	29 Apr 2006 07:52:16 -0000
@@ -51,11 +51,12 @@ GType         pango_context_get_type    
 
 #ifdef PANGO_ENABLE_BACKEND
 PangoContext *pango_context_new           (void);
+void          pango_context_changed       (PangoContext                 *context);
 void          pango_context_set_font_map  (PangoContext                 *context,
 					   PangoFontMap                 *font_map);
 #endif /* PANGO_ENABLE_BACKEND */
 PangoFontMap *pango_context_get_font_map  (PangoContext                 *context);
-
+int           pango_context_get_serial    (PangoContext                 *context);
 void          pango_context_list_families (PangoContext                 *context,
 					   PangoFontFamily            ***families,
 					   int                          *n_families);
Index: pango/pango-layout-private.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-layout-private.h,v
retrieving revision 1.1
diff -u -p -d -r1.1 pango-layout-private.h
--- pango/pango-layout-private.h	14 Jul 2004 22:17:35 -0000	1.1
+++ pango/pango-layout-private.h	29 Apr 2006 07:52:16 -0000
@@ -34,6 +34,7 @@ struct _PangoLayout
    * the _copy function
    */
   
+  int context_serial;
   PangoContext *context;
   PangoAttrList *attrs;
   PangoFontDescription *font_desc;
Index: pango/pango-layout.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-layout.c,v
retrieving revision 1.174
diff -u -p -d -r1.174 pango-layout.c
--- pango/pango-layout.c	14 Apr 2006 06:56:43 -0000	1.174
+++ pango/pango-layout.c	29 Apr 2006 07:52:17 -0000
@@ -239,6 +239,7 @@ pango_layout_new (PangoContext *context)
   layout = g_object_new (PANGO_TYPE_LAYOUT, NULL);
 
   layout->context = context;
+  layout->context_serial = pango_context_get_serial (context);
   g_object_ref (context);
 
   return layout;
@@ -993,6 +994,8 @@ pango_layout_context_changed (PangoLayou
 {
   pango_layout_clear_lines (layout);
   layout->tab_width = -1;
+
+  layout->context_serial = pango_context_get_serial (layout->context);
 }
 
 /**
@@ -3245,6 +3248,9 @@ pango_layout_check_lines (PangoLayout *l
   PangoAttrIterator *iter;
   PangoDirection prev_base_dir = PANGO_DIRECTION_NEUTRAL, base_dir = PANGO_DIRECTION_NEUTRAL;
   
+  if (pango_context_get_serial (layout->context) != layout->context_serial)
+    pango_layout_context_changed (layout);
+
   if (layout->lines)
     return;
 
Index: pango/pango.def
===================================================================
RCS file: /cvs/gnome/pango/pango/pango.def,v
retrieving revision 1.41
diff -u -p -d -r1.41 pango.def
--- pango/pango.def	31 Mar 2006 00:21:30 -0000	1.41
+++ pango/pango.def	29 Apr 2006 07:52:17 -0000
@@ -50,12 +50,14 @@ EXPORTS
 	pango_color_get_type
 	pango_color_parse
 	pango_config_key_get
+	pango_context_changed
 	pango_context_get_base_dir
 	pango_context_get_font_description
 	pango_context_get_font_map
 	pango_context_get_language
 	pango_context_get_matrix
 	pango_context_get_metrics
+	pango_context_get_serial
 	pango_context_get_type
 	pango_context_list_families
 	pango_context_load_font
Index: pango/pangocairo-fontmap.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pangocairo-fontmap.c,v
retrieving revision 1.21
diff -u -p -d -r1.21 pangocairo-fontmap.c
--- pango/pangocairo-fontmap.c	6 Apr 2006 20:09:31 -0000	1.21
+++ pango/pangocairo-fontmap.c	29 Apr 2006 07:52:17 -0000
@@ -297,6 +297,8 @@ pango_cairo_update_context (cairo_t     
       cairo_font_options_destroy (info->merged_options);
       info->merged_options = NULL;
     }
+
+  pango_context_changed (context);
 }
 
 /**
@@ -318,6 +320,10 @@ pango_cairo_context_set_resolution (Pang
 				    double        dpi)
 {
   PangoCairoContextInfo *info = get_context_info (context, TRUE);
+
+  if (info->dpi != dpi)
+    pango_context_changed (context);
+
   info->dpi = dpi;
 }
 
@@ -370,6 +376,9 @@ pango_cairo_context_set_font_options (Pa
   
   info  = get_context_info (context, TRUE);
 
+  if (info->set_options || options)
+    pango_context_changed (context);
+
   if (info->set_options)
     cairo_font_options_destroy (info->set_options);
 
@@ -473,9 +482,10 @@ pango_cairo_create_layout  (cairo_t *cr)
 
   fontmap = pango_cairo_font_map_get_default ();
   context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
+  pango_cairo_update_context (cr, context);
+
   layout = pango_layout_new (context);
 
-  pango_cairo_update_context (cr, context);
   g_object_unref (context);
 
   return layout;
@@ -500,6 +510,5 @@ pango_cairo_update_layout (cairo_t     *
   g_return_if_fail (PANGO_IS_LAYOUT (layout));
 
   pango_cairo_update_context (cr, pango_layout_get_context (layout));
-  pango_layout_context_changed (layout);
 }
 

