aboutsummaryrefslogtreecommitdiff
path: root/libstorycode
diff options
context:
space:
mode:
Diffstat (limited to 'libstorycode')
-rw-r--r--libstorycode/gtk/gtknarrativeview.c5
-rw-r--r--libstorycode/gtk/gtkslideview.c4
-rw-r--r--libstorycode/narrative_render_cairo.c28
-rw-r--r--libstorycode/narrative_render_cairo.h4
4 files changed, 37 insertions, 4 deletions
diff --git a/libstorycode/gtk/gtknarrativeview.c b/libstorycode/gtk/gtknarrativeview.c
index 83d6d23..82dd138 100644
--- a/libstorycode/gtk/gtknarrativeview.c
+++ b/libstorycode/gtk/gtknarrativeview.c
@@ -885,6 +885,11 @@ static int find_cursor(Narrative *n, double x, double y, struct edit_pos *pos)
pango_units_from_double(y - n->space_t - para_top(n, pos->para)),
&pos->pos, &pos->trail);
+ /* pos->pos is the byte index into item->layout_text */
+ //printf("click pos = %i\n", pos->pos);
+ //pos->pos = index_before_removal(item->chars_removed, item->n_chars_removed, pos->pos);
+ //printf("after adjustment: %i\n", pos->pos);
+
return 0;
}
diff --git a/libstorycode/gtk/gtkslideview.c b/libstorycode/gtk/gtkslideview.c
index 9766572..0ec1c5f 100644
--- a/libstorycode/gtk/gtkslideview.c
+++ b/libstorycode/gtk/gtkslideview.c
@@ -570,8 +570,8 @@ static int find_cursor(SlideItem *item, Stylesheet *stylesheet,
pos->para = i-1;
pango_layout_xy_to_index(item->paras[i-1].layout,
- pango_units_from_double(x),
- pango_units_from_double(y - top),
+ pango_units_from_double(x - padl),
+ pango_units_from_double(y - top - padt),
&pos->pos, &pos->trail);
return 0;
}
diff --git a/libstorycode/narrative_render_cairo.c b/libstorycode/narrative_render_cairo.c
index 17f22aa..b001132 100644
--- a/libstorycode/narrative_render_cairo.c
+++ b/libstorycode/narrative_render_cairo.c
@@ -146,7 +146,7 @@ int index_with_removal(int *chars_removed, int n_chars_removed, int idx)
int i;
for ( i=0; i<n_chars_removed; i++ ) {
- if ( chars_removed[i] > idx ) break;
+ if ( chars_removed[i] >= idx ) break;
}
return idx - i;
@@ -172,6 +172,8 @@ static void process_tags(struct narrative_item *item, PangoAttrList *attrs)
int i, j, k;
size_t len;
+ printf("Processing '%s'\n", item->text);
+
item->n_chars_removed = 0;
free(item->chars_removed);
item->chars_removed = NULL;
@@ -205,9 +207,26 @@ static void process_tags(struct narrative_item *item, PangoAttrList *attrs)
text = g_utf8_find_next_char(efend, NULL);
}
+ printf("Found %i ranges:\n", n_add);
+ for ( i=0; i<n_add; i++ ) {
+ printf("%c : %i - %i\n", add[i].type, add[i].start, add[i].end);
+ }
+
+ printf("%i characters to remove: ", item->n_chars_removed);
+ for ( i=0; i<item->n_chars_removed; i++ ) {
+ printf("%i ", item->chars_removed[i]);
+ }
+ printf("\n");
+
/* Sort the list of removed characters */
qsort(item->chars_removed, item->n_chars_removed, sizeof(int), cmpi);
+ printf("Sorted: ");
+ for ( i=0; i<item->n_chars_removed; i++ ) {
+ printf("%i ", item->chars_removed[i]);
+ }
+ printf("\n");
+
/* Go through the list of attributes, and correct the character ranges
* so that they refer to the text with characters removed, and add them
* to the PangoAttrList */
@@ -235,10 +254,13 @@ static void process_tags(struct narrative_item *item, PangoAttrList *attrs)
attr->end_index = index_with_removal(item->chars_removed,
item->n_chars_removed,
- add[i].end) + 1;
+ add[i].end);
pango_attr_list_insert(attrs, attr);
+ printf("Adding %c with indices %i - %i\n",
+ add[i].type, attr->start_index, attr->end_index);
+
}
/* Create the version of the text with characters removed */
@@ -258,6 +280,8 @@ static void process_tags(struct narrative_item *item, PangoAttrList *attrs)
}
}
+ printf("The edited text: '%s'\n", item->layout_text);
+
free(add);
}
diff --git a/libstorycode/narrative_render_cairo.h b/libstorycode/narrative_render_cairo.h
index c62d2e9..635cfed 100644
--- a/libstorycode/narrative_render_cairo.h
+++ b/libstorycode/narrative_render_cairo.h
@@ -51,4 +51,8 @@ extern int narrative_render_item_cairo(Narrative*n, cairo_t *cr, int i);
extern int narrative_render_cairo(Narrative *n, cairo_t *cr,
Stylesheet *stylesheet);
+extern int index_with_removal(int *chars_removed, int n_chars_removed, int idx);
+
+extern int index_before_removal(int *chars_removed, int n_chars_removed, int idx);
+
#endif /* NARRATIVE_RENDER_CAIRO_H */