make adjustments to the font substitution and load Japanese and Korean fonts from the Windows font folder.
This commit is contained in:
parent
a016bf1ef2
commit
0838433d1f
3 changed files with 60 additions and 41 deletions
|
|
@ -2,6 +2,12 @@
|
|||
#include <zwidget/core/resourcedata.h>
|
||||
#include "filesystem.h"
|
||||
#include "printf.h"
|
||||
#include "zstring.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
FResourceFile* WidgetResources;
|
||||
|
||||
|
|
@ -17,11 +23,11 @@ void CloseWidgetResources()
|
|||
if (WidgetResources) delete WidgetResources;
|
||||
}
|
||||
|
||||
static std::vector<uint8_t> LoadFile(const std::string& name)
|
||||
static std::vector<uint8_t> LoadFile(const char* name)
|
||||
{
|
||||
auto lump = WidgetResources->FindEntry(name.c_str());
|
||||
auto lump = WidgetResources->FindEntry(name);
|
||||
if (lump == -1)
|
||||
I_FatalError("Unable to find %s", name.c_str());
|
||||
I_FatalError("Unable to find %s", name);
|
||||
|
||||
auto reader = WidgetResources->GetEntryReader(lump, FileSys::READER_SHARED);
|
||||
std::vector<uint8_t> buffer(reader.GetLength());
|
||||
|
|
@ -29,31 +35,53 @@ static std::vector<uint8_t> LoadFile(const std::string& name)
|
|||
return buffer;
|
||||
}
|
||||
|
||||
// this must be allowed to fail without throwing.
|
||||
static std::vector<uint8_t> LoadDiskFile(const char* name)
|
||||
{
|
||||
std::vector<uint8_t> buffer;
|
||||
FileSys::FileReader lump;
|
||||
if (lump.OpenFile(name))
|
||||
{
|
||||
buffer.resize(lump.GetLength());
|
||||
lump.Read(buffer.data(), buffer.size());
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// This interface will later require some significant redesign.
|
||||
std::vector<SingleFontData> LoadWidgetFontData(const std::string& name)
|
||||
{
|
||||
std::vector<SingleFontData> returnv;
|
||||
if (!stricmp(name.c_str(), "notosans"))
|
||||
{
|
||||
returnv.resize(3);
|
||||
returnv[2].fontdata = LoadFile("widgets/noto/notosans-regular.ttf");
|
||||
returnv[0].fontdata = LoadFile("widgets/noto/notosansarmenian-regular.ttf");
|
||||
returnv[1].fontdata = LoadFile("widgets/noto/notosansgeorgian-regular.ttf");
|
||||
returnv[0].ranges.push_back(std::make_pair(0x531, 0x58f));
|
||||
returnv[1].ranges.push_back(std::make_pair(0x10a0, 0x10ff));
|
||||
returnv[1].ranges.push_back(std::make_pair(0x1c90, 0x1cbf));
|
||||
returnv[1].ranges.push_back(std::make_pair(0x2d00, 0x2d2f));
|
||||
// todo: load system CJK fonts here
|
||||
returnv.resize(5);
|
||||
returnv[0].fontdata = LoadFile("widgets/noto/notosans-regular.ttf");
|
||||
returnv[1].fontdata = LoadFile("widgets/noto/notosansarmenian-regular.ttf");
|
||||
returnv[2].fontdata = LoadFile("widgets/noto/notosansgeorgian-regular.ttf");
|
||||
#ifdef _WIN32
|
||||
wchar_t wbuffer[256];
|
||||
if (GetWindowsDirectoryW(wbuffer, 256))
|
||||
{
|
||||
FString windir(wbuffer);
|
||||
returnv[3].fontdata = LoadDiskFile((windir + "/fonts/yugothm.ttc").GetChars());
|
||||
returnv[3].language = "ja";
|
||||
returnv[4].fontdata = LoadDiskFile((windir + "/fonts/malgun.ttf").GetChars());
|
||||
returnv[4].language = "ko";
|
||||
// Don't fail if these cannot be found
|
||||
if (returnv[4].fontdata.size() == 0) returnv.erase(returnv.begin() + 4);
|
||||
if (returnv[3].fontdata.size() == 0) returnv.erase(returnv.begin() + 3);
|
||||
}
|
||||
#endif
|
||||
return returnv;
|
||||
|
||||
}
|
||||
returnv.resize(1);
|
||||
std::string fn = "widgets/font/" +name + ".ttf";
|
||||
returnv[0].fontdata = LoadFile(fn);
|
||||
returnv[0].fontdata = LoadFile(fn.c_str());
|
||||
return returnv;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> LoadWidgetImageData(const std::string& name)
|
||||
{
|
||||
return LoadFile(name);
|
||||
return LoadFile(name.c_str());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue