Index: pango/pango-context.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.c,v
retrieving revision 1.77
diff -u -p -r1.77 pango-context.c
--- pango/pango-context.c	14 Jun 2005 19:54:18 -0000	1.77
+++ pango/pango-context.c	6 Sep 2005 14:17:13 -0000
@@ -567,14 +567,21 @@ struct _ItemizeState
 static void
 update_embedding_end (ItemizeState *state)
 {
-  state->embedding = state->embedding_levels[state->embedding_end_offset];
-  while (state->embedding_end < state->end &&
-	 state->embedding_levels[state->embedding_end_offset] == state->embedding)
+  if (state->embedding_levels)
     {
-      state->embedding_end_offset++;
-      state->embedding_end = g_utf8_next_char (state->embedding_end);
+      state->embedding = state->embedding_levels[state->embedding_end_offset];
+      while (state->embedding_end < state->end &&
+	     state->embedding_levels[state->embedding_end_offset] == state->embedding)
+	{
+	  state->embedding_end_offset++;
+	  state->embedding_end = g_utf8_next_char (state->embedding_end);
+	}
     }
-  
+  else
+    {
+      state->embedding_end = state->end;
+    }
+
   state->changed |= EMBEDDING_CHANGED;
 }
 
@@ -646,6 +653,7 @@ itemize_state_init (ItemizeState      *s
 {
   gunichar *text_ucs4;
   long n_chars;
+  gboolean bidi = TRUE;
 
   state->context = context;
   state->text = text;
@@ -661,10 +669,17 @@ itemize_state_init (ItemizeState      *s
    */
   text_ucs4 = g_utf8_to_ucs4_fast (text + start_index, length, &n_chars);
   state->embedding_levels = g_new (guint8, n_chars);
-  pango_log2vis_get_embedding_levels (text_ucs4, n_chars, &base_dir,
-                                      state->embedding_levels);
+  bidi = pango_log2vis_get_embedding_levels (text_ucs4, n_chars, &base_dir,
+					     state->embedding_levels);
   g_free (text_ucs4);
   
+  if (!bidi)
+    {
+      state->embedding = state->embedding_levels[0];
+      g_free (state->embedding_levels);
+      state->embedding_levels = NULL;
+    }
+
   state->embedding_end_offset = 0;
   state->embedding_end = text + start_index;
   update_embedding_end (state);
@@ -1134,7 +1149,8 @@ itemize_state_process_run (ItemizeState 
 static void
 itemize_state_finish (ItemizeState *state)
 {
-  g_free (state->embedding_levels);
+  if (state->embedding_levels)
+    g_free (state->embedding_levels);
   if (state->free_attr_iter)
     pango_attr_iterator_destroy (state->attr_iter);
   pango_script_iter_free (state->script_iter);
Index: pango/mini-fribidi/fribidi.c
===================================================================
RCS file: /cvs/gnome/pango/pango/mini-fribidi/fribidi.c,v
retrieving revision 1.13
diff -u -p -r1.13 fribidi.c
--- pango/mini-fribidi/fribidi.c	2 Mar 2004 00:59:01 -0000	1.13
+++ pango/mini-fribidi/fribidi.c	6 Sep 2005 14:17:18 -0000
@@ -518,6 +518,7 @@ fribidi_analyse_string (/* input */
   FriBidiCharType base_dir;
   FriBidiStrIndex i;
   TypeLink *type_rl_list, *explicits_list, *explicits_list_end, *pp;
+  gboolean has_ltr = FALSE, has_rtl = FALSE;
 
   DBG ("Entering fribidi_analyse_string()\n");
 
@@ -527,7 +528,27 @@ fribidi_analyse_string (/* input */
     FriBidiCharType *char_type =
       (FriBidiCharType *) g_malloc (len * sizeof (FriBidiCharType));
     for (i = 0; i < len; i++)
-      char_type[i] = _pango_fribidi_get_type (str[i]);
+      {
+	char_type[i] = _pango_fribidi_get_type (str[i]);
+
+	if (char_type[i] & FRIBIDI_MASK_STRONG)
+	  {
+	    if (char_type[i] & FRIBIDI_MASK_RTL)
+	      has_rtl = TRUE;
+	    else
+	      has_ltr = TRUE;
+	  }
+      }
+
+    /* If there are no strong RTL characters then it is all LTR (and vice
+       versa), so we don't need to do any more. */
+    if (!(has_rtl && has_ltr))
+      {
+	g_free (char_type);
+	*ptype_rl_list = NULL;
+	*pmax_level = has_rtl ? 1 : 0;
+	return;
+      }
 
     /* Run length encode the character types */
     type_rl_list = run_length_encode_types (char_type, len);
@@ -1035,19 +1056,27 @@ pango_log2vis_get_embedding_levels (/* i
                                  /* output */
                                  &type_rl_list, &max_level);
 
-  for (pp = type_rl_list->next; pp->next; pp = pp->next)
+  if (type_rl_list)
     {
-      gint i, pos = RL_POS (pp),
-        len = RL_LEN (pp);
-      gint level = RL_LEVEL (pp);
-      for (i = 0; i < len; i++)
-        embedding_level_list[pos + i] = level;
-    }
-
-  free_rl_list (type_rl_list);
+      for (pp = type_rl_list->next; pp->next; pp = pp->next)
+	{
+	  gint i, pos = RL_POS (pp),
+	    len = RL_LEN (pp);
+	  gint level = RL_LEVEL (pp);
+	  for (i = 0; i < len; i++)
+	    embedding_level_list[pos + i] = level;
+	}
 
-  DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
-  return TRUE;
+      free_rl_list (type_rl_list);
+      DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
+      return TRUE;
+    }
+  else
+    {
+      embedding_level_list[0] = max_level;
+      DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
+      return FALSE;
+    }
 }
 
 PangoDirection
