commit be6c03f356990e4a791128d878f76bf7c3d1eafd
parent df1980de31eefb106013e78bf6f7b0604b77bf19
Author: nibo <nibo@relim.de>
Date: Sun, 7 Jul 2024 21:09:46 +0200
Add config option 'fonts.subtitle_font'
Diffstat:
3 files changed, 65 insertions(+), 1 deletion(-)
diff --git a/config.c b/config.c
@@ -14,6 +14,12 @@ struct Config *config_load_default(void)
config->title_font->style = FS_ROMAN;
config->title_font->weight = FW_BOLD;
config->title_font->size = 18.0;
+ config->subtitle_font = malloc(sizeof(struct Font));
+ config->subtitle_font->family = FF_NORMAL;
+ config->subtitle_font->name = strdup("Inter");
+ config->subtitle_font->style = FS_ROMAN;
+ config->subtitle_font->weight = FW_REGULAR;
+ config->subtitle_font->size = 12.0;
config->text_font = malloc(sizeof(struct Font));
config->text_font->name = strdup("Inter");
config->text_font->family = FF_NORMAL;
@@ -70,6 +76,7 @@ void config_print_default(void)
struct Config *config = config_load_default();
printf("[fonts]\n\n");
cho_font_print_as_toml(config->title_font, "title");
+ cho_font_print_as_toml(config->subtitle_font, "subtitle");
cho_font_print_as_toml(config->text_font, "text");
cho_font_print_as_toml(config->chord_font, "chord");
cho_font_print_as_toml(config->comment_font, "comment");
@@ -149,6 +156,42 @@ struct Config *config_load(const char *filepath)
}
if (size.ok)
config->title_font->size = size.u.i;
+ } else if (strcmp(key_name, "subtitle") == 0) {
+ if (name.ok) {
+ free(config->subtitle_font->name);
+ config->subtitle_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 subtitle section font family value.\n");
+ return NULL;
+ } else {
+ config->subtitle_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 subtitle section font style value.\n");
+ return NULL;
+ } else {
+ config->subtitle_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 subtitle section font weight value.\n");
+ return NULL;
+ } else {
+ config->subtitle_font->weight = font_weight;
+ }
+ free(weight.u.s);
+ }
+ if (size.ok)
+ config->subtitle_font->size = size.u.i;
} else if (strcmp(key_name, "text") == 0) {
if (name.ok) {
free(config->text_font->name);
@@ -462,6 +505,7 @@ struct Config *config_load(const char *filepath)
void config_free(struct Config *config)
{
cho_font_free(config->title_font);
+ cho_font_free(config->subtitle_font);
cho_font_free(config->text_font);
cho_font_free(config->chord_font);
cho_font_free(config->comment_font);
diff --git a/config.h b/config.h
@@ -1,5 +1,6 @@
struct Config {
struct Font *title_font;
+ struct Font *subtitle_font;
struct Font *text_font;
struct Font *chord_font;
struct Font *comment_font;
diff --git a/out_pdf.c b/out_pdf.c
@@ -205,6 +205,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->subtitle_font);
+ added = out_pdf_font_add_if_not_in(font, &fonts);
+ if (!added)
+ cho_font_free(font);
font = cho_font_duplicate(config->text_font);
added = out_pdf_font_add_if_not_in(font, &fonts);
if (!added)
@@ -581,13 +585,28 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config
fprintf(stderr, "out_pdf_text_show failed.\n");
return false;
}
- if (!out_pdf_text_show(page1_stream, "", CENTER, true)) {
+ }
+ m++;
+ }
+ m = 0;
+ while (songs[so]->metadata[m] != NULL) {
+ if (strcmp(songs[so]->metadata[m]->name, "subtitle") == 0) {
+ const char *subtitle = songs[so]->metadata[m]->value;
+ if (!out_pdf_font_set(page1_stream, config->subtitle_font)) {
+ fprintf(stderr, "out_pdf_font_set failed.\n");
+ return false;
+ }
+ if (!out_pdf_text_show(page1_stream, subtitle, CENTER, true)) {
fprintf(stderr, "out_pdf_text_show failed.\n");
return false;
}
}
m++;
}
+ if (!out_pdf_text_show(page1_stream, "", CENTER, true)) {
+ fprintf(stderr, "out_pdf_text_show failed.\n");
+ return false;
+ }
m = 0;
while (songs[so]->sections[se] != NULL) {
if (songs[so]->sections[se]->name) {