summaryrefslogtreecommitdiff
path: root/textscreen/txt_gui.c
diff options
context:
space:
mode:
authorSimon Howard2012-02-03 20:21:17 +0000
committerSimon Howard2012-02-03 20:21:17 +0000
commitc818fb021632cbb68229ba265f01b060e6b6d0f4 (patch)
treec78816ab19c5106a0a008061f0d2beb06eba058d /textscreen/txt_gui.c
parentd4df22aa1e8e2ee8d389be9fb485985c4d80d47e (diff)
downloadchocolate-doom-c818fb021632cbb68229ba265f01b060e6b6d0f4.tar.gz
chocolate-doom-c818fb021632cbb68229ba265f01b060e6b6d0f4.tar.bz2
chocolate-doom-c818fb021632cbb68229ba265f01b060e6b6d0f4.zip
Split off UTF-8 code into separate file and add extra functions.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2489
Diffstat (limited to 'textscreen/txt_gui.c')
-rw-r--r--textscreen/txt_gui.c57
1 files changed, 3 insertions, 54 deletions
diff --git a/textscreen/txt_gui.c b/textscreen/txt_gui.c
index 1bcc2e9e..bc869255 100644
--- a/textscreen/txt_gui.c
+++ b/textscreen/txt_gui.c
@@ -25,6 +25,7 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_main.h"
+#include "txt_utf8.h"
typedef struct txt_cliparea_s txt_cliparea_t;
@@ -296,58 +297,6 @@ void TXT_DrawString(const char *s)
TXT_GotoXY(x + strlen(s), y);
}
-// Decode UTF-8 character, incrementing *ptr over the decoded bytes.
-
-static unsigned int DecodeUTF8(const char **ptr)
-{
- const char *p = *ptr;
- unsigned int c;
-
- // UTF-8 decode.
-
- if ((*p & 0x80) == 0) // 1 character (ASCII):
- {
- c = *p;
- *ptr += 1;
- }
- else if ((p[0] & 0xe0) == 0xc0 // 2 character:
- && (p[1] & 0xc0) == 0x80)
- {
- c = ((p[0] & 0x1f) << 6)
- | (p[1] & 0x3f);
- *ptr += 2;
- }
- else if ((p[0] & 0xf0) == 0xe0 // 3 character:
- && (p[1] & 0xc0) == 0x80
- && (p[2] & 0xc0) == 0x80)
- {
- c = ((p[0] & 0x0f) << 12)
- | ((p[1] & 0x3f) << 6)
- | (p[2] & 0x3f);
- *ptr += 3;
- }
- else if ((p[0] & 0xf8) == 0xf0 // 4 character:
- && (p[1] & 0xc0) == 0x80
- && (p[2] & 0xc0) == 0x80
- && (p[3] & 0xc0) == 0x80)
- {
- c = ((p[0] & 0x07) << 18)
- | ((p[1] & 0x3f) << 12)
- | ((p[2] & 0x3f) << 6)
- | (p[3] & 0x3f);
- *ptr += 4;
- }
- else
- {
- // Decode failure.
- // Don't bother with 5/6 byte sequences.
-
- c = 0;
- }
-
- return c;
-}
-
static void PutUnicodeChar(unsigned int c)
{
unsigned int i;
@@ -389,7 +338,7 @@ void TXT_DrawUTF8String(const char *s)
for (p = s; *p != '\0'; )
{
- c = DecodeUTF8(&p);
+ c = TXT_DecodeUTF8(&p);
if (c == 0)
{
@@ -406,7 +355,7 @@ void TXT_DrawUTF8String(const char *s)
}
}
- TXT_GotoXY(x + strlen(s), y);
+ TXT_GotoXY(x + TXT_UTF8_Strlen(s), y);
}
void TXT_DrawHorizScrollbar(int x, int y, int w, int cursor, int range)