Skip to content

Commit

Permalink
Added a check for if the breakable byte is the start of char.
Browse files Browse the repository at this point in the history
  • Loading branch information
onpon4 committed Jul 27, 2020
1 parent 6e8d32f commit eb2c61c
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@ int gfx_renderUnicode(const char *in, int x, int y, int fontColor, int wrap, SDL
}

#else
static int gfx_charIsUTF8Start(unsigned char c)
{
// Top bit not set (single byte ASCII character)
if ((c & 0x80) == 0)
return 1;

// Top two bits set (start of multi-byte character)
if ((c & 0x80) && (c & 0x40))
return 1;

// Top bit set, but second bit not set (somewhere in the middle)
return 0;
}

int gfx_unicodeWidth(const char *in)
{
int w;
Expand Down Expand Up @@ -360,7 +374,8 @@ int gfx_renderUnicodeBase(const char *in, int x, int y, int real_x, int fontColo
nBreakPoints = 0;
for (i = 0; i < nLogAttrs; i++)
{
if (logAttrs[i].is_line_break)
if (logAttrs[i].is_line_break
&& gfx_charIsUTF8Start(remainingStr[i]))
{
breakPoints[nBreakPoints] = i;
nBreakPoints++;
Expand Down

0 comments on commit eb2c61c

Please sign in to comment.