added FontNull, should hopefully prevent crashes from trying to load fonts with no fallback

This commit is contained in:
zetaPRIME 2017-05-11 17:42:07 -04:00
parent 15dbabd917
commit e183532747
4 changed files with 27 additions and 3 deletions

View File

@ -19,6 +19,7 @@
#include "starlight/gfx/DrawableNinePatch.h"
#include "starlight/gfx/DrawableTest.h"
#include "starlight/gfx/FontBMF.h"
#include "starlight/gfx/FontNull.h"
#include "starlight/gfx/RenderCore.h"
#include "starlight/gfx/BitmapFont.h"
@ -264,6 +265,10 @@ shared_ptr<Drawable> ThemeManager::LoadAsset(string& path, ThemeRefContainer<Dra
void ThemeManager::Fulfill(ThemeRefContainer<Font>& ref) {
string path = ResolveFontPath(ref.name);
if (path == "") { // no fonts found, emergency fallback
ref.ptr = make_shared<starlight::gfx::FontNull>();
return;
}
auto font = make_shared<starlight::gfx::FontBMF>();
{ // using:
json j;

View File

@ -14,8 +14,6 @@ namespace starlight {
namespace gfx {
class Font {
public:
static constexpr const int defaultSize = 16;
Font() { }
virtual ~Font() { }

View File

@ -0,0 +1,21 @@
#pragma once
#include "starlight/_global.h"
namespace starlight {
namespace gfx {
class FontNull : public Font {
public:
FontNull() { }
~FontNull() override { }
void Print(Vector2 position, const std::string& text, float scale = 1, Color color = Color::white, Vector2 justification = Vector2::zero, OptRef<Color> borderColor = nullptr) override {}
void Print(VRect rect, const std::string& text, float scale = 1, Color color = Color::white, Vector2 justification = Vector2::zero, OptRef<Color> borderColor = nullptr) override {}
Vector2 Measure(const std::string& text, float scale = 1, float maxWidth = 400) override { return Vector2::zero; }
Vector2 GetCursorPosition(VRect rect, const std::string& text, unsigned int end, float scale = 1) override { return Vector2::zero; }
unsigned int GetCursorFromPoint(VRect rect, const std::string& text, Vector2 pt, float scale = 1) override { return Vector2::zero; }
};
}
}

View File

@ -2,7 +2,7 @@
roadmap to v0.5.1 {
make font-not-found not outright crash the app
- make font-not-found not outright crash the app (hopefully)
make asset gc actually sweep every 5sec
maybe entirely replace clearing with transparent knockout on bind?
implement more blend modes??