lorid

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

commit e2ab5f2fe37f6cdb985d10d5164da8dc916d918a
parent e0eeaa3985a7d6eb15968a4969ac27a66e38ccb2
Author: nibo <nibo@relim.de>
Date:   Thu, 23 Jan 2025 19:06:57 +0100

Add option to not show a page number

Diffstat:
Mconfig.c | 38+++++++++++++++++++++++++-------------
Mconfig.h | 7++++++-
Mout_pdf.c | 28+++++++++++++++++-----------
3 files changed, 48 insertions(+), 25 deletions(-)

diff --git a/config.c b/config.c @@ -426,8 +426,10 @@ config_load_default(void) config->output->diagram = emalloc(sizeof(struct ChordDiagram)); config->output->diagram->show = true; config->output->diagram->instrument = INS_GUITAR; + config->output->page_no = emalloc(sizeof(struct ConfigPageNo)); + config->output->page_no->show = true; + config->output->page_no->align = A_CENTER; config->output->system = NS_COMMON; - config->output->page_no_position = A_CENTER; config->output->styles = emalloc(TT_LENGTH * sizeof(struct ChoStyle *)); config->output->styles[TT_CHORD] = cho_style_new(); @@ -498,7 +500,6 @@ config_print_default(void) config_notes_print_as_toml(NS_NASHVILLE); printf("[output]\n"); printf("system = \"%s\"\n", config_naming_system_to_config_string(config->output->system)); - printf("page_no_position = \"%s\"\n\n", config_alignment_to_config_string(config->output->page_no_position)); printf("[output.toc]\n"); printf("show = %s\n", config->output->toc->show ? "true" : "false"); printf("title = \"%s\"\n\n", config->output->toc->title); @@ -508,6 +509,9 @@ config_print_default(void) printf("[output.chorus]\n"); printf("label = \"Chorus\"\n"); printf("quote = false\n\n"); + printf("[output.page_no]\n"); + printf("show = %s\n", config->output->page_no->show ? "true" : "false"); + printf("alignment = \"%s\"\n\n", config_alignment_to_config_string(config->output->page_no->align)); printf("[output.styles]\n"); int i; for (i = 1; i<TT_LENGTH; i++) { @@ -867,11 +871,11 @@ config_load(const char *filepath) } toml_table_t *output = toml_table_table(table, "output"); if (output) { - toml_table_t *notes, *chorus, *diagram, *toc; + toml_table_t *styles, *notes, *chorus, *diagram, *toc, *page_no; toml_value_t value; enum NamingSystem system; enum Instrument instrument; - enum Alignment position; + enum Alignment align; struct Note **custom_notes; chorus = toml_table_table(output, "chorus"); if (chorus) { @@ -938,17 +942,24 @@ config_load(const char *filepath) } free(value.u.s); } - value = toml_table_string(output, "page_no_position"); - if (value.ok) { - position = config_alignment_parse(value.u.s); - if (position == -1) { - LOG_DEBUG("config_alignment_parse failed."); - return NULL; + page_no = toml_table_table(output, "page_no"); + if (page_no) { + value = toml_table_bool(page_no, "show"); + if (value.ok) { + config->output->page_no->show = value.u.b; + } + value = toml_table_string(page_no, "alignment"); + if (value.ok) { + align = config_alignment_parse(value.u.s); + if (align == -1) { + LOG_DEBUG("config_alignment_parse failed."); + return NULL; + } + config->output->page_no->align = align; + free(value.u.s); } - config->output->page_no_position = position; - free(value.u.s); } - toml_table_t *styles = toml_table_table(output, "styles"); + styles = toml_table_table(output, "styles"); if (styles) { int i, unused; const char *key_name; @@ -1035,6 +1046,7 @@ config_free(struct Config *config) free(config->output->styles); config_notes_free(config->output->notes); free(config->output->diagram); + free(config->output->page_no); free(config->output); free(config->parser->chords); config_notes_free(config->parser->notes); diff --git a/config.h b/config.h @@ -91,12 +91,17 @@ struct ConfigToc { char *title; }; +struct ConfigPageNo { + bool show; + enum Alignment align; +}; + struct ConfigOutput { struct ConfigChorus *chorus; struct ConfigToc *toc; struct ConfigChordDiagram *diagram; + struct ConfigPageNo *page_no; enum NamingSystem system; - enum Alignment page_no_position; struct ChoStyle **styles; struct Note **notes; }; diff --git a/out_pdf.c b/out_pdf.c @@ -1727,7 +1727,7 @@ pdf_page_add_page_no(struct PDFContext *ctx, enum NumeralSystem numeral_system) (*texts)[ctx->text]->x = MEDIABOX_WIDTH - MARGIN_HORIZONTAL / 2 - width; (*texts)[ctx->text]->y = ctx->margin_bottom / 2; (*texts)[ctx->text]->width = width; - switch (g_config->output->page_no_position) { + switch (g_config->output->page_no->align) { case A_LEFT: x = MARGIN_HORIZONTAL / 2; break; @@ -1738,7 +1738,7 @@ pdf_page_add_page_no(struct PDFContext *ctx, enum NumeralSystem numeral_system) x = MEDIABOX_WIDTH - MARGIN_HORIZONTAL / 2 - width; break; default: - util_log(LOG_ERR, "Invalid Alignment enum value '%d'.", g_config->output->page_no_position); + util_log(LOG_ERR, "Invalid Alignment enum value '%d'.", g_config->output->page_no->align); return false; } (*texts)[ctx->text]->x = x; @@ -1771,9 +1771,11 @@ pdf_page_close_then_add(struct PDFContext *ctx, enum NumeralSystem numeral_syste ctx->content->pages = erealloc(ctx->content->pages, (ctx->page+1) * sizeof(struct PDFPage *)); ctx->content->pages[ctx->page] = pdf_page_new(); ctx->y = MEDIABOX_HEIGHT - MARGIN_TOP; - if (!pdf_page_add_page_no(ctx, numeral_system)) { - LOG_DEBUG("pdf_page_add_page_no failed."); - return false; + if (g_config->output->page_no->show) { + if (!pdf_page_add_page_no(ctx, numeral_system)) { + LOG_DEBUG("pdf_page_add_page_no failed."); + return false; + } } return true; } @@ -2150,9 +2152,11 @@ pdf_toc_create( ctx.content->pages = emalloc(sizeof(struct PDFPage *)); ctx.content->pages[ctx.page] = pdf_page_new(); texts = &ctx.content->pages[ctx.page]->texts; - if (!pdf_page_add_page_no(&ctx, NUS_ROMAN)) { - LOG_DEBUG("pdf_page_add_page_no failed."); - return false; + if (config->output->page_no->show) { + if (!pdf_page_add_page_no(&ctx, NUS_ROMAN)) { + LOG_DEBUG("pdf_page_add_page_no failed."); + return false; + } } toc_style = config->output->styles[TT_TOC]; toc = pdf_content->toc; @@ -2216,9 +2220,11 @@ pdf_content_create( texts = &ctx.content->pages[ctx.page]->texts; imgs = &ctx.content->pages[ctx.page]->images; diagrams = &ctx.content->pages[ctx.page]->diagrams; - if (!pdf_page_add_page_no(&ctx, NUS_WESTERN_ARABIC)) { - LOG_DEBUG("pdf_page_add_page_no failed."); - return false; + if (config->output->page_no->show) { + if (!pdf_page_add_page_no(&ctx, NUS_WESTERN_ARABIC)) { + LOG_DEBUG("pdf_page_add_page_no failed."); + return false; + } } int s; // int the_page;