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_skottie": False,
|
||||||
"enable_bentleyottmann": True # for some reason, setting this to False results in an error when creating the project
|
"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:
|
else:
|
||||||
self.requires("skia-infinipaint/143.20251028.0", options = {
|
self.requires("skia-infinipaint/143.20251028.0", options = {
|
||||||
"use_system_expat": False,
|
"use_system_expat": False,
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,15 @@
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
#include <include/ports/SkFontMgr_directory.h>
|
#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
|
#elif _WIN32
|
||||||
#include <include/ports/SkTypeface_win.h>
|
#include <include/ports/SkTypeface_win.h>
|
||||||
#include "WindowsFontData/CustomFontSetManager.h"
|
#include "WindowsFontData/CustomFontSetManager.h"
|
||||||
|
|
||||||
DWriteCustomFontSets::CustomFontSetManager fontSetManagerWindows;
|
DWriteCustomFontSets::CustomFontSetManager fontSetManagerWindows;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#include <include/ports/SkFontMgr_fontconfig.h>
|
#include <include/ports/SkFontMgr_fontconfig.h>
|
||||||
#include <include/ports/SkFontScanner_FreeType.h>
|
#include <include/ports/SkFontScanner_FreeType.h>
|
||||||
|
|
@ -21,17 +24,30 @@
|
||||||
#include <src/base/SkUTF.h>
|
#include <src/base/SkUTF.h>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
|
||||||
|
#include <Helpers/Logger.hpp>
|
||||||
|
|
||||||
FontData::FontData()
|
FontData::FontData()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
localFontMgr = SkFontMgr_New_Custom_Empty();
|
|
||||||
defaultFontMgr = SkFontMgr_New_Custom_Directory("data/fonts");
|
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
|
#elif _WIN32
|
||||||
localFontMgr = SkFontMgr_New_DirectWrite();
|
localFontMgr = SkFontMgr_New_DirectWrite();
|
||||||
std::vector<std::wstring> fontPaths;
|
std::vector<std::wstring> fontPaths;
|
||||||
for(const std::filesystem::path& dirEntry : std::filesystem::recursive_directory_iterator(std::filesystem::path(L"data\\fonts")))
|
for(const auto& dirEntry : std::filesystem::recursive_directory_iterator(std::filesystem::path(L"data\\fonts"))) {
|
||||||
fontPaths.emplace_back(dirEntry.wstring());
|
if(dirEntry.is_regular_file())
|
||||||
|
fontPaths.emplace_back(dirEntry.path().wstring());
|
||||||
|
}
|
||||||
fontSetManagerWindows.CreateFontSetUsingLocalFontFiles(fontPaths);
|
fontSetManagerWindows.CreateFontSetUsingLocalFontFiles(fontPaths);
|
||||||
fontSetManagerWindows.CreateFontCollectionFromFontSet();
|
fontSetManagerWindows.CreateFontCollectionFromFontSet();
|
||||||
|
|
||||||
|
|
@ -46,6 +62,7 @@ FontData::FontData()
|
||||||
|
|
||||||
collection = sk_make_sp<skia::textlayout::FontCollection>();
|
collection = sk_make_sp<skia::textlayout::FontCollection>();
|
||||||
collection->setDefaultFontManager(defaultFontMgr, std::vector<SkString>{SkString{"Roboto"}, SkString{"Noto Emoji"}, SkString{"Noto Kufi Arabic"}});
|
collection->setDefaultFontManager(defaultFontMgr, std::vector<SkString>{SkString{"Roboto"}, SkString{"Noto Emoji"}, SkString{"Noto Kufi Arabic"}});
|
||||||
|
if(localFontMgr)
|
||||||
collection->setDynamicFontManager(localFontMgr);
|
collection->setDynamicFontManager(localFontMgr);
|
||||||
std::string s = "🙂";
|
std::string s = "🙂";
|
||||||
const char* sPtr = s.data();
|
const char* sPtr = s.data();
|
||||||
|
|
@ -74,6 +91,10 @@ void FontData::push_default_font_families(std::vector<SkString>& fontFamilies) c
|
||||||
}
|
}
|
||||||
|
|
||||||
FontData::~FontData() {
|
FontData::~FontData() {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
if(fontCollectionRef)
|
||||||
|
CFRelease(fontCollectionRef);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2f get_str_font_bounds(const SkFont& font, const std::string& str) {
|
Vector2f get_str_font_bounds(const SkFont& font, const std::string& str) {
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@
|
||||||
#include <modules/skparagraph/src/ParagraphBuilderImpl.h>
|
#include <modules/skparagraph/src/ParagraphBuilderImpl.h>
|
||||||
#include <modules/skunicode/include/SkUnicode_icu.h>
|
#include <modules/skunicode/include/SkUnicode_icu.h>
|
||||||
#include <Helpers/Random.hpp>
|
#include <Helpers/Random.hpp>
|
||||||
|
#include <Helpers/Logger.hpp>
|
||||||
|
|
||||||
bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GUIManager* gui) {
|
bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GUIManager* gui) {
|
||||||
if(sortedFontList.empty()) {
|
if(sortedFontList.empty()) {
|
||||||
auto icu = SkUnicodes::ICU::Make();
|
auto icu = SkUnicodes::ICU::Make();
|
||||||
std::set<std::string> sortedFontSet;
|
std::set<std::string> sortedFontSet;
|
||||||
|
|
||||||
|
if(io.fonts->localFontMgr) {
|
||||||
for(int i = 0; i < io.fonts->localFontMgr->countFamilies(); i++) {
|
for(int i = 0; i < io.fonts->localFontMgr->countFamilies(); i++) {
|
||||||
SkString familyNameSkString;
|
SkString familyNameSkString;
|
||||||
io.fonts->localFontMgr->getFamilyName(i, &familyNameSkString);
|
io.fonts->localFontMgr->getFamilyName(i, &familyNameSkString);
|
||||||
|
|
@ -20,6 +22,7 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
|
||||||
std::string familyName(familyNameSkString.c_str(), familyNameSkString.size());
|
std::string familyName(familyNameSkString.c_str(), familyNameSkString.size());
|
||||||
sortedFontSet.emplace(familyName);
|
sortedFontSet.emplace(familyName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for(int i = 0; i < io.fonts->defaultFontMgr->countFamilies(); i++) {
|
for(int i = 0; i < io.fonts->defaultFontMgr->countFamilies(); i++) {
|
||||||
SkString familyNameSkString;
|
SkString familyNameSkString;
|
||||||
io.fonts->defaultFontMgr->getFamilyName(i, &familyNameSkString);
|
io.fonts->defaultFontMgr->getFamilyName(i, &familyNameSkString);
|
||||||
|
|
@ -30,8 +33,10 @@ bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GU
|
||||||
}
|
}
|
||||||
sortedFontList = std::vector<std::string>(sortedFontSet.begin(), sortedFontSet.end());
|
sortedFontList = std::vector<std::string>(sortedFontSet.begin(), sortedFontSet.end());
|
||||||
sortedFontListLowercase = sortedFontList;
|
sortedFontListLowercase = sortedFontList;
|
||||||
for(std::string& s : sortedFontListLowercase)
|
for(std::string& s : sortedFontListLowercase) {
|
||||||
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
|
||||||
|
Logger::get().log("INFO", s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!fontName)
|
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);
|
auto it = std::find(sortedFontList.begin(), sortedFontList.end(), *fontName);
|
||||||
size_t val = (it != sortedFontList.end() && *it == *fontName) ? (it - sortedFontList.begin()): std::numeric_limits<size_t>::max();
|
size_t val = std::numeric_limits<size_t>::max();
|
||||||
if(val == std::numeric_limits<size_t>::max()) {
|
if(it == sortedFontList.end()) {
|
||||||
std::string lowerFamilyName = *fontName;
|
std::string lowerFamilyName = *fontName;
|
||||||
std::transform(lowerFamilyName.begin(), lowerFamilyName.end(), lowerFamilyName.begin(), ::tolower);
|
std::transform(lowerFamilyName.begin(), lowerFamilyName.end(), lowerFamilyName.begin(), ::tolower);
|
||||||
auto itLower = std::lower_bound(sortedFontListLowercase.begin(), sortedFontListLowercase.end(), lowerFamilyName);
|
auto itLower = std::find(sortedFontListLowercase.begin(), sortedFontListLowercase.end(), lowerFamilyName);
|
||||||
val = (itLower != sortedFontListLowercase.end() && *itLower == lowerFamilyName) ? (itLower - sortedFontListLowercase.begin()): std::numeric_limits<size_t>::max();
|
if(itLower != sortedFontListLowercase.end()) {
|
||||||
if(val != std::numeric_limits<size_t>::max())
|
val = itLower - sortedFontListLowercase.begin();
|
||||||
*fontName = sortedFontList[val];
|
*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)) {
|
if(gui->svg_icon_button("Open font dropdown", "data/icons/droparrow.svg", dropdownOpen, GUIManager::SMALL_BUTTON_SIZE)) {
|
||||||
dropdownOpen = !dropdownOpen;
|
dropdownOpen = !dropdownOpen;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ template <typename T> class TextBox : public Element {
|
||||||
force_update_textbox(io, false);
|
force_update_textbox(io, false);
|
||||||
|
|
||||||
textbox->set_width(std::numeric_limits<float>::max());
|
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({
|
CLAY({
|
||||||
.layout = {
|
.layout = {
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,6 @@ void Toolbar::load_icons_at(const std::filesystem::path& pathToLoad) {
|
||||||
io->svgData[iconRelativePath] = svgDom;
|
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