diff -r -u pango-1.2.1/pango/break.c pango-1.2.1.dov/pango/break.c
--- pango-1.2.1/pango/break.c	2001-12-06 14:51:49.000000000 -0500
+++ pango-1.2.1.dov/pango/break.c	2003-03-03 23:43:55.000000000 -0500
@@ -21,7 +21,11 @@
 
 #include "pango-break.h"
 #include "pango-modules.h"
+#include "pango-utils.h"
 #include <string.h>
+#ifdef HAVE_FRIBIDI
+#include <fribidi/fribidi.h>
+#endif
 
 /* See http://www.unicode.org/unicode/reports/tr14/ if you hope
  * to understand the line breaking code.
@@ -1529,3 +1533,80 @@
                  attrs_len - chars_broken);
 }
 
+
+/**
+ * pango_find_base_dir:
+ * @str: string to examine
+ * @len: end of string
+ *
+ * Searches the string @str for the first strong character and returns
+ * it. If no such character is found, it returns PANGO_DIRECITON_NEUTRAL.
+ */
+PangoDirection
+pango_find_base_dir(gunichar *str,
+		    int len)
+{
+  gunichar *p;
+  PangoDirection dir = PANGO_DIRECTION_NEUTRAL;
+  
+  for (p=str; p<str+len; p++)
+    {
+      dir = pango_get_char_dir(*p);
+      
+      if (dir != PANGO_DIRECTION_NEUTRAL)
+	break;
+    }
+
+  return dir;
+      
+}
+
+/**
+ * pango_find_base_dir_utf8:
+ * @str: string to examine
+ * @len: end of string
+ *
+ * Searches the string utf8 encoded string @str for the first
+ * strong character and returns it. If no such character is found,
+ * it returns PANGO_DIRECITON_NEUTRAL.
+ */
+PangoDirection
+pango_find_base_dir_utf8(char *str,
+			 int len)
+{
+  const char *p = str;
+  PangoDirection dir = PANGO_DIRECTION_NEUTRAL;
+  
+  while (p < str + len)
+    {
+      gunichar ch = g_utf8_get_char(p);
+
+      dir = pango_get_char_dir(ch);
+
+      if (dir != PANGO_DIRECTION_NEUTRAL)
+	break;
+
+      p = g_utf8_next_char(p);
+    }
+
+  return dir;
+}
+
+
+/**
+ * pango_direction_strong_to_weak:
+ * @dir: Strong direction
+ *
+ * Given a strong direction, it returns a weak direction. This transformation 
+ * is useful when inheriting a direction from a previous paragraph.
+ *
+ * Return value: weak direction
+ */
+PangoDirection
+pango_direction_strong_to_weak(PangoDirection dir)
+{
+  if (dir >= PANGO_DIRECTION_LTR
+      && dir <= PANGO_DIRECTION_RTL)
+    dir = dir - PANGO_DIRECTION_LTR + PANGO_DIRECTION_WEAK_LTR;
+  return dir;
+}
diff -r -u pango-1.2.1/pango/mini-fribidi/fribidi.c pango-1.2.1.dov/pango/mini-fribidi/fribidi.c
--- pango-1.2.1/pango/mini-fribidi/fribidi.c	2002-01-10 16:28:47.000000000 -0500
+++ pango-1.2.1.dov/pango/mini-fribidi/fribidi.c	2003-03-03 23:44:04.000000000 -0500
@@ -1068,7 +1068,20 @@
 
   DBG ("Entering fribidi_log2vis_get_embedding_levels()\n");
 
-  fribidi_base_dir = (*pbase_dir == PANGO_DIRECTION_LTR) ? FRIBIDI_TYPE_L : FRIBIDI_TYPE_R;
+  switch (*pbase_dir) {
+  case PANGO_DIRECTION_LTR:
+    fribidi_base_dir = FRIBIDI_TYPE_L;
+    break;
+  case PANGO_DIRECTION_RTL:
+    fribidi_base_dir = FRIBIDI_TYPE_R;
+    break;
+  case PANGO_DIRECTION_WEAK_RTL:
+    fribidi_base_dir = FRIBIDI_TYPE_WR;
+    break;
+  default:
+    fribidi_base_dir = FRIBIDI_TYPE_WL;
+    break;
+  }
 
   if (len == 0)
     {
@@ -1097,3 +1110,23 @@
   DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
   return TRUE;
 }
+
+/**
+ * pango_get_char_dir:
+ * @ch: character to examine
+ *
+ * Returns the BiDi direction of a unicode character.
+ */
+PangoDirection
+pango_get_char_dir(gunichar ch)
+{
+  FriBidiCharType fribidi_ch_type = _pango_fribidi_get_type(ch);
+
+  if (!FRIBIDI_IS_LETTER(fribidi_ch_type))
+    return PANGO_DIRECTION_NEUTRAL;
+  else if (FRIBIDI_IS_RTL(fribidi_ch_type))
+    return PANGO_DIRECTION_RTL;
+  else
+    return PANGO_DIRECTION_LTR;
+}
+
diff -r -u pango-1.2.1/pango/mini-fribidi/fribidi_types.h pango-1.2.1.dov/pango/mini-fribidi/fribidi_types.h
--- pango-1.2.1/pango/mini-fribidi/fribidi_types.h	2002-02-25 16:40:47.000000000 -0500
+++ pango-1.2.1.dov/pango/mini-fribidi/fribidi_types.h	2003-02-27 20:25:55.000000000 -0500
@@ -154,7 +154,7 @@
 #define FRIBIDI_DIR_TO_LEVEL(dir) (dir & 1)
 
 /* Is right to left? */
-#define FRIBIDI_IS_RTL(p)      ((P) & FRIBIDI_MASK_RTL)
+#define FRIBIDI_IS_RTL(p)      ((p) & FRIBIDI_MASK_RTL)
 /* Is arabic? */
 #define FRIBIDI_IS_ARABIC(p)   ((p) & FRIBIDI_MASK_ARABIC)
 
diff -r -u pango-1.2.1/pango/pango-break.h pango-1.2.1.dov/pango/pango-break.h
--- pango-1.2.1/pango/pango-break.h	2001-10-03 16:29:55.000000000 -0400
+++ pango-1.2.1.dov/pango/pango-break.h	2003-02-27 20:38:37.000000000 -0500
@@ -87,6 +87,21 @@
                           PangoLogAttr  *log_attrs,
                           int            attrs_len);
 
+
+/* Resolve and find the base direction of a string according to the
+   Bidi algorithm. */
+
+PangoDirection
+pango_find_base_dir(gunichar *str,
+		    int len);
+
+PangoDirection
+pango_find_base_dir_utf8(gchar *str,
+			 int len);
+
+PangoDirection
+pango_direction_strong_to_weak(PangoDirection dir);
+
 #ifdef PANGO_ENABLE_ENGINE
 
 /* This is the default break algorithm, used if no language
diff -r -u pango-1.2.1/pango/pango-context.h pango-1.2.1.dov/pango/pango-context.h
--- pango-1.2.1/pango/pango-context.h	2001-11-18 18:23:14.000000000 -0500
+++ pango-1.2.1.dov/pango/pango-context.h	2003-02-27 21:01:07.000000000 -0500
@@ -77,6 +77,7 @@
 void                      pango_context_set_base_dir         (PangoContext               *context,
 							      PangoDirection              direction);
 PangoDirection            pango_context_get_base_dir         (PangoContext               *context);
+PangoDirection            pango_context_get_resolved_base_dir(PangoContext               *context);
 
 /* Break a string of Unicode characters into segments with
  * consistent shaping/language engine and bidrectional level.
diff -r -u pango-1.2.1/pango/pango-enum-types.c pango-1.2.1.dov/pango/pango-enum-types.c
--- pango-1.2.1/pango/pango-enum-types.c	2003-01-29 12:50:40.000000000 -0500
+++ pango-1.2.1.dov/pango/pango-enum-types.c	2003-02-27 20:03:38.000000000 -0500
@@ -224,6 +224,9 @@
       { PANGO_DIRECTION_RTL, "PANGO_DIRECTION_RTL", "rtl" },
       { PANGO_DIRECTION_TTB_LTR, "PANGO_DIRECTION_TTB_LTR", "ttb-ltr" },
       { PANGO_DIRECTION_TTB_RTL, "PANGO_DIRECTION_TTB_RTL", "ttb-rtl" },
+      { PANGO_DIRECTION_WEAK_LTR, "PANGO_DIRECTION_WEAK_LTR", "weak-ltr" },
+      { PANGO_DIRECTION_WEAK_RTL, "PANGO_DIRECTION_WEAK_RTL", "weak-rtl" },
+      { PANGO_DIRECTION_NEUTRAL, "PANGO_DIRECTION_NEUTRAL", "neutral" },
       { 0, NULL, NULL }
     };
     etype = g_enum_register_static ("PangoDirection", values);
diff -r -u pango-1.2.1/pango/pango-types.h pango-1.2.1.dov/pango/pango-types.h
--- pango-1.2.1/pango/pango-types.h	2001-09-18 16:05:17.000000000 -0400
+++ pango-1.2.1.dov/pango/pango-types.h	2003-02-27 20:37:56.000000000 -0500
@@ -73,7 +73,10 @@
   PANGO_DIRECTION_LTR,
   PANGO_DIRECTION_RTL,
   PANGO_DIRECTION_TTB_LTR,
-  PANGO_DIRECTION_TTB_RTL
+  PANGO_DIRECTION_TTB_RTL,
+  PANGO_DIRECTION_WEAK_LTR,
+  PANGO_DIRECTION_WEAK_RTL,
+  PANGO_DIRECTION_NEUTRAL
 } PangoDirection;
 
 #define PANGO_TYPE_LANGUAGE (pango_language_get_type ())
diff -r -u pango-1.2.1/pango/pango-utils.c pango-1.2.1.dov/pango/pango-utils.c
--- pango-1.2.1/pango/pango-utils.c	2002-12-06 19:00:53.000000000 -0500
+++ pango-1.2.1.dov/pango/pango-utils.c	2003-02-27 21:50:48.000000000 -0500
@@ -1244,7 +1244,20 @@
   FriBidiCharType fribidi_base_dir;
   gboolean result;
 
-  fribidi_base_dir = (*pbase_dir == PANGO_DIRECTION_LTR) ? FRIBIDI_TYPE_L : FRIBIDI_TYPE_R;
+  switch (*pbase_dir) {
+  case PANGO_DIRECTION_LTR:
+    fribidi_base_dir = FRIBIDI_TYPE_L;
+    break;
+  case PANGO_DIRECTION_RTL:
+    fribidi_base_dir = FRIBIDI_TYPE_R;
+    break;
+  case PANGO_DIRECTION_WEAK_RTL:
+    fribidi_base_dir = FRIBIDI_TYPE_WR;
+    break;
+  default:
+    fribidi_base_dir = FRIBIDI_TYPE_WL;
+    break;
+  }
 
   result = fribidi_log2vis_get_embedding_levels (str, len, &fribidi_base_dir,
 						 embedding_level_list);
@@ -1254,7 +1267,6 @@
   return result;
 }
 
-
 gboolean 
 pango_get_mirror_char (gunichar        ch,
 		       gunichar       *mirrored_ch)
diff -r -u pango-1.2.1/pango/pango-utils.h pango-1.2.1.dov/pango/pango-utils.h
--- pango-1.2.1/pango/pango-utils.h	2001-11-18 11:06:01.000000000 -0500
+++ pango-1.2.1.dov/pango/pango-utils.h	2003-02-27 20:23:30.000000000 -0500
@@ -91,5 +91,7 @@
 gboolean pango_get_mirror_char              (gunichar        ch,
 					     gunichar       *mirrored_ch);
 
+
 G_CONST_RETURN char *pango_language_get_sample_string (PangoLanguage *language);
 
+PangoDirection pango_get_char_dir(gunichar ch);
diff -r -u pango-1.2.1/pango/pangoft2.c pango-1.2.1.dov/pango/pangoft2.c
--- pango-1.2.1/pango/pangoft2.c	2002-12-07 01:08:39.000000000 -0500
+++ pango-1.2.1.dov/pango/pangoft2.c	2003-02-27 22:26:25.000000000 -0500
@@ -403,6 +403,10 @@
 
 	  rendered_glyph = pango_ft2_font_get_cache_glyph_data (font, glyph_index);
 	  add_glyph_to_cache = FALSE;
+	  
+	  if (glyph_index == 0)
+	    continue;
+
 	  if (rendered_glyph == NULL)
 	    {
 	      rendered_glyph = pango_ft2_font_render_glyph (font, glyph_index);
