infinipaint/src/FontData.cpp

45 lines
1.3 KiB
C++
Raw Normal View History

2025-07-06 20:43:53 +03:00
#include "FontData.hpp"
//#include <include/ports/SkFontMgr_directory.h>
#include <include/ports/SkFontMgr_empty.h>
#include <include/core/SkFontMetrics.h>
#include <include/core/SkTextBlob.h>
#include <iostream>
#ifdef __EMSCRIPTEN__
#elif _WIN32
#include <include/ports/SkTypeface_win.h>
#elif __APPLE__
#include <include/ports/SkFontMgr_mac_ct.h>
#elif __linux__
#include <include/ports/SkFontMgr_fontconfig.h>
#include <include/ports/SkFontScanner_FreeType.h>
#endif
FontData::FontData()
2025-07-06 20:43:53 +03:00
{
#ifdef __EMSCRIPTEN__
mgr = SkFontMgr_New_Custom_Empty();
#elif _WIN32
mgr = SkFontMgr_New_GDI();
#elif __APPLE__
mgr = SkFontMgr_New_Custom_Empty();
#elif __linux__
mgr = SkFontMgr_New_FontConfig(nullptr, SkFontScanner_Make_FreeType());
#else
mgr = SkFontMgr_New_Custom_Empty();
#endif
2025-07-06 20:43:53 +03:00
map["Roboto"] = mgr->makeFromFile("data/fonts/Roboto-variable.ttf");
collection = sk_make_sp<skia::textlayout::FontCollection>();
2025-11-08 20:50:23 +03:00
collection->setDefaultFontManager(mgr, {SkString{"Roboto"}});
2025-07-06 20:43:53 +03:00
}
FontData::~FontData() {
}
Vector2f get_str_font_bounds(const SkFont& font, const std::string& str) {
SkFontMetrics metrics;
font.getMetrics(&metrics);
float nextText = font.measureText(str.data(), str.length(), SkTextEncoding::kUTF8, nullptr);
return Vector2f{nextText, - metrics.fAscent + metrics.fDescent};
}