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 {
return unlockDuring([&]() {
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;
});
}

View File

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

View File

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

View File

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