From a9f46496535cb47e1e15a47a4b7b3282926988c7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 5 Oct 2019 16:56:28 +0200 Subject: Fix narrative_pos_trail_to_offset for runs (use which_run) --- libstorycode/narrative_render_cairo.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/libstorycode/narrative_render_cairo.c b/libstorycode/narrative_render_cairo.c index 53011cd..894c730 100644 --- a/libstorycode/narrative_render_cairo.c +++ b/libstorycode/narrative_render_cairo.c @@ -198,27 +198,25 @@ static void wrap_slide(struct narrative_item *item, Stylesheet *ss, ImageStore * size_t narrative_pos_trail_to_offset(Narrative *n, int i, int offs, int trail) { int run; + glong char_offs; + char *ptr; + size_t run_offs; struct narrative_item *item = &n->items[i]; - size_t pos; + int j; + size_t prev_len; if ( !narrative_item_is_text(n, i) ) return offs; - pos = 0; - for ( run=0; runn_runs; run++ ) { - pos += strlen(item->runs[run].text); - if ( pos >= offs ) { - glong char_offs; - char *ptr; - char_offs = g_utf8_pointer_to_offset(item->runs[run].text, - item->runs[run].text+offs); - char_offs += trail; - ptr = g_utf8_offset_to_pointer(item->runs[run].text, char_offs); - return ptr - item->runs[run].text; - } - } + run = which_run(item, offs, &run_offs); - fprintf(stderr, "narrative_pos_trail_to_offset: Outside last run\n"); - return 0; + char_offs = g_utf8_pointer_to_offset(item->runs[run].text, + item->runs[run].text+run_offs); + char_offs += trail; + ptr = g_utf8_offset_to_pointer(item->runs[run].text, char_offs); + + prev_len = 0; + for ( j=0; jruns[j].text); + return prev_len + ptr - item->runs[run].text; } -- cgit v1.2.3