diff options
-rw-r--r-- | src/frame.c | 12 | ||||
-rw-r--r-- | src/frame.h | 2 | ||||
-rw-r--r-- | src/sc_interp.c | 25 |
3 files changed, 25 insertions, 14 deletions
diff --git a/src/frame.c b/src/frame.c index e315d5f..27e2210 100644 --- a/src/frame.c +++ b/src/frame.c @@ -417,7 +417,7 @@ void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock, } -Paragraph *create_paragraph(struct frame *fr) +Paragraph *create_paragraph(struct frame *fr, SCBlock *bl, SCBlock *rbl) { Paragraph **paras_new; Paragraph *pnew; @@ -434,6 +434,8 @@ Paragraph *create_paragraph(struct frame *fr) /* For now, assume the paragraph is going to be for text. * However, this can easily be changed */ pnew->type = PARA_TYPE_TEXT; + pnew->scblock = bl; + pnew->rscblock = rbl; pnew->n_runs = 0; pnew->runs = NULL; pnew->layout = NULL; @@ -481,7 +483,7 @@ void add_callback_para(struct frame *fr, SCBlock *bl, SCBlock *rbl, { Paragraph *pnew; - pnew = create_paragraph(fr); + pnew = create_paragraph(fr, bl, rbl); if ( pnew == NULL ) { fprintf(stderr, "Failed to add callback paragraph\n"); return; @@ -512,7 +514,7 @@ void add_image_para(struct frame *fr, SCBlock *scblock, SCBlock *rscblock, return; } - pnew = create_paragraph(fr); + pnew = create_paragraph(fr, scblock, rscblock); if ( pnew == NULL ) { fprintf(stderr, "Failed to add image paragraph\n"); return; @@ -1385,6 +1387,7 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po enum para_type type1, type2; size_t p2offs; SCBlock *scblock; + int wrap_end; sort_positions(&p1, &p2); @@ -1394,6 +1397,7 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po p1rscblock = pos_to_rscblock(fr, p1); p2rscblock = pos_to_rscblock(fr, p2); p2offs = pos_to_offset(fr, p2); + wrap_end = p2.para; printf("SCBlocks %p to %p\n", p1scblock, p2scblock); //show_sc_blocks(p1scblock); @@ -1507,7 +1511,7 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po /* If any paragraphs have been deleted, this will wrap too many * paragraphs, but it doesn't matter as long as we don't wrap * past the end of the frame's contents. */ - for ( i=p1.para; i<=p2.para; i++ ) { + for ( i=p1.para; i<=wrap_end; i++ ) { if ( i >= fr->n_paras ) break; printf("Wrapping para %i (%p)\n", i, fr->paras[i]); wrap_paragraph(fr->paras[i], NULL, wrapw, 0, 0); diff --git a/src/frame.h b/src/frame.h index 7a132b5..2548d6d 100644 --- a/src/frame.h +++ b/src/frame.h @@ -193,7 +193,7 @@ extern int get_sc_pos(struct frame *fr, int pn, size_t pos, extern void *get_para_bvp(Paragraph *para); extern void merge_paragraphs(struct frame *fr, int para); -extern Paragraph *create_paragraph(struct frame *fr); +extern Paragraph *create_paragraph(struct frame *fr, SCBlock *bl, SCBlock *rbl); extern enum para_type para_type(Paragraph *para); extern SCBlock *para_scblock(Paragraph *para); diff --git a/src/sc_interp.c b/src/sc_interp.c index d827326..0301aad 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -943,7 +943,7 @@ static int in_macro(SCInterpreter *scin) } -static void add_newpara(struct frame *fr, SCBlock *bl) +static void add_newpara(struct frame *fr, SCBlock *bl, SCBlock *mrb) { Paragraph *last_para; @@ -952,7 +952,9 @@ static void add_newpara(struct frame *fr, SCBlock *bl) set_newline_at_end(last_para, bl); - create_paragraph(fr); + /* The block after the \newpara will always be the first one of the + * next paragraph, by definition, even if it's \f or another \newpara */ + create_paragraph(fr, sc_block_next(mrb), sc_block_next(bl)); } @@ -973,18 +975,19 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, fontdesc = sc_interp_get_fontdesc(scin); col = sc_interp_get_fgcol(scin); + rbl = bl; + if ( st->macro_real_block != NULL ) { + bl = st->macro_real_block; + } + para = last_para(fr); if ( (para == NULL) || (para_type(para) != PARA_TYPE_TEXT) ) { /* Last paragraph is not text. * or: no paragraphs yet. * Either way: Create the first one */ - para = create_paragraph(fr); + para = create_paragraph(fr, bl, rbl); } - rbl = bl; - if ( st->macro_real_block != NULL ) { - bl = st->macro_real_block; - } add_run(para, bl, rbl, fontdesc, col); set_para_spacing(para, st->paraspace); @@ -1011,7 +1014,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) { SCBlock *rbl = bl; if ( st->macro_real_block != NULL ) { - rbl = st->macro_real_block; + bl = st->macro_real_block; } add_image_para(sc_interp_get_frame(scin), bl, rbl, filename, scin->is, w, h, 1); @@ -1048,7 +1051,11 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) } else if ( strcmp(name, "newpara")==0 ) { struct frame *fr = sc_interp_get_frame(scin); - add_newpara(fr, bl); + SCBlock *rbl = bl; + if ( st->macro_real_block != NULL ) { + bl = st->macro_real_block; + } + add_newpara(fr, bl, rbl); } else { return 0; |