commit 1fca32b60fd464d3f08ee9424e364497474cb1db
parent a76f6b36b9a99ac1135384cd14b1cf4a38ee4c18
Author: nibo <nibo@relim.de>
Date: Mon, 18 Nov 2024 17:54:31 +0100
Get rid of some types
Diffstat:
| M | out_pdf.c | | | 83 | +++++++++++++++++++++++++++---------------------------------------------------- |
| M | out_pdf.h | | | 30 | ------------------------------ |
2 files changed, 28 insertions(+), 85 deletions(-)
diff --git a/out_pdf.c b/out_pdf.c
@@ -10,7 +10,7 @@
#include "fontconfig.h"
#include "util.h"
-static struct Fnt **g_fonts = NULL;
+static struct Obj **g_fonts = NULL;
static char g_current_font_name[200];
static double g_current_font_size;
static pdfio_obj_t *g_current_font_obj = NULL;
@@ -23,7 +23,7 @@ out_pdf_fnt_obj_get_by_name(const char *name)
int i = 0;
while (g_fonts[i] != NULL) {
if (!strcmp(g_fonts[i]->name, name))
- return g_fonts[i]->font;
+ return g_fonts[i]->value;
i++;
}
return NULL;
@@ -241,15 +241,6 @@ out_pdf_filename_create(struct ChoSong **songs, const char *cho_filepath, const
}
}
-static struct Fnt *
-out_pdf_fnt_new(void)
-{
- struct Fnt *fnt = malloc(sizeof(struct Fnt));
- fnt->name = NULL;
- fnt->font = NULL;
- return fnt;
-}
-
static char *
out_pdf_fnt_name_create(struct Font *font)
{
@@ -294,41 +285,6 @@ out_pdf_fnt_name_create(struct Font *font)
return fnt_name;
}
-static void
-out_pdf_fnt_free(struct Fnt *fnt)
-{
- free(fnt->name);
- free(fnt);
-}
-
-static void
-out_pdf_fnts_free(struct Fnt **fnts)
-{
- struct Fnt **start = fnts;
- while (*fnts) {
- out_pdf_fnt_free(*fnts);
- fnts++;
- }
- free(start);
-}
-
-static void
-out_pdf_fnt_add(struct Fnt *fnt, struct Fnt ***array)
-{
- int a = 0;
- if (!*array) {
- *array = realloc(*array, 2 * sizeof(struct Fnt *));
- (*array)[0] = fnt;
- (*array)[1] = NULL;
- } else {
- while ((*array)[a] != NULL)
- a++;
- *array = realloc(*array, (a+2) * sizeof(struct Fnt *));
- (*array)[a] = fnt;
- (*array)[a+1] = NULL;
- }
-}
-
static bool
out_pdf_font_set(pdfio_stream_t *stream, struct Font *font)
{
@@ -625,7 +581,7 @@ out_pdf_page_create(pdfio_file_t *pdf, struct Image **imgs, pdfio_array_t *annot
}
}
for (f = 0; g_fonts[f]; f++) {
- if (!pdfioPageDictAddFont(page_dict, g_fonts[f]->name, g_fonts[f]->font)) {
+ if (!pdfioPageDictAddFont(page_dict, g_fonts[f]->name, g_fonts[f]->value)) {
LOG_DEBUG("pdfioPageDictAddFont failed.");
return NULL;
}
@@ -701,6 +657,23 @@ objs_get_obj(struct Obj **objs, const char *name)
return NULL;
}
+static void
+objs_add_obj(struct Obj ***array, struct Obj *obj)
+{
+ int a = 0;
+ if (!*array) {
+ *array = realloc(*array, 2 * sizeof(struct Obj *));
+ (*array)[0] = obj;
+ (*array)[1] = NULL;
+ } else {
+ while ((*array)[a])
+ a++;
+ *array = realloc(*array, (a+2) * sizeof(struct Obj *));
+ (*array)[a] = obj;
+ (*array)[a+1] = NULL;
+ }
+}
+
static double
image_width(struct ChoImage *image, pdfio_obj_t *obj)
{
@@ -1801,24 +1774,24 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
return NULL;
}
struct Font **needed_fonts = out_pdf_font_get_all(songs, config);
- struct Fnt *fnt;
+ struct Obj *fnt;
int f = 0;
char *fontpath;
while (needed_fonts[f] != NULL) {
fontpath = fontconfig_fontpath_find(needed_fonts[f], FT_TTF);
if (fontpath) {
- fnt = out_pdf_fnt_new();
+ fnt = obj_new();
fnt->name = out_pdf_fnt_name_create(needed_fonts[f]);
- fnt->font = pdfioFileCreateFontObjFromFile(pdf_file, fontpath, true);
- out_pdf_fnt_add(fnt, &g_fonts);
+ fnt->value = pdfioFileCreateFontObjFromFile(pdf_file, fontpath, true);
+ objs_add_obj(&g_fonts, fnt);
free(fontpath);
} else {
fontpath = fontconfig_fontpath_find(needed_fonts[f], FT_OTF);
if (fontpath) {
- fnt = out_pdf_fnt_new();
+ fnt = obj_new();
fnt->name = out_pdf_fnt_name_create(needed_fonts[f]);
- fnt->font = pdfioFileCreateFontObjFromFile(pdf_file, fontpath, true);
- out_pdf_fnt_add(fnt, &g_fonts);
+ fnt->value = pdfioFileCreateFontObjFromFile(pdf_file, fontpath, true);
+ objs_add_obj(&g_fonts, fnt);
free(fontpath);
} else {
util_log(LOG_ERR, "Didn't find font file for following font:");
@@ -1849,7 +1822,7 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
return NULL;
}
pdf_file = NULL;
- out_pdf_fnts_free(g_fonts);
+ objs_free(g_fonts);
g_fonts = NULL;
return pdf_filename;
}
diff --git a/out_pdf.h b/out_pdf.h
@@ -13,13 +13,6 @@
#define PATH_MAX 4096
-// TODO: Find a good way to get rid of this type
-enum Bool {
- B_ERROR = -1,
- B_FALSE,
- B_TRUE
-};
-
struct Fnt {
char *name;
pdfio_obj_t *font;
@@ -42,29 +35,6 @@ struct CharPosition {
int text_index;
};
-struct TextLineItem {
- char *text;
- struct Style *style;
- double x;
-};
-
-struct TextLineMetadata {
- int text_index;
- int text_line_index;
- bool is_lyrics;
-};
-
-struct TextLine {
- struct TextLineItem **items;
- double height;
- enum BreakType btype;
- enum SongFragmentType ftype;
-};
-
-struct Text {
- struct TextLine **lines;
-};
-
struct Image {
double x;
double y;