commit 2a5b102a973f7813b95ce7e6e14d18d124e08d62
parent e2ab5f2fe37f6cdb985d10d5164da8dc916d918a
Author: nibo <nibo@relim.de>
Date: Sat, 25 Jan 2025 10:57:34 +0100
Add option to start every song on a new page
Diffstat:
3 files changed, 22 insertions(+), 14 deletions(-)
diff --git a/config.c b/config.c
@@ -430,6 +430,7 @@ config_load_default(void)
config->output->page_no->show = true;
config->output->page_no->align = A_CENTER;
config->output->system = NS_COMMON;
+ config->output->start_song_on_new_page = true;
config->output->styles = emalloc(TT_LENGTH * sizeof(struct ChoStyle *));
config->output->styles[TT_CHORD] = cho_style_new();
@@ -500,6 +501,7 @@ 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("start_song_on_new_page = %s\n\n", config->output->start_song_on_new_page ? "true" : "false");
printf("[output.toc]\n");
printf("show = %s\n", config->output->toc->show ? "true" : "false");
printf("title = \"%s\"\n\n", config->output->toc->title);
@@ -942,6 +944,10 @@ config_load(const char *filepath)
}
free(value.u.s);
}
+ value = toml_table_bool(output, "start_song_on_new_page");
+ if (value.ok) {
+ config->output->start_song_on_new_page = value.u.b;
+ }
page_no = toml_table_table(output, "page_no");
if (page_no) {
value = toml_table_bool(page_no, "show");
diff --git a/config.h b/config.h
@@ -101,9 +101,10 @@ struct ConfigOutput {
struct ConfigToc *toc;
struct ConfigChordDiagram *diagram;
struct ConfigPageNo *page_no;
- enum NamingSystem system;
- struct ChoStyle **styles;
+ struct ChoStyle **styles; // TODO: Make array of size 7
struct Note **notes;
+ enum NamingSystem system;
+ bool start_song_on_new_page;
};
struct Config {
diff --git a/out_pdf.c b/out_pdf.c
@@ -2227,15 +2227,7 @@ pdf_content_create(
}
}
int s;
- // int the_page;
for (s = 0; songs[s]; s++) {
- /* if (the_page == ctx.page) {
- counter++;
- } else {
- counter = 0;
- }
- the_page = ctx.page; */
- // printf("song '%d' start on page '%d'.\n", s, ctx.page);
if (config->output->diagram->show) {
struct ChoChord **chords = NULL;
if (!pdf_get_chords(songs[s], &chords)) {
@@ -2527,7 +2519,10 @@ pdf_content_create(
text_above_update_positions(left_aboves, ctx.consumed_lyrics);
}
if ((*li)->btype == BT_PAGE) {
- pdf_page_close_then_add(&ctx, NUS_WESTERN_ARABIC);
+ if (!pdf_page_close_then_add(&ctx, NUS_WESTERN_ARABIC)) {
+ LOG_DEBUG("pdf_page_close_then_add failed.");
+ return false;
+ }
texts = &ctx.content->pages[ctx.page]->texts;
imgs = &ctx.content->pages[ctx.page]->images;
diagrams = &ctx.content->pages[ctx.page]->diagrams;
@@ -2535,9 +2530,15 @@ pdf_content_create(
}
ctx.y -= SECTION_GAP_WIDTH;
}
- /* if (config->output->max_songs_per_page == 1) {
- // create new page
- } */
+ if (config->output->start_song_on_new_page) {
+ if (!pdf_page_close_then_add(&ctx, NUS_WESTERN_ARABIC)) {
+ LOG_DEBUG("pdf_page_close_then_add failed.");
+ return false;
+ }
+ texts = &ctx.content->pages[ctx.page]->texts;
+ imgs = &ctx.content->pages[ctx.page]->images;
+ diagrams = &ctx.content->pages[ctx.page]->diagrams;
+ }
}
*texts = erealloc(*texts, (ctx.text+1) * sizeof(struct PDFText *));
(*texts)[ctx.text] = NULL;