lorid

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

commit 60244ad2cdae9c85c97cf68ed758a18b6857987b
parent 2e3a70e669bb009089ed7ab01ec0a78586749b5c
Author: nibo <nibo@relim.de>
Date:   Fri, 16 Aug 2024 20:05:40 +0200

Change code style here and there

Diffstat:
Mchordpro.c | 14+++++++-------
Mlorid.c | 2+-
Mout_pdf.c | 36++++++++++++++++++------------------
Mout_pdf.h | 7++++---
Mtodo | 3+--
5 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -148,6 +148,10 @@ static const char *chord_extensions_minor[] = { NULL }; +static enum SongFragmentType g_current_ftype = SF_TEXT; +static enum SongFragmentType g_prev_ftype = SF_TEXT; +static struct Config *g_config = NULL; + #ifdef DEBUG static const char *cho_debug_chord_qualifier_to_string(enum ChordQualifier qual) @@ -192,10 +196,6 @@ static void cho_debug_chord_print(struct ChoChord *chord) #endif /* DEBUG */ -static enum SongFragmentType g_current_ftype = SF_TEXT; -static enum SongFragmentType g_prev_ftype = SF_TEXT; -static struct Config *g_config = NULL; - static const char *cho_state_to_string(enum State state) { switch (state) { @@ -371,7 +371,7 @@ struct RGBColor *cho_color_parse(const char *str) struct RGBColor *color = malloc(sizeof(struct RGBColor)); if (str[0] == '#') { struct RGBColor *rgb_color = cho_rgbcolor_parse(str); - if (rgb_color != NULL) { + if (rgb_color) { free(color); color = rgb_color; } else { @@ -2580,7 +2580,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config) cho_tag_attr_free(tags[ta]->attrs[at]); tags[ta]->attrs[at] = NULL; tag_style = cho_style_parse(tag_begin, tags[ta]->attrs, cho_tag_style_inherit(tags, ta-1)); - if (tag_style == NULL) { + if (!tag_style) { fprintf(stderr, "cho_style_parse failed.\n"); return NULL; } @@ -2652,7 +2652,7 @@ struct ChoSong **cho_songs_parse(FILE *fp, struct Config *config) tags[ta]->attrs = realloc(tags[ta]->attrs, (at+1) * sizeof(struct Attr *)); tags[ta]->attrs[at] = NULL; tag_style = cho_style_parse(tag_begin, tags[ta]->attrs, cho_tag_style_inherit(tags, ta-1)); - if (tag_style == NULL) { + if (!tag_style) { fprintf(stderr, "cho_style_parse failed.\n"); return NULL; } diff --git a/lorid.c b/lorid.c @@ -54,7 +54,7 @@ int main(int argc, char *argv[]) fp = stdin; } else if (argc == optind+1) { fp = fopen(argv[argc-1], "r"); - if (fp == NULL) { + if (!fp) { fprintf(stderr, "fopen failed.\n"); return 1; } diff --git a/out_pdf.c b/out_pdf.c @@ -341,7 +341,7 @@ static bool out_pdf_font_set(pdfio_stream_t *stream, struct Font *font) return false; } pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name); - if (font_obj == NULL) { + if (!font_obj) { fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n"); return false; } @@ -356,7 +356,7 @@ static double text_width(struct TextLineItem *item) { char *name = out_pdf_fnt_name_create(item->style->font); pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name); - if (font_obj == NULL) { + if (!font_obj) { fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n"); return -1.0; } @@ -607,7 +607,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) struct PrintableItem *printable_item; int so, se, li, ly, ch; double width; - double y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + double y = MEDIABOX_HEIGHT - MARGIN_TOP; bool add_space_to_next_chord = false; struct ChoLine **lines; struct ChoLineItemAbove **text_above; @@ -636,12 +636,12 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) fprintf(stderr, "text_width failed.\n"); return NULL; } - text[t]->lines[tl]->items[0]->x = PADDING + (LINE_LEN - width) / 2; + text[t]->lines[tl]->items[0]->x = MARGIN_HORIZONTAL + (LINE_LEN - width) / 2; text[t]->lines[tl]->items[1] = NULL; text[t]->lines[tl]->btype = BT_LINE; y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT); if (y < MARGIN_BOTTOM) { - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; text[t]->lines[tl]->btype = BT_PAGE; } tl++; @@ -665,12 +665,12 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) fprintf(stderr, "text_width failed.\n"); return NULL; } - text[t]->lines[tl]->items[0]->x = PADDING + (LINE_LEN - width) / 2; + text[t]->lines[tl]->items[0]->x = MARGIN_HORIZONTAL + (LINE_LEN - width) / 2; text[t]->lines[tl]->items[1] = NULL; text[t]->lines[tl]->btype = BT_LINE; y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT); if (y < MARGIN_BOTTOM) { - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; text[t]->lines[tl]->btype = BT_PAGE; } tl++; @@ -690,12 +690,12 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) 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]->x = PADDING; + text[t]->lines[tl]->items[0]->x = MARGIN_HORIZONTAL; text[t]->lines[tl]->items[1] = NULL; text[t]->lines[tl]->btype = BT_LINE; y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT); if (y < MARGIN_BOTTOM) { - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; text[t]->lines[tl]->btype = BT_PAGE; } tl++; @@ -720,9 +720,9 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) return NULL; } if (tli == 0) { - text[t]->lines[tl]->items[tli]->x = PADDING + width_until; + text[t]->lines[tl]->items[tli]->x = MARGIN_HORIZONTAL + width_until; } else { - text[t]->lines[tl]->items[tli]->x = PADDING + width_until + added_space; + text[t]->lines[tl]->items[tli]->x = MARGIN_HORIZONTAL + width_until + added_space; } if (ch > 0 && text_above[ch-1]->position == text_above[ch]->position) { int b; @@ -777,7 +777,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) y -= text_line_set_lineheight(text[t]->lines[tl], SF_CHORD); if (y < MARGIN_BOTTOM) { // INFO: we don't split the chords and corresponding lyrics - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; y -= text[t]->lines[tl]->height; text[t]->lines[tl-1]->btype = BT_PAGE; } @@ -796,7 +796,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) text[t]->lines[tl]->items[tli]->text = NULL; text[t]->lines[tl]->items[tli]->style = cho_style_duplicate(lines[li]->lyrics[ly]->style); if (ly == 0) { - text[t]->lines[tl]->items[tli]->x = PADDING; + text[t]->lines[tl]->items[tli]->x = MARGIN_HORIZONTAL; } else { last_text_line_item_width = text_width(text[t]->lines[tl]->items[tli-1]); if (last_text_line_item_width == EMPTY) { @@ -840,7 +840,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config) text[t]->lines[tl]->btype = lines[li]->btype; y -= text_line_set_lineheight(text[t]->lines[tl], SF_TEXT); if (y < MARGIN_BOTTOM) { - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; text[t]->lines[tl]->btype = BT_PAGE; } tli = 0; @@ -917,7 +917,7 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text struct TextLineItem *item; pdfio_dict_t *annot; pdfio_rect_t rect; - double y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + double y = MEDIABOX_HEIGHT - MARGIN_TOP; double width; int t, tl, tli; pdfio_array_t *page_annots = pdfioArrayCreate(pdf); @@ -958,7 +958,7 @@ static bool annots_create(pdfio_file_t *pdf, pdfio_array_t *annots, struct Text fprintf(stderr, "pdfioArrayCreate failed.\n"); return false; } - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; } else { y -= text[t]->lines[tl]->height; } @@ -1080,7 +1080,7 @@ bool out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, st pdfio_stream_t *page_stream; int p = 0; page_stream = out_pdf_page_create(pdf, annots, p); - double y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + double y = MEDIABOX_HEIGHT - MARGIN_TOP; int t, tl, tli; for (t = 0; text[t]; t++) { for (tl = 0; text[t]->lines[tl]; tl++) { @@ -1096,7 +1096,7 @@ bool out_pdf_new(const char *cho_filepath, const char *output_folder_or_file, st } p++; page_stream = out_pdf_page_create(pdf, annots, p); - y = MEDIABOX_HEIGHT - VERTICAL_MARGIN; + y = MEDIABOX_HEIGHT - MARGIN_TOP; } else { y -= text[t]->lines[tl]->height; } diff --git a/out_pdf.h b/out_pdf.h @@ -2,13 +2,14 @@ #define MEDIABOX_HEIGHT 878.0 #define MEDIABOX_WIDTH 631.0 -#define VERTICAL_MARGIN 40.0 +#define MARGIN_TOP 40.0 #define MARGIN_BOTTOM 180.0 -#define PADDING 80.0 -#define LINE_LEN MEDIABOX_WIDTH - PADDING * 2 +#define MARGIN_HORIZONTAL 80.0 +#define LINE_LEN MEDIABOX_WIDTH - MARGIN_HORIZONTAL * 2 #define MIN_CHORD_GAP_WIDTH 5.0 #define SECTION_GAP_WIDTH 10.0 +// TODO: Find a good way to get rid of this type enum Bool { B_ERROR = -1, B_FALSE, diff --git a/todo b/todo @@ -13,9 +13,8 @@ chords make parser bulletproof should it just parse valid input correctly and crash on invalid input? -*_to_string functions sometimes return stringified enum and sometimes config value -allow {start_of_*},{end_of_*} custom directives parse environment directive value when: label="Verse 1" # pdf output break lines when too long +render in two or more columns