commit e75e94315d50f3f216abbdeb5379dc7f8362a8ae
parent 1fca32b60fd464d3f08ee9424e364497474cb1db
Author: nibo <nibo@relim.de>
Date: Mon, 18 Nov 2024 18:04:01 +0100
Improve variable naming
Diffstat:
| M | out_pdf.c | | | 60 | ++++++++++++++++++++++++++++++------------------------------ |
| M | out_pdf.h | | | 17 | ++++++----------- |
2 files changed, 36 insertions(+), 41 deletions(-)
diff --git a/out_pdf.c b/out_pdf.c
@@ -11,11 +11,11 @@
#include "util.h"
static struct Obj **g_fonts = NULL;
+static char g_cho_dirpath[PATH_MAX];
static char g_current_font_name[200];
static double g_current_font_size;
static pdfio_obj_t *g_current_font_obj = NULL;
-static char g_cho_dirpath[PATH_MAX];
-static pdfio_file_t *pdf_file = NULL;
+static pdfio_file_t *g_pdf_file = NULL;
static pdfio_obj_t *
out_pdf_fnt_obj_get_by_name(const char *name)
@@ -511,7 +511,7 @@ annot_add(struct PDFContext *ctx, struct Style *style, double width)
rect.x2 = ctx->x + width;
rect.y1 = ctx->y - 2.0;
rect.y2 = ctx->y + style->font->size * 0.8;
- annot = pdfioDictCreate(pdf_file);
+ annot = pdfioDictCreate(g_pdf_file);
if (!pdfioDictSetName(annot, "Subtype", "Link")) {
LOG_DEBUG("pdfioDictSetName failed.");
return false;
@@ -520,7 +520,7 @@ annot_add(struct PDFContext *ctx, struct Style *style, double width)
LOG_DEBUG("pdfioDictSetRect failed.");
return false;
}
- action = pdfioDictCreate(pdf_file);
+ action = pdfioDictCreate(g_pdf_file);
if (!pdfioDictSetName(action, "S", "URI")) {
LOG_DEBUG("pdfioDictSetName failed.");
return false;
@@ -557,7 +557,7 @@ out_pdf_set_title(pdfio_file_t *pdf, struct ChoSong **songs)
}
static pdfio_stream_t *
-out_pdf_page_create(pdfio_file_t *pdf, struct Image **imgs, pdfio_array_t *annots)
+out_pdf_page_create(pdfio_file_t *pdf, struct PDFImage **imgs, pdfio_array_t *annots)
{
pdfio_dict_t *page_dict;
pdfio_stream_t *page_stream;
@@ -861,10 +861,10 @@ line_width_until_text_above(
return width;
}
-static struct Image *
-image_new(void)
+static struct PDFImage *
+pdf_image_new(void)
{
- struct Image *image = malloc(sizeof(struct Image));
+ struct PDFImage *image = malloc(sizeof(struct PDFImage));
image->x = 0.0;
image->y = 0.0;
image->width = 0.0;
@@ -875,7 +875,7 @@ image_new(void)
}
static void
-image_free(struct Image *image)
+pdf_image_free(struct PDFImage *image)
{
if (!image) {
return;
@@ -912,7 +912,7 @@ pdf_page_new()
struct PDFPage *page = malloc(sizeof(struct PDFPage));
page->texts = NULL;
page->images = NULL;
- page->annots = pdfioArrayCreate(pdf_file);
+ page->annots = pdfioArrayCreate(g_pdf_file);
return page;
}
@@ -923,7 +923,7 @@ pdf_page_free(struct PDFPage *page)
return;
}
struct PDFText **t;
- struct Image **i;
+ struct PDFImage **i;
t = page->texts;
if (t) {
while (*t) {
@@ -935,7 +935,7 @@ pdf_page_free(struct PDFPage *page)
i = page->images;
if (i) {
while (*i) {
- image_free(*i);
+ pdf_image_free(*i);
i++;
}
free(page->images);
@@ -1392,7 +1392,7 @@ pdf_content_create(
struct ChoSection **se;
struct ChoLine **li;
struct PDFText ***texts;
- struct Image ***imgs;
+ struct PDFImage ***imgs;
struct PDFContext ctx;
double width, height;
ctx.x = MARGIN_HORIZONTAL;
@@ -1557,7 +1557,7 @@ pdf_content_create(
}
*texts = realloc(*texts, (ctx.text+1) * sizeof(struct PDFText *));
(*texts)[ctx.text] = NULL;
- *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct Image *));
+ *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct PDFImage *));
(*imgs)[ctx.image] = NULL;
ctx.text = 0;
ctx.image = 0;
@@ -1589,8 +1589,8 @@ pdf_content_create(
if ((*left_items)->is_text) {
pdf_texts_add_lyrics(*left_items, &ctx, i);
} else {
- *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct Image *));
- (*imgs)[ctx.image] = image_new();
+ *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct PDFImage *));
+ (*imgs)[ctx.image] = pdf_image_new();
(*imgs)[ctx.image]->name = image_name((*left_items)->u.image);
(*imgs)[ctx.image]->obj = objs_get_obj(img_objs, (*imgs)[ctx.image]->name);
if (!(*imgs)[ctx.image]->obj) {
@@ -1619,8 +1619,8 @@ pdf_content_create(
} else
if (pos->line_item_index != -1 && pos->text_index == -1) {
if (!(*left_items)->is_text) {
- *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct Image *));
- (*imgs)[ctx.image] = image_new();
+ *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct PDFImage *));
+ (*imgs)[ctx.image] = pdf_image_new();
(*imgs)[ctx.image]->name = image_name((*left_items)->u.image);
(*imgs)[ctx.image]->obj = objs_get_obj(img_objs, (*imgs)[ctx.image]->name);
if (!(*imgs)[ctx.image]->obj) {
@@ -1639,7 +1639,7 @@ pdf_content_create(
if (ctx.y < MARGIN_BOTTOM) {
*texts = realloc(*texts, (ctx.text+1) * sizeof(struct PDFText *));
(*texts)[ctx.text] = NULL;
- *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct Image *));
+ *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct PDFImage *));
(*imgs)[ctx.image] = NULL;
ctx.text = 0;
ctx.image = 0;
@@ -1659,7 +1659,7 @@ pdf_content_create(
if ((*li)->btype == BT_PAGE) {
*texts = realloc(*texts, (ctx.text+1) * sizeof(struct PDFText *));
(*texts)[ctx.text] = NULL;
- *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct Image *));
+ *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct PDFImage *));
(*imgs)[ctx.image] = NULL;
ctx.text = 0;
ctx.image = 0;
@@ -1679,7 +1679,7 @@ pdf_content_create(
}
*texts = realloc(*texts, (ctx.text+1) * sizeof(struct PDFText *));
(*texts)[ctx.text] = NULL;
- *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct Image *));
+ *imgs = realloc(*imgs, (ctx.image+1) * sizeof(struct PDFImage *));
(*imgs)[ctx.image] = NULL;
ctx.page++;
ctx.content->pages = realloc(ctx.content->pages, (ctx.page+1) * sizeof(struct PDFPage *));
@@ -1709,7 +1709,7 @@ pdf_content_render(struct PDFContent *content, pdfio_file_t *file)
{
struct PDFPage **pages;
struct PDFText **texts;
- struct Image **imgs;
+ struct PDFImage **imgs;
pdfio_stream_t *stream;
pages = content->pages;
while (*pages) {
@@ -1768,8 +1768,8 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
struct Obj **img_objs = NULL;
pdfio_rect_t media_box_a4 = { 0.0, 0.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT };
pdfio_rect_t crop_box = { 0.0, 0.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT };
- pdf_file = pdfioFileCreate(pdf_filename, "2.0", &media_box_a4, &crop_box, NULL, NULL);
- if (!out_pdf_set_title(pdf_file, songs)) {
+ g_pdf_file = pdfioFileCreate(pdf_filename, "2.0", &media_box_a4, &crop_box, NULL, NULL);
+ if (!out_pdf_set_title(g_pdf_file, songs)) {
LOG_DEBUG("out_pdf_set_title failed.");
return NULL;
}
@@ -1782,7 +1782,7 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
if (fontpath) {
fnt = obj_new();
fnt->name = out_pdf_fnt_name_create(needed_fonts[f]);
- fnt->value = pdfioFileCreateFontObjFromFile(pdf_file, fontpath, true);
+ fnt->value = pdfioFileCreateFontObjFromFile(g_pdf_file, fontpath, true);
objs_add_obj(&g_fonts, fnt);
free(fontpath);
} else {
@@ -1790,7 +1790,7 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
if (fontpath) {
fnt = obj_new();
fnt->name = out_pdf_fnt_name_create(needed_fonts[f]);
- fnt->value = pdfioFileCreateFontObjFromFile(pdf_file, fontpath, true);
+ fnt->value = pdfioFileCreateFontObjFromFile(g_pdf_file, fontpath, true);
objs_add_obj(&g_fonts, fnt);
free(fontpath);
} else {
@@ -1802,7 +1802,7 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
f++;
}
cho_fonts_free(needed_fonts);
- if (!out_pdf_load_images(&img_objs, pdf_file, songs)) {
+ if (!out_pdf_load_images(&img_objs, g_pdf_file, songs)) {
LOG_DEBUG("out_pdf_load_images failed.");
return NULL;
}
@@ -1811,17 +1811,17 @@ out_pdf_create(const char *cho_filepath, const char *output_folder_or_file, stru
LOG_DEBUG("pdf_content_create failed.");
return NULL;
}
- if (!pdf_content_render(pdf_content, pdf_file)) {
+ if (!pdf_content_render(pdf_content, g_pdf_file)) {
LOG_DEBUG("pdf_content_render failed.");
return NULL;
}
objs_free(img_objs);
pdf_content_free(pdf_content);
- if (!pdfioFileClose(pdf_file)) {
+ if (!pdfioFileClose(g_pdf_file)) {
LOG_DEBUG("pdfioFileClose failed.");
return NULL;
}
- pdf_file = NULL;
+ g_pdf_file = NULL;
objs_free(g_fonts);
g_fonts = NULL;
return pdf_filename;
diff --git a/out_pdf.h b/out_pdf.h
@@ -13,9 +13,10 @@
#define PATH_MAX 4096
-struct Fnt {
- char *name;
- pdfio_obj_t *font;
+enum LineLocation {
+ LL_OVER,
+ LL_STRIKETHROUGH,
+ LL_UNDER
};
struct Obj {
@@ -35,7 +36,7 @@ struct CharPosition {
int text_index;
};
-struct Image {
+struct PDFImage {
double x;
double y;
double width;
@@ -53,7 +54,7 @@ struct PDFText {
struct PDFPage {
struct PDFText **texts;
- struct Image **images;
+ struct PDFImage **images;
pdfio_array_t *annots;
};
@@ -61,12 +62,6 @@ struct PDFContent {
struct PDFPage **pages;
};
-enum LineLocation {
- LL_OVER,
- LL_STRIKETHROUGH,
- LL_UNDER
-};
-
struct PDFContext {
struct PDFContent *content;
double x;