mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Fix bitmap font resize failing silently when resizing to an unsupported pixel size (#448), fixed getKerning returning scaled values even for bitmap fonts.
This commit is contained in:
parent
0124ad0a85
commit
da79517b36
@ -152,6 +152,10 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve a glyph of the font
|
||||
///
|
||||
/// If the font is a bitmap font, not all character sizes
|
||||
/// might be available. If the glyph is not available at the
|
||||
/// requested size, an empty glyph is returned.
|
||||
///
|
||||
/// \param codePoint Unicode code point of the character to get
|
||||
/// \param characterSize Reference character size
|
||||
/// \param bold Retrieve the bold version or the regular one?
|
||||
@ -379,6 +383,12 @@ private :
|
||||
/// with this class. However, it may be useful to access the
|
||||
/// font metrics or rasterized glyphs for advanced usage.
|
||||
///
|
||||
/// Note that if the font is a bitmap font, it is not scalable,
|
||||
/// thus not all requested sizes will be available to use. This
|
||||
/// needs to be taken into consideration when using sf::Text.
|
||||
/// If you need to display text of a certain size, make sure the
|
||||
/// corresponding bitmap font that supports that size is used.
|
||||
///
|
||||
/// \see sf::Text
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -72,6 +72,13 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Construct the text from a string, font and size
|
||||
///
|
||||
/// Note that if the used font is a bitmap font, it is not
|
||||
/// scalable, thus not all requested sizes will be available
|
||||
/// to use. This needs to be taken into consideration when
|
||||
/// setting the character size. If you need to display text
|
||||
/// of a certain size, make sure the corresponding bitmap
|
||||
/// font that supports that size is used.
|
||||
///
|
||||
/// \param string Text assigned to the string
|
||||
/// \param font Font used to draw the string
|
||||
/// \param characterSize Base size of characters, in pixels
|
||||
@ -122,6 +129,13 @@ public :
|
||||
///
|
||||
/// The default size is 30.
|
||||
///
|
||||
/// Note that if the used font is a bitmap font, it is not
|
||||
/// scalable, thus not all requested sizes will be available
|
||||
/// to use. This needs to be taken into consideration when
|
||||
/// setting the character size. If you need to display text
|
||||
/// of a certain size, make sure the corresponding bitmap
|
||||
/// font that supports that size is used.
|
||||
///
|
||||
/// \param size New character size, in pixels
|
||||
///
|
||||
/// \see getCharacterSize
|
||||
|
@ -332,6 +332,10 @@ int Font::getKerning(Uint32 first, Uint32 second, unsigned int characterSize) co
|
||||
FT_Vector kerning;
|
||||
FT_Get_Kerning(face, index1, index2, FT_KERNING_DEFAULT, &kerning);
|
||||
|
||||
// X advance is already in pixels for bitmap fonts
|
||||
if (!FT_IS_SCALABLE(face))
|
||||
return kerning.x;
|
||||
|
||||
// Return the X advance
|
||||
return kerning.x >> 6;
|
||||
}
|
||||
@ -476,7 +480,8 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold) c
|
||||
int ascender = face->size->metrics.ascender >> 6;
|
||||
|
||||
// Offset to make up for empty space between ascender and virtual top of the typeface
|
||||
int offset = characterSize - ascender;
|
||||
// Only applied to scalable fonts i.e. not to bitmap fonts
|
||||
int offset = FT_IS_SCALABLE(face) ? (characterSize - ascender) : 0;
|
||||
|
||||
if ((width > 0) && (height > 0))
|
||||
{
|
||||
@ -627,7 +632,23 @@ bool Font::setCurrentSize(unsigned int characterSize) const
|
||||
|
||||
if (currentSize != characterSize)
|
||||
{
|
||||
return FT_Set_Pixel_Sizes(face, 0, characterSize) == 0;
|
||||
FT_Error result = FT_Set_Pixel_Sizes(face, 0, characterSize);
|
||||
|
||||
if (result == FT_Err_Invalid_Pixel_Size)
|
||||
{
|
||||
// In the case of bitmap fonts, resizing can
|
||||
// fail if the requested size is not available
|
||||
if (!FT_IS_SCALABLE(face))
|
||||
{
|
||||
err() << "Failed to set bitmap font size to " << characterSize << std::endl;
|
||||
err() << "Available sizes are: ";
|
||||
for (int i = 0; i < face->num_fixed_sizes; ++i)
|
||||
err() << face->available_sizes[i].height << " ";
|
||||
err() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
return result == FT_Err_Ok;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user