diff options
author | Thomas White <taw@bitwiz.org.uk> | 2016-03-21 23:25:31 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2016-03-21 23:25:31 +0100 |
commit | 504b29168f4cb5b492541c5e439beb861951efce (patch) | |
tree | aee7d0811097d8ea6ca9425aa0bf7d47ae027b5f /src | |
parent | 1ee3354534505a62a28a8aa9ee927ae91cc6e3ec (diff) |
get_cursor_pos(): Fix handling of multi-byte characters
Diffstat (limited to 'src')
-rw-r--r-- | src/wrap.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -142,6 +142,7 @@ static double text_box_index_to_x(struct wrap_box *box, int pos) int p; int i; int err; + ptrdiff_t offs_p; nseg = which_segment(box, pos, &err); if ( err ) return 0.0; @@ -159,10 +160,16 @@ static double text_box_index_to_x(struct wrap_box *box, int pos) box->offs_char + seg->offs_char); ep = g_utf8_offset_to_pointer(seg_text, seg->len_chars); - /* FIXME: pos should be in bytes, not chars */ + /* Make character position relative to segment start (not box start) */ + pos -= seg->offs_char; + + /* Convert the character position to a byte offset */ + offs_p = g_utf8_offset_to_pointer(seg_text, pos) - seg_text; + pango_glyph_string_index_to_x(seg->glyphs, (char *)seg_text, ep - seg_text, &seg->analysis, - pos, FALSE, &p); + offs_p, FALSE, &p); + return pango_units_to_double(x+p); } |