commit dcb6d62024e4b11f1339cf0a4e1ecf5635036e44
parent 7fcb2d8fa267c05dc576d30f9a9ef8b7b5192b2c
Author: nibo <nibo@relim.de>
Date: Fri, 26 Jul 2024 22:27:08 +0200
Solve compiler warning issues
Diffstat:
5 files changed, 37 insertions(+), 21 deletions(-)
diff --git a/chordpro.c b/chordpro.c
@@ -284,6 +284,7 @@ void the_default_style_properties(void)
printf("NULL\n");
break;
default:
+ printf("Invalid StylePropertyType value '%d'.\n", default_style_properties[i].type);
}
}
}
@@ -671,6 +672,8 @@ static bool cho_style_property_apply_default(enum SongFragmentType current_ftype
}
break;
default:
+ fprintf(stderr, "INFO: Invalid style property type '%d'.\n", ptype);
+ return false;
}
}
}
@@ -775,6 +778,9 @@ void cho_style_free(struct Style *style)
struct Font *cho_style_font_desc_parse(const char *str)
{
+ if (strlen(str) == 0) {
+ return NULL;
+ }
struct Font *font = cho_font_new();
double size = -1.0;
char **words = malloc(sizeof(char *));
@@ -806,54 +812,57 @@ struct Font *cho_style_font_desc_parse(const char *str)
words = realloc(words, (w+1) * sizeof(char *));
words[w] = NULL;
w = 0;
- int stop_at = -1;
+ int stop_at = EMPTY;
while (words[w] != NULL) {
if (strcasecmp(words[w], "italic") == 0) {
font->style = FS_ITALIC;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w;
} else if (strcasecmp(words[w], "bold") == 0) {
font->weight = FW_BOLD;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w;
} else if (strcasecmp(words[w], "oblique") == 0) {
font->style = FS_OBLIQUE;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w;
// TODO: Is that smart?
} else if (strcasecmp(words[w], "regular") == 0) {
font->weight = FW_REGULAR;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w;
// TODO: Is that smart?
} else if (strcasecmp(words[w], "normal") == 0) {
font->style = FS_ROMAN;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
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)
+ if (stop_at == EMPTY)
stop_at = w;
} else if (strcasecmp(words[w], "serif") == 0) {
font->family = FF_SERIF;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w; */
} else if (strcasecmp(words[w], "monospace") == 0) {
font->family = FF_MONOSPACE;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w;
} else {
size = strtod(words[w], NULL);
if (size == 0.0)
goto SKIP;
font->size = size;
- if (stop_at == -1)
+ if (stop_at == EMPTY)
stop_at = w;
}
SKIP:
w++;
}
+ if (stop_at == EMPTY) {
+ stop_at = w;
+ }
k = 0;
int n = 0;
for (int i=0; i<stop_at; i++) {
@@ -894,14 +903,10 @@ struct Style *cho_style_get(const char *tag_name, struct Attr **attrs, struct St
while (attrs[a] != NULL) {
if (strcmp(attrs[a]->name, "font_desc") == 0) {
font = cho_style_font_desc_parse(attrs[a]->value);
- cho_font_free(style->font);
- style->font = font;
- /* style->font = strdup(font->name);
- style->font_family = font->family;
- style->font_style = font->style;
- style->font_weight = font->weight;
- style->font_size = font->size;
- cho_font_free(font); */
+ if (font) {
+ cho_font_free(style->font);
+ style->font = font;
+ }
} else if (
strcmp(attrs[a]->name, "font_family") == 0 ||
strcmp(attrs[a]->name, "face") == 0
@@ -1194,6 +1199,7 @@ static void cho_style_change_default(struct StyleProperty sprop)
default_style_properties[i].u.foreground_color = cho_rgbcolor_duplicate(sprop.u.foreground_color);
break;
default:
+ fprintf(stderr, "INFO: Invalid style property type '%d'.\n", sprop.type);
}
}
}
@@ -1873,6 +1879,7 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
}
break;
default:
+ fprintf(stderr, "INFO: Invalid position value '%d'.\n", directive->position);
}
break;
case DT_METADATA:
@@ -1913,6 +1920,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 '%s'.\n", directive_name);
}
cho_directive_free(directive);
directive = NULL;
@@ -1976,6 +1984,7 @@ struct ChoSong **cho_parse(FILE *fp, struct Config *config)
}
break;
default:
+ fprintf(stderr, "INFO: Invalid position value '%d'.\n", directive->position);
}
break;
case DT_METADATA:
diff --git a/fontconfig.c b/fontconfig.c
@@ -54,6 +54,8 @@ char *fontconfig_fontpath_find(struct Font *font, enum FontType font_type)
style.u.i = FC_SLANT_ITALIC;
break;
default:
+ fprintf(stderr, "INFO: Invalid font style value '%d'.\n", font->style);
+ return NULL;
}
FcPatternAdd(pattern, FC_SLANT, style, FcFalse);
FcValue weight;
@@ -66,6 +68,8 @@ char *fontconfig_fontpath_find(struct Font *font, enum FontType font_type)
weight.u.i = FC_WEIGHT_BOLD;
break;
default:
+ fprintf(stderr, "INFO: Invalid font weight value '%d'.\n", font->weight);
+ return NULL;
}
FcPatternAdd(pattern, FC_WEIGHT, weight, FcFalse);
FcFontSet *set = FcFontList(NULL, pattern, obj);
diff --git a/out_pdf.c b/out_pdf.c
@@ -414,7 +414,9 @@ static double text_width(struct TextLineItem *item)
static double line_width_until_chord(struct ChoLine *line, struct ChoChord *chord, struct SpaceNeeded *space)
{
- int ly, i, last_ly, last_i;
+ int i = -1;
+ int ly = -1;
+ int last_ly, last_i;
int pos = 0;
char *name;
double width = 0.0;
@@ -461,7 +463,7 @@ static bool out_pdf_chord_is_enough_space(struct ChoLine *line, struct ChoChord
free(name);
double prev_chord_width = pdfioContentTextMeasure(font_obj, prev_chord->chord, chord_font->size);
if (prev_chord_width > width_between_chords) {
- space->amount = prev_chord_width - width_between_chords;
+ space->amount = prev_chord_width - width_between_chords + MIN_CHORD_GAP_WIDTH;
return false;
}
return true;
diff --git a/out_pdf.h b/out_pdf.h
@@ -4,6 +4,7 @@
#define MEDIABOX_WIDTH 631.0
#define PADDING 80.0
#define LINE_LEN MEDIABOX_WIDTH - PADDING * 2
+#define MIN_CHORD_GAP_WIDTH 5.0
enum Alignment {
LEFT,
diff --git a/todo b/todo
@@ -3,7 +3,6 @@ apply config in cho_parse() instead of out_pdf_new()
decide how to implement
metadata directives
%{blabla}
-font, size, colour directives
'image' directive; decide if implement
https://chordpro.org/chordpro/directives-image/
chordpro markup
@@ -16,3 +15,4 @@ 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
+ font, size, colour directives