mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 03:27:48 +02:00
don't crash if font load fails
This commit is contained in:
parent
dd64eeb282
commit
9fcb7591e6
1 changed files with 10 additions and 2 deletions
|
@ -511,6 +511,9 @@ TextRenderer::TextRenderer(const char* family, float pointSize, int weight,
|
||||||
bool italic, EffectType effect, int effectThickness,
|
bool italic, EffectType effect, int effectThickness,
|
||||||
const QColor& color) :
|
const QColor& color) :
|
||||||
_effectType(effect), _effectThickness(effectThickness), _pointSize(pointSize), _color(color), _font(loadFont(family)) {
|
_effectType(effect), _effectThickness(effectThickness), _pointSize(pointSize), _color(color), _font(loadFont(family)) {
|
||||||
|
if (!_font) {
|
||||||
|
qWarning() << "Unable to load font with family " << family;
|
||||||
|
}
|
||||||
if (1 != _effectThickness) {
|
if (1 != _effectThickness) {
|
||||||
qWarning() << "Effect thickness not current supported";
|
qWarning() << "Effect thickness not current supported";
|
||||||
}
|
}
|
||||||
|
@ -524,7 +527,10 @@ TextRenderer::~TextRenderer() {
|
||||||
|
|
||||||
glm::vec2 TextRenderer::computeExtent(const QString & str) const {
|
glm::vec2 TextRenderer::computeExtent(const QString & str) const {
|
||||||
float scale = (_pointSize / DEFAULT_POINT_SIZE) * 0.25f;
|
float scale = (_pointSize / DEFAULT_POINT_SIZE) * 0.25f;
|
||||||
return _font->computeExtent(str) * scale;
|
if (_font) {
|
||||||
|
return _font->computeExtent(str) * scale;
|
||||||
|
}
|
||||||
|
return glm::vec2(0.1f,0.1f);
|
||||||
}
|
}
|
||||||
|
|
||||||
float TextRenderer::draw(float x, float y, const QString & str,
|
float TextRenderer::draw(float x, float y, const QString & str,
|
||||||
|
@ -544,7 +550,9 @@ float TextRenderer::draw(float x, float y, const QString & str,
|
||||||
// scale at all.
|
// scale at all.
|
||||||
mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale));
|
mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale));
|
||||||
// The font does all the OpenGL work
|
// The font does all the OpenGL work
|
||||||
result = _font->drawString(x, y, str, actualColor, _effectType, bounds / scale);
|
if (_font) {
|
||||||
|
result = _font->drawString(x, y, str, actualColor, _effectType, bounds / scale);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return result.x;
|
return result.x;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue