aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-10-05 16:56:28 +0200
committerThomas White <taw@physics.org>2019-10-05 17:03:43 +0200
commita9f46496535cb47e1e15a47a4b7b3282926988c7 (patch)
treeb53b9dbcd73fa4c4207348561edfad2a238f4dbc
parent0c398ce606d6ef3c890d731c3c4f992ae75d983d (diff)
Fix narrative_pos_trail_to_offset for runs (use which_run)narrative_runs
-rw-r--r--libstorycode/narrative_render_cairo.c30
1 files 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; run<item->n_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; j<run; j++ ) prev_len += strlen(item->runs[j].text);
+ return prev_len + ptr - item->runs[run].text;
}