mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 14:21:04 +08:00
Added getAscent and getDescent functions to Font
This commit is contained in:
parent
7987d3cedc
commit
95448f8c11
@ -206,6 +206,30 @@ public:
|
||||
////////////////////////////////////////////////////////////
|
||||
float getKerning(std::uint32_t first, std::uint32_t second, unsigned int characterSize, bool bold = false) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the font's ascent
|
||||
///
|
||||
/// The ascent is the distance between the top of the font and the baseline.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Font's ascent, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getAscent(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the font's descent
|
||||
///
|
||||
/// The descent is the distance between the baseline and the bottom of the font.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Font's descent, in pixels
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
float getDescent(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the line spacing
|
||||
///
|
||||
|
@ -375,6 +375,48 @@ float Font::getKerning(std::uint32_t first, std::uint32_t second, unsigned int c
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Font::getAscent(unsigned int characterSize) const
|
||||
{
|
||||
assert(m_fontHandles);
|
||||
|
||||
FT_Face face = m_fontHandles->face;
|
||||
|
||||
if (setCurrentSize(characterSize))
|
||||
{
|
||||
if (!FT_IS_SCALABLE(face))
|
||||
return static_cast<float>(face->size->metrics.ascender) / static_cast<float>(1 << 6);
|
||||
|
||||
return static_cast<float>(FT_MulFix(face->ascender, face->size->metrics.y_scale)) / static_cast<float>(1 << 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Font::getDescent(unsigned int characterSize) const
|
||||
{
|
||||
assert(m_fontHandles);
|
||||
|
||||
FT_Face face = m_fontHandles->face;
|
||||
|
||||
if (setCurrentSize(characterSize))
|
||||
{
|
||||
if (!FT_IS_SCALABLE(face))
|
||||
return static_cast<float>(-face->size->metrics.descender) / static_cast<float>(1 << 6);
|
||||
|
||||
return static_cast<float>(FT_MulFix(-face->descender, face->size->metrics.y_scale)) / static_cast<float>(1 << 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
float Font::getLineSpacing(unsigned int characterSize) const
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user