Skip to content

Commit

Permalink
Fix widths for base fonts (was converting back to UTF-8 instead of pr…
Browse files Browse the repository at this point in the history
…eserving

the CP-1252 character set.
  • Loading branch information
michaelrsweet committed Dec 14, 2024
1 parent d3d6683 commit 2e5319a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/md2pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 4 additions & 19 deletions pdfio-content.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 2e5319a

Please sign in to comment.