lorid

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

commit df1980de31eefb106013e78bf6f7b0604b77bf19
parent 8f4748478faf0da5f3cb9fdca11c6f5276a4795e
Author: nibo <nibo@relim.de>
Date:   Sun,  7 Jul 2024 20:34:22 +0200

Add config option 'fonts.label'

Diffstat:
Mconfig.c | 45+++++++++++++++++++++++++++++++++++++++++++++
Mconfig.h | 2+-
Mout_pdf.c | 17++++++++++++++---
3 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/config.c b/config.c @@ -56,6 +56,12 @@ struct Config *config_load_default(void) config->grid_font->style = FS_ROMAN; config->grid_font->weight = FW_BOLD; config->grid_font->size = 14.0; + config->label_font = malloc(sizeof(struct Font)); + config->label_font->name = strdup("Inter"); + config->label_font->family = FF_NORMAL; + config->label_font->style = FS_ITALIC; + config->label_font->weight = FW_REGULAR; + config->label_font->size = 14.0; return config; } @@ -71,6 +77,7 @@ void config_print_default(void) cho_font_print_as_toml(config->comment_box_font, "comment_box"); cho_font_print_as_toml(config->tab_font, "tab"); cho_font_print_as_toml(config->grid_font, "grid"); + cho_font_print_as_toml(config->label_font, "label"); config_free(config); } @@ -400,6 +407,43 @@ struct Config *config_load(const char *filepath) if (size.ok) { config->grid_font->size = size.u.i; } + } else if (strcmp(key_name, "label") == 0) { + if (name.ok) { + free(config->label_font->name); + config->label_font->name = name.u.s; + } + if (family.ok) { + font_family = cho_font_family_parse(family.u.s); + if (font_family == FF_EMPTY) { + fprintf(stderr, "INFO: Invalid config label section font family value.\n"); + return NULL; + } else { + config->label_font->family = font_family; + } + } + if (style.ok) { + font_style = cho_font_style_parse(style.u.s); + if (font_style == FS_EMPTY) { + fprintf(stderr, "INFO: Invalid config label section font style value.\n"); + return NULL; + } else { + config->label_font->style = font_style; + } + free(style.u.s); + } + if (weight.ok) { + font_weight = cho_font_weight_parse(weight.u.s); + if (font_weight == FW_EMPTY) { + fprintf(stderr, "INFO: Invalid config label section font weight value.\n"); + return NULL; + } else { + config->label_font->weight = font_weight; + } + free(weight.u.s); + } + if (size.ok) { + config->label_font->size = size.u.i; + } } else { fprintf(stderr, "INFO: Ignoring [fonts.%s] section in config file.\n", key_name); if (name.ok) @@ -425,5 +469,6 @@ void config_free(struct Config *config) cho_font_free(config->comment_box_font); cho_font_free(config->tab_font); cho_font_free(config->grid_font); + cho_font_free(config->label_font); free(config); } diff --git a/config.h b/config.h @@ -7,7 +7,7 @@ struct Config { struct Font *comment_box_font; struct Font *tab_font; struct Font *grid_font; - // TODO: section_name_font? + struct Font *label_font; }; struct Config *config_load(const char *filepath); diff --git a/out_pdf.c b/out_pdf.c @@ -233,6 +233,10 @@ static struct Font **out_pdf_font_get_all(struct ChoSong **songs, struct Config added = out_pdf_font_add_if_not_in(font, &fonts); if (!added) cho_font_free(font); + font = cho_font_duplicate(config->label_font); + added = out_pdf_font_add_if_not_in(font, &fonts); + if (!added) + cho_font_free(font); int so = 0; int se = 0; int li = 0; @@ -463,13 +467,16 @@ static void out_pdf_fnt_add(struct Fnt *fnt, struct Fnt ***array) static bool out_pdf_font_set(pdfio_stream_t *stream, struct Font *font) { char *name = out_pdf_fnt_name_create(font); + printf("setting font '%s'\n", name); if (!pdfioContentSetTextFont(stream, name, font->size)) { fprintf(stderr, "pdfioContentSetTextFont failed.\n"); return false; } pdfio_obj_t *font_obj = out_pdf_fnt_obj_get_by_name(name); - if (font_obj == NULL) + if (font_obj == NULL) { + fprintf(stderr, "out_pdf_fnt_obj_get_by_name failed.\n"); return false; + } strcpy(current_font, name); current_font_obj = font_obj; current_font_size = font->size; @@ -479,8 +486,10 @@ static bool out_pdf_font_set(pdfio_stream_t *stream, struct Font *font) bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config *config) { + if (config->label_font) { + printf("label_font is not NULL.\n"); + } char *pdf_filename = out_pdf_filename_create(cho_filename); - printf("pdf: %s\n", pdf_filename); pdfio_rect_t media_box_a4 = { 0.0, 0.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT }; pdfio_rect_t crop_box = { 36.0, 36.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT }; pdfio_file_t *pdf = pdfioFileCreate(pdf_filename, "2.0", &media_box_a4, &crop_box, NULL, NULL); @@ -493,6 +502,7 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config while (needed_fonts[f] != NULL) { fontpath = fontconfig_fontpath_find(needed_fonts[f], FT_TTF); if (fontpath) { + printf("ttf fontpath: %s\n", fontpath); fnt = out_pdf_fnt_new(); fnt->name = out_pdf_fnt_name_create(needed_fonts[f]); fnt->font = pdfioFileCreateFontObjFromFile(pdf, fontpath, true); @@ -505,6 +515,7 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config } else { fontpath = fontconfig_fontpath_find(needed_fonts[f], FT_OTF); if (fontpath) { + printf("otf fontpath: %s\n", fontpath); fnt = out_pdf_fnt_new(); fnt->name = out_pdf_fnt_name_create(needed_fonts[f]); fnt->font = pdfioFileCreateFontObjFromFile(pdf, fontpath, true); @@ -581,7 +592,7 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config while (songs[so]->sections[se] != NULL) { if (songs[so]->sections[se]->name) { const char *section_name = songs[so]->sections[se]->name; - if (!out_pdf_font_set(page1_stream, config->comment_italic_font)) { + if (!out_pdf_font_set(page1_stream, config->label_font)) { fprintf(stderr, "out_pdf_font_set failed.\n"); return false; }