Displaying text works on emscripten version
This commit is contained in:
parent
cdbff3c043
commit
b8fb00e218
6 changed files with 38 additions and 15 deletions
|
|
@ -290,7 +290,7 @@ class ConanSkia(ConanFile):
|
|||
self.options.enable_fontmgr_android = enabled
|
||||
|
||||
if self.options.enable_fontmgr_custom_directory == None:
|
||||
enabled = self.options.use_freetype and arch != "wasm"
|
||||
enabled = self.options.use_freetype
|
||||
self.options.enable_fontmgr_custom_directory = enabled
|
||||
|
||||
if self.options.enable_fontmgr_custom_embedded == None:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#include "FontData.hpp"
|
||||
//#include <include/ports/SkFontMgr_directory.h>
|
||||
#include <include/ports/SkFontMgr_directory.h>
|
||||
#include <include/ports/SkFontMgr_empty.h>
|
||||
#include <include/core/SkFontMetrics.h>
|
||||
#include <include/core/SkTextBlob.h>
|
||||
|
|
@ -18,19 +18,24 @@
|
|||
FontData::FontData()
|
||||
{
|
||||
#ifdef __EMSCRIPTEN__
|
||||
mgr = SkFontMgr_New_Custom_Empty();
|
||||
localFontMgr = SkFontMgr_New_Custom_Empty();
|
||||
#elif _WIN32
|
||||
mgr = SkFontMgr_New_GDI();
|
||||
localFontMgr = SkFontMgr_New_GDI();
|
||||
#elif __APPLE__
|
||||
mgr = SkFontMgr_New_Custom_Empty();
|
||||
localFontMgr = SkFontMgr_New_Custom_Empty();
|
||||
#elif __linux__
|
||||
mgr = SkFontMgr_New_FontConfig(nullptr, SkFontScanner_Make_FreeType());
|
||||
localFontMgr = SkFontMgr_New_FontConfig(nullptr, SkFontScanner_Make_FreeType());
|
||||
#else
|
||||
mgr = SkFontMgr_New_Custom_Empty();
|
||||
localFontMgr = SkFontMgr_New_Custom_Empty();
|
||||
#endif
|
||||
map["Roboto"] = mgr->makeFromFile("data/fonts/Roboto-variable.ttf");
|
||||
|
||||
defaultFontMgr = SkFontMgr_New_Custom_Directory("data/fonts");
|
||||
|
||||
map["Roboto"] = defaultFontMgr->makeFromFile("data/fonts/Roboto-variable.ttf");
|
||||
|
||||
collection = sk_make_sp<skia::textlayout::FontCollection>();
|
||||
collection->setDefaultFontManager(mgr, {SkString{"Roboto"}});
|
||||
collection->setDefaultFontManager(defaultFontMgr, {SkString{"Roboto"}});
|
||||
collection->setDynamicFontManager(localFontMgr);
|
||||
}
|
||||
|
||||
FontData::~FontData() {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ using namespace Eigen;
|
|||
|
||||
struct FontData {
|
||||
FontData();
|
||||
sk_sp<SkFontMgr> mgr;
|
||||
sk_sp<SkFontMgr> defaultFontMgr;
|
||||
sk_sp<SkFontMgr> localFontMgr;
|
||||
sk_sp<skia::textlayout::FontCollection> collection;
|
||||
std::unordered_map<std::string, sk_sp<SkTypeface>> map;
|
||||
~FontData();
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <Eigen/Dense>
|
||||
#include <include/core/SkFont.h>
|
||||
#include <include/core/SkFontMgr.h>
|
||||
#include <include/core/SkTypeface.h>
|
||||
#include <modules/skparagraph/include/FontCollection.h>
|
||||
#include <modules/svg/include/SkSVGDOM.h>
|
||||
#include <Helpers/SCollision.hpp>
|
||||
|
|
@ -108,7 +109,6 @@ struct UpdateInputData {
|
|||
SkFont get_font(float fSize) const;
|
||||
|
||||
uint16_t fontSize = 16;
|
||||
sk_sp<SkTypeface> textTypeface;
|
||||
|
||||
sk_sp<skia::textlayout::FontCollection> fontCollection;
|
||||
|
||||
|
|
@ -116,7 +116,11 @@ struct UpdateInputData {
|
|||
bool hoverObstructed = false;
|
||||
bool acceptingTextInput = false;
|
||||
float deltaTime = 0.0f;
|
||||
sk_sp<SkFontMgr> textFontMgr;
|
||||
|
||||
sk_sp<SkFontMgr> textFontMgrLocal;
|
||||
sk_sp<SkFontMgr> textFontMgrFallback;
|
||||
sk_sp<SkTypeface> textTypeface;
|
||||
|
||||
DefaultStringArena* strArena;
|
||||
std::shared_ptr<Theme> theme;
|
||||
std::unordered_map<std::string, sk_sp<SkSVGDOM>> svgData;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,21 @@
|
|||
bool GUIStuff::FontPicker::update(UpdateInputData& io, std::string* fontName, GUIManager* gui) {
|
||||
if(sortedFontList.empty()) {
|
||||
auto icu = SkUnicodes::ICU::Make();
|
||||
for(int i = 0; i < io.textFontMgr->countFamilies(); i++) {
|
||||
for(int i = 0; i < io.textFontMgrLocal->countFamilies(); i++) {
|
||||
SkString familyNameSkString;
|
||||
io.textFontMgr->getFamilyName(i, &familyNameSkString);
|
||||
io.textFontMgrLocal->getFamilyName(i, &familyNameSkString);
|
||||
if(familyNameSkString.isEmpty())
|
||||
continue;
|
||||
std::string familyName(familyNameSkString.c_str(), familyNameSkString.size());
|
||||
sortedFontList.emplace_back(familyName);
|
||||
std::transform(familyName.begin(), familyName.end(), familyName.begin(), ::tolower);
|
||||
sortedFontListLowercase.emplace_back(familyName);
|
||||
}
|
||||
for(int i = 0; i < io.textFontMgrFallback->countFamilies(); i++) {
|
||||
SkString familyNameSkString;
|
||||
io.textFontMgrFallback->getFamilyName(i, &familyNameSkString);
|
||||
if(familyNameSkString.isEmpty())
|
||||
continue;
|
||||
std::string familyName(familyNameSkString.c_str(), familyNameSkString.size());
|
||||
sortedFontList.emplace_back(familyName);
|
||||
std::transform(familyName.begin(), familyName.end(), familyName.begin(), ::tolower);
|
||||
|
|
|
|||
|
|
@ -39,7 +39,8 @@ Toolbar::Toolbar(MainProgram& initMain):
|
|||
main(initMain)
|
||||
{
|
||||
io->textTypeface = main.fonts.map["Roboto"];
|
||||
io->textFontMgr = main.fonts.mgr;
|
||||
io->textFontMgrLocal = main.fonts.localFontMgr;
|
||||
io->textFontMgrFallback = main.fonts.defaultFontMgr;
|
||||
io->fontCollection = main.fonts.collection;
|
||||
|
||||
load_default_palette();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue