Fixed a bug where the characters size was sometimes wrong in sf::Text

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1532 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-07-18 15:59:59 +00:00
parent 1f906c0643
commit dcbc7f29a4
2 changed files with 19 additions and 19 deletions

View File

@ -281,7 +281,6 @@ private :
int* myRefCount; ///< Reference counter used by implicit sharing
mutable PageTable myPages; ///< Table containing the glyphs pages by character size
mutable std::vector<Uint8> myPixelBuffer; ///< Pixel buffer holding a glyph's pixels before being written to the texture
mutable unsigned int myCurrentSize; ///< Current character size in use
};
} // namespace sf

View File

@ -38,10 +38,9 @@ namespace sf
{
////////////////////////////////////////////////////////////
Font::Font() :
myLibrary (NULL),
myFace (NULL),
myRefCount (NULL),
myCurrentSize(0)
myLibrary (NULL),
myFace (NULL),
myRefCount(NULL)
{
}
@ -50,12 +49,11 @@ myCurrentSize(0)
////////////////////////////////////////////////////////////
Font::Font(const Font& copy) :
Resource<Font>(),
myLibrary (copy.myLibrary),
myFace (copy.myFace),
myRefCount (copy.myRefCount),
myPages (copy.myPages),
myPixelBuffer (copy.myPixelBuffer),
myCurrentSize (copy.myCurrentSize)
myLibrary (copy.myLibrary),
myFace (copy.myFace),
myRefCount (copy.myRefCount),
myPages (copy.myPages),
myPixelBuffer(copy.myPixelBuffer)
{
// Note: as FreeType doesn't provide functions for copying/cloning,
// we must share all the FreeType pointers
@ -155,6 +153,9 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes)
////////////////////////////////////////////////////////////
const Glyph& Font::GetGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) const
{
if (codePoint == 100)
codePoint = codePoint;
// Get the page corresponding to the character size
GlyphTable& glyphs = myPages[characterSize].Glyphs;
@ -239,7 +240,6 @@ Font& Font::operator =(const Font& right)
std::swap(myFace, temp.myFace);
std::swap(myPages, temp.myPages);
std::swap(myPixelBuffer, temp.myPixelBuffer);
std::swap(myCurrentSize, temp.myCurrentSize);
std::swap(myRefCount, temp.myRefCount);
return *this;
@ -294,10 +294,9 @@ void Font::Cleanup()
}
// Reset members
myLibrary = NULL;
myFace = NULL;
myRefCount = NULL;
myCurrentSize = 0;
myLibrary = NULL;
myFace = NULL;
myRefCount = NULL;
myPages.clear();
myPixelBuffer.clear();
}
@ -496,10 +495,12 @@ bool Font::SetCurrentSize(unsigned int characterSize) const
// FT_Set_Pixel_Sizes is an expensive function, so we must call it
// only when necessary to avoid killing performances
if (myCurrentSize != characterSize)
FT_Face face = static_cast<FT_Face>(myFace);
FT_UShort currentSize = face->size->metrics.x_ppem;
if (currentSize != characterSize)
{
myCurrentSize = characterSize;
return FT_Set_Pixel_Sizes(static_cast<FT_Face>(myFace), 0, characterSize) == 0;
return FT_Set_Pixel_Sizes(face, 0, characterSize) == 0;
}
else
{