diff options
author | Owen Taylor <otaylor@redhat.com> | 2003-05-02 21:46:09 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2003-05-02 21:46:09 +0000 |
commit | 0a0e6dfabc1532f03d68c1f154956a501a3aa31d (patch) | |
tree | f40ddd1d5ec7b45976d61e1555442acb7e15a603 /pango | |
parent | e4916dc98bb89b57a6dd3b68d2b54168bb44e8fe (diff) | |
download | pango-0a0e6dfabc1532f03d68c1f154956a501a3aa31d.tar.gz |
Fix some incorrect edge cases for RTL text. (#102952, Padraig O'Briain)
Fri May 2 17:20:23 2003 Owen Taylor <otaylor@redhat.com>
* pango/mapping.c (pango_glyph_string_x_to_index):
Fix some incorrect edge cases for RTL text.
(#102952, Padraig O'Briain)
Diffstat (limited to 'pango')
-rw-r--r-- | pango/mapping.c | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/pango/mapping.c b/pango/mapping.c index f25dd9aa..c1672519 100644 --- a/pango/mapping.c +++ b/pango/mapping.c @@ -275,23 +275,53 @@ pango_glyph_string_x_to_index (PangoGlyphString *glyphs, } else { - double cp = ((double)(x_pos - start_xpos) * cluster_chars) / (end_xpos - start_xpos); - - if (index) + double cp = ((double)(x_pos - start_xpos) * cluster_chars) / (end_xpos - start_xpos); + + /* LTR and right-to-left have to be handled separately + * here because of the edge condition when we are exactly + * at a pixel boundary; end_xpos goes with the next + * character for LTR, with the previous character for RTL. + */ + if (start_xpos < end_xpos) /* Left-to-right */ { - char *p = text + start_index; - int i = 0; - - while (i + 1 <= cp) + if (index) { - p = g_utf8_next_char (p); - i++; + char *p = text + start_index; + int i = 0; + + while (i + 1 <= cp) + { + p = g_utf8_next_char (p); + i++; + } + + *index = (p - text); + } + + if (trailing) + *trailing = (cp - (int)cp >= 0.5) ? 1 : 0; + } + else /* Right-to-left */ + { + if (index) + { + char *p = text + start_index; + int i = 0; + + while (i + 1 < cp) + { + p = g_utf8_next_char (p); + i++; + } + + *index = (p - text); + } + + if (trailing) + { + double cp_flip = cluster_chars - cp; + *trailing = (cp_flip - (int)cp_flip >= 0.5) ? 0 : 1; } - - *index = (p - text); } - - if (trailing) - *trailing = (cp - (int)cp > 0.5) ? 1 : 0; } } |