lorid

convert chordpro to pdf
git clone git://git.relim.de/lorid.git
Log | Files | Refs | README | LICENSE

commit 874456f641efd2f86160ae6d735ec16bcf481858
parent e50dda0ca0d012a671074546df083f51c743b694
Author: nibo <nibo@relim.de>
Date:   Sun,  1 Dec 2024 12:26:43 +0100

Refactor enums in general

Diffstat:
Mchordpro.c | 260+++++++++++++++++++++++++++++++++++--------------------------------------------
Mchordpro.h | 39+++++----------------------------------
Mout_pdf.c | 72+++++++++++++++++++++++++++++++++++-------------------------------------
3 files changed, 156 insertions(+), 215 deletions(-)

diff --git a/chordpro.c b/chordpro.c @@ -12,49 +12,6 @@ #include "config.h" #include "util.h" -static const char *environment_directives[] = { - "start_of_chorus", "soc", "end_of_chorus", "eoc", "chorus", - "start_of_verse", "sov", "end_of_verse", "eov", - "start_of_bridge", "sob", "end_of_bridge", "eob", - "start_of_tab", "sot", "end_of_tab", "eot", - "start_of_grid", "sog", "end_of_grid", "eog", NULL -}; - -static const char *metadata_directives[] = { - "title", "t", "subtitle", "st", "sorttitle", - "artist", "composer", "lyricist", - "copyright", "album", "year", "key", - "time", "tempo", "duration", "capo", - "meta", "arranger", NULL -}; - -static const char *formatting_directives[] = { - "comment", "c", "highlight", "comment_italic", "ci", - "comment_box", "cb", NULL -}; - -static const char *image_directives[] = { "image", NULL }; -static const char *preamble_directives[] = { "new_song", "ns", NULL }; - -static const char *font_directives[] = { - "chordfont", "cf", "chordsize", "cs", "chordcolour", - "chorusfont", "chorussize", "choruscolour", - "gridfont", "gridsize", "gridcolour", - "tabfont", "tabsize", "tabcolour", - "textfont", "tf", "textsize", "ts", "textcolour", - "titlefont", "titlesize", "titlecolour", NULL - /* "footerfont", "footersize", "footercolour", - "tocfont", "tocsize", "toccolour", */ -}; - -static const char *chord_directives[] = { - "transpose", "define", /* "chord", */ NULL -}; - -static const char *output_directives[] = { - "new_page", "np", "column_break", "colb", NULL -}; - static const char *font_families[] = { "normal", "sans", "serif", "monospace", "empty" }; static const char *font_styles[] = { "normal", "oblique", "italic", "empty" }; static const char *font_weights[] = { "normal", "bold", "empty" }; @@ -77,22 +34,22 @@ static const char *state_enums[] = { struct StyleProperty default_style_properties[18] = { { SF_CHORD, SPT_FONT, { .font_name = NULL } }, - { SF_CHORD, SPT_SIZE, { .font_size = EMPTY } }, + { SF_CHORD, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, { SF_CHORD, SPT_COLOR, { .foreground_color = NULL } }, { SF_CHORUS, SPT_FONT, { .font_name = NULL } }, - { SF_CHORUS, SPT_SIZE, { .font_size = EMPTY } }, + { SF_CHORUS, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, { SF_CHORUS, SPT_COLOR, { .foreground_color = NULL } }, { SF_GRID, SPT_FONT, { .font_name = NULL } }, - { SF_GRID, SPT_SIZE, { .font_size = EMPTY } }, + { SF_GRID, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, { SF_GRID, SPT_COLOR, { .foreground_color = NULL } }, { SF_TAB, SPT_FONT, { .font_name = NULL } }, - { SF_TAB, SPT_SIZE, { .font_size = EMPTY } }, + { SF_TAB, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, { SF_TAB, SPT_COLOR, { .foreground_color = NULL } }, { SF_TEXT, SPT_FONT, { .font_name = NULL } }, - { SF_TEXT, SPT_SIZE, { .font_size = EMPTY } }, + { SF_TEXT, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, { SF_TEXT, SPT_COLOR, { .foreground_color = NULL } }, { SF_TITLE, SPT_FONT, { .font_name = NULL } }, - { SF_TITLE, SPT_SIZE, { .font_size = EMPTY } }, + { SF_TITLE, SPT_SIZE, { .font_size = EMPTY_DOUBLE } }, { SF_TITLE, SPT_COLOR, { .foreground_color = NULL } }, }; @@ -810,7 +767,7 @@ cho_style_property_apply_default(enum SongFragmentType current_ftype, enum Style } break; case SPT_SIZE: - if (default_style_properties[i].u.font_size != EMPTY) { + if (default_style_properties[i].u.font_size != EMPTY_DOUBLE) { style->font->size = default_style_properties[i].u.font_size; return true; } else { @@ -989,55 +946,55 @@ cho_style_font_desc_parse(const char *str) words = erealloc(words, (w+1) * sizeof(char *)); words[w] = NULL; w = 0; - int stop_at = EMPTY; + int stop_at = EMPTY_INT; while (words[w] != NULL) { if (strcasecmp(words[w], "italic") == 0) { font->style = FS_ITALIC; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; } else if (strcasecmp(words[w], "bold") == 0) { font->weight = FW_BOLD; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; } else if (strcasecmp(words[w], "oblique") == 0) { font->style = FS_OBLIQUE; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; // TODO: Is that smart? } else if (strcasecmp(words[w], "regular") == 0) { font->weight = FW_REGULAR; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; // TODO: Is that smart? } else if (strcasecmp(words[w], "normal") == 0) { font->style = FS_ROMAN; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) 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 == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; } else if (strcasecmp(words[w], "serif") == 0) { font->family = FF_SERIF; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; */ } else if (strcasecmp(words[w], "monospace") == 0) { font->family = FF_MONOSPACE; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; } else { size = strtod(words[w], NULL); if (size == 0.0) goto SKIP; font->size = size; - if (stop_at == EMPTY) + if (stop_at == EMPTY_INT) stop_at = w; } SKIP: w++; } - if (stop_at == EMPTY) { + if (stop_at == EMPTY_INT) { stop_at = w; } k = 0; @@ -1409,7 +1366,7 @@ cho_style_reset_default(void) default_style_properties[i].u.font_name = NULL; return true; case SPT_SIZE: - default_style_properties[i].u.font_size = EMPTY; + default_style_properties[i].u.font_size = EMPTY_DOUBLE; return true; case SPT_COLOR: free(default_style_properties[i].u.foreground_color); @@ -2048,7 +2005,7 @@ cho_image_new(void) image->width_scale = NULL; image->height_scale = NULL; image->align = A_CENTER; - image->border = EMPTY; + image->border = EMPTY_DOUBLE; image->spread_space = NULL; image->href = NULL; image->x = NULL; @@ -2963,7 +2920,7 @@ cho_directive_new(void) directive->sprop = SPT_EMPTY; directive->ftype = SF_EMPTY; directive->btype = BT_EMPTY; - directive->meta = OTHER; + directive->meta = -1; directive->ctype = -1; directive->style = cho_style_new_default(); return directive; @@ -2983,10 +2940,9 @@ static struct ChoDirective * cho_directive_parse(const char *name) { struct ChoDirective *directive = cho_directive_new(); - int i = 0; if ( - !strcmp(name, environment_directives[START_OF_CHORUS]) || - !strcmp(name, environment_directives[SOC]) + !strcmp(name, "start_of_chorus") || + !strcmp(name, "soc") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; @@ -2994,21 +2950,21 @@ cho_directive_parse(const char *name) directive->ftype = SF_CHORUS; goto END; } else if ( - !strcmp(name, environment_directives[END_OF_CHORUS]) || - !strcmp(name, environment_directives[EOC]) + !strcmp(name, "end_of_chorus") || + !strcmp(name, "eoc") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; directive->stype = ST_CHORUS; directive->ftype = SF_TEXT; goto END; - } else if (!strcmp(name, environment_directives[CHORUS])) { + } else if (!strcmp(name, "chorus")) { directive->dtype = DT_ENVIRONMENT; directive->ftype = SF_LABEL; goto END; } else if ( - !strcmp(name, environment_directives[START_OF_VERSE]) || - !strcmp(name, environment_directives[SOV]) + !strcmp(name, "start_of_verse") || + !strcmp(name, "sov") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; @@ -3016,8 +2972,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_TEXT; goto END; } else if ( - !strcmp(name, environment_directives[END_OF_VERSE]) || - !strcmp(name, environment_directives[EOV]) + !strcmp(name, "end_of_verse") || + !strcmp(name, "eov") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; @@ -3025,8 +2981,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_TEXT; goto END; } else if ( - !strcmp(name, environment_directives[START_OF_BRIDGE]) || - !strcmp(name, environment_directives[SOB]) + !strcmp(name, "start_of_bridge") || + !strcmp(name, "sob") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; @@ -3034,8 +2990,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_TEXT; goto END; } else if ( - !strcmp(name, environment_directives[END_OF_BRIDGE]) || - !strcmp(name, environment_directives[EOB]) + !strcmp(name, "end_of_bridge") || + !strcmp(name, "eob") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; @@ -3043,8 +2999,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_TEXT; goto END; } else if ( - !strcmp(name, environment_directives[START_OF_TAB]) || - !strcmp(name, environment_directives[SOT]) + !strcmp(name, "start_of_tab") || + !strcmp(name, "sot") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; @@ -3052,8 +3008,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_TAB; goto END; } else if ( - !strcmp(name, environment_directives[END_OF_TAB]) || - !strcmp(name, environment_directives[EOT]) + !strcmp(name, "end_of_tab") || + !strcmp(name, "eot") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; @@ -3061,8 +3017,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_TEXT; goto END; } else if ( - !strcmp(name, environment_directives[START_OF_GRID]) || - !strcmp(name, environment_directives[SOG]) + !strcmp(name, "start_of_grid") || + !strcmp(name, "sog") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_START; @@ -3070,8 +3026,8 @@ cho_directive_parse(const char *name) directive->ftype = SF_GRID; goto END; } else if ( - !strcmp(name, environment_directives[END_OF_GRID]) || - !strcmp(name, environment_directives[EOG]) + !strcmp(name, "end_of_grid") || + !strcmp(name, "eog") ) { directive->dtype = DT_ENVIRONMENT; directive->position = POS_END; @@ -3080,8 +3036,8 @@ cho_directive_parse(const char *name) goto END; } if ( - !strcmp(name, metadata_directives[TITLE]) || - !strcmp(name, metadata_directives[T]) + !strcmp(name, "title") || + !strcmp(name, "t") ) { directive->dtype = DT_METADATA; directive->meta = TITLE; @@ -3093,8 +3049,8 @@ cho_directive_parse(const char *name) goto END; } else if ( - !strcmp(name, metadata_directives[SUBTITLE]) || - !strcmp(name, metadata_directives[ST]) + !strcmp(name, "subtitle") || + !strcmp(name, "st") ) { directive->dtype = DT_METADATA; directive->meta = SUBTITLE; @@ -3105,172 +3061,188 @@ cho_directive_parse(const char *name) g_current_ftype = g_prev_ftype; goto END; } - i = 4; - while (metadata_directives[i] != NULL) { - if (!strcmp(metadata_directives[i], name)) { - directive->dtype = DT_METADATA; - goto END; - } - i++; + if ( + !strcmp(name, "artist") || + !strcmp(name, "composer") || + !strcmp(name, "lyricist") || + !strcmp(name, "copyright") || + !strcmp(name, "album") || + !strcmp(name, "year") || + !strcmp(name, "key") || + !strcmp(name, "time") || + !strcmp(name, "tempo") || + !strcmp(name, "duration") || + !strcmp(name, "capo") || + !strcmp(name, "meta") || + !strcmp(name, "arranger") + ) { + directive->dtype = DT_METADATA; + goto END; } - i = 0; if ( - !strcmp(formatting_directives[COMMENT], name) || - !strcmp(formatting_directives[C], name) || - !strcmp(formatting_directives[HIGHLIGHT], name) + !strcmp(name, "comment") || + !strcmp(name, "c") || + !strcmp(name, "highlight") ) { directive->style->background_color = cho_rgbcolor_new(228, 228, 228); directive->dtype = DT_FORMATTING; goto END; } else if ( - !strcmp(formatting_directives[COMMENT_ITALIC], name) || - !strcmp(formatting_directives[CI], name) + !strcmp(name, "comment_italic") || + !strcmp(name, "ci") ) { directive->style->font->style = FS_ITALIC; directive->dtype = DT_FORMATTING; goto END; } else if ( - !strcmp(formatting_directives[COMMENT_BOX], name) || - !strcmp(formatting_directives[CB], name) + !strcmp(name, "comment_box") || + !strcmp(name, "cb") ) { directive->style->boxed = true; directive->dtype = DT_FORMATTING; goto END; } - if (!strcmp(image_directives[IMAGE], name)) { + if (!strcmp(name, "image")) { directive->dtype = DT_IMAGE; goto END; } - while (preamble_directives[i] != NULL) { - if (!strcmp(preamble_directives[i], name)) { - directive->dtype = DT_PREAMBLE; - directive->stype = ST_NEWSONG; - goto END; - } - i++; + if ( + !strcmp(name, "new_song") || + !strcmp(name, "ns") + ) { + directive->dtype = DT_PREAMBLE; + directive->stype = ST_NEWSONG; + goto END; } if ( - !strcmp(font_directives[CHORDFONT], name) || - !strcmp(font_directives[CF], name) + !strcmp(name, "chordfont") || + !strcmp(name, "cf") ) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; directive->ftype = SF_CHORD; goto END; } else if ( - !strcmp(font_directives[CHORDSIZE], name) || - !strcmp(font_directives[CS], name) + !strcmp(name, "chordsize") || + !strcmp(name, "cs") ) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; directive->ftype = SF_CHORD; goto END; - } else if (!strcmp(font_directives[CHORDCOLOR], name)) { + } else if (!strcmp(name, "chordcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; directive->ftype = SF_CHORD; goto END; - } else if (!strcmp(font_directives[CHORUSFONT], name)) { + } else if (!strcmp(name, "chorusfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; directive->ftype = SF_CHORUS; goto END; - } else if (!strcmp(font_directives[CHORUSSIZE], name)) { + } else if (!strcmp(name, "chorussize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; directive->ftype = SF_CHORUS; goto END; - } else if (!strcmp(font_directives[CHORUSCOLOR], name)) { + } else if (!strcmp(name, "choruscolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; directive->ftype = SF_CHORUS; goto END; - } else if (!strcmp(font_directives[GRIDFONT], name)) { + } else if (!strcmp(name, "gridfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; directive->ftype = SF_GRID; goto END; - } else if (!strcmp(font_directives[GRIDSIZE], name)) { + } else if (!strcmp(name, "gridsize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; directive->ftype = SF_GRID; goto END; - } else if (!strcmp(font_directives[GRIDCOLOR], name)) { + } else if (!strcmp(name, "gridcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; directive->ftype = SF_GRID; goto END; - } else if (!strcmp(font_directives[TABFONT], name)) { + } else if (!strcmp(name, "tabfont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; directive->ftype = SF_TAB; goto END; - } else if (!strcmp(font_directives[TABSIZE], name)) { + } else if (!strcmp(name, "tabsize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; directive->ftype = SF_TAB; goto END; - } else if (!strcmp(font_directives[TABCOLOR], name)) { + } else if (!strcmp(name, "tabcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; directive->ftype = SF_TAB; goto END; } else if ( - !strcmp(font_directives[TEXTFONT], name) || - !strcmp(font_directives[TF], name) + !strcmp(name, "textfont") || + !strcmp(name, "tf") ) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; directive->ftype = SF_TEXT; goto END; } else if ( - !strcmp(font_directives[TEXTSIZE], name) || - !strcmp(font_directives[TS], name) + !strcmp(name, "textsize") || + !strcmp(name, "ts") ) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; directive->ftype = SF_TEXT; goto END; - } else if (!strcmp(font_directives[TEXTCOLOR], name)) { + } else if (!strcmp(name, "textcolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; directive->ftype = SF_TEXT; goto END; - } else if (!strcmp(font_directives[TITLEFONT], name)) { + } else if (!strcmp(name, "titlefont")) { directive->dtype = DT_FONT; directive->sprop = SPT_FONT; directive->ftype = SF_TITLE; goto END; - } else if (!strcmp(font_directives[TITLESIZE], name)) { + } else if (!strcmp(name, "titlesize")) { directive->dtype = DT_FONT; directive->sprop = SPT_SIZE; directive->ftype = SF_TITLE; goto END; - } else if (!strcmp(font_directives[TITLECOLOR], name)) { + } else if (!strcmp(name, "titlecolour")) { directive->dtype = DT_FONT; directive->sprop = SPT_COLOR; directive->ftype = SF_TITLE; goto END; - } - if (!strcmp(chord_directives[TRANSPOSE], name)) { + } /* else if (!strcmp(name, "footerfont")) { + } else if (!strcmp(name, "footersize")) { + } else if (!strcmp(name, "footercolour")) { + } else if (!strcmp(name, "tocfont")) { + } else if (!strcmp(name, "tocsize")) { + } else if (!strcmp(name, "toccolour")) { + } */ + if (!strcmp(name, "transpose")) { directive->dtype = DT_CHORD; directive->ctype = TRANSPOSE; goto END; - } else if (!strcmp(chord_directives[DEFINE], name)) { + } else if (!strcmp(name, "define")) { directive->dtype = DT_CHORD; directive->ctype = DEFINE; goto END; - } + } /* else if (!strcmp(name, "chord")) { + } */ if ( - !strcmp(output_directives[NEW_PAGE], name) || - !strcmp(output_directives[NP], name) + !strcmp(name, "new_page") || + !strcmp(name, "np") ) { directive->dtype = DT_OUTPUT; directive->btype = BT_PAGE; goto END; } else if ( - !strcmp(output_directives[COLUMN_BREAK], name) || - !strcmp(output_directives[COLB], name) + !strcmp(name, "column_break") || + !strcmp(name, "colb") ) { directive->dtype = DT_OUTPUT; directive->btype = BT_COLUMN; @@ -3723,7 +3695,7 @@ cho_songs_parse(FILE *fp, const char *chordpro_filepath, struct Config *config) sprop.u.font_name = NULL; break; case SPT_SIZE: - sprop.u.font_size = EMPTY; + sprop.u.font_size = EMPTY_DOUBLE; break; case SPT_COLOR: sprop.u.foreground_color = NULL; diff --git a/chordpro.h b/chordpro.h @@ -3,53 +3,24 @@ #ifndef _CHORDPRO_H_ #define _CHORDPRO_H_ -#define EMPTY -1.0 +#define ERROR -1.0 +#define EMPTY_DOUBLE -1.0 +#define EMPTY_INT -1 #define DEFAULT_FONT_SIZE 14.0 #define DEFAULT_TITLE_FONT_SIZE 18.0 // INFO: Based on https://stackoverflow.com/a/417184 #define URL_MAX_LEN 2000 #define FONT_NAME_MAX 100 -enum EnvironmentDirective { - START_OF_CHORUS, SOC, END_OF_CHORUS, EOC, CHORUS, - START_OF_VERSE, SOV, END_OF_VERSE, EOV, - START_OF_BRIDGE, SOB, END_OF_BRIDGE, EOB, - START_OF_TAB, SOT, END_OF_TAB, EOT, - START_OF_GRID, SOG, END_OF_GRID, EOG -}; - enum MetadataDirective { - TITLE, T, SUBTITLE, ST, OTHER -}; - -enum FormattingDirective { - COMMENT, C, HIGHLIGHT, COMMENT_ITALIC, CI, - COMMENT_BOX, CB -}; - -enum ImageDirectve { - IMAGE -}; - -enum FontDirective { - CHORDFONT, CF, CHORDSIZE, CS, CHORDCOLOR, - CHORUSFONT, CHORUSSIZE, CHORUSCOLOR, - GRIDFONT, GRIDSIZE, GRIDCOLOR, - TABFONT, TABSIZE, TABCOLOR, - TEXTFONT, TF, TEXTSIZE, TS, TEXTCOLOR, - TITLEFONT, TITLESIZE, TITLECOLOR, - /* FOOTERFONT, FOOTERSIZE, FOOTERCOLOR, - TOCFONT, TOCSIZE, TOCCOLOR */ + TITLE, + SUBTITLE }; enum ChordDirective { TRANSPOSE, DEFINE /* , CHORD */ }; -enum OutputDirective { - NEW_PAGE, NP, COLUMN_BREAK, COLB -}; - enum FontFamily { FF_NORMAL, FF_SANS, diff --git a/out_pdf.c b/out_pdf.c @@ -331,16 +331,16 @@ text_above_width(struct ChoLineItemAbove *above) if (above->is_chord) { name = cho_chord_name_generate(above->u.chord); width = text_width(name, above->u.chord->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); - return EMPTY; + return ERROR; } free(name); } else { width = text_width(above->u.annot->text, above->u.annot->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); - return EMPTY; + return ERROR; } } return width; @@ -371,13 +371,13 @@ text_find_fitting(const char *str, struct ChoStyle *style, double x) i = find_whitespace((const char *)&tmp, start); if (i == -1) { util_log(LOG_ERR, "Can't split text because no whitespace was found."); - return EMPTY; + return ERROR; } tmp[i] = 0; width = text_width((const char *)&tmp, style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); - return EMPTY; + return ERROR; } start = i - 1; } while (x + width > LINE_WIDTH); @@ -433,7 +433,7 @@ out_pdf_text_show(pdfio_stream_t *stream, struct PDFText *text) double red, green, blue, width; // TODO: Maybe store the width in PDFText!? width = text_width(text->text, text->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -857,10 +857,8 @@ line_width_until_text_above( struct SpaceNeeded *space ) { - int i = EMPTY; - int k = EMPTY; - int save_i = EMPTY; - int save_k = EMPTY; + int i, save_i, save_k; + int k = EMPTY_INT; int pos = 0; double width = 0.0; char *name; @@ -894,7 +892,7 @@ line_width_until_text_above( font_obj = out_pdf_fnt_obj_get_by_name(name); if (!font_obj) { LOG_DEBUG("out_pdf_fnt_obj_get_by_name failed."); - return EMPTY; + return ERROR; } if (save_i == i) { char tmp[strlen(text->text)+1]; @@ -910,7 +908,7 @@ line_width_until_text_above( obj = objs_get_obj(img_objs, name); if (!obj) { LOG_DEBUG("objs_get_obj failed."); - return EMPTY; + return ERROR; } width += image_width(items[i]->u.image, obj); free(name); @@ -1040,18 +1038,18 @@ calc_space_between_text_above( double width_until_prev; double prev_width; width_until_cur = line_width_until_text_above(items, text_above[i], img_objs, NULL); - if (width_until_cur == EMPTY) { + if (width_until_cur == ERROR) { LOG_DEBUG("line_width_until_text_above failed."); return false; } i--; width_until_prev = line_width_until_text_above(items, text_above[i], img_objs, &space); - if (width_until_prev == EMPTY) { + if (width_until_prev == ERROR) { LOG_DEBUG("line_width_until_text_above failed."); return false; } prev_width = text_above_width(text_above[i]); - if (prev_width == EMPTY) { + if (prev_width == ERROR) { LOG_DEBUG("text_above_width failed."); return false; } @@ -1079,9 +1077,9 @@ item_width(struct ChoLineItem *item, int i, struct SpaceNeeded **spaces, struct struct SpaceNeeded **s = spaces; if (item->is_text) { width = text_width(item->u.text->text, item->u.text->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); - return EMPTY; + return ERROR; } if (s) { while (*s) { @@ -1097,12 +1095,12 @@ item_width(struct ChoLineItem *item, int i, struct SpaceNeeded **spaces, struct name = image_name(item->u.image); if (!name) { LOG_DEBUG("image_name failed."); - return EMPTY; + return ERROR; } obj = objs_get_obj(img_objs, name); if (!obj) { LOG_DEBUG("objs_get_obj failed."); - return EMPTY; + return ERROR; } free(name); width = image_width(item->u.image, obj); @@ -1118,15 +1116,15 @@ items_find_position_to_break_line( ) { struct CharPosition *pos = emalloc(sizeof(struct CharPosition)); - pos->line_item_index = -1; - pos->text_index = -1; + pos->line_item_index = EMPTY_INT; + pos->text_index = EMPTY_INT; double width = 0.0; double d; struct ChoLineItem **it = items; int i; for (i = 0; it[i]; i++) { d = item_width(it[i], i, spaces, img_objs); - if (d == EMPTY) { + if (d == ERROR) { LOG_DEBUG("item_width failed."); return NULL; } @@ -1138,7 +1136,7 @@ items_find_position_to_break_line( it[i]->u.text->style, width ); - if (pos->text_index == EMPTY) { + if (pos->text_index == EMPTY_INT) { LOG_DEBUG("text_find_fitting failed."); return NULL; } @@ -1173,7 +1171,7 @@ images_find_biggest_height(struct ChoLineItem **left_items, int line_item_index, obj = objs_get_obj(img_objs, name); if (!obj) { LOG_DEBUG("objs_get_obj failed."); - return EMPTY; + return ERROR; } height = image_height((*items)->u.image, obj); if (height > biggest) { @@ -1256,7 +1254,7 @@ pdf_texts_add_lyrics( (*texts)[ctx->text]->x = ctx->x; (*texts)[ctx->text]->y = ctx->y; width = text_width((*texts)[ctx->text]->text, item->u.text->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1287,7 +1285,7 @@ pdf_texts_add_lyrics( (*texts)[ctx->text]->x = ctx->x; (*texts)[ctx->text]->y = ctx->y; width = text_width((*texts)[ctx->text]->text, item->u.text->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1314,7 +1312,7 @@ pdf_texts_add_lyrics( (*texts)[ctx->text]->x = ctx->x; (*texts)[ctx->text]->y = ctx->y; width = text_width((*texts)[ctx->text]->text, item->u.text->style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1357,7 +1355,7 @@ pdf_texts_add_text( strcpy((char *)&str, text); texts = &ctx->content->pages[ctx->page]->texts; width = text_width(text, style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1365,13 +1363,13 @@ pdf_texts_add_text( char *t = (char *)&str; while (width > LINE_WIDTH) { index = text_find_fitting(t, style, 0.0); - if (index == EMPTY) { + if (index == ERROR) { LOG_DEBUG("text_find_fitting failed."); return false; } t[index] = 0; width = text_width(t, style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1392,13 +1390,13 @@ pdf_texts_add_text( ctx->y -= 8.0 + style->font->size; t += index+1; width = text_width(t, style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } } width = text_width(t, style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1546,7 +1544,7 @@ pdf_content_create( int i; for (i = 0; left_aboves[i] && i<text_above_index; i++) { width = line_width_until_text_above(left_items, left_aboves[i], img_objs, NULL); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("line_width_until_text_aboave failed."); return false; } @@ -1574,7 +1572,7 @@ pdf_content_create( (*texts)[ctx.text]->style = style; if (style->href) { width = text_width(string, style); - if (width == EMPTY) { + if (width == ERROR) { LOG_DEBUG("text_width failed."); return false; } @@ -1589,7 +1587,7 @@ pdf_content_create( ctx.text++; } height = images_find_biggest_height(left_items, pos->line_item_index, img_objs); - if (height == EMPTY) { + if (height == ERROR) { LOG_DEBUG("images_find_biggest_height failed."); return false; }