Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-21 23:13:37 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-21 23:13:37 +1000
commit92ef4dba0fe7a9bd152466cfa4fd194024105895 (patch)
tree30f9cd5c6322c5e99d91d72b04c185baa9e60673
parentf0fec34dc9c2dbc86dd424e4963983cbb2ed9b41 (diff)
fonts can reload now
-rw-r--r--source/rendering/StarFontTextureGroup.cpp5
-rw-r--r--source/rendering/StarFontTextureGroup.hpp1
-rw-r--r--source/rendering/StarTextPainter.cpp32
-rw-r--r--source/rendering/StarTextPainter.hpp3
4 files changed, 30 insertions, 11 deletions
diff --git a/source/rendering/StarFontTextureGroup.cpp b/source/rendering/StarFontTextureGroup.cpp
index d8c14d0..fe15381 100644
--- a/source/rendering/StarFontTextureGroup.cpp
+++ b/source/rendering/StarFontTextureGroup.cpp
@@ -34,6 +34,11 @@ void FontTextureGroup::addFont(FontPtr const& font, String const& name, bool def
m_defaultFont = m_font = font;
}
+void FontTextureGroup::clearFonts() {
+ m_fonts.clear();
+ m_font = m_defaultFont;
+}
+
const FontTextureGroup::GlyphTexture& FontTextureGroup::glyphTexture(String::Char c, unsigned size, String const& processingDirectives)
{
auto res = m_glyphs.insert(GlyphDescriptor{c, size, processingDirectives, m_font.get() }, GlyphTexture());
diff --git a/source/rendering/StarFontTextureGroup.hpp b/source/rendering/StarFontTextureGroup.hpp
index 9dfc248..e75fd56 100644
--- a/source/rendering/StarFontTextureGroup.hpp
+++ b/source/rendering/StarFontTextureGroup.hpp
@@ -36,6 +36,7 @@ public:
void switchFont(String const& font);
String const& activeFont();
void addFont(FontPtr const& font, String const& name, bool default = false);
+ void clearFonts();
private:
StringMap<FontPtr> m_fonts;
String m_fontName;
diff --git a/source/rendering/StarTextPainter.cpp b/source/rendering/StarTextPainter.cpp
index 1d3cd9c..599ffaf 100644
--- a/source/rendering/StarTextPainter.cpp
+++ b/source/rendering/StarTextPainter.cpp
@@ -92,17 +92,9 @@ TextPainter::TextPainter(RendererPtr renderer, TextureGroupPtr textureGroup)
m_splitIgnore(" \t"),
m_splitForce("\n\v"),
m_nonRenderedCharacters("\n\v\r") {
- auto assets = Root::singleton().assets();
- auto defaultFont = assets->font("/hobo.ttf");
- for (auto& fontPath : assets->scanExtension("ttf")) {
- auto font = assets->font(fontPath);
- if (font == defaultFont)
- continue;
-
- auto fileName = AssetPath::filename(fontPath);
- addFont(font->clone(), fileName.substr(0, fileName.findLast(".")));
- }
- m_fontTextureGroup.addFont(defaultFont->clone(), "hobo", true);
+ reloadFonts();
+ m_reloadTracker = make_shared<TrackerListener>();
+ Root::singleton().registerReloadListener(m_reloadTracker);
}
RectF TextPainter::renderText(String const& s, TextPositioning const& position) {
@@ -313,6 +305,22 @@ void TextPainter::addFont(FontPtr const& font, String const& name) {
m_fontTextureGroup.addFont(font, name);
}
+void TextPainter::reloadFonts() {
+ m_fontTextureGroup.clearFonts();
+ m_fontTextureGroup.cleanup(0);
+ auto assets = Root::singleton().assets();
+ auto defaultFont = assets->font("/hobo.ttf");
+ for (auto& fontPath : assets->scanExtension("ttf")) {
+ auto font = assets->font(fontPath);
+ if (font == defaultFont)
+ continue;
+
+ auto fileName = AssetPath::filename(fontPath);
+ addFont(font->clone(), fileName.substr(0, fileName.findLast(".")));
+ }
+ m_fontTextureGroup.addFont(defaultFont->clone(), "hobo", true);
+}
+
void TextPainter::cleanup(int64_t timeout) {
m_fontTextureGroup.cleanup(timeout);
}
@@ -346,6 +354,8 @@ RectF TextPainter::doRenderText(String const& s, TextPositioning const& position
}
RectF TextPainter::doRenderLine(String const& s, TextPositioning const& position, bool reallyRender, unsigned* charLimit) {
+ if (m_reloadTracker->pullTriggered())
+ reloadFonts();
String text = s;
TextPositioning pos = position;
diff --git a/source/rendering/StarTextPainter.hpp b/source/rendering/StarTextPainter.hpp
index 0d0b9eb..3ab468f 100644
--- a/source/rendering/StarTextPainter.hpp
+++ b/source/rendering/StarTextPainter.hpp
@@ -76,6 +76,7 @@ public:
void setProcessingDirectives(String directives);
void setFont(String const& font);
void addFont(FontPtr const& font, String const& name);
+ void reloadFonts();
void cleanup(int64_t textureTimeout);
@@ -105,6 +106,8 @@ private:
String m_splitIgnore;
String m_splitForce;
String m_nonRenderedCharacters;
+
+ TrackerListenerPtr m_reloadTracker;
};
}