mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 15:45:38 +00:00
Fixed an issue where defining a really small font size would crash the application.
This commit is contained in:
parent
5366af6999
commit
c78386e648
|
@ -79,7 +79,14 @@ Font::Font(int size, const std::string& path)
|
||||||
: mSize(size)
|
: mSize(size)
|
||||||
, mPath(path)
|
, mPath(path)
|
||||||
{
|
{
|
||||||
assert(mSize > 0);
|
if (mSize < 9) {
|
||||||
|
mSize = 9;
|
||||||
|
LOG(LogWarning) << "Requested font size too small, changing to minimum supported size";
|
||||||
|
}
|
||||||
|
else if (mSize > Renderer::getScreenHeight()) {
|
||||||
|
mSize = Renderer::getScreenHeight();
|
||||||
|
LOG(LogWarning) << "Requested font size too large, changing to maximum supported size";
|
||||||
|
}
|
||||||
|
|
||||||
mMaxGlyphHeight = 0;
|
mMaxGlyphHeight = 0;
|
||||||
|
|
||||||
|
@ -274,8 +281,6 @@ FT_Face Font::getFaceForChar(unsigned int id)
|
||||||
return mFaceCache.cbegin()->second->face;
|
return mFaceCache.cbegin()->second->face;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Font::clearFaceCache() { mFaceCache.clear(); }
|
|
||||||
|
|
||||||
Font::Glyph* Font::getGlyph(unsigned int id)
|
Font::Glyph* Font::getGlyph(unsigned int id)
|
||||||
{
|
{
|
||||||
// Is it already loaded?
|
// Is it already loaded?
|
||||||
|
@ -339,7 +344,6 @@ Font::Glyph* Font::getGlyph(unsigned int id)
|
||||||
return &glyph;
|
return &glyph;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Completely recreate the texture data for all textures based on mGlyphs information.
|
|
||||||
void Font::rebuildTextures()
|
void Font::rebuildTextures()
|
||||||
{
|
{
|
||||||
// Recreate OpenGL textures.
|
// Recreate OpenGL textures.
|
||||||
|
@ -441,7 +445,6 @@ float Font::getLetterHeight()
|
||||||
return glyph->texSize.y * glyph->texture->textureSize.y;
|
return glyph->texSize.y * glyph->texture->textureSize.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Breaks up a normal string with newlines to make it fit xLen.
|
|
||||||
std::string Font::wrapText(std::string text, float xLen)
|
std::string Font::wrapText(std::string text, float xLen)
|
||||||
{
|
{
|
||||||
std::string out;
|
std::string out;
|
||||||
|
@ -666,8 +669,6 @@ TextCache* Font::buildTextCache(const std::string& text,
|
||||||
x += glyph->advance.x;
|
x += glyph->advance.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TextCache::CacheMetrics metrics = { sizeText(text, lineSpacing) };
|
|
||||||
|
|
||||||
TextCache* cache = new TextCache();
|
TextCache* cache = new TextCache();
|
||||||
cache->vertexLists.resize(vertMap.size());
|
cache->vertexLists.resize(vertMap.size());
|
||||||
cache->metrics = {sizeText(text, lineSpacing)};
|
cache->metrics = {sizeText(text, lineSpacing)};
|
||||||
|
|
|
@ -141,6 +141,7 @@ private:
|
||||||
virtual ~FontFace();
|
virtual ~FontFace();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Completely recreate the texture data for all textures based on mGlyphs information.
|
||||||
void rebuildTextures();
|
void rebuildTextures();
|
||||||
void unloadTextures();
|
void unloadTextures();
|
||||||
|
|
||||||
|
@ -152,7 +153,7 @@ private:
|
||||||
|
|
||||||
std::map<unsigned int, std::unique_ptr<FontFace>> mFaceCache;
|
std::map<unsigned int, std::unique_ptr<FontFace>> mFaceCache;
|
||||||
FT_Face getFaceForChar(unsigned int id);
|
FT_Face getFaceForChar(unsigned int id);
|
||||||
void clearFaceCache();
|
void clearFaceCache() { mFaceCache.clear(); }
|
||||||
|
|
||||||
struct Glyph {
|
struct Glyph {
|
||||||
FontTexture* texture;
|
FontTexture* texture;
|
||||||
|
@ -170,7 +171,7 @@ private:
|
||||||
|
|
||||||
int mMaxGlyphHeight;
|
int mMaxGlyphHeight;
|
||||||
|
|
||||||
const int mSize;
|
int mSize;
|
||||||
const std::string mPath;
|
const std::string mPath;
|
||||||
|
|
||||||
float getNewlineStartOffset(const std::string& text,
|
float getNewlineStartOffset(const std::string& text,
|
||||||
|
|
Loading…
Reference in a new issue