Index: pango/pango-layout.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-layout.c,v
retrieving revision 1.129.4.1
diff -u -r1.129.4.1 pango-layout.c
--- pango/pango-layout.c	17 Dec 2004 17:47:48 -0000	1.129.4.1
+++ pango/pango-layout.c	28 Feb 2005 12:35:14 -0000
@@ -103,6 +103,9 @@
 {
   PangoLayoutLine line;
   guint ref_count;
+  gboolean has_cache;
+  PangoRectangle ink_rect;
+  PangoRectangle logical_rect;
 };
 
 struct _PangoLayoutClass
@@ -1109,7 +1112,7 @@
       if (!properties.shape_set)
 	{
 	  PangoRectangle logical_rect;
-	  
+          
 	  pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
 				      NULL, &logical_rect);
 	  width += logical_rect.width;
@@ -2712,6 +2715,7 @@
   PangoLayoutRun *run = g_new (PangoLayoutRun, 1);
 
   run->item = run_item;
+  run->has_cache = FALSE;
 
   if (last_run && state->log_widths_offset == 0)
     run->glyphs = state->glyphs;
@@ -3811,10 +3815,15 @@
 		     properties.shape_ink_rect,
 		     properties.shape_logical_rect,
 		     need_ink ? &tmp_ink : NULL, run_logical);
-  else
-    pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
-                                need_ink ? &tmp_ink : NULL,
-                                run_logical);
+  else {
+    if (!run->has_cache) {
+      pango_glyph_string_extents (run->glyphs, run->item->analysis.font,
+                                  &run->ink_rect, &run->logical_rect);
+      run->has_cache = TRUE;
+    }
+    if (need_ink) tmp_ink = run->ink_rect;
+    if (run_logical) *run_logical = run->logical_rect;
+  }
 
   if (run_ink)
     *run_ink = tmp_ink;
@@ -3879,6 +3888,7 @@
 			       PangoRectangle  *ink_rect,
 			       PangoRectangle  *logical_rect)
 {
+  PangoLayoutLinePrivate *private = (PangoLayoutLinePrivate *)line;
   GSList *tmp_list;
   int x_pos = 0;
   
@@ -3887,21 +3897,24 @@
   if (!LINE_IS_VALID (line))
     return;
 
-  if (ink_rect)
+  if (private->has_cache)
     {
-      ink_rect->x = 0;
-      ink_rect->y = 0;
-      ink_rect->width = 0;
-      ink_rect->height = 0;
-    }
-  
-  if (logical_rect)
-    {
-      logical_rect->x = 0;
-      logical_rect->y = 0;
-      logical_rect->width = 0;
-      logical_rect->height = 0;
+      if (ink_rect)
+        *ink_rect = private->ink_rect;
+      if (logical_rect)
+        *logical_rect = private->logical_rect;
+      return;
     }
+
+  private->ink_rect.x = 0;
+  private->ink_rect.y = 0;
+  private->ink_rect.width = 0;
+  private->ink_rect.height = 0;
+  
+  private->logical_rect.x = 0;
+  private->logical_rect.y = 0;
+  private->logical_rect.width = 0;
+  private->logical_rect.height = 0;
   
   tmp_list = line->runs;
   while (tmp_list)
@@ -3912,45 +3925,44 @@
       PangoRectangle run_logical;
 
       pango_layout_run_get_extents (run,
-                                    ink_rect ? &run_ink : NULL,
-                                    &run_logical);
-      
-      if (ink_rect)
-	{
-	  new_pos = MIN (ink_rect->x, x_pos + run_ink.x);
-	  ink_rect->width = MAX (ink_rect->x + ink_rect->width,
-				 x_pos + run_ink.x + run_ink.width) - new_pos;
-	  ink_rect->x = new_pos;
-	  
-	  new_pos = MIN (ink_rect->y, run_ink.y);
-	  ink_rect->height = MAX (ink_rect->y + ink_rect->height,
-				  run_ink.y + run_ink.height) - new_pos;
-	  ink_rect->y = new_pos;
-	}
+                                    &run_ink, &run_logical);
       
-      if (logical_rect)
-	{
-	  new_pos = MIN (logical_rect->x, x_pos + run_logical.x);
-	  logical_rect->width = MAX (logical_rect->x + logical_rect->width,
-				     x_pos + run_logical.x + run_logical.width) - new_pos;
-	  logical_rect->x = new_pos;
-	  
-	  new_pos = MIN (logical_rect->y, run_logical.y);
-	  logical_rect->height = MAX (logical_rect->y + logical_rect->height,
-				      run_logical.y + run_logical.height) - new_pos;
-	  logical_rect->y = new_pos;
-	}
+      new_pos = MIN (private->ink_rect.x, x_pos + run_ink.x);
+      private->ink_rect.width = MAX (private->ink_rect.x + private->ink_rect.width,
+                                     x_pos + run_ink.x + run_ink.width) - new_pos;
+      private->ink_rect.x = new_pos;
+	  
+      new_pos = MIN (private->ink_rect.y, run_ink.y);
+      private->ink_rect.height = MAX (private->ink_rect.y + private->ink_rect.height,
+                                      run_ink.y + run_ink.height) - new_pos;
+      private->ink_rect.y = new_pos;
+      
+      new_pos = MIN (private->logical_rect.x, x_pos + run_logical.x);
+      private->logical_rect.width = MAX (private->logical_rect.x + private->logical_rect.width,
+                                         x_pos + run_logical.x + run_logical.width) - new_pos;
+      private->logical_rect.x = new_pos;
+      
+      new_pos = MIN (private->logical_rect.y, run_logical.y);
+      private->logical_rect.height = MAX (private->logical_rect.y + private->logical_rect.height,
+                                          run_logical.y + run_logical.height) - new_pos;
+      private->logical_rect.y = new_pos;
       
      x_pos += run_logical.width;
      tmp_list = tmp_list->next;
     }
   
-  if (logical_rect && logical_rect->height == 0) 
+  if (logical_rect && private->logical_rect.height == 0) 
     {
       PangoRectangle temp_rect;
       pango_layout_line_get_empty_extents (line, &temp_rect);
-      logical_rect->height = temp_rect.height;
+      private->logical_rect.height = temp_rect.height;
     }
+
+  private->has_cache = TRUE;
+  if (ink_rect)
+    *ink_rect = private->ink_rect;
+  if (logical_rect)
+    *logical_rect = private->logical_rect;
 }
 
 static PangoLayoutLine *
@@ -3962,7 +3974,7 @@
   private->line.layout = layout;
   private->line.runs = 0;
   private->line.length = 0;
-
+  private->has_cache = FALSE;
   /* Note that we leave start_index, resolved_dir, and is_paragraph_start
    *  uninitialized */
 
Index: pango/pango-glyph-item.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-glyph-item.h,v
retrieving revision 1.3
diff -u -r1.3 pango-glyph-item.h
--- pango/pango-glyph-item.h	14 Jul 2004 22:17:35 -0000	1.3
+++ pango/pango-glyph-item.h	28 Feb 2005 12:35:14 -0000
@@ -36,6 +36,11 @@
 {
   PangoItem        *item;
   PangoGlyphString *glyphs;
+
+  /*< private >*/
+  gboolean has_cache;
+  PangoRectangle ink_rect;
+  PangoRectangle logical_rect;
 };
 
 PangoGlyphItem *pango_glyph_item_split        (PangoGlyphItem *orig,
Index: pango/pango-glyph-item.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-glyph-item.c,v
retrieving revision 1.8
diff -u -r1.8 pango-glyph-item.c
--- pango/pango-glyph-item.c	14 Jul 2004 22:17:35 -0000	1.8
+++ pango/pango-glyph-item.c	28 Feb 2005 12:35:14 -0000
@@ -96,6 +96,7 @@
   num_remaining = orig->glyphs->num_glyphs - num_glyphs;
 
   new = g_new (PangoGlyphItem, 1);
+  new->has_cache = FALSE;
   split_offset = g_utf8_pointer_to_offset (text + orig->item->offset,
 					   text + orig->item->offset + split_index);
   new->item = pango_item_split (orig->item, split_index, split_offset);
