lorid

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

commit d9c47c88cabf983d380fdf5c2688d1687d972ed1
parent ab27811272099122bc6f0e040af4e2f54c8cb124
Author: nibo <nibo@relim.de>
Date:   Fri, 17 Jan 2025 19:27:39 +0100

Add toc title and its style

Finally the toc title is shown above the toc.
It got its own style definition at [output.styles.toc_title].

Diffstat:
Mchordpro.h | 1+
Mconfig.c | 10++++++++--
Mout_pdf.c | 38++++++++++++--------------------------
3 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/chordpro.h b/chordpro.h @@ -12,6 +12,7 @@ enum TextType { SF_GRID, SF_TAB, SF_TOC, + SF_TOC_TITLE, SF_TEXT, SF_TITLE, SF_SUBTITLE, diff --git a/config.c b/config.c @@ -32,7 +32,7 @@ static const char *instruments[] = { static const char *text_types[] = { "empty", "chord", "annotation", "chorus", - "footer", "grid", "tab", "toc", "text", + "footer", "grid", "tab", "toc", "toc_title", "text", "title", "subtitle", "label", "comment", "comment_italic", "comment_box" }; @@ -122,7 +122,6 @@ static struct Note notes_nashville[] = { static enum TextType config_text_type_parse(const char *str) { - // TODO: can g_valid_styles be replaced by the song fragment types? if (!strcmp(str, text_types[SF_CHORD])) { return SF_CHORD; } else @@ -144,6 +143,9 @@ config_text_type_parse(const char *str) if (!strcmp(str, text_types[SF_TOC])) { return SF_TOC; } else + if (!strcmp(str, text_types[SF_TOC_TITLE])) { + return SF_TOC_TITLE; + } else if (!strcmp(str, text_types[SF_TEXT])) { return SF_TEXT; } else @@ -420,6 +422,10 @@ config_load_default(void) config->output->styles[SF_TOC] = cho_style_new(); config->output->styles[SF_TOC]->font->name = strdup(DEFAULT_FONT_FAMILY); config->output->styles[SF_TOC]->font->size = 12.0; + config->output->styles[SF_TOC_TITLE] = cho_style_new(); + config->output->styles[SF_TOC_TITLE]->font->name = strdup(DEFAULT_FONT_FAMILY); + config->output->styles[SF_TOC_TITLE]->font->weight = FW_BOLD; + config->output->styles[SF_TOC_TITLE]->font->size = 18.0; config->output->styles[SF_TEXT] = cho_style_new(); config->output->styles[SF_TEXT]->font->name = strdup(DEFAULT_FONT_FAMILY); config->output->styles[SF_TITLE] = cho_style_new(); diff --git a/out_pdf.c b/out_pdf.c @@ -1772,7 +1772,7 @@ pdf_texts_add_toc_entry( struct PDFContext *ctx, struct TocEntry *entry, struct ChoStyle *style, - double max_title_width, + double max_song_title_width, int toc_page_count, double dot_width ) @@ -1790,15 +1790,15 @@ pdf_texts_add_toc_entry( return false; } width += MARGIN_HORIZONTAL; - if (width > max_title_width) { + if (width > max_song_title_width) { char *t = (char *)&tmp; line_count = 0; - while (width > max_title_width) { + while (width > max_song_title_width) { if (ctx->y < MARGIN_BOTTOM) { pdf_page_close_then_add(ctx); texts = &ctx->content->pages[ctx->page]->texts; } - index = text_find_fitting(t, style, MARGIN_HORIZONTAL, max_title_width); + index = text_find_fitting(t, style, MARGIN_HORIZONTAL, max_song_title_width); if (index == EMPTY_INT) { LOG_DEBUG("text_find_fitting failed."); return false; @@ -1946,11 +1946,11 @@ pdf_toc_create( struct Config *config ) { - double max_title_width, dot_width; + double max_song_title_width, dot_width; int toc_page_count; struct PDFContext ctx; struct PDFText ***texts; - struct ChoStyle *toc_style; + struct ChoStyle *toc_style, *title_style; struct TocEntry **toc; pdf_context_init(&ctx); @@ -1960,42 +1960,28 @@ pdf_toc_create( texts = &ctx.content->pages[ctx.page]->texts; toc_style = config->output->styles[SF_TOC]; toc = pdf_content->toc; - max_title_width = LINE_WIDTH * 0.85; - toc_page_count = pdf_toc_page_count(toc, toc_style, max_title_width); + max_song_title_width = LINE_WIDTH * 0.85; + toc_page_count = pdf_toc_page_count(toc, toc_style, max_song_title_width); if (toc_page_count == -1) { LOG_DEBUG("pdf_toc_page_count failed."); return false; } - /* struct ChoStyle *toc_title_style = cho_style_copy(toc_style); - toc_title_style->font->size = 18.0; - // toc_title_style->font->weight = FW_BOLD; - if (!pdf_texts_add_text(&ctx, config->output->toc->title, toc_title_style, A_CENTER)) { + title_style = config->output->styles[SF_TOC_TITLE]; + if (!pdf_texts_add_text(&ctx, config->output->toc->title, title_style, A_CENTER)) { LOG_DEBUG("pdf_texts_add_text failed."); return false; } - cho_style_free(toc_title_style); */ + ctx.y -= 30.0; dot_width = text_width(".", toc_style); if (dot_width == ERROR) { LOG_DEBUG("text_width failed."); return false; } for (; *toc; toc++) { - if (!pdf_texts_add_toc_entry(&ctx, *toc, toc_style, max_title_width, toc_page_count, dot_width)) { + if (!pdf_texts_add_toc_entry(&ctx, *toc, toc_style, max_song_title_width, toc_page_count, dot_width)) { LOG_DEBUG("pdf_texts_add_toc_entry failed."); return false; } - // TODO: create (multi)line with title, dots and the page number - /* space_for_dots = LINE_WIDTH; - space_for_dots -= width; - width = text_width((*toc)->title, toc_style); - space_for_dots -= width; - printf("width for dots '%.1f'\n", space_for_dots); - char line[4096]; - sprintf((char *)&line, "%s ........ %d", (*toc)->title, (*toc)->page_index+1); - if (!pdf_texts_add_text(&ctx, (char *)&line, toc_style, A_LEFT)) { - LOG_DEBUG("pdf_texts_add_text failed."); - return false; - } */ } texts = &ctx.content->pages[ctx.page]->texts; *texts = erealloc(*texts, (ctx.text+1) * sizeof(struct PDFText *));