diff --git a/conanfile.py b/conanfile.py index ca479dc..515ad1a 100644 --- a/conanfile.py +++ b/conanfile.py @@ -49,6 +49,24 @@ class CompressorRecipe(ConanFile): "enable_skottie": False, "enable_bentleyottmann": True # for some reason, setting this to False results in an error when creating the project }) + elif self.settings.os == "Macos": + self.requires("skia-infinipaint/143.20251028.0", options = { + "use_system_expat": False, + "use_freetype": False, + "use_system_harfbuzz": True, + "use_conan_harfbuzz": True, + "use_system_icu": True, + "use_conan_icu": True, + "use_system_libjpeg_turbo": False, + "use_system_libpng": False, + "use_system_libwebp": False, + "use_system_zlib": False, + "use_x11": False, + "use_egl": False, + "enable_svg": True, + "enable_skottie": False, + "enable_bentleyottmann": True # for some reason, setting this to False results in an error when creating the project + }) else: self.requires("skia-infinipaint/143.20251028.0", options = { "use_system_expat": False, diff --git a/src/FontData.cpp b/src/FontData.cpp index 444e94e..13eee6c 100644 --- a/src/FontData.cpp +++ b/src/FontData.cpp @@ -6,12 +6,15 @@ #ifdef __EMSCRIPTEN__ #include +#elif __APPLE__ + #include + #include +#include + CTFontCollectionRef fontCollectionRef = nullptr; #elif _WIN32 #include #include "WindowsFontData/CustomFontSetManager.h" - DWriteCustomFontSets::CustomFontSetManager fontSetManagerWindows; - #else #include #include @@ -21,17 +24,30 @@ #include #include +#include + FontData::FontData() { #ifdef __EMSCRIPTEN__ - localFontMgr = SkFontMgr_New_Custom_Empty(); defaultFontMgr = SkFontMgr_New_Custom_Directory("data/fonts"); +#elif __APPLE__ + for(const auto& dirEntry : std::filesystem::recursive_directory_iterator("data/fonts")) { + if(dirEntry.is_regular_file()) { + std::string urlStr = std::string(std::filesystem::canonical(dirEntry.path()).string()); + CFURLRef fontURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, reinterpret_cast(urlStr.c_str()), urlStr.size(), false); + CTFontManagerRegisterFontsForURL(fontURL, CTFontManagerScope::kCTFontManagerScopeProcess, nullptr); + CFRelease(fontURL); + } + } + defaultFontMgr = SkFontMgr_New_CoreText(nullptr); #elif _WIN32 localFontMgr = SkFontMgr_New_DirectWrite(); std::vector fontPaths; - for(const std::filesystem::path& dirEntry : std::filesystem::recursive_directory_iterator(std::filesystem::path(L"data\\fonts"))) - fontPaths.emplace_back(dirEntry.wstring()); + for(const auto& dirEntry : std::filesystem::recursive_directory_iterator(std::filesystem::path(L"data\\fonts"))) { + if(dirEntry.is_regular_file()) + fontPaths.emplace_back(dirEntry.path().wstring()); + } fontSetManagerWindows.CreateFontSetUsingLocalFontFiles(fontPaths); fontSetManagerWindows.CreateFontCollectionFromFontSet(); @@ -46,7 +62,8 @@ FontData::FontData() collection = sk_make_sp(); collection->setDefaultFontManager(defaultFontMgr, std::vector{SkString{"Roboto"}, SkString{"Noto Emoji"}, SkString{"Noto Kufi Arabic"}}); - collection->setDynamicFontManager(localFontMgr); + if(localFontMgr) + collection->setDynamicFontManager(localFontMgr); std::string s = "🙂"; const char* sPtr = s.data(); SkFontStyle defaultStyle; @@ -74,6 +91,10 @@ void FontData::push_default_font_families(std::vector& fontFamilies) c } FontData::~FontData() { +#ifdef __APPLE__ + if(fontCollectionRef) + CFRelease(fontCollectionRef); +#endif } Vector2f get_str_font_bounds(const SkFont& font, const std::string& str) { diff --git a/src/GUIStuff/Elements/FontPicker.cpp b/src/GUIStuff/Elements/FontPicker.cpp index 34d38d2..b1efed7 100644 --- a/src/GUIStuff/Elements/FontPicker.cpp +++ b/src/GUIStuff/Elements/FontPicker.cpp @@ -6,19 +6,22 @@ #include #include #include +#include bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GUIManager* gui) { if(sortedFontList.empty()) { auto icu = SkUnicodes::ICU::Make(); std::set sortedFontSet; - for(int i = 0; i < io.fonts->localFontMgr->countFamilies(); i++) { - SkString familyNameSkString; - io.fonts->localFontMgr->getFamilyName(i, &familyNameSkString); - if(familyNameSkString.isEmpty()) - continue; - std::string familyName(familyNameSkString.c_str(), familyNameSkString.size()); - sortedFontSet.emplace(familyName); + if(io.fonts->localFontMgr) { + for(int i = 0; i < io.fonts->localFontMgr->countFamilies(); i++) { + SkString familyNameSkString; + io.fonts->localFontMgr->getFamilyName(i, &familyNameSkString); + if(familyNameSkString.isEmpty()) + continue; + std::string familyName(familyNameSkString.c_str(), familyNameSkString.size()); + sortedFontSet.emplace(familyName); + } } for(int i = 0; i < io.fonts->defaultFontMgr->countFamilies(); i++) { SkString familyNameSkString; @@ -30,8 +33,10 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU } sortedFontList = std::vector(sortedFontSet.begin(), sortedFontSet.end()); sortedFontListLowercase = sortedFontList; - for(std::string& s : sortedFontListLowercase) + for(std::string& s : sortedFontListLowercase) { std::transform(s.begin(), s.end(), s.begin(), ::tolower); + Logger::get().log("INFO", s); + } } if(!fontName) @@ -57,16 +62,19 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU } }); - auto it = std::lower_bound(sortedFontList.begin(), sortedFontList.end(), *fontName); - size_t val = (it != sortedFontList.end() && *it == *fontName) ? (it - sortedFontList.begin()): std::numeric_limits::max(); - if(val == std::numeric_limits::max()) { + auto it = std::find(sortedFontList.begin(), sortedFontList.end(), *fontName); + size_t val = std::numeric_limits::max(); + if(it == sortedFontList.end()) { std::string lowerFamilyName = *fontName; std::transform(lowerFamilyName.begin(), lowerFamilyName.end(), lowerFamilyName.begin(), ::tolower); - auto itLower = std::lower_bound(sortedFontListLowercase.begin(), sortedFontListLowercase.end(), lowerFamilyName); - val = (itLower != sortedFontListLowercase.end() && *itLower == lowerFamilyName) ? (itLower - sortedFontListLowercase.begin()): std::numeric_limits::max(); - if(val != std::numeric_limits::max()) + auto itLower = std::find(sortedFontListLowercase.begin(), sortedFontListLowercase.end(), lowerFamilyName); + if(itLower != sortedFontListLowercase.end()) { + val = itLower - sortedFontListLowercase.begin(); *fontName = sortedFontList[val]; + } } + else + val = it - sortedFontList.begin(); if(gui->svg_icon_button("Open font dropdown", "data/icons/droparrow.svg", dropdownOpen, GUIManager::SMALL_BUTTON_SIZE)) { dropdownOpen = !dropdownOpen; diff --git a/src/GUIStuff/Elements/TextBox.hpp b/src/GUIStuff/Elements/TextBox.hpp index 075dc2b..b77ec5d 100644 --- a/src/GUIStuff/Elements/TextBox.hpp +++ b/src/GUIStuff/Elements/TextBox.hpp @@ -21,7 +21,7 @@ template class TextBox : public Element { force_update_textbox(io, false); textbox->set_width(std::numeric_limits::max()); - textbox->set_text_direction_between(0, 0, textbox->get_suggested_direction(0)); + //textbox->set_text_direction_between(0, 0, textbox->get_suggested_direction(0)); CLAY({ .layout = { diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index e418d4f..f777b81 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -72,8 +72,6 @@ void Toolbar::load_icons_at(const std::filesystem::path& pathToLoad) { io->svgData[iconRelativePath] = svgDom; } } - else if(iconDirEntry.is_directory()) - load_icons_at(iconDirEntry.path()); } }