Got text working on macOS, changed some stuff in icon search, and disabled right to left detection for GUI text boxes
This commit is contained in:
parent
eb1cf55063
commit
7ecd333b74
5 changed files with 68 additions and 23 deletions
18
conanfile.py
18
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,
|
||||
|
|
|
|||
|
|
@ -6,12 +6,15 @@
|
|||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <include/ports/SkFontMgr_directory.h>
|
||||
#elif __APPLE__
|
||||
#include <include/ports/SkFontMgr_mac_ct.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <string>
|
||||
CTFontCollectionRef fontCollectionRef = nullptr;
|
||||
#elif _WIN32
|
||||
#include <include/ports/SkTypeface_win.h>
|
||||
#include "WindowsFontData/CustomFontSetManager.h"
|
||||
|
||||
DWriteCustomFontSets::CustomFontSetManager fontSetManagerWindows;
|
||||
|
||||
#else
|
||||
#include <include/ports/SkFontMgr_fontconfig.h>
|
||||
#include <include/ports/SkFontScanner_FreeType.h>
|
||||
|
|
@ -21,17 +24,30 @@
|
|||
#include <src/base/SkUTF.h>
|
||||
#include <filesystem>
|
||||
|
||||
#include <Helpers/Logger.hpp>
|
||||
|
||||
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<const UInt8*>(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<std::wstring> 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<skia::textlayout::FontCollection>();
|
||||
collection->setDefaultFontManager(defaultFontMgr, std::vector<SkString>{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<SkString>& fontFamilies) c
|
|||
}
|
||||
|
||||
FontData::~FontData() {
|
||||
#ifdef __APPLE__
|
||||
if(fontCollectionRef)
|
||||
CFRelease(fontCollectionRef);
|
||||
#endif
|
||||
}
|
||||
|
||||
Vector2f get_str_font_bounds(const SkFont& font, const std::string& str) {
|
||||
|
|
|
|||
|
|
@ -6,19 +6,22 @@
|
|||
#include <modules/skparagraph/src/ParagraphBuilderImpl.h>
|
||||
#include <modules/skunicode/include/SkUnicode_icu.h>
|
||||
#include <Helpers/Random.hpp>
|
||||
#include <Helpers/Logger.hpp>
|
||||
|
||||
bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GUIManager* gui) {
|
||||
if(sortedFontList.empty()) {
|
||||
auto icu = SkUnicodes::ICU::Make();
|
||||
std::set<std::string> 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<std::string>(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<size_t>::max();
|
||||
if(val == std::numeric_limits<size_t>::max()) {
|
||||
auto it = std::find(sortedFontList.begin(), sortedFontList.end(), *fontName);
|
||||
size_t val = std::numeric_limits<size_t>::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<size_t>::max();
|
||||
if(val != std::numeric_limits<size_t>::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;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ template <typename T> class TextBox : public Element {
|
|||
force_update_textbox(io, false);
|
||||
|
||||
textbox->set_width(std::numeric_limits<float>::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 = {
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue