From 2e5319a6235c7a9a7d2a0964221fc561656cab68 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Fri, 13 Dec 2024 19:56:00 -0500 Subject: [PATCH] Fix widths for base fonts (was converting back to UTF-8 instead of preserving the CP-1252 character set. --- examples/md2pdf.c | 2 +- pdfio-content.c | 23 ++++------------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/examples/md2pdf.c b/examples/md2pdf.c index 9699c05..49ca5e4 100644 --- a/examples/md2pdf.c +++ b/examples/md2pdf.c @@ -138,7 +138,7 @@ typedef struct tablerow_s // Table row // Constants... // -#define USE_TRUETYPE 1 // Set to 1 to use Roboto TrueType fonts +#define USE_TRUETYPE 0 // Set to 1 to use Roboto TrueType fonts #if USE_TRUETYPE # define UNICODE_VALUE true // `true` for Unicode text, `false` for ISO-8859-1 diff --git a/pdfio-content.c b/pdfio-content.c index 3009636..a3ee04a 100644 --- a/pdfio-content.c +++ b/pdfio-content.c @@ -1131,28 +1131,13 @@ pdfioContentTextMeasure( break; } - if (i >= (sizeof(_pdfio_cp1252) / sizeof(_pdfio_cp1252[0]))) + if (i < (sizeof(_pdfio_cp1252) / sizeof(_pdfio_cp1252[0]))) + ch = i + 0x80; // Extra characters from 0x80 to 0x9f + else ch = '?'; // Unsupported chars map to ? } - if (ch < 128) - { - // ASCII - *tempptr++ = (char)ch; - } - else if (ch < 2048) - { - // 2-byte UTF-8 - *tempptr++ = (char)(0xc0 | ((ch >> 6) & 0x1f)); - *tempptr++ = (char)(0x80 | (ch & 0x3f)); - } - else - { - // 3-byte UTF-8 - *tempptr++ = (char)(0xe0 | ((ch >> 12) & 0x0f)); - *tempptr++ = (char)(0x80 | ((ch >> 6) & 0x3f)); - *tempptr++ = (char)(0x80 | (ch & 0x3f)); - } + *tempptr++ = (char)ch; } *tempptr = '\0';