1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-14 04:03:51 +02:00

Extended memory loading support

This commit is contained in:
Brian Fiete 2025-01-17 10:18:50 -08:00
parent 0efdecb719
commit 29c0f82bba
7 changed files with 136 additions and 33 deletions

View file

@ -147,13 +147,24 @@ bool FTFont::Load(const StringImpl& fileName, float pointSize)
String useFileName = fileName;
int faceIdx = 0;
int atPos = (int)useFileName.IndexOf('@');
int atPos = (int)useFileName.IndexOf('@', 1);
if (atPos != -1)
{
faceIdx = atoi(useFileName.c_str() + atPos + 1);
useFileName.RemoveToEnd(atPos);
}
auto error = FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);
void* memPtr = NULL;
int memLen = 0;
if (ParseMemorySpan(fileName, memPtr, memLen))
{
FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace);
}
else
{
FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);
}
face->mFTFace = ftFace;
}
else

View file

@ -150,14 +150,12 @@ Texture* RenderDevice::LoadTexture(const StringImpl& fileName, int flags)
if (!handled)
{
imageData->mWantsAlphaPremultiplied = (flags & TextureFlag_NoPremult) == 0;
if (fileName.StartsWith("@"))
{
int colon = (int)fileName.IndexOf(':');
String addrStr = fileName.Substring(1, colon - 1);
String lenStr = fileName.Substring(colon + 1);
void* addr = (void*)(intptr)strtoll(addrStr.c_str(), NULL, 16);
int len = (int)strtol(lenStr.c_str(), NULL, 10);
if (!imageData->LoadFromMemory(addr, len))
void* memPtr = NULL;
int memLen = 0;
if (ParseMemorySpan(fileName, memPtr, memLen))
{
if (!imageData->LoadFromMemory(memPtr, memLen))
{
failed = true;
delete imageData;