Index: pango/pango-context.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-context.c,v
retrieving revision 1.51
diff -u -p -r1.51 pango-context.c
--- pango/pango-context.c	27 May 2003 16:35:33 -0000	1.51
+++ pango/pango-context.c	29 Jul 2003 04:31:30 -0000
@@ -318,6 +318,13 @@ pango_context_get_language (PangoContext
  * @direction: the new base direction
  * 
  * Sets the base direction for the context.
+ *
+ * The base direction is used in applying the Unicode bidirectional
+ * algorithm; if the @direction is %PANGO_DIRECTION_LTR or
+ * %PANGO_DIRECTION_RTL, then the value will be used as the paragraph
+ * direction in the Unicode bidirectional algorithm.  A value of
+ * %PANGO_DIRECTION_WEAK_LTR or %PANGO_DIRECTION_WEAK_RTL is used only
+ * for paragraphs that do not contain any strong characters themselves. 
  **/
 void
 pango_context_set_base_dir (PangoContext  *context,
@@ -330,9 +337,10 @@ pango_context_set_base_dir (PangoContext
 
 /**
  * pango_context_get_base_dir:
- * @context: 
+ * @context: a #PangoContext
  * 
- * Retrieves the base direction for the context.
+ * Retrieves the base direction for the context. See
+ * pango_context_set_base_dir().
  * 
  * Return value: the base direction for the context.
  **/
Index: pango/pango-types.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-types.h,v
retrieving revision 1.12
diff -u -p -r1.12 pango-types.h
--- pango/pango-types.h	18 Sep 2001 20:05:17 -0000	1.12
+++ pango/pango-types.h	29 Jul 2003 04:31:31 -0000
@@ -65,15 +65,46 @@ struct _PangoRectangle
 #define PANGO_LBEARING(rect) ((rect).x)
 #define PANGO_RBEARING(rect) ((rect).x + (rect).width)
 
-/* Information about a segment of text with a consistent
- * shaping/language engine and bidirectional level
- */
-
+/**
+ * PangoDirection:
+ * 
+ * The #PangoDirection type represents a direction in the
+ * Unicode bidirectional algorithm; not every value in this
+ * enumeration makes sense for every usage of #PangoDirection;
+ * for example, the return value of pango_unichar_direction()
+ * and pango_find_base_direction() cannot be %PANGO_DIRECTION_WEAK_LTR
+ * or %PANGO_DIRECTION_WEAK_RTL, since every character is either
+ * neutral or has a strong direction; on the other hand
+ * %PANGO_DIRECTION_NEUTRAL doesn't make sense to pass
+ * to pango_log2vis_get_embedding_levels().
+ *
+ * The %PANGO_DIRECTION_TTB_LTR, %PANGO_DIRECTION_TTB_RTL
+ * values come from an earlier interpretation of this
+ * enumeration as the writing direction of a block of
+ * text and are no longer used; See the Text module of the
+ * CSS3 spec for how vertical text is planned to be handled
+ * in a future version of Pango. The explanation of why
+ * %PANGO_DIRECTION_TTB_LTR is treated as %PANGO_DIRECTION_RTL
+ * can be found there as well.
+ *
+ * @PANGO_DIRECTION_LTR: A strong left-to-right direction
+ * @PANGO_DIRECTION_RTL: A strong right-to-left direction
+ * @PANGO_DIRECTION_TTB_LTR: Deprecated value; treated the
+ *   same as %PANGO_DIRECTION_RTL.
+ * @PANGO_DIRECTION_TTB_RTL: Deprecated value; treated the
+ *   same as PANGO_DIRECTION_LTR
+ * @PANGO_DIRECTION_WEAK_LTR: A weak left-to-right direction
+ * @PANGO_DIRECTION_WEAK_RTL: A weak right-to-left direction
+ * @PANGO_DIRECTION_NEUTRAL: No direction specified
+ */			  
 typedef enum {
   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 ())
@@ -84,6 +115,12 @@ PangoLanguage *pango_language_from_strin
 
 gboolean      pango_language_matches  (PangoLanguage *language,
 				       const char *range_list);
+
+gboolean       pango_get_mirror_char        (gunichar     ch,
+					     gunichar    *mirrored_ch);
+PangoDirection pango_unichar_direction      (gunichar     ch);
+PangoDirection pango_find_base_dir          (const gchar *text,
+					     gint         length);
 
 G_END_DECLS
 
Index: pango/pango-utils.c
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-utils.c,v
retrieving revision 1.40
diff -u -p -r1.40 pango-utils.c
--- pango/pango-utils.c	24 Jul 2003 18:38:16 -0000	1.40
+++ pango/pango-utils.c	29 Jul 2003 04:31:32 -0000
@@ -1234,38 +1234,6 @@ pango_language_get_sample_string (PangoL
   return result;
 }
 
-#ifdef HAVE_FRIBIDI
-
-gboolean
-pango_log2vis_get_embedding_levels (gunichar       *str,
-				    int             len,
-				    PangoDirection *pbase_dir,
-				    guint8         *embedding_level_list)
-{
-  FriBidiCharType fribidi_base_dir;
-  gboolean result;
-
-  fribidi_base_dir = (*pbase_dir == PANGO_DIRECTION_LTR) ? FRIBIDI_TYPE_L : FRIBIDI_TYPE_R;
-
-  result = fribidi_log2vis_get_embedding_levels (str, len, &fribidi_base_dir,
-						 embedding_level_list);
-  
-  *pbase_dir = (fribidi_base_dir == FRIBIDI_TYPE_L) ?  PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL;
-
-  return result;
-}
-
-
-gboolean 
-pango_get_mirror_char (gunichar        ch,
-		       gunichar       *mirrored_ch)
-{
-  return fribidi_get_mirror_char (ch, mirrored_ch); 
-}
-
-#endif /* HAVE_FRIBIDI */
-
-
 static guint
 alias_hash (struct PangoAlias *alias)
 {
@@ -1496,3 +1464,40 @@ pango_lookup_aliases (const char   *font
       *n_families = 0;
     }
 }
+
+/**
+ * pango_find_base_dir:
+ * @text:   the text to process
+ * @length: length of @text in bytes (may be -1 if @text is nul-terminated)
+ *
+ * Searches a string the first character that has a strong 
+ * direction, according to the Unicode bidirectional algorithm.
+ *
+ * Return value: The direction corresponding to the first strong character.
+ * If no such character is found, then %PANGO_DIRECTION_NEUTRAL is returned.
+ */
+PangoDirection
+pango_find_base_dir (const gchar *text,
+		     gint         length)
+{
+  PangoDirection dir = PANGO_DIRECTION_NEUTRAL;
+  const gchar *p;
+
+  g_return_val_if_fail (text != NULL, PANGO_DIRECTION_NEUTRAL);
+
+  p = text;
+  while ((length < 0 || p < text + length) && *p)
+    {
+      gunichar wc = g_utf8_get_char (p);
+
+      dir = pango_unichar_direction (wc);
+
+      if (dir != PANGO_DIRECTION_NEUTRAL)
+	break;
+
+      p = g_utf8_next_char (p);
+    }
+
+  return dir;
+}
+
Index: pango/pango-utils.h
===================================================================
RCS file: /cvs/gnome/pango/pango/pango-utils.h,v
retrieving revision 1.15
diff -u -p -r1.15 pango-utils.h
--- pango/pango-utils.h	18 Nov 2001 16:06:01 -0000	1.15
+++ pango/pango-utils.h	29 Jul 2003 04:31:32 -0000
@@ -19,10 +19,15 @@
  * Boston, MA 02111-1307, USA.
  */
 
+#ifndef __PANGO_UTILS_H__
+#define __PANGO_UTILS_H__
+
 #include <stdio.h>
 #include <glib.h>
 #include <pango/pango-font.h>
 
+G_BEGIN_DECLS
+
 char **  pango_split_file_list (const char *str);
 
 char    *pango_trim_string     (const char *str);
@@ -88,8 +93,9 @@ gboolean pango_log2vis_get_embedding_lev
 					     int             len,
 					     PangoDirection *pbase_dir,
 					     guint8         *embedding_level_list);
-gboolean pango_get_mirror_char              (gunichar        ch,
-					     gunichar       *mirrored_ch);
 
 G_CONST_RETURN char *pango_language_get_sample_string (PangoLanguage *language);
 
+G_BEGIN_DECLS
+
+#endif /* __PANGO_UTILS_H__ */
Index: pango/mini-fribidi/fribidi.c
===================================================================
RCS file: /cvs/gnome/pango/pango/mini-fribidi/fribidi.c,v
retrieving revision 1.9
diff -u -p -r1.9 fribidi.c
--- pango/mini-fribidi/fribidi.c	27 May 2003 23:24:28 -0000	1.9
+++ pango/mini-fribidi/fribidi.c	29 Jul 2003 04:31:32 -0000
@@ -1077,7 +1077,23 @@ pango_log2vis_get_embedding_levels (	/* 
 
   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:
+    case PANGO_DIRECTION_TTB_RTL:
+      fribidi_base_dir = FRIBIDI_TYPE_L;
+      break;
+    case PANGO_DIRECTION_RTL:
+    case PANGO_DIRECTION_TTB_LTR:
+      fribidi_base_dir = FRIBIDI_TYPE_R;
+      break;
+    case PANGO_DIRECTION_WEAK_LTR:
+      fribidi_base_dir = FRIBIDI_TYPE_WL;
+      break;
+    case PANGO_DIRECTION_WEAK_RTL:
+      fribidi_base_dir = FRIBIDI_TYPE_WR;
+      break;
+    }
 
   if (len == 0)
     {
@@ -1106,3 +1122,24 @@ pango_log2vis_get_embedding_levels (	/* 
   DBG ("Leaving fribidi_log2vis_get_embedding_levels()\n");
   return TRUE;
 }
+
+/**
+ * pango_unichar_direction:
+ * @ch: character to examine
+ *
+ * Returns the direction of a character, as used in the
+ *  Unicode bidirectional algorithm.
+ */
+PangoDirection
+pango_unichar_direction (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;
+}
+
Index: pango/mini-fribidi/fribidi_types.h
===================================================================
RCS file: /cvs/gnome/pango/pango/mini-fribidi/fribidi_types.h,v
retrieving revision 1.4
diff -u -p -r1.4 fribidi_types.h
--- pango/mini-fribidi/fribidi_types.h	25 Feb 2002 21:40:47 -0000	1.4
+++ pango/mini-fribidi/fribidi_types.h	29 Jul 2003 04:31:32 -0000
@@ -154,7 +154,7 @@ FriBidiCharType;
 #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)
 
