Kernel: Fix PC Screen font parsing

I had misread the format and the parsing code was incorrect. I also
changed fonts to store unicode codepoints as 32 bit integers, so
every character can be represented
This commit is contained in:
Bananymous
2023-03-20 14:52:42 +02:00
parent 896b4c280c
commit f9ae1f0023
3 changed files with 81 additions and 61 deletions

View File

@@ -6,23 +6,41 @@
namespace BAN
{
static constexpr uint16_t utf8_to_codepoint(uint8_t* bytes, size_t count)
namespace UTF8
{
if (count > 3)
return 0xFFFF;
static constexpr uint32_t invalid = 0xFFFFFFFF;
}
for (size_t i = 1; i < count; i++)
static constexpr uint32_t utf8_byte_length(uint8_t first_byte)
{
if ((first_byte & 0x80) == 0x00)
return 1;
if ((first_byte & 0xE0) == 0xC0)
return 2;
if ((first_byte & 0xF0) == 0xE0)
return 3;
if ((first_byte & 0xF8) == 0xF0)
return 4;
return 0;
}
static constexpr uint32_t utf8_to_codepoint(uint8_t* bytes)
{
uint32_t length = utf8_byte_length(bytes[0]);
for (uint32_t i = 1; i < length; i++)
if ((bytes[i] & 0xC0) != 0x80)
return 0xFFFF;
switch (count)
return UTF8::invalid;
switch (length)
{
case 1: return bytes[0];
case 2: return ((bytes[0] & 0x1F) << 6) | (bytes[1] & 0x3F);
case 3: return ((bytes[0] & 0x1F) << 12) | ((bytes[1] & 0x3F) << 6) | (bytes[2] & 0x3F);
case 1: return ((bytes[0] & 0x80) != 0x00) ? UTF8::invalid : bytes[0];
case 2: return ((bytes[0] & 0xE0) != 0xC0) ? UTF8::invalid : ((bytes[0] & 0x1F) << 6) | (bytes[1] & 0x3F);
case 3: return ((bytes[0] & 0xF0) != 0xE0) ? UTF8::invalid : ((bytes[0] & 0x0F) << 12) | ((bytes[1] & 0x3F) << 6) | (bytes[2] & 0x3F);
case 4: return ((bytes[0] & 0xF8) != 0xF0) ? UTF8::invalid : ((bytes[0] & 0x07) << 18) | ((bytes[1] & 0x3F) << 12) | ((bytes[2] & 0x3F) << 6) | (bytes[3] & 0x3F);
}
return 0xFFFF;
return UTF8::invalid;
}
}