summaryrefslogtreecommitdiff
path: root/pango/mapping.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2003-05-02 21:46:20 +0000
committerOwen Taylor <otaylor@src.gnome.org>2003-05-02 21:46:20 +0000
commitcf90e371a93f175dc1c2ad2f8ba5a9023af1aa5e (patch)
tree8b2e9b5aa2ff1900c61033056c068f8ee17457e5 /pango/mapping.c
parent5602b79801fe06980d106652302ed53d2e199e42 (diff)
downloadpango-cf90e371a93f175dc1c2ad2f8ba5a9023af1aa5e.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/mapping.c')
-rw-r--r--pango/mapping.c58
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;
}
}