commit 2a46c89da10c7b09428c83d79a27462a78ad9da8
parent f192af7f4bcf9bf575dbec88402188ddc121e2e1
Author: nibo <nibo@relim.de>
Date: Sat, 15 Feb 2025 20:31:57 +0100
Fix character spacing issue with base font
Diffstat:
4 files changed, 50 insertions(+), 47 deletions(-)
diff --git a/src/chord_diagram.c b/src/chord_diagram.c
@@ -20,6 +20,7 @@ void chord_diagram_set_base_font(bool is_base_font)
static bool
text_show(
pdfio_stream_t *stream,
+ bool unicode,
const char *text,
double x,
double y
@@ -37,7 +38,7 @@ text_show(
fprintf(stderr, "pdfioContentTextMoveTo failed.\n");
return false;
}
- if (!pdfioContentTextShow(stream, true, text)) {
+ if (!pdfioContentTextShow(stream, unicode, text)) {
fprintf(stderr, "pdfioContentTextShow failed.\n");
return false;
}
@@ -286,7 +287,7 @@ draw_circle_with_char_inside(
fprintf(stderr, "pdfioContentSetFillColorRGB failed.\n");
return false;
}
- if (!text_show(stream, "/", x-field_width/2, y-field_width/2.8)) {
+ if (!text_show(stream, true, "/", x-field_width/2, y-field_width/2.8)) {
fprintf(stderr, "text_show failed.");
return false;
}
@@ -294,7 +295,7 @@ draw_circle_with_char_inside(
fprintf(stderr, "pdfioContentSetFillColorRGB failed.\n");
return false;
}
- if (!text_show(stream, (char *)&str, x-field_width/2, y-field_width/2.8)) {
+ if (!text_show(stream, true, (char *)&str, x-field_width/2, y-field_width/2.8)) {
fprintf(stderr, "text_show failed.");
return false;
}
@@ -451,7 +452,7 @@ string_diagram_draw(
fprintf(stderr, "pdfioContentSetTextFont failed.\n");
return false;
}
- if (!text_show(stream, base_position, base_pos_x, y+field_width*3+field_width*0.1)) {
+ if (!text_show(stream, !g_is_base_font, base_position, base_pos_x, y+field_width*3+field_width*0.1)) {
fprintf(stderr, "text_show failed.\n");
return false;
}
@@ -500,7 +501,7 @@ string_diagram_draw(
if (g_is_base_font) {
centered_x -= width / 10.0;
}
- if (!text_show(stream, diagram->name, x+centered_x, y_above_diagram + 7.0)) {
+ if (!text_show(stream, !g_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
@@ -316,48 +316,6 @@ fontpath_find(struct Font *font, enum FontType font_type)
return filepath;
}
-static const char *
-is_base_font(struct Font *font)
-{
- if (!strcmp(font->name, "Courier")) {
- if (font->style == FS_ITALIC && font->weight == FW_BOLD) {
- return "Courier-BoldItalic";
- } else
- if (font->style == FS_ITALIC) {
- return "Courier-Italic";
- } else
- if (font->weight == FW_BOLD) {
- return "Courier-Bold";
- }
- return "Courier";
- } else
- if (!strcmp(font->name, "Helvetica")) {
- if (font->style == FS_OBLIQUE && font->weight == FW_BOLD) {
- return "Helvetica-BoldOblique";
- } else
- if (font->style == FS_OBLIQUE) {
- return "Helvetica-Oblique";
- } else
- if (font->weight == FW_BOLD) {
- return "Helvetica-Bold";
- }
- return "Helvetica";
- } else
- if (!strcmp(font->name, "Times")) {
- if (font->style == FS_ITALIC && font->weight == FW_BOLD) {
- return "Times-BoldItalic";
- } else
- if (font->style == FS_ITALIC) {
- return "Times-Italic";
- } else
- if (font->weight == FW_BOLD) {
- return "Times-Bold";
- }
- return "Times-Roman";
- }
- return NULL;
-}
-
static bool
pdf_load_chord_diagram_fonts(void)
{
diff --git a/src/util.c b/src/util.c
@@ -500,3 +500,45 @@ size_to_string(struct Size *size)
}
return str;
}
+
+const char *
+is_base_font(struct Font *font)
+{
+ if (!strcmp(font->name, "Courier")) {
+ if (font->style == FS_ITALIC && font->weight == FW_BOLD) {
+ return "Courier-BoldItalic";
+ } else
+ if (font->style == FS_ITALIC) {
+ return "Courier-Italic";
+ } else
+ if (font->weight == FW_BOLD) {
+ return "Courier-Bold";
+ }
+ return "Courier";
+ } else
+ if (!strcmp(font->name, "Helvetica")) {
+ if (font->style == FS_OBLIQUE && font->weight == FW_BOLD) {
+ return "Helvetica-BoldOblique";
+ } else
+ if (font->style == FS_OBLIQUE) {
+ return "Helvetica-Oblique";
+ } else
+ if (font->weight == FW_BOLD) {
+ return "Helvetica-Bold";
+ }
+ return "Helvetica";
+ } else
+ if (!strcmp(font->name, "Times")) {
+ if (font->style == FS_ITALIC && font->weight == FW_BOLD) {
+ return "Times-BoldItalic";
+ } else
+ if (font->style == FS_ITALIC) {
+ return "Times-Italic";
+ } else
+ if (font->weight == FW_BOLD) {
+ return "Times-Bold";
+ }
+ return "Times-Roman";
+ }
+ return NULL;
+}
diff --git a/src/util.h b/src/util.h
@@ -57,3 +57,5 @@ char *filepath_resolve_tilde(const char *path);
struct Size *size_create(const char *str);
struct Size *size_copy(struct Size *size);
const char *size_to_string(struct Size *size);
+
+const char *is_base_font(struct Font *font);