mirror of
https://github.com/SFML/SFML.git
synced 2025-01-19 07:45:13 +08:00
Fix font pages not being created with the desired smoothness
This commit is contained in:
parent
470822cfe4
commit
f7c88ee7ef
@ -335,7 +335,7 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
struct Page
|
struct Page
|
||||||
{
|
{
|
||||||
Page();
|
explicit Page(bool smooth);
|
||||||
|
|
||||||
GlyphTable glyphs; //!< Table mapping code points to their corresponding glyph
|
GlyphTable glyphs; //!< Table mapping code points to their corresponding glyph
|
||||||
Texture texture; //!< Texture containing the pixels of the glyphs
|
Texture texture; //!< Texture containing the pixels of the glyphs
|
||||||
@ -349,6 +349,16 @@ private:
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
/// \brief Find or create the glyphs page corresponding to the given character size
|
||||||
|
///
|
||||||
|
/// \param characterSize Reference character size
|
||||||
|
///
|
||||||
|
/// \return The glyphs page corresponding to \a characterSize
|
||||||
|
///
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
Page& loadPage(unsigned int characterSize) const;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Load a new glyph and store it in the cache
|
/// \brief Load a new glyph and store it in the cache
|
||||||
///
|
///
|
||||||
|
@ -348,7 +348,7 @@ const Font::Info& Font::getInfo() const
|
|||||||
const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
|
const Glyph& Font::getGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
|
||||||
{
|
{
|
||||||
// Get the page corresponding to the character size
|
// Get the page corresponding to the character size
|
||||||
GlyphTable& glyphs = m_pages[characterSize].glyphs;
|
GlyphTable& glyphs = loadPage(characterSize).glyphs;
|
||||||
|
|
||||||
// Build the key by combining the glyph index (based on code point), bold flag, and outline thickness
|
// Build the key by combining the glyph index (based on code point), bold flag, and outline thickness
|
||||||
Uint64 key = combine(outlineThickness, bold, FT_Get_Char_Index(static_cast<FT_Face>(m_face), codePoint));
|
Uint64 key = combine(outlineThickness, bold, FT_Get_Char_Index(static_cast<FT_Face>(m_face), codePoint));
|
||||||
@ -476,7 +476,7 @@ float Font::getUnderlineThickness(unsigned int characterSize) const
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
const Texture& Font::getTexture(unsigned int characterSize) const
|
const Texture& Font::getTexture(unsigned int characterSize) const
|
||||||
{
|
{
|
||||||
return m_pages[characterSize].texture;
|
return loadPage(characterSize).texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -567,6 +567,18 @@ void Font::cleanup()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
Font::Page& Font::loadPage(unsigned int characterSize) const
|
||||||
|
{
|
||||||
|
// TODO: Remove this method and use try_emplace instead when updating to C++17
|
||||||
|
PageTable::iterator pageIterator = m_pages.find(characterSize);
|
||||||
|
if (pageIterator == m_pages.end())
|
||||||
|
pageIterator = m_pages.insert(std::make_pair(characterSize, Page(m_isSmooth))).first;
|
||||||
|
|
||||||
|
return pageIterator->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
|
Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, float outlineThickness) const
|
||||||
{
|
{
|
||||||
@ -652,7 +664,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f
|
|||||||
height += 2 * padding;
|
height += 2 * padding;
|
||||||
|
|
||||||
// Get the glyphs page corresponding to the character size
|
// Get the glyphs page corresponding to the character size
|
||||||
Page& page = m_pages[characterSize];
|
Page& page = loadPage(characterSize);
|
||||||
|
|
||||||
// Find a good position for the new glyph into the texture
|
// Find a good position for the new glyph into the texture
|
||||||
glyph.textureRect = findGlyphRect(page, width, height);
|
glyph.textureRect = findGlyphRect(page, width, height);
|
||||||
@ -842,7 +854,7 @@ bool Font::setCurrentSize(unsigned int characterSize) const
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
Font::Page::Page() :
|
Font::Page::Page(bool smooth) :
|
||||||
nextRow(3)
|
nextRow(3)
|
||||||
{
|
{
|
||||||
// Make sure that the texture is initialized by default
|
// Make sure that the texture is initialized by default
|
||||||
@ -856,7 +868,7 @@ nextRow(3)
|
|||||||
|
|
||||||
// Create the texture
|
// Create the texture
|
||||||
texture.loadFromImage(image);
|
texture.loadFromImage(image);
|
||||||
texture.setSmooth(true);
|
texture.setSmooth(smooth);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
Loading…
Reference in New Issue
Block a user