From 91eeae07bd6a4d4db2ec81c4237819c73d79b0de Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 23 Mar 2019 11:34:48 +0100 Subject: Combine slide text strings and layouts in one structure --- libstorycode/slide.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) (limited to 'libstorycode/slide.c') diff --git a/libstorycode/slide.c b/libstorycode/slide.c index 0702f52..cb2a5a1 100644 --- a/libstorycode/slide.c +++ b/libstorycode/slide.c @@ -62,7 +62,7 @@ static SlideItem *add_item(Slide *s) s->items = new_items; item = &s->items[s->n_items++]; - item->layouts = NULL; + item->paras = NULL; return item; } @@ -94,16 +94,16 @@ int add_text_item(Slide *s, char **text, int n_text, struct frame_geom geom, if ( item == NULL ) return 1; item->type = slide_item; - item->layouts = NULL; - item->paragraphs = malloc(n_text*sizeof(char *)); - if ( item->paragraphs == NULL ) { + item->paras = malloc(n_text*sizeof(struct slide_text_paragraph)); + if ( item->paras == NULL ) { s->n_items--; return 1; } for ( i=0; in_paras = n_text; - item->paragraphs[i] = text[i]; + item->paras[i].text = text[i]; + item->paras[i].layout = NULL; } item->n_paras = n_text; @@ -311,33 +311,18 @@ void slide_item_get_padding(SlideItem *item, Stylesheet *ss, void slide_item_split_text_paragraph(SlideItem *item, int para, size_t off) { - char **np; + struct slide_text_paragraph *np; - np = realloc(item->paragraphs, (item->n_paras+1)*sizeof(char *)); + np = realloc(item->paras, (item->n_paras+1)*sizeof(struct slide_text_paragraph)); if ( np == NULL ) return; -#ifdef HAVE_PANGO - PangoLayout **nl; - nl = realloc(item->layouts, (item->n_paras+1)*sizeof(PangoLayout *)); - if ( nl == NULL ) { - free(np); - return; - } - item->layouts = nl; -#endif - - item->paragraphs = np; + item->paras = np; item->n_paras++; - memmove(&item->paragraphs[para+1], &item->paragraphs[para], - (item->n_paras - para - 1)*sizeof(char *)); - -#ifdef HAVE_PANGO - memmove(&item->layouts[para+1], &item->layouts[para], - (item->n_paras - para - 1)*sizeof(PangoLayout *)); - item->layouts[para+1] = NULL; -#endif + memmove(&item->paras[para+1], &item->paras[para], + (item->n_paras - para - 1)*sizeof(struct slide_text_paragraph)); - item->paragraphs[para+1] = strdup(&item->paragraphs[para][off]); - item->paragraphs[para][off] = '\0'; + item->paras[para+1].text = strdup(&item->paras[para].text[off]); + item->paras[para+1].layout = NULL; + item->paras[para].text[off] = '\0'; } -- cgit v1.2.3