commit 000c4c1402b1029617451ce0bb74b3fcdacc39ca
parent baa5020439fd6c22c05c88bf0ccd3526d7ecb888
Author: nibo <nibo@relim.de>
Date: Mon, 30 Jun 2025 13:32:55 +0200
Replace global variable with struct member variable
This allows calling 'out_pdf_create' from multiple
threads at the same time.
Diffstat:
3 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/src/chord_diagram.c b/src/chord_diagram.c
@@ -9,13 +9,6 @@
#include "chord_diagram.h"
#include "diagrams.h"
-static bool g_is_base_font = false;
-
-void chord_diagram_set_base_font(bool is_base_font)
-{
- g_is_base_font = is_base_font;
-}
-
static bool
text_show(
pdfio_stream_t *stream,
@@ -473,7 +466,7 @@ string_diagram_draw(
fprintf(stderr, "pdfioContentSetTextFont failed.\n");
return false;
}
- if (!text_show(stream, !g_is_base_font, base_position, base_pos_x, y+field_width*3+field_width*0.1)) {
+ if (!text_show(stream, !ctx->diagram_font_is_base_font, base_position, base_pos_x, y+field_width*3+field_width*0.1)) {
fprintf(stderr, "text_show failed.\n");
return false;
}
@@ -519,10 +512,7 @@ string_diagram_draw(
fprintf(stderr, "pdfioContentSetTextFont failed.\n");
return false;
}
- if (g_is_base_font) {
- centered_x -= width / 10.0;
- }
- if (!text_show(stream, !g_is_base_font, diagram->name, x+centered_x, y_above_diagram + 7.0)) {
+ if (!text_show(stream, !ctx->diagram_font_is_base_font, diagram->name, x+centered_x, y_above_diagram + 7.0)) {
fprintf(stderr, "text_show failed.\n");
return false;
}
diff --git a/src/out_pdf.c b/src/out_pdf.c
@@ -331,7 +331,7 @@ pdf_load_chord_diagram_fonts(struct PDFContext *ctx)
fnt->name = strdup("chord-diagram-regular-font");
if ((font_name = is_base_font(&font))) {
fnt->value = pdfioFileCreateFontObjFromBase(ctx->pdf_file, font_name);
- chord_diagram_set_base_font(true);
+ ctx->diagram_font_is_base_font = true;
} else {
fontpath = fontpath_find(&font, FT_TTF);
if (!fontpath) {
@@ -2854,6 +2854,7 @@ out_pdf_create(
pdfio_rect_t crop_box = { 0.0, 0.0, MEDIABOX_WIDTH, MEDIABOX_HEIGHT };
char *dirpath, *pdf_filepath;
+ ctx.diagram_font_is_base_font = false;
ctx.fonts = NULL;
ctx.config = config;
ctx.current_page_index = 0;
diff --git a/src/out_pdf.h b/src/out_pdf.h
@@ -106,6 +106,7 @@ struct PDFContext {
int current_page_index;
char cho_dirpath[PATH_MAX];
char current_font_name[200];
+ bool diagram_font_is_base_font;
struct PDFContentContext t_ctx; // INFO: context for pdf_toc_create()
struct PDFContentContext b_ctx; // INFO: context for pdf_body_create()
};