Merge pull request #4303 from sethalves/font-load-failed

Font load failed
This commit is contained in:
Andrew Meadows 2015-02-17 17:31:26 -08:00
commit d7664718ee
2 changed files with 12 additions and 3 deletions

View file

@ -40,7 +40,7 @@ if (WIN32)
elseif (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unknown-pragmas")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-strict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-strict-aliasing -ggdb")
endif(WIN32)
if (NOT MSVC12)

View file

@ -511,6 +511,10 @@ TextRenderer::TextRenderer(const char* family, float pointSize, int weight,
bool italic, EffectType effect, int effectThickness,
const QColor& color) :
_effectType(effect), _effectThickness(effectThickness), _pointSize(pointSize), _color(color), _font(loadFont(family)) {
if (!_font) {
qWarning() << "Unable to load font with family " << family;
_font = loadFont("Courier");
}
if (1 != _effectThickness) {
qWarning() << "Effect thickness not current supported";
}
@ -524,7 +528,10 @@ TextRenderer::~TextRenderer() {
glm::vec2 TextRenderer::computeExtent(const QString & str) const {
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,
@ -544,7 +551,9 @@ float TextRenderer::draw(float x, float y, const QString & str,
// scale at all.
mv.translate(glm::vec2(x, y)).scale(glm::vec3(scale, -scale, scale));
// 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;
}