diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2008-04-22 00:18:41 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2008-04-22 00:18:41 +0000 |
commit | f9343aa01ff8e71406a167de3ae186b615804f57 (patch) | |
tree | a4b7704133b2c044b85d7c9d928cd57032c71d6d /pango/pango-bidi-type.c | |
parent | 03cab3cab0ca0a48dc712ffce290a259bc2b49c5 (diff) | |
download | pango-f9343aa01ff8e71406a167de3ae186b615804f57.tar.gz |
Group bidi stuff together. Add a section in the docs for them.
2008-04-21 Behdad Esfahbod <behdad@gnome.org>
* docs/pango-docs.sgml:
* docs/pango-sections.txt:
* docs/tmpl/bidi.sgml:
* docs/tmpl/main.sgml:
* docs/tmpl/vertical.sgml:
* pango/pango-bidi-type.c (pango_log2vis_get_embedding_levels),
(pango_unichar_direction), (pango_get_mirror_char):
* pango/pango-bidi-type.h:
* pango/pango-types.h:
* pango/pango-utils.c:
Group bidi stuff together. Add a section in the docs for them.
svn path=/trunk/; revision=2608
Diffstat (limited to 'pango/pango-bidi-type.c')
-rw-r--r-- | pango/pango-bidi-type.c | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/pango/pango-bidi-type.c b/pango/pango-bidi-type.c index 45d1d936..029a030f 100644 --- a/pango/pango-bidi-type.c +++ b/pango/pango-bidi-type.c @@ -73,3 +73,128 @@ pango_bidi_type_for_unichar (gunichar ch) return PANGO_BIDI_TYPE_ON; } } + +/* Some bidi-related functions */ + +/** + * pango_log2vis_get_embedding_levels: + * @text: the text to itemize. + * @length: the number of bytes (not characters) to process, or -1 + * if @text is nul-terminated and the length should be calculated. + * @pbase_dir: input base direction, and output resolved direction. + * + * This will return the bidirectional embedding levels of the input paragraph + * as defined by the Unicode Bidirectional Algorithm available at: + * + * http://www.unicode.org/reports/tr9/ + * + * If the input base direction is a weak direction, the direction of the + * characters in the text will determine the final resolved direction. + * + * Return value: a newly allocated array of embedding levels, one item per + * character (not byte), that should be freed using g_free. + * + * Since: 1.4 + */ +guint8 * +pango_log2vis_get_embedding_levels (const gchar *text, + int length, + PangoDirection *pbase_dir) +{ + FriBidiCharType fribidi_base_dir; + guint8 *embedding_levels_list; + + 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_RTL: + fribidi_base_dir = FRIBIDI_TYPE_WR; + break; + case PANGO_DIRECTION_WEAK_LTR: + case PANGO_DIRECTION_NEUTRAL: + default: + fribidi_base_dir = FRIBIDI_TYPE_WL; + break; + } + +#ifdef FRIBIDI_HAVE_UTF8 + { + if (length < 0) + length = strlen (text); + embedding_levels_list = fribidi_log2vis_get_embedding_levels_new_utf8 (text, length, &fribidi_base_dir); + } +#else + { + gunichar *text_ucs4; + int n_chars; + text_ucs4 = g_utf8_to_ucs4_fast (text, length, &n_chars); + embedding_levels_list = g_new (guint8, n_chars); + fribidi_log2vis_get_embedding_levels ((FriBidiChar*)text_ucs4, n_chars, + &fribidi_base_dir, + (FriBidiLevel*)embedding_levels_list); + g_free (text_ucs4); + } +#endif + + *pbase_dir = (fribidi_base_dir == FRIBIDI_TYPE_L) ? PANGO_DIRECTION_LTR : PANGO_DIRECTION_RTL; + + return embedding_levels_list; +} + +/** + * pango_unichar_direction: + * @ch: a Unicode character + * + * Determines the inherent direction of a character; either + * %PANGO_DIRECTION_LTR, %PANGO_DIRECTION_RTL, or + * %PANGO_DIRECTION_NEUTRAL. + * + * This function is useful to categorize characters into left-to-right + * letters, right-to-left letters, and everything else. If full + * Unicode bidirectional type of a character is needed, + * pango_bidi_type_for_gunichar() can be used instead. + * + * Return value: the direction of the character. + */ +PangoDirection +pango_unichar_direction (gunichar ch) +{ + FriBidiCharType fribidi_ch_type = fribidi_get_type (ch); + + if (!FRIBIDI_IS_STRONG (fribidi_ch_type)) + return PANGO_DIRECTION_NEUTRAL; + else if (FRIBIDI_IS_RTL (fribidi_ch_type)) + return PANGO_DIRECTION_RTL; + else + return PANGO_DIRECTION_LTR; +} + +/** + * pango_get_mirror_char: + * @ch: a Unicode character + * @mirrored_ch: location to store the mirrored character + * + * If @ch has the Unicode mirrored property and there is another Unicode + * character that typically has a glyph that is the mirror image of @ch's + * glyph, puts that character in the address pointed to by @mirrored_ch. + * + * Use g_unichar_get_mirror_char() instead; the docs for that function + * provide full details. + * + * Return value: %TRUE if @ch has a mirrored character and @mirrored_ch is + * filled in, %FALSE otherwise + **/ +gboolean +pango_get_mirror_char (gunichar ch, + gunichar *mirrored_ch) +{ + return g_unichar_get_mirror_char (ch, mirrored_ch); +} + |