diff options
-rw-r--r-- | src/sc_editor.c | 28 | ||||
-rw-r--r-- | src/shape.c | 8 |
2 files changed, 32 insertions, 4 deletions
diff --git a/src/sc_editor.c b/src/sc_editor.c index c8ef09a..6619b06 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -568,7 +568,9 @@ static void update_local(SCEditor *e, struct frame *fr, int line, int bn) cairo_t *cr; /* Shape the box again */ - shape_box(box); + shape_box(box->cf->cf); + box->glyphs = box->cf->cf->glyphs; + box->cf->glyphs = box->cf->cf->glyphs; /* Wrap the paragraph again */ wrap_contents(fr); /* FIXME: Only the current paragraph */ @@ -585,6 +587,26 @@ static void update_local(SCEditor *e, struct frame *fr, int line, int bn) } +static void shift_box_offsets(struct frame *fr, struct wrap_box *box, int n) +{ + int i; + int sn = 0; + + for ( i=0; i<fr->boxes->n_boxes; i++ ) { + if ( &fr->boxes->boxes[i] == box ) { + sn = i+1; + break; + } + } + + assert(sn > 0); /* Lowest it can possibly be is 1 */ + + for ( i=sn; i<fr->boxes->n_boxes; i++ ) { + fr->boxes->boxes[i].offs_char += n; + } +} + + static void insert_text(char *t, SCEditor *e) { int sln, sbx, sps; @@ -612,11 +634,13 @@ static void insert_text(char *t, SCEditor *e) /* ... and also in the paragraph split but unwrapped box */ sbox->cf->len_chars += 1; + /* Tweak the offsets of all the subsequent boxes */ + shift_box_offsets(fr, sbox->cf->cf, 1); + fr->empty = 0; update_local(e, fr, sln, sbx); - /* ... by doing this properly */ fixup_cursor(e); advance_cursor(e); diff --git a/src/shape.c b/src/shape.c index 24848e5..1983ae6 100644 --- a/src/shape.c +++ b/src/shape.c @@ -57,11 +57,15 @@ void shape_box(struct wrap_box *box) ep = g_utf8_offset_to_pointer(sc_block_contents(box->scblock), box->offs_char+box->len_chars); + if ( box->glyphs != NULL ) { + pango_glyph_string_free(box->glyphs); + } + box->glyphs = pango_glyph_string_new(); pango_shape(tp, ep-tp, &box->analysis, box->glyphs); pango_glyph_string_extents(box->glyphs, box->font, NULL, &rect); - box->width += rect.width; + box->width = rect.width; if ( rect.height > box->height ) { box->height = rect.height; } @@ -108,7 +112,7 @@ static void add_wrap_box(gpointer vi, gpointer vb) box->col[1] = col[1]; /* Green */ box->col[2] = col[2]; /* Blue */ box->col[3] = col[3]; /* Alpha */ - box->glyphs = pango_glyph_string_new(); + box->glyphs = NULL; box->analysis = item->analysis; bas->line->n_boxes++; |