Index: pango/mini-fribidi/fribidi.c
===================================================================
RCS file: /cvs/gnome/pango/pango/mini-fribidi/fribidi.c,v
retrieving revision 1.14
diff -u -p -r1.14 fribidi.c
--- pango/mini-fribidi/fribidi.c	3 Nov 2005 21:13:13 -0000	1.14
+++ pango/mini-fribidi/fribidi.c	3 Nov 2005 22:16:40 -0000
@@ -126,10 +126,13 @@ free_type_link (TypeLink *link)
 
 static TypeLink *
 run_length_encode_types_utf8 (const char *s,
-			      int bytelen, FriBidiStrIndex *len)
+			      int bytelen,
+			      FriBidiStrIndex *len,
+			      fribidi_boolean *phas_rtl)
 {
   TypeLink *list, *last, *link;
   FriBidiCharType char_type;
+  fribidi_boolean has_rtl = 0;
   FriBidiStrIndex i;
   const char *p;
 
@@ -143,6 +146,8 @@ run_length_encode_types_utf8 (const char
   i = 0;
   for (p = s; p < s + bytelen; p = g_utf8_next_char(p)) {
     char_type = fribidi_get_type (g_utf8_get_char (p));
+    if (FRIBIDI_IS_RTL (char_type))
+      has_rtl = 1;
     if (char_type != last->type)
       {
 	link = new_type_link ();
@@ -163,6 +168,9 @@ run_length_encode_types_utf8 (const char
   if (len)
     *len = i;
 
+  if (phas_rtl)
+    *phas_rtl = has_rtl;
+
   return list;
 }
 
@@ -370,6 +378,46 @@ compact_neutrals (TypeLink *list)
     }
 }
 
+/*======================================================================
+ *  Frees up the rl_list, must be called after each call to
+ *  fribidi_analyse_string(), after the list is not needed anymore.
+ *----------------------------------------------------------------------*/
+static void
+free_rl_list (TypeLink *type_rl_list)
+{
+
+  TypeLink *pp;
+
+  DBG ("Entering free_rl_list()\n");
+
+  if (!type_rl_list)
+    {
+      DBG ("Leaving free_rl_list()\n");
+      return;
+    }
+
+#ifdef USE_SIMPLE_MALLOC
+  pp = type_rl_list;
+  while (pp)
+    {
+      TypeLink *p;
+
+      p = pp;
+      pp = pp->next;
+      free_type_link (p);
+    };
+#else
+  for (pp = type_rl_list->next; pp->next; pp = pp->next)
+    /* Nothing */ ;
+  pp->next = free_type_links;
+  free_type_links = type_rl_list;
+  type_rl_list = NULL;
+#endif
+
+  DBG ("Leaving free_rl_list()\n");
+  return;
+}
+
 /*=========================================================================
  * define macros for push and pop the status in to / out of the stack
  *-------------------------------------------------------------------------*/
@@ -468,7 +516,7 @@ compact_neutrals (TypeLink *list)
 /*======================================================================
  *  This function should follow the Unicode specification closely!
  *----------------------------------------------------------------------*/
-static void
+static fribidi_boolean
 fribidi_analyse_string_utf8 (	/* input */
 			 const char *str,
 			 int bytelen,
@@ -487,8 +535,21 @@ fribidi_analyse_string_utf8 (	/* input *
   /* Determinate character types */
   DBG ("  Determine character types\n");
   {
+    fribidi_boolean has_rtl;
+
     /* Run length encode the character types */
-    type_rl_list = run_length_encode_types_utf8 (str, bytelen, len);
+    type_rl_list = run_length_encode_types_utf8 (str, bytelen, len, &has_rtl);
+
+    if (!(FRIBIDI_IS_RTL (*pbase_dir)) && !has_rtl)
+      {
+	free_rl_list (type_rl_list);
+
+	*ptype_rl_list = NULL;
+	*pmax_level = 0;
+	*pbase_dir = FRIBIDI_TYPE_LTR;
+
+	return 0;
+      }
   }
   DBG ("  Determine character types, Done\n");
 
@@ -852,47 +913,7 @@ fribidi_analyse_string_utf8 (	/* input *
   *pbase_dir = base_dir;
 
   DBG ("Leaving fribidi_analyse_string()\n");
-  return;
-}
-
-/*======================================================================
- *  Frees up the rl_list, must be called after each call to
- *  fribidi_analyse_string(), after the list is not needed anymore.
- *----------------------------------------------------------------------*/
-static void
-free_rl_list (TypeLink *type_rl_list)
-{
-
-  TypeLink *pp;
-
-  DBG ("Entering free_rl_list()\n");
-
-  if (!type_rl_list)
-    {
-      DBG ("Leaving free_rl_list()\n");
-      return;
-    }
-
-#ifdef USE_SIMPLE_MALLOC
-  pp = type_rl_list;
-  while (pp)
-    {
-      TypeLink *p;
-
-      p = pp;
-      pp = pp->next;
-      free_type_link (p);
-    };
-#else
-  for (pp = type_rl_list->next; pp->next; pp = pp->next)
-    /* Nothing */ ;
-  pp->next = free_type_links;
-  free_type_links = type_rl_list;
-  type_rl_list = NULL;
-#endif
-
-  DBG ("Leaving free_rl_list()\n");
-  return;
+  return 1;
 }
 
 /*======================================================================
@@ -917,9 +938,14 @@ fribidi_log2vis_get_embedding_levels_new
       return NULL;
     }
 
-  fribidi_analyse_string_utf8 (str, bytelen, pbase_dir,
+  if (!fribidi_analyse_string_utf8 (str, bytelen, pbase_dir,
 			  /* output */
-			  &len, &type_rl_list, &max_level);
+			  &len, &type_rl_list, &max_level))
+    {
+      /* no rtl characters, fill in everything as ltr */
+     return g_new0 (FriBidiLevel, len);
+     
+    }
 
   embedding_level_list = g_new (FriBidiLevel, len);
   for (pp = type_rl_list->next; pp->next; pp = pp->next)
