mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-09 06:04:03 +00:00
ttf: enhance UWP portability with alternative file loading
Enhances the portability of the TTF loader on UWP platforms by implementing an alternative file loading mechanism. This is designed to support environments where the file mapping feature is not available, ensuring wider compatibility and reliability in file handling. Issue: https://github.com/thorvg/thorvg/issues/1912
This commit is contained in:
parent
ba82ba08a8
commit
d9926edb2f
1 changed files with 42 additions and 4 deletions
|
@ -23,9 +23,9 @@
|
||||||
|
|
||||||
#include "tvgTtfLoader.h"
|
#include "tvgTtfLoader.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#elif defined(__linux__)
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
@ -36,7 +36,7 @@
|
||||||
/* Internal Class Implementation */
|
/* Internal Class Implementation */
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
|
|
||||||
#ifdef _WIN32
|
#if defined(_WIN32)
|
||||||
|
|
||||||
static bool _map(TtfLoader* loader, const string& path)
|
static bool _map(TtfLoader* loader, const string& path)
|
||||||
{
|
{
|
||||||
|
@ -83,7 +83,7 @@ static void _unmap(TtfLoader* loader)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#elif defined(__linux__)
|
||||||
|
|
||||||
static bool _map(TtfLoader* loader, const string& path)
|
static bool _map(TtfLoader* loader, const string& path)
|
||||||
{
|
{
|
||||||
|
@ -115,6 +115,44 @@ static void _unmap(TtfLoader* loader)
|
||||||
reader.data = (uint8_t*)-1;
|
reader.data = (uint8_t*)-1;
|
||||||
reader.size = 0;
|
reader.size = 0;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
static bool _map(TtfLoader* loader, const string& path)
|
||||||
|
{
|
||||||
|
auto& reader = loader->reader;
|
||||||
|
|
||||||
|
auto f = fopen(path.c_str(), "rb");
|
||||||
|
if (!f) return false;
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
|
||||||
|
reader.size = ftell(f);
|
||||||
|
if (reader.size == 0) {
|
||||||
|
fclose(f);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
reader.data = (uint8_t*)malloc(reader.size);
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
auto ret = fread(reader.data, sizeof(char), reader.size, f);
|
||||||
|
if (ret < reader.size) {
|
||||||
|
fclose(f);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void _unmap(TtfLoader* loader)
|
||||||
|
{
|
||||||
|
auto& reader = loader->reader;
|
||||||
|
free(reader.data);
|
||||||
|
reader.data = nullptr;
|
||||||
|
reader.size = 0;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue