lorid

convert chordpro to pdf
git clone git://git.relim.de/lorid.git
Log | Files | Refs | README | LICENSE

commit e6de8e6633a1fd7f49f57c7c748e839b7981c318
parent 10908ceb7380ef4261ac978f76f3436ac67c678d
Author: nibo <nibo@relim.de>
Date:   Sun,  4 Aug 2024 12:26:28 +0200

Add label style in cho_songs_parse

All style that exists should be set
in the parser and not when generating
the pdf.

Diffstat:
Mchordpro.c | 25++++++++++++++++++-------
Mchordpro.h | 10++++++++--
Mconfig.c | 14+++++++-------
Mout_pdf.c | 11+++--------
4 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -245,6 +245,8 @@ const char *the_song_fragment_type(enum SongFragmentType ftype) return "SF_TEXT"; case SF_TITLE: return "SF_TITLE"; + case SF_LABEL: + return "SF_LABEL"; } return ""; } @@ -755,10 +757,10 @@ struct Style *cho_style_duplicate(struct Style *style) return copy; } -struct Style *cho_style_new_from_config(void) +struct Style *cho_style_new_from_config(enum SongFragmentType ftype) { struct PrintableItem *printable_item; - switch (g_current_ftype) { + switch (ftype) { case SF_CHORD: printable_item = config_printable_item_get(g_config->printable_items, "chord"); return cho_style_duplicate(printable_item->style); @@ -771,6 +773,9 @@ struct Style *cho_style_new_from_config(void) case SF_TAB: printable_item = config_printable_item_get(g_config->printable_items, "tab"); return cho_style_duplicate(printable_item->style); + case SF_LABEL: + printable_item = config_printable_item_get(g_config->printable_items, "label"); + return cho_style_duplicate(printable_item->style); default: printable_item = config_printable_item_get(g_config->printable_items, "text"); return cho_style_duplicate(printable_item->style); @@ -779,7 +784,7 @@ struct Style *cho_style_new_from_config(void) struct Style *cho_style_new_default(void) { - struct Style *style = cho_style_new_from_config(); + struct Style *style = cho_style_new_from_config(g_current_ftype); cho_style_apply_default(g_current_ftype, style); return style; } @@ -1437,7 +1442,7 @@ static struct ChoSection *cho_section_new(void) { struct ChoSection *section = malloc(sizeof(struct ChoSection)); section->type = ST_EMPTY; - section->name = NULL; + section->label = NULL; section->lines = NULL; return section; } @@ -1473,7 +1478,11 @@ static void cho_song_free(struct ChoSong *song) free(song->metadata); i = 0; while (song->sections[i] != NULL) { - free(song->sections[i]->name); + if (song->sections[i]->label) { + free(song->sections[i]->label->name); + cho_style_free(song->sections[i]->label->style); + free(song->sections[i]->label); + } while (song->sections[i]->lines[k] != NULL) { while (song->sections[i]->lines[k]->lyrics[ly] != NULL) { cho_style_free(song->sections[i]->lines[k]->lyrics[ly]->style); @@ -1978,7 +1987,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config) songs[so]->sections[se]->lines[li]->lyrics[ly] = cho_line_item_new(); break; case DT_FONT: - config_style = cho_style_new_from_config(); + config_style = cho_style_new_from_config(g_current_ftype); sprop.ftype = directive->ftype; sprop.type = directive->sprop; switch (directive->sprop) { @@ -2045,7 +2054,9 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config) songs[so]->sections = realloc(songs[so]->sections, (se+1) * sizeof(struct ChoSection *)); songs[so]->sections[se] = cho_section_new(); songs[so]->sections[se]->type = directive->stype; - songs[so]->sections[se]->name = str_remove_leading_whitespace(directive_value); + songs[so]->sections[se]->label = malloc(sizeof(struct ChoLabel)); + songs[so]->sections[se]->label->name = str_remove_leading_whitespace(directive_value); + songs[so]->sections[se]->label->style = cho_style_new_from_config(SF_LABEL); li = 0; songs[so]->sections[se]->lines = malloc(sizeof(struct ChoLine *)); songs[so]->sections[se]->lines[li] = cho_line_new(); diff --git a/chordpro.h b/chordpro.h @@ -116,7 +116,8 @@ enum SongFragmentType { SF_TAB, SF_TOC, SF_TEXT, - SF_TITLE + SF_TITLE, + SF_LABEL }; enum StylePropertyType { @@ -207,9 +208,14 @@ struct ChoLine { struct ChoLineItem **lyrics; }; +struct ChoLabel { + char *name; + struct Style *style; +}; + struct ChoSection { enum SectionType type; - char *name; + struct ChoLabel *label; struct ChoLine **lines; }; diff --git a/config.c b/config.c @@ -8,7 +8,7 @@ static const char *g_valid_styles[] = { "title", "subtitle", - "footer", + "footer", // TODO "text", "chorus", "chord", @@ -18,13 +18,13 @@ static const char *g_valid_styles[] = { "comment_boxed", "tab", "label", - "toc", + "toc", // TODO "grid", - "grid_margin", - "empty", - "diagram", - "diagram_base", - "chordfingers" + "grid_margin", // TODO + "empty", // TODO + "diagram", // TODO + "diagram_base", // TODO + "chordfingers" // TODO }; static struct PrintableItem *config_printable_item_new(const char *name) diff --git a/out_pdf.c b/out_pdf.c @@ -688,18 +688,13 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) text[t]->lines[tl]->height = 30.0; tl++; for (se = 0; songs[so]->sections[se]; se++) { - if (songs[so]->sections[se]->name) { + if (songs[so]->sections[se]->label) { text[t]->lines = realloc(text[t]->lines, (tl+1) * sizeof(struct TextLine *)); text[t]->lines[tl] = malloc(sizeof(struct TextLine)); text[t]->lines[tl]->items = malloc(2 * sizeof(struct TextLineItem *)); text[t]->lines[tl]->items[0] = malloc(sizeof(struct TextLineItem)); - text[t]->lines[tl]->items[0]->text = strdup(songs[so]->sections[se]->name); - printable_item = config_printable_item_get(config->printable_items, "label"); - if (!printable_item) { - fprintf(stderr, "config_printable_item_get failed.\n"); - return NULL; - } - text[t]->lines[tl]->items[0]->style = cho_style_duplicate(printable_item->style); + text[t]->lines[tl]->items[0]->text = strdup(songs[so]->sections[se]->label->name); + text[t]->lines[tl]->items[0]->style = cho_style_duplicate(songs[so]->sections[se]->label->style); text[t]->lines[tl]->items[0]->x = PADDING; text[t]->lines[tl]->items[1] = NULL; text_line_set_lineheight(text[t]->lines[tl], SF_TEXT);