commit d966cc31da06a63942a70d9646ca5bff6cf3037c
parent 84566db79a88cda5832ace7703ea6f4982e9cff5
Author: nibo <nibo@relim.de>
Date: Thu, 25 Jul 2024 19:14:27 +0200
Remove compiler warnings and remove unused code
Diffstat:
4 files changed, 29 insertions(+), 228 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -1755,6 +1755,7 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li]->lyrics[ly] = cho_line_item_new();
struct Tag **tags = NULL;
struct Style *tag_style;
+ struct StyleProperty sprop;
while (feof(fp) == 0) {
read = fread(&buf, 1, 1, fp);
if (read == 1) {
@@ -1906,7 +1907,7 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
songs[so]->sections[se]->lines[li] = cho_line_new();
break;
case DT_FONT:
- // Reset directive value to default
+ // TODO: Reset directive value to default
break;
case DT_CUSTOM:
fprintf(stderr, "INFO: Ignoring custom directive '%s'.\n", directive_name);
@@ -2013,7 +2014,6 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
fprintf(stderr, "INFO: Preamble directive '%s' can't have a value.\n", directive_name);
break;
case DT_FONT:
- struct StyleProperty sprop;
sprop.ftype = directive->ftype;
char *dir_value = string_remove_leading_whitespace(directive_value);
switch (directive->sprop) {
@@ -2041,6 +2041,7 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
sprop.type = SPT_COLOR;
break;
default:
+ fprintf(stderr, "INFO: Ignoring invalid style property type '%d'.\n", directive->sprop);
}
cho_style_change_default(sprop);
if (sprop.type == SPT_FONT) {
@@ -2054,6 +2055,7 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
fprintf(stderr, "INFO: Ignoring custom directive '%s'.\n", directive_name);
break;
default:
+ fprintf(stderr, "INFO: Ignoring invalid directive '%d'.\n", directive->dtype);
}
memset(directive_value, 0, strlen(directive_value));
cho_directive_free(directive);
diff --git a/out_pdf.c b/out_pdf.c
@@ -12,7 +12,6 @@ static struct Fnt **g_fonts = NULL;
static char g_current_font_name[200];
static double g_current_font_size;
-static double g_current_y = MEDIABOX_HEIGHT - 25.0;
static pdfio_obj_t *g_current_font_obj = NULL;
static pdfio_obj_t *out_pdf_fnt_obj_get_by_name(const char *name)
@@ -26,28 +25,6 @@ static pdfio_obj_t *out_pdf_fnt_obj_get_by_name(const char *name)
return NULL;
}
-static char *out_pdf_concat_line_items(struct ChoLineItem **items)
-{
- char *line = NULL;
- int size = 1;
- int i = 0;
- int k = 0;
- int li = 0;
- while (items[i] != NULL) {
- size += strlen(items[i]->text);
- line = realloc(line, size * sizeof(char));
- while (items[i]->text[k] != 0) {
- line[li] = items[i]->text[k];
- li++;
- k++;
- }
- k = 0;
- i++;
- }
- line[li] = 0;
- return line;
-}
-
static char *string_trim(const char *text)
{
char *trimmed_text = NULL;
@@ -215,48 +192,6 @@ static struct Font **out_pdf_font_get_all(struct ChoSong **songs, struct Config
return fonts;
}
-static void out_pdf_adjust_line(struct ChoLine *line)
-{
-}
-
-static bool out_pdf_chord_show(pdfio_stream_t *stream, const char *lyrics_line, struct ChoChord *chord, bool linebreak)
-{
- double width;
- char line[strlen(lyrics_line)+1];
- strcpy(line, lyrics_line);
- // size_t line_len = strlen(line);
- line[chord->position] = 0;
- width = pdfioContentTextMeasure(g_current_font_obj, line, g_current_font_size);
- /* if (chord->position < line_len) {
- line[chord->position] = 0;
- width = pdfioContentTextMeasure(g_current_font_obj, line, g_current_font_size);
- } else {
- double space_width = pdfioContentTextMeasure(g_current_font_obj, " ", g_current_font_size);
- width = pdfioContentTextMeasure(g_current_font_obj, line, g_current_font_size);
- width += (line_len - chord->position) * space_width;
- } */
- if (!pdfioContentTextBegin(stream)) {
- fprintf(stderr, "pdfioContentTextBegin failed.\n");
- return false;
- }
- if (!pdfioContentTextMoveTo(stream, PADDING + width, g_current_y)) {
- fprintf(stderr, "pdfioContentTextMoveTo failed.\n");
- return false;
- }
- if (!pdfioContentTextShow(stream, true, chord->chord)) {
- fprintf(stderr, "pdfioContentTextShow failed.\n");
- return false;
- }
- if (!pdfioContentTextEnd(stream)) {
- fprintf(stderr, "pdfioContentTextEnd failed.\n");
- return false;
- }
- if (linebreak) {
- g_current_y -= g_current_font_size + 2.0;
- }
- return true;
-}
-
size_t out_pdf_text_find_fitting_length(const char *str, size_t len)
{
char tmp[512];
@@ -725,7 +660,7 @@ static struct Text **text_create(struct ChoSong **songs, struct Config *config)
}
int tlii = 0;
for (ii = 0; lines[li]->lyrics[ly]->text[ii] != 0; ii++) {
- if (sp = needs_space(spaces, ly, ii)) {
+ if ((sp = needs_space(spaces, ly, ii))) {
text[t]->lines[tl]->items[tli]->text = realloc(text[t]->lines[tl]->items[tli]->text, (tlii+1) * sizeof(char));
text[t]->lines[tl]->items[tli]->text[tlii] = lines[li]->lyrics[ly]->text[ii];
tlii++;
@@ -794,6 +729,22 @@ static void text_free(struct Text **text)
free(text);
}
+bool out_pdf_set_title(pdfio_file_t *pdf, struct ChoSong **songs)
+{
+ // Set pdf title only if single song exist
+ if (songs[0] && !songs[1]) {
+ int m;
+ for (m = 0; songs[0]->metadata[m]; m++) {
+ if (strcmp(songs[0]->metadata[m]->name, "title") == 0) {
+ pdfioFileSetTitle(pdf, songs[0]->metadata[m]->value);
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+}
+
bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config *config)
{
memset(&g_current_font_name, 0, sizeof(g_current_font_name));
@@ -802,6 +753,10 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config
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);
free(pdf_filename);
+ if (!out_pdf_set_title(pdf, songs)) {
+ fprintf(stderr, "out_pdf_set_title failed.\n");
+ return false;
+ }
pdfio_dict_t *page1_dict = pdfioDictCreate(pdf);
struct Font **needed_fonts = out_pdf_font_get_all(songs, config);
struct Fnt *fnt;
@@ -840,11 +795,6 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config
f++;
}
cho_fonts_free(needed_fonts);
- /* f = 0;
- while (g_fonts[f] != NULL) {
- printf("name: %s\n", g_fonts[f]->name);
- f++;
- } */
struct Text **text = text_create(songs, config);
if (!text) {
fprintf(stderr, "text_create failed.\n");
@@ -877,158 +827,6 @@ bool out_pdf_new(const char *cho_filename, struct ChoSong **songs, struct Config
}
}
text_free(text);
- /* pdfio_array_t *color_array = pdfioArrayCreateColorFromStandard(pdf, 3, PDFIO_CS_ADOBE);
- if (!pdfioPageDictAddColorSpace(page1_dict, "rgbcolorspace", color_array)) {
- fprintf(stderr, "pdfioPageDictAddColorSpace failed.\n");
- return 1;
- }
- pdfio_stream_t *page1_stream = pdfioFileCreatePage(pdf, page1_dict);
- if (!pdfioContentSetFillColorSpace(page1_stream, "rgbcolorspace")) {
- fprintf(stderr, "pdfioContentSetFillColorSpace failed.\n");
- return 1;
- }
- int so = 0;
- int se = 0;
- int m = 0;
- int li = 0;
- int ly = 0;
- int ch = 0;
- struct ChoChord **chords;
- struct PrintableItem *printable_item;
- if (!pdfioContentTextBegin(page1_stream)) {
- fprintf(stderr, "pdfioContentTextBegin failed.\n");
- return false;
- }
- while (songs[so] != NULL) {
- while (songs[so]->metadata[m] != NULL) {
- if (strcmp(songs[so]->metadata[m]->name, "title") == 0) {
- const char *title = songs[so]->metadata[m]->value;
- pdfioFileSetTitle(pdf, title);
- printable_item = config_printable_item_get(config->printable_items, "title");
- if (!printable_item) {
- fprintf(stderr, "config_printable_item_get failed.\n");
- return false;
- }
- if (!out_pdf_font_set(page1_stream, printable_item->style->font)) {
- fprintf(stderr, "out_pdf_font_set failed.\n");
- return false;
- }
- if (!out_pdf_text_show(page1_stream, title, CENTER, true)) {
- fprintf(stderr, "out_pdf_text_show failed.\n");
- return false;
- }
- }
- 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;
- printable_item = config_printable_item_get(config->printable_items, "subtitle");
- if (!printable_item) {
- fprintf(stderr, "config_printable_item_get failed.\n");
- return false;
- }
- if (!out_pdf_font_set(page1_stream, printable_item->style->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) {
- const char *section_name = songs[so]->sections[se]->name;
- printable_item = config_printable_item_get(config->printable_items, "label");
- if (!printable_item) {
- fprintf(stderr, "config_printable_item_get failed.\n");
- return false;
- }
- if (!out_pdf_font_set(page1_stream, printable_item->style->font)) {
- fprintf(stderr, "out_pdf_font_set failed.\n");
- return false;
- }
- if (!out_pdf_text_show(page1_stream, section_name, LEFT, true)) {
- fprintf(stderr, "out_pdf_text_show failed.\n");
- return false;
- }
- }
- while (songs[so]->sections[se]->lines[li] != NULL) {
- out_pdf_adjust_line(songs[so]->sections[se]->lines[li]);
- chords = songs[so]->sections[se]->lines[li]->chords;
- int count = cho_chord_count(chords);
- if (count > 0) {
- printable_item = config_printable_item_get(config->printable_items, "chord");
- if (!printable_item) {
- fprintf(stderr, "config_printable_item_get failed.\n");
- return false;
- }
- if (!out_pdf_font_set(page1_stream, printable_item->style->font)) {
- fprintf(stderr, "out_pdf_font_set failed.\n");
- return false;
- }
- char *lyrics_line = out_pdf_concat_line_items(songs[so]->sections[se]->lines[li]->lyrics);
- while (ch < count - 1) {
- my_helper(lyrics_line, ch == 0 ? NULL : chords[ch-1], chords[ch]);
- if (!out_pdf_chord_show(page1_stream, lyrics_line, chords[ch], false)) {
- fprintf(stderr, "out_pdf_chord_show failed.\n");
- return false;
- }
- ch++;
- }
- my_helper(lyrics_line, ch == 0 ? NULL : chords[ch-1], chords[ch]);
- if (!out_pdf_chord_show(page1_stream, lyrics_line, chords[ch], true)) {
- fprintf(stderr, "out_pdf_chord_show failed.\n");
- return false;
- }
- ch = 0;
- free(lyrics_line);
- }
- char *text;
- struct Style *style;
- int items_count = cho_line_item_count(songs[so]->sections[se]->lines[li]->lyrics);
- while (ly < items_count - 1) {
- text = songs[so]->sections[se]->lines[li]->lyrics[ly]->text;
- if (!out_pdf_style_apply(page1_stream, songs[so]->sections[se]->lines[li]->lyrics[ly]->style)) {
- fprintf(stderr, "out_pdf_style_apply failed.\n");
- return false;
- }
- style = songs[so]->sections[se]->lines[li]->lyrics[ly]->style;
- if (!out_pdf_text_show(page1_stream, text, CONTINUE, false)) {
- fprintf(stderr, "out_pdf_text_show failed.\n");
- return false;
- }
- ly++;
- }
- text = songs[so]->sections[se]->lines[li]->lyrics[ly]->text;
- if (!out_pdf_style_apply(page1_stream, songs[so]->sections[se]->lines[li]->lyrics[ly]->style)) {
- fprintf(stderr, "out_pdf_style_apply failed.\n");
- return false;
- }
- style = songs[so]->sections[se]->lines[li]->lyrics[ly]->style;
- if (!out_pdf_text_show(page1_stream, text, CONTINUE, true)) {
- fprintf(stderr, "out_pdf_text_show failed.\n");
- return false;
- }
- ly = 0;
- li++;
- }
- g_current_y -= 10.0;
- li = 0;
- se++;
- }
- se = 0;
- so++;
- } */
if (!pdfioStreamClose(page1_stream)) {
fprintf(stderr, "pdfioStreamClose failed.\n");
return false;
diff --git a/out_pdf.h b/out_pdf.h
@@ -2,8 +2,8 @@
#define MEDIABOX_HEIGHT 842.0
#define MEDIABOX_WIDTH 595.0
-#define PAGE_HEIGHT MEDIABOX_HEIGHT - 36.0
-#define PAGE_WIDTH MEDIABOX_WIDTH - 36.0
+// #define PAGE_HEIGHT MEDIABOX_HEIGHT - 36.0
+// #define PAGE_WIDTH MEDIABOX_WIDTH - 36.0
#define PADDING 80.0
#define LINE_LEN MEDIABOX_WIDTH - PADDING * 2
diff --git a/todo b/todo
@@ -1,4 +1,4 @@
-apply config is cho_parse() instead of out_pdf_new()
+apply config in cho_parse() instead of out_pdf_new()
'chorus' directive
decide how to implement
metadata directives
@@ -15,3 +15,4 @@ the whole chords advanced stuff
introduce parse errors
still very unclear to me when the parser should warn
and continue execution and when it should fail
+metadata items need a style