commit 58ddb994d72612971dfc42310d12d35359ffdcd9
parent 11ebd41a6c1db534165bf5eb2b22c87ea2c93f9e
Author: nibo <nibo@relim.de>
Date: Tue, 15 Oct 2024 10:16:15 +0200
Rename 'PrintableItem' to 'OutputStyle'
Diffstat:
| M | chordpro.c | | | 34 | +++++++++++++++++----------------- |
| M | config.c | | | 94 | ++++++++++++++++++++++++++++++++++++++++---------------------------------------- |
| M | config.h | | | 6 | +++--- |
| M | out_pdf.c | | | 14 | +++++++------- |
| M | todo | | | 3 | ++- |
5 files changed, 76 insertions(+), 75 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -849,32 +849,32 @@ cho_style_copy(struct Style *style)
struct Style *
cho_style_new_from_config(enum SongFragmentType ftype)
{
- struct PrintableItem *printable_item;
+ struct OutputStyle *style;
switch (ftype) {
case SF_CHORD:
- printable_item = config_printable_item_get(g_config->output->printable_items, "chord");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "chord");
+ return cho_style_copy(style->style);
case SF_ANNOT:
- printable_item = config_printable_item_get(g_config->output->printable_items, "annotation");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "annotation");
+ return cho_style_copy(style->style);
case SF_GRID:
- printable_item = config_printable_item_get(g_config->output->printable_items, "grid");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "grid");
+ return cho_style_copy(style->style);
case SF_TAB:
- printable_item = config_printable_item_get(g_config->output->printable_items, "tab");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "tab");
+ return cho_style_copy(style->style);
case SF_LABEL:
- printable_item = config_printable_item_get(g_config->output->printable_items, "label");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "label");
+ return cho_style_copy(style->style);
case SF_TITLE:
- printable_item = config_printable_item_get(g_config->output->printable_items, "title");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "title");
+ return cho_style_copy(style->style);
case SF_SUBTITLE:
- printable_item = config_printable_item_get(g_config->output->printable_items, "subtitle");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "subtitle");
+ return cho_style_copy(style->style);
default:
- printable_item = config_printable_item_get(g_config->output->printable_items, "text");
- return cho_style_copy(printable_item->style);
+ style = config_output_style_get(g_config->output->styles, "text");
+ return cho_style_copy(style->style);
}
}
diff --git a/config.c b/config.c
@@ -103,25 +103,25 @@ static struct Note notes_nashville[] = {
{ .note = "7", .sharp = NULL, .flat = "7b" },
};
-static struct PrintableItem *
-config_printable_item_new(const char *name)
+static struct OutputStyle *
+config_output_style_new(const char *name)
{
- struct PrintableItem *item = malloc(sizeof(struct PrintableItem));
+ struct OutputStyle *item = malloc(sizeof(struct OutputStyle));
item->name = strdup(name);
item->style = cho_style_new();
return item;
}
static void
-config_printable_item_free(struct PrintableItem *item)
+config_output_style_free(struct OutputStyle *item)
{
free(item->name);
cho_style_free(item->style);
free(item);
}
-struct PrintableItem *
-config_printable_item_get(struct PrintableItem **items, const char *name)
+struct OutputStyle *
+config_output_style_get(struct OutputStyle **items, const char *name)
{
int i = 0;
while (items[i] != NULL) {
@@ -315,38 +315,38 @@ config_load_default(void)
config->output->chorus->label = strdup("Chorus");
config->output->chorus->quote = false;
config->output->system = NS_COMMON;
- config->output->printable_items = malloc(12 * sizeof(struct PrintableItem *));
- config->output->printable_items[0] = config_printable_item_new("title");
- config->output->printable_items[0]->style->font->name = strdup("Inter");
- config->output->printable_items[0]->style->font->weight = FW_BOLD;
- config->output->printable_items[0]->style->font->size = 18.0;
- config->output->printable_items[1] = config_printable_item_new("subtitle");
- config->output->printable_items[1]->style->font->name = strdup("Inter");
- config->output->printable_items[1]->style->font->size = 12.0;
- config->output->printable_items[2] = config_printable_item_new("text");
- config->output->printable_items[2]->style->font->name = strdup("Inter");
- config->output->printable_items[3] = config_printable_item_new("chord");
- config->output->printable_items[3]->style->font->name = strdup("Inter");
- config->output->printable_items[3]->style->font->weight = FW_BOLD;
- config->output->printable_items[4] = config_printable_item_new("comment");
- config->output->printable_items[4]->style->font->name = strdup("Inter");
- config->output->printable_items[5] = config_printable_item_new("comment_italic");
- config->output->printable_items[5]->style->font->name = strdup("Inter");
- config->output->printable_items[5]->style->font->style = FS_ITALIC;
- config->output->printable_items[6] = config_printable_item_new("comment_box");
- config->output->printable_items[6]->style->font->name = strdup("Inter");
- config->output->printable_items[7] = config_printable_item_new("tab");
- config->output->printable_items[7]->style->font->name = strdup("Inter");
- config->output->printable_items[8] = config_printable_item_new("grid");
- config->output->printable_items[8]->style->font->name = strdup("Inter");
- config->output->printable_items[8]->style->font->weight = FW_BOLD;
- config->output->printable_items[9] = config_printable_item_new("label");
- config->output->printable_items[9]->style->font->name = strdup("Inter");
- config->output->printable_items[9]->style->font->style = FS_ITALIC;
- config->output->printable_items[10] = config_printable_item_new("annotation");
- config->output->printable_items[10]->style->font->name = strdup("Inter");
- config->output->printable_items[10]->style->font->style = FS_ITALIC;
- config->output->printable_items[11] = NULL;
+ config->output->styles = malloc(12 * sizeof(struct OutputStyle *));
+ config->output->styles[0] = config_output_style_new("title");
+ config->output->styles[0]->style->font->name = strdup("Inter");
+ config->output->styles[0]->style->font->weight = FW_BOLD;
+ config->output->styles[0]->style->font->size = 18.0;
+ config->output->styles[1] = config_output_style_new("subtitle");
+ config->output->styles[1]->style->font->name = strdup("Inter");
+ config->output->styles[1]->style->font->size = 12.0;
+ config->output->styles[2] = config_output_style_new("text");
+ config->output->styles[2]->style->font->name = strdup("Inter");
+ config->output->styles[3] = config_output_style_new("chord");
+ config->output->styles[3]->style->font->name = strdup("Inter");
+ config->output->styles[3]->style->font->weight = FW_BOLD;
+ config->output->styles[4] = config_output_style_new("comment");
+ config->output->styles[4]->style->font->name = strdup("Inter");
+ config->output->styles[5] = config_output_style_new("comment_italic");
+ config->output->styles[5]->style->font->name = strdup("Inter");
+ config->output->styles[5]->style->font->style = FS_ITALIC;
+ config->output->styles[6] = config_output_style_new("comment_box");
+ config->output->styles[6]->style->font->name = strdup("Inter");
+ config->output->styles[7] = config_output_style_new("tab");
+ config->output->styles[7]->style->font->name = strdup("Inter");
+ config->output->styles[8] = config_output_style_new("grid");
+ config->output->styles[8]->style->font->name = strdup("Inter");
+ config->output->styles[8]->style->font->weight = FW_BOLD;
+ config->output->styles[9] = config_output_style_new("label");
+ config->output->styles[9]->style->font->name = strdup("Inter");
+ config->output->styles[9]->style->font->style = FS_ITALIC;
+ config->output->styles[10] = config_output_style_new("annotation");
+ config->output->styles[10]->style->font->name = strdup("Inter");
+ config->output->styles[10]->style->font->style = FS_ITALIC;
+ config->output->styles[11] = NULL;
config->output->notes = config_notes_new_default(NS_COMMON);
config->parser = malloc(sizeof(struct ConfigParser));
config->parser->chords = malloc(sizeof(struct ConfigChords));
@@ -357,7 +357,7 @@ config_load_default(void)
}
static void
-config_printable_item_print_as_toml(struct PrintableItem *item)
+config_output_style_print_as_toml(struct OutputStyle *item)
{
printf("[output.styles.%s]\n\n", item->name);
cho_style_print_as_toml(item->style, item->name);
@@ -376,8 +376,8 @@ config_print_default(void)
printf("quote = false\n\n");
printf("[output.styles]\n\n");
int i = 0;
- while (config->output->printable_items[i] != NULL) {
- config_printable_item_print_as_toml(config->output->printable_items[i]);
+ while (config->output->styles[i] != NULL) {
+ config_output_style_print_as_toml(config->output->styles[i]);
i++;
}
printf("[parser]\n\n");
@@ -646,13 +646,13 @@ config_load(const char *filepath)
int unused;
const char *key_name;
toml_table_t *key;
- struct PrintableItem *item;
+ struct OutputStyle *item;
for (int i=0; i<toml_table_len(styles); i++) {
key_name = toml_table_key(styles, i, &unused);
if (config_is_style(key_name)) {
key = toml_table_table(styles, key_name);
if (key) {
- item = config_printable_item_get(config->output->printable_items, key_name);
+ item = config_output_style_get(config->output->styles, key_name);
if (item) {
if (!config_load_style(item->style, key, key_name)) {
LOG_DEBUG("config_load_style failed.");
@@ -715,13 +715,13 @@ config_load(const char *filepath)
void
config_free(struct Config *config)
{
- struct PrintableItem **start_items = config->output->printable_items;
+ struct OutputStyle **start_items = config->output->styles;
struct Note **start_notes = config->output->notes;
free(config->output->chorus->label);
free(config->output->chorus);
- while (*config->output->printable_items) {
- config_printable_item_free(*config->output->printable_items);
- config->output->printable_items++;
+ while (*config->output->styles) {
+ config_output_style_free(*config->output->styles);
+ config->output->styles++;
}
free(start_items);
while (*config->output->notes) {
diff --git a/config.h b/config.h
@@ -1,7 +1,7 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
-struct PrintableItem {
+struct OutputStyle {
char *name;
struct Style *style;
};
@@ -51,7 +51,7 @@ struct ConfigParser {
struct ConfigOutput {
struct ConfigChorus *chorus;
enum NamingSystem system;
- struct PrintableItem **printable_items;
+ struct OutputStyle **styles;
struct Note **notes;
};
@@ -63,6 +63,6 @@ struct Config {
struct Config *config_load(const char *filepath);
void config_free(struct Config *config);
void config_print_default(void);
-struct PrintableItem *config_printable_item_get(struct PrintableItem **items, const char *name);
+struct OutputStyle *config_output_style_get(struct OutputStyle **items, const char *name);
#endif /* _CONFIG_H_ */
diff --git a/out_pdf.c b/out_pdf.c
@@ -105,8 +105,8 @@ out_pdf_font_get_all(struct ChoSong **songs, struct Config *config)
struct Font *font;
bool added = false;
int i = 0;
- while (config->output->printable_items[i] != NULL) {
- font = cho_font_copy(config->output->printable_items[i]->style->font);
+ while (config->output->styles[i] != NULL) {
+ font = cho_font_copy(config->output->styles[i]->style->font);
added = out_pdf_font_add_if_not_in(font, &fonts);
if (!added)
cho_font_free(font);
@@ -764,7 +764,7 @@ needs_space(struct SpaceNeeded **spaces, int ly, int i)
static struct Text **
text_create(struct ChoSong **songs, struct Config *config)
{
- struct PrintableItem *printable_item;
+ struct OutputStyle *output_style;
int so, se, li, ly, ch;
double width;
double y = MEDIABOX_HEIGHT - MARGIN_TOP;
@@ -842,9 +842,9 @@ text_create(struct ChoSong **songs, struct Config *config)
return NULL;
}
if (fits) {
- printable_item = config_printable_item_get(config->output->printable_items, "subtitle");
- if (!printable_item) {
- LOG_DEBUG("config_printable_item_get failed.");
+ output_style = config_output_style_get(config->output->styles, "subtitle");
+ if (!output_style) {
+ LOG_DEBUG("config_output_style_get failed.");
return NULL;
}
text[t]->lines = realloc(text[t]->lines, (tl+1) * sizeof(struct TextLine *));
@@ -852,7 +852,7 @@ text_create(struct ChoSong **songs, struct Config *config)
text[t]->lines[tl]->items = malloc(2 * sizeof(struct TextLineItem *));
text[t]->lines[tl]->items[0] = malloc(sizeof(struct TextLineItem));
text[t]->lines[tl]->items[0]->text = strdup(songs[so]->metadata[m]->value);
- text[t]->lines[tl]->items[0]->style = cho_style_copy(printable_item->style);
+ text[t]->lines[tl]->items[0]->style = cho_style_copy(output_style->style);
width = text_width(text[t]->lines[tl]->items[0]);
if (width == EMPTY) {
LOG_DEBUG("text_width failed.");
diff --git a/todo b/todo
@@ -12,6 +12,7 @@ chords
strict and relaxed parsing makes no difference!?
make parser bulletproof
try to detect invalid input as much as possible
+ try to be as restrictive as possible
# pdf output
break lines when too long
@@ -19,6 +20,6 @@ break lines when too long
don't create text line based but text line item based
render in two or more columns
-find better name for PrintableItem, TextAbove
+find better name for TextAbove
consider freeing memory in case of errors
decide and then change consistent global variables prefix 'g_' or not