Starting work on Android port
This commit is contained in:
parent
5d1b7678f0
commit
ab13ccd595
183 changed files with 6790 additions and 906 deletions
|
|
@ -6,6 +6,13 @@
|
|||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <include/ports/SkFontMgr_directory.h>
|
||||
#elif __ANDROID__
|
||||
#include <include/ports/SkFontScanner_FreeType.h>
|
||||
#include <include/ports/SkFontMgr_data.h>
|
||||
#include <include/ports/SkFontMgr_android_ndk.h>
|
||||
#include <SDL3/SDL_filesystem.h>
|
||||
#include <Helpers/StringHelpers.hpp>
|
||||
#include <Helpers/Logger.hpp>
|
||||
#elif __APPLE__
|
||||
#include <include/ports/SkFontMgr_mac_ct.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
|
@ -27,6 +34,29 @@ FontData::FontData()
|
|||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
defaultFontMgr = SkFontMgr_New_Custom_Directory("data/fonts");
|
||||
#elif __ANDROID__
|
||||
{
|
||||
std::vector<sk_sp<SkData>> fontFiles;
|
||||
int globCount;
|
||||
std::filesystem::path fontFolderPath("data/fonts");
|
||||
char** filesInPath = SDL_GlobDirectory(fontFolderPath.c_str(), nullptr, 0, &globCount);
|
||||
if(filesInPath) {
|
||||
Logger::get().cross_platform_println("Yay!");
|
||||
for(int i = 0; i < globCount; i++) {
|
||||
std::filesystem::path filePath = fontFolderPath / std::filesystem::path(filesInPath[i]);
|
||||
SDL_PathInfo fileInfo;
|
||||
Logger::get().cross_platform_println("Font: " + filePath.string());
|
||||
if(SDL_GetPathInfo(filePath.c_str(), &fileInfo) && fileInfo.type == SDL_PATHTYPE_FILE) {
|
||||
std::string strData = read_file_to_string(filePath);
|
||||
fontFiles.emplace_back(SkData::MakeWithCopy(strData.data(), strData.size()));
|
||||
Logger::get().cross_platform_println("loaded!");
|
||||
}
|
||||
}
|
||||
SDL_free(filesInPath);
|
||||
defaultFontMgr = SkFontMgr_New_Custom_Data(SkSpan(fontFiles.data(), fontFiles.size()));
|
||||
}
|
||||
}
|
||||
localFontMgr = SkFontMgr_New_AndroidNDK(true, SkFontScanner_Make_FreeType());
|
||||
#elif __APPLE__
|
||||
for(const auto& dirEntry : std::filesystem::recursive_directory_iterator("data/fonts")) {
|
||||
if(dirEntry.is_regular_file()) {
|
||||
|
|
@ -53,7 +83,6 @@ FontData::FontData()
|
|||
localFontMgr = SkFontMgr_New_FontConfig(nullptr, SkFontScanner_Make_FreeType());
|
||||
defaultFontMgr = SkFontMgr_New_Custom_Directory("data/fonts");
|
||||
#endif
|
||||
|
||||
map["Roboto"] = defaultFontMgr->makeFromFile("data/fonts/Roboto-variable.ttf");
|
||||
|
||||
collection = sk_make_sp<skia::textlayout::FontCollection>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue