lorid

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

commit e1f9c3cb8e52b848dd3b4998b12acbccebfb43cd
parent 1eeaad2ae0779e34f6a80dc0310f9bd2d6bb2867
Author: nibo <nibo@relim.de>
Date:   Fri, 11 Oct 2024 18:11:28 +0200

Rename *_duplicate functions to *_copy

Diffstat:
Mchordpro.c | 70+++++++++++++++++++++++++++++++++++-----------------------------------
Mchordpro.h | 4++--
Mout_pdf.c | 18+++++++++---------
Mtodo | 3---
4 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -350,7 +350,7 @@ struct RGBColor *cho_rgbcolor_new(uint8_t red, uint8_t green, uint8_t blue) return color; } -struct RGBColor *cho_rgbcolor_duplicate(struct RGBColor *color) +struct RGBColor *cho_rgbcolor_copy(struct RGBColor *color) { struct RGBColor *copy = malloc(sizeof(struct RGBColor)); copy->red = color->red; @@ -537,7 +537,7 @@ struct Font *cho_font_new(void) return font; } -struct Font *cho_font_duplicate(struct Font *font) +struct Font *cho_font_copy(struct Font *font) { struct Font *copy = malloc(sizeof(struct Font)); if (font->name) @@ -751,7 +751,7 @@ static bool cho_style_property_apply_default(enum SongFragmentType current_ftype case SPT_COLOR: if (default_style_properties[i].u.foreground_color) { free(style->foreground_color); - style->foreground_color = cho_rgbcolor_duplicate(default_style_properties[i].u.foreground_color); + style->foreground_color = cho_rgbcolor_copy(default_style_properties[i].u.foreground_color); return true; } else { return false; @@ -804,20 +804,20 @@ struct Style *cho_style_new(void) return style; } -struct Style *cho_style_duplicate(struct Style *style) +struct Style *cho_style_copy(struct Style *style) { struct Style *copy = malloc(sizeof(struct Style)); - copy->font = cho_font_duplicate(style->font); - copy->foreground_color = cho_rgbcolor_duplicate(style->foreground_color); - copy->background_color = cho_rgbcolor_duplicate(style->background_color); + copy->font = cho_font_copy(style->font); + copy->foreground_color = cho_rgbcolor_copy(style->foreground_color); + copy->background_color = cho_rgbcolor_copy(style->background_color); copy->underline_style = style->underline_style; - copy->underline_color = cho_rgbcolor_duplicate(style->underline_color); + copy->underline_color = cho_rgbcolor_copy(style->underline_color); copy->overline_style = style->overline_style; - copy->overline_color = cho_rgbcolor_duplicate(style->overline_color); + copy->overline_color = cho_rgbcolor_copy(style->overline_color); copy->strikethrough = style->strikethrough; - copy->strikethrough_color = cho_rgbcolor_duplicate(style->strikethrough_color); + copy->strikethrough_color = cho_rgbcolor_copy(style->strikethrough_color); copy->boxed = style->boxed; - copy->boxed_color = cho_rgbcolor_duplicate(style->boxed_color); + copy->boxed_color = cho_rgbcolor_copy(style->boxed_color); copy->rise = style->rise; copy->href = style->href ? strdup(style->href) : NULL; return copy; @@ -829,28 +829,28 @@ struct Style *cho_style_new_from_config(enum SongFragmentType ftype) switch (ftype) { case SF_CHORD: printable_item = config_printable_item_get(g_config->output->printable_items, "chord"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); case SF_ANNOT: printable_item = config_printable_item_get(g_config->output->printable_items, "annotation"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); case SF_GRID: printable_item = config_printable_item_get(g_config->output->printable_items, "grid"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); case SF_TAB: printable_item = config_printable_item_get(g_config->output->printable_items, "tab"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); case SF_LABEL: printable_item = config_printable_item_get(g_config->output->printable_items, "label"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); case SF_TITLE: printable_item = config_printable_item_get(g_config->output->printable_items, "title"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); case SF_SUBTITLE: printable_item = config_printable_item_get(g_config->output->printable_items, "subtitle"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); default: printable_item = config_printable_item_get(g_config->output->printable_items, "text"); - return cho_style_duplicate(printable_item->style); + return cho_style_copy(printable_item->style); } } @@ -993,7 +993,7 @@ struct Style *cho_style_parse(const char *tag_name, struct Attr **attrs, struct struct Style *style; struct Font *font; if (inherited_style) - style = cho_style_duplicate(inherited_style); + style = cho_style_copy(inherited_style); else style = cho_style_new_default(); if (!strcmp(tag_name, "span")) { @@ -1302,7 +1302,7 @@ static bool cho_style_change_default(struct StyleProperty sprop) case SPT_COLOR: free(default_style_properties[i].u.foreground_color); if (sprop.u.foreground_color) { - default_style_properties[i].u.foreground_color = cho_rgbcolor_duplicate(sprop.u.foreground_color); + default_style_properties[i].u.foreground_color = cho_rgbcolor_copy(sprop.u.foreground_color); } else { default_style_properties[i].u.foreground_color = NULL; } @@ -1622,7 +1622,7 @@ static void cho_chord_free(struct ChoChord *chord) static struct ChoChord *cho_chord_copy(struct ChoChord *chord) { struct ChoChord *copy = malloc(sizeof(struct ChoChord)); - copy->style = cho_style_duplicate(chord->style); + copy->style = cho_style_copy(chord->style); copy->is_canonical = chord->is_canonical; copy->qual = chord->qual; copy->name = strdup(chord->name); @@ -1856,7 +1856,7 @@ static void cho_annotation_free(struct ChoAnnotation *annot) static struct ChoAnnotation *cho_annotation_copy(struct ChoAnnotation *annot) { struct ChoAnnotation *copy = malloc(sizeof(struct ChoAnnotation)); - copy->style = cho_style_duplicate(annot->style); + copy->style = cho_style_copy(annot->style); copy->text = strdup(annot->text); return copy; } @@ -1910,7 +1910,7 @@ static void cho_line_item_free(struct ChoLineItem *item) static struct ChoLineItem *cho_line_item_copy(struct ChoLineItem *item) { struct ChoLineItem *copy = malloc(sizeof(struct ChoLineItem)); - copy->style = cho_style_duplicate(item->style); + copy->style = cho_style_copy(item->style); copy->text = strdup(item->text); return copy; } @@ -1963,7 +1963,7 @@ static struct ChoLabel *cho_section_label_copy(struct ChoLabel *label) { struct ChoLabel *copy = malloc(sizeof(struct ChoLabel)); copy->name = strdup(label->name); - copy->style = cho_style_duplicate(label->style); + copy->style = cho_style_copy(label->style); return copy; } @@ -3049,7 +3049,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct songs[so]->sections[se]->lines[li]->lyrics = realloc(songs[so]->sections[se]->lines[li]->lyrics, (ly+1) * sizeof(struct ChoLineItem *)); songs[so]->sections[se]->lines[li]->lyrics[ly] = cho_line_item_new(); cho_style_free(songs[so]->sections[se]->lines[li]->lyrics[ly]->style); - songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_duplicate(directive->style); + songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_copy(directive->style); char *trimmed_directive_value = str_remove_leading_whitespace(directive_value); songs[so]->sections[se]->lines[li]->lyrics[ly]->text = trimmed_directive_value; te += strlen(trimmed_directive_value); @@ -3243,15 +3243,15 @@ struct ChoSong **cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct switch (prev_state) { case STATE_LYRICS: cho_style_free(songs[so]->sections[se]->lines[li]->lyrics[ly]->style); - songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_copy(tag_style); break; case STATE_CHORD: cho_style_free(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style); - songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style = cho_style_copy(tag_style); break; case STATE_ANNOTATION: cho_style_free(songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style); - songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_copy(tag_style); break; default: cho_log(LOG_ERR, "Invalid prev_state '%s'.", state_enums[prev_state]); @@ -3350,15 +3350,15 @@ struct ChoSong **cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct switch (prev_state) { case STATE_LYRICS: cho_style_free(songs[so]->sections[se]->lines[li]->lyrics[ly]->style); - songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_copy(tag_style); break; case STATE_CHORD: cho_style_free(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style); - songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style = cho_style_copy(tag_style); break; case STATE_ANNOTATION: cho_style_free(songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style); - songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_copy(tag_style); break; default: cho_log(LOG_ERR, "Invalid prev_state '%s'.", state_enums[prev_state]); @@ -3422,15 +3422,15 @@ struct ChoSong **cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct switch (prev_state) { case STATE_LYRICS: cho_style_free(songs[so]->sections[se]->lines[li]->lyrics[ly]->style); - songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->lyrics[ly]->style = cho_style_copy(tag_style); break; case STATE_CHORD: cho_style_free(songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style); - songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->text_above[c]->u.chord->style = cho_style_copy(tag_style); break; case STATE_ANNOTATION: cho_style_free(songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style); - songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_duplicate(tag_style); + songs[so]->sections[se]->lines[li]->text_above[c]->u.annot->style = cho_style_copy(tag_style); break; default: cho_log(LOG_ERR, "Invalid prev_state '%s'.", state_enums[prev_state]); diff --git a/chordpro.h b/chordpro.h @@ -335,7 +335,7 @@ const char *cho_metadata_get(struct ChoMetadata **metadata, const char *name); struct Style *cho_style_new(void); void cho_style_free(struct Style *style); -struct Style *cho_style_duplicate(struct Style *style); +struct Style *cho_style_copy(struct Style *style); struct Font *cho_style_font_desc_parse(const char *str); void cho_style_print_as_toml(struct Style *style, const char *section); @@ -345,7 +345,7 @@ enum LineStyle cho_linestyle_parse(const char *str); struct Font *cho_font_new(void); void cho_font_free(struct Font *font); void cho_font_print(struct Font *font); -struct Font *cho_font_duplicate(struct Font *font); +struct Font *cho_font_copy(struct Font *font); void cho_fonts_free(struct Font **fonts); char *cho_font_name_normalize(const char *name); enum FontFamily cho_font_family_parse(const char *str); diff --git a/out_pdf.c b/out_pdf.c @@ -102,7 +102,7 @@ static struct Font **out_pdf_font_get_all(struct ChoSong **songs, struct Config bool added = false; int i = 0; while (config->output->printable_items[i] != NULL) { - font = cho_font_duplicate(config->output->printable_items[i]->style->font); + font = cho_font_copy(config->output->printable_items[i]->style->font); added = out_pdf_font_add_if_not_in(font, &fonts); if (!added) cho_font_free(font); @@ -361,7 +361,7 @@ static struct TextLine *text_line_create(const char *str, struct Style *style) line->items = malloc(2 * sizeof(struct TextLineItem *)); line->items[0] = malloc(sizeof(struct TextLineItem)); line->items[0]->text = strdup(str); - line->items[0]->style = cho_style_duplicate(style); + line->items[0]->style = cho_style_copy(style); line->items[0]->x = MARGIN_HORIZONTAL; line->items[1] = NULL; text_line_set_lineheight(line, SF_TEXT); @@ -752,7 +752,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) 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]->metadata[m]->value); - text[t]->lines[tl]->items[0]->style = cho_style_duplicate(songs[so]->metadata[m]->style); + text[t]->lines[tl]->items[0]->style = cho_style_copy(songs[so]->metadata[m]->style); width = text_width(text[t]->lines[tl]->items[0]); if (width == EMPTY) { LOG_DEBUG("text_width failed."); @@ -804,7 +804,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) 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]->metadata[m]->value); - text[t]->lines[tl]->items[0]->style = cho_style_duplicate(printable_item->style); + text[t]->lines[tl]->items[0]->style = cho_style_copy(printable_item->style); width = text_width(text[t]->lines[tl]->items[0]); if (width == EMPTY) { LOG_DEBUG("text_width failed."); @@ -857,7 +857,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) 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]->label->name); - text[t]->lines[tl]->items[0]->style = cho_style_duplicate(songs[so]->sections[se]->label->style); + text[t]->lines[tl]->items[0]->style = cho_style_copy(songs[so]->sections[se]->label->style); text[t]->lines[tl]->items[0]->x = MARGIN_HORIZONTAL; text[t]->lines[tl]->items[1] = NULL; text[t]->lines[tl]->btype = BT_LINE; @@ -940,10 +940,10 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) add_space_to_next_chord = false; } if (text_above[ch]->is_chord) { - text[t]->lines[tl]->items[tli]->style = cho_style_duplicate(text_above[ch]->u.chord->style); + text[t]->lines[tl]->items[tli]->style = cho_style_copy(text_above[ch]->u.chord->style); text[t]->lines[tl]->items[tli]->text = cho_chord_name_generate(text_above[ch]->u.chord); } else { - text[t]->lines[tl]->items[tli]->style = cho_style_duplicate(text_above[ch]->u.annot->style); + text[t]->lines[tl]->items[tli]->style = cho_style_copy(text_above[ch]->u.annot->style); text[t]->lines[tl]->items[tli]->text = strdup(text_above[ch]->u.annot->text); } if (text_above_len == ch+1) { @@ -1006,7 +1006,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) text[t]->lines[tl]->items = realloc(text[t]->lines[tl]->items, (tli+1) * sizeof(struct TextLineItem *)); text[t]->lines[tl]->items[tli] = malloc(sizeof(struct TextLineItem)); text[t]->lines[tl]->items[tli]->text = NULL; - text[t]->lines[tl]->items[tli]->style = cho_style_duplicate(lines[li]->lyrics[ly]->style); + text[t]->lines[tl]->items[tli]->style = cho_style_copy(lines[li]->lyrics[ly]->style); if (ly == 0) { text[t]->lines[tl]->items[tli]->x = MARGIN_HORIZONTAL; } else { @@ -1030,7 +1030,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) text[t]->lines[tl]->items = realloc(text[t]->lines[tl]->items, (tli+1) * sizeof(struct TextLineItem *)); text[t]->lines[tl]->items[tli] = malloc(sizeof(struct TextLineItem)); text[t]->lines[tl]->items[tli]->text = NULL; - text[t]->lines[tl]->items[tli]->style = cho_style_duplicate(lines[li]->lyrics[ly]->style); + text[t]->lines[tl]->items[tli]->style = cho_style_copy(lines[li]->lyrics[ly]->style); last_text_line_item_width = text_width(text[t]->lines[tl]->items[tli-1]); if (last_text_line_item_width == EMPTY) { LOG_DEBUG("text_width failed."); diff --git a/todo b/todo @@ -1,5 +1,3 @@ -'chorus' directive - add config options 'default_label' and 'quote' 'image' directive https://chordpro.org/chordpro/directives-image/ metadata directives @@ -23,4 +21,3 @@ render in two or more columns find better name for PrintableItem, TextAbove consider freeing memory in case of errors decide and then change consistent global variables prefix 'g_' or not -rename functions *_duplicate to *_copy