aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2017-09-11 22:42:34 +0200
committerThomas White <taw@physics.org>2017-09-11 22:47:28 +0200
commit663249781907aeba19069ca558f3275ac4ff6cd7 (patch)
tree3cae437d9b32399a4df4705d108351157de6ae60
parentb69fb0c999d97dba8b790838cd9d3a8be350a099 (diff)
Fix incorrect handling of paragraph split already on run boundary
-rw-r--r--src/frame.c49
1 files changed, 35 insertions, 14 deletions
diff --git a/src/frame.c b/src/frame.c
index aa4ab86..eebb171 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -1245,6 +1245,7 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos,
int run;
Paragraph *para = fr->paras[pn];
struct text_run *rr;
+ int bf_pos;
pnew = insert_paragraph(fr, pn);
if ( pnew == NULL ) {
@@ -1267,30 +1268,50 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos,
/* Copy spacing */
for ( i=0; i<4; i++ ) pnew->space[i] = para->space[i];
- /* First run of the new paragraph contains the leftover text */
rr = &para->runs[run];
- pnew->runs[0].scblock = rr->scblock;
- pnew->runs[0].macro_real_block = rr->macro_real_block;
run_offs = pos - rr->para_offs_bytes;
- pnew->runs[0].scblock_offs_bytes = rr->scblock_offs_bytes + run_offs;
- pnew->runs[0].para_offs_bytes = 0;
- pnew->runs[0].len_bytes = rr->len_bytes - run_offs;
- pnew->runs[0].fontdesc = pango_font_description_copy(rr->fontdesc);
- pnew->runs[0].col[0] = rr->col[0];
- pnew->runs[0].col[1] = rr->col[1];
- pnew->runs[0].col[2] = rr->col[2];
- pnew->runs[0].col[3] = rr->col[3];
- pnew->n_runs = 1;
+
+ if ( rr->len_bytes == run_offs ) {
+
+ /* We are splitting at a run boundary, so things are easy */
+ pnew->runs[0] = para->runs[run+1];
+ pnew->runs[0].para_offs_bytes = 0;
+ pnew->n_runs = 1;
+
+ /* We start copying runs after the whole second one which we
+ * just brought forward, i.e. we start at the THIRD run */
+ bf_pos = 2;
+
+ } else {
+
+ /* First run of the new paragraph contains the leftover text */
+ pnew->runs[0].scblock = rr->scblock;
+ pnew->runs[0].macro_real_block = rr->macro_real_block;
+ pnew->runs[0].scblock_offs_bytes = rr->scblock_offs_bytes + run_offs;
+ pnew->runs[0].para_offs_bytes = 0;
+ pnew->runs[0].len_bytes = rr->len_bytes - run_offs;
+ pnew->runs[0].fontdesc = pango_font_description_copy(rr->fontdesc);
+ pnew->runs[0].col[0] = rr->col[0];
+ pnew->runs[0].col[1] = rr->col[1];
+ pnew->runs[0].col[2] = rr->col[2];
+ pnew->runs[0].col[3] = rr->col[3];
+ pnew->n_runs = 1;
+
+ /* We start copying runs at the second run of the paragraph */
+ bf_pos = 1;
+
+ }
/* All later runs just get moved to the new paragraph */
offs = pnew->runs[0].len_bytes;
- for ( i=run+1; i<para->n_runs; i++ ) {
+ for ( i=run+bf_pos; i<para->n_runs; i++ ) {
pnew->runs[pnew->n_runs] = para->runs[i];
pnew->runs[pnew->n_runs].para_offs_bytes = offs;
pnew->n_runs++;
- offs += rr->len_bytes;
+ offs += para->runs[i].len_bytes;
}
+
/* Truncate the first paragraph at the appropriate position */
rr->len_bytes = run_offs;
para->n_runs = run+1;