commit 8f4748478faf0da5f3cb9fdca11c6f5276a4795e
parent b8ffeb167f0bb1a4efec711b3eaea904f73264de
Author: nibo <nibo@relim.de>
Date: Sun, 7 Jul 2024 19:44:29 +0200
Add --print-default-config argument
Diffstat:
5 files changed, 34 insertions(+), 14 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -426,6 +426,8 @@ enum FontFamily cho_font_family_parse(const char *str)
return FF_SERIF;
} else if (strcasecmp(str, "monospace") == 0) {
return FF_MONOSPACE;
+ } else if (strcasecmp(str, "normal") == 0) {
+ return FF_NORMAL;
} else {
return FF_EMPTY;
}
@@ -471,8 +473,6 @@ enum FontWeight cho_font_weight_parse(const char *str)
{
if (strcasecmp(str, "bold") == 0) {
return FW_BOLD;
- } else if (strcasecmp(str, "regular") == 0) {
- return FW_REGULAR;
} else if (strcasecmp(str, "normal") == 0) {
return FW_REGULAR;
} else {
@@ -484,15 +484,20 @@ const char *cho_font_weight_to_string(enum FontWeight weight)
{
if (weight == FW_BOLD)
return "bold";
- return "regular";
+ return "normal";
}
-/* int cho_font_weight_to_int(enum FontWeight weight)
+void cho_font_print_as_toml(struct Font *font, const char *section)
{
- if (weight == FW_BOLD)
- return 200;
- return 80;
-} */
+ printf("[fonts.%s]\n", section);
+ printf("\n");
+ printf("name = \"%s\"\n", font->name);
+ printf("family = \"%s\"\n", cho_font_family_to_string(font->family));
+ printf("style = \"%s\"\n", cho_font_style_to_string(font->style));
+ printf("weight = \"%s\"\n", cho_font_weight_to_string(font->weight));
+ printf("size = %.1f\n", font->size);
+ printf("\n");
+}
struct Style *cho_style_new(void)
{
@@ -592,14 +597,17 @@ struct Font *cho_style_font_desc_parse(const char *str)
font->style = FS_OBLIQUE;
if (stop_at == -1)
stop_at = w;
+ // TODO: Is that smart?
} else if (strcasecmp(words[w], "regular") == 0) {
font->weight = FW_REGULAR;
if (stop_at == -1)
stop_at = w;
+ // TODO: Is that smart?
} else if (strcasecmp(words[w], "normal") == 0) {
font->style = FS_ROMAN;
if (stop_at == -1)
stop_at = w;
+ /* Commented because the family name sometimes contains 'sans' or 'serif' */
/* } else if (strcasecmp(words[w], "sans") == 0) {
font->family = FF_SANS;
if (stop_at == -1)
diff --git a/chordpro.h b/chordpro.h
@@ -182,7 +182,7 @@ const char *cho_font_style_to_string(enum FontStyle style);
enum FontWeight cho_font_weight_parse(const char *str);
const char *cho_font_weight_to_string(enum FontWeight weight);
-// int cho_font_weight_to_int(enum FontWeight weight);
+void cho_font_print_as_toml(struct Font *font, const char *section);
/* Debugging */
void cho_font_print(struct Font *font);
diff --git a/config.c b/config.c
@@ -59,6 +59,21 @@ struct Config *config_load_default(void)
return config;
}
+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->text_font, "text");
+ cho_font_print_as_toml(config->chord_font, "chord");
+ cho_font_print_as_toml(config->comment_font, "comment");
+ cho_font_print_as_toml(config->comment_italic_font, "comment_italic");
+ 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");
+ config_free(config);
+}
+
struct Config *config_load(const char *filepath)
{
struct Config *config = config_load_default();
@@ -106,7 +121,6 @@ struct Config *config_load(const char *filepath)
}
}
if (style.ok) {
- printf("style here\n");
font_style = cho_font_style_parse(style.u.s);
if (font_style == FS_EMPTY) {
fprintf(stderr, "INFO: Invalid config title section font style value.\n");
diff --git a/config.h b/config.h
@@ -12,3 +12,4 @@ struct Config {
struct Config *config_load(const char *filepath);
void config_free(struct Config *config);
+void config_print_default(void);
diff --git a/lorid.c b/lorid.c
@@ -10,9 +10,6 @@
int main(int argc, char *argv[])
{
- char *new = cho_font_name_sanitize("Noto Sans");
- printf("new: %s\n", new);
- free(new);
static struct option long_options[] = {
{ "print-default-config", no_argument, 0, 'p' },
{ "config", required_argument, 0, 'c' },
@@ -24,7 +21,7 @@ int main(int argc, char *argv[])
while ((o = getopt_long(argc, argv, "pc:", long_options, &option_index)) != -1) {
switch(o) {
case 'p':
- printf("--print-default-config\n");
+ config_print_default();
return 0;
case 'c':
config_filepath = malloc((strlen(optarg)+1) * sizeof(char));