Add initial font metrics and equation rendering.
This commit is contained in:
parent
c2027801be
commit
5ddd54dd6d
24 changed files with 868 additions and 63 deletions
|
@ -39,3 +39,53 @@ std::wstring UnicodeUtils::utf8ToUtf16WString(const std::string& input)
|
|||
throw std::logic_error("Not implemented");
|
||||
#endif
|
||||
}
|
||||
|
||||
std::vector<uint32_t> UnicodeUtils::utf8ToUtf32(const std::string& input)
|
||||
{
|
||||
const auto utf_16 = utf8ToUtf16WString(input);
|
||||
|
||||
std::vector<uint32_t> output;
|
||||
std::size_t pos = 0;
|
||||
while (pos < utf_16.size())
|
||||
{
|
||||
const auto c = utf_16[pos];
|
||||
pos++;
|
||||
if (!isSurrogate(c))
|
||||
{
|
||||
output.push_back(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isHighSurrogate(c) && pos < utf_16.size() && isLowSurrogate(utf_16[pos]))
|
||||
{
|
||||
output.push_back(surrogateToUtf32(c, utf_16[pos]));
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::logic_error("Unexpected UTF16 content given for conversion to UTF32");
|
||||
}
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isSurrogate(wchar_t c)
|
||||
{
|
||||
return (c - 0xd800u) < 2048u;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isHighSurrogate(wchar_t c)
|
||||
{
|
||||
return (c & 0xfffffc00) == 0xd800;
|
||||
}
|
||||
|
||||
bool UnicodeUtils::isLowSurrogate(wchar_t c)
|
||||
{
|
||||
return (c & 0xfffffc00) == 0xdc00;
|
||||
}
|
||||
|
||||
uint32_t UnicodeUtils::surrogateToUtf32(wchar_t high, wchar_t low)
|
||||
{
|
||||
return (high << 10) + low - 0x35fdc00;
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class UnicodeUtils
|
||||
{
|
||||
|
@ -8,4 +9,12 @@ public:
|
|||
static std::string utf16ToUtf8String(const std::wstring& input);
|
||||
|
||||
static std::wstring utf8ToUtf16WString(const std::string& input);
|
||||
|
||||
static std::vector<uint32_t> utf8ToUtf32(const std::string& input);
|
||||
|
||||
private:
|
||||
static bool isSurrogate(wchar_t c);
|
||||
static bool isHighSurrogate(wchar_t c);
|
||||
static bool isLowSurrogate(wchar_t c);
|
||||
static uint32_t surrogateToUtf32(wchar_t high, wchar_t low);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue