change fonts to woff2

This commit is contained in:
Kae 2024-03-25 12:49:18 +11:00
parent 9aaaf874e9
commit 84a2d8f7f8
54 changed files with 19 additions and 15 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1181,7 +1181,7 @@ shared_ptr<Assets::AssetData> Assets::loadAudio(AssetPath const& path) const {
shared_ptr<Assets::AssetData> Assets::loadFont(AssetPath const& path) const { shared_ptr<Assets::AssetData> Assets::loadFont(AssetPath const& path) const {
return unlockDuring([&]() { return unlockDuring([&]() {
auto newData = make_shared<FontData>(); auto newData = make_shared<FontData>();
newData->font = Font::loadTrueTypeFont(make_shared<ByteArray>(read(path.basePath))); newData->font = Font::loadFont(make_shared<ByteArray>(read(path.basePath)));
return newData; return newData;
}); });
} }

View File

@ -32,11 +32,11 @@ struct FontImpl {
FT_Face face; FT_Face face;
}; };
FontPtr Font::loadTrueTypeFont(String const& fileName, unsigned pixelSize) { FontPtr Font::loadFont(String const& fileName, unsigned pixelSize) {
return loadTrueTypeFont(make_shared<ByteArray>(File::readFile(fileName)), pixelSize); return loadFont(make_shared<ByteArray>(File::readFile(fileName)), pixelSize);
} }
FontPtr Font::loadTrueTypeFont(ByteArrayConstPtr const& bytes, unsigned pixelSize) { FontPtr Font::loadFont(ByteArrayConstPtr const& bytes, unsigned pixelSize) {
FontPtr font = make_shared<Font>(); FontPtr font = make_shared<Font>();
font->m_fontBuffer = bytes; font->m_fontBuffer = bytes;
@ -54,7 +54,7 @@ FontPtr Font::loadTrueTypeFont(ByteArrayConstPtr const& bytes, unsigned pixelSiz
Font::Font() : m_pixelSize(0), m_alphaThreshold(0) {} Font::Font() : m_pixelSize(0), m_alphaThreshold(0) {}
FontPtr Font::clone() const { FontPtr Font::clone() const {
return Font::loadTrueTypeFont(m_fontBuffer, m_pixelSize); return Font::loadFont(m_fontBuffer, m_pixelSize);
} }
void Font::setPixelSize(unsigned pixelSize) { void Font::setPixelSize(unsigned pixelSize) {

View File

@ -14,8 +14,8 @@ STAR_CLASS(Font);
class Font { class Font {
public: public:
static FontPtr loadTrueTypeFont(String const& fileName, unsigned pixelSize = 12); static FontPtr loadFont(String const& fileName, unsigned pixelSize = 12);
static FontPtr loadTrueTypeFont(ByteArrayConstPtr const& bytes, unsigned pixelSize = 12); static FontPtr loadFont(ByteArrayConstPtr const& bytes, unsigned pixelSize = 12);
Font(); Font();

View File

@ -337,15 +337,19 @@ void TextPainter::reloadFonts() {
auto assets = Root::singleton().assets(); auto assets = Root::singleton().assets();
String defaultName = "hobo"; String defaultName = "hobo";
auto defaultFont = loadFont("/hobo.ttf", defaultName); auto defaultFont = loadFont("/hobo.ttf", defaultName);
for (auto& fontPath : assets->scanExtension("ttf")) { auto loadFontsByExtension = [&](String const& ext) {
auto font = assets->font(fontPath); for (auto& fontPath : assets->scanExtension(ext)) {
if (font == defaultFont) auto font = assets->font(fontPath);
continue; if (font == defaultFont)
continue;
auto name = AssetPath::filename(fontPath); auto name = AssetPath::filename(fontPath);
name = name.substr(0, name.findLast(".")); name = name.substr(0, name.findLast("."));
addFont(loadFont(fontPath, name), name); addFont(loadFont(fontPath, name), name);
} }
};
loadFontsByExtension("ttf");
loadFontsByExtension("woff2");
m_fontTextureGroup.addFont(defaultFont, defaultName, true); m_fontTextureGroup.addFont(defaultFont, defaultName, true);
} }