mirror of
https://github.com/SFML/SFML.git
synced 2024-11-25 12:51:05 +08:00
Replaced Text underline offset/thickness with nicer font dependent values.
This commit is contained in:
parent
da79517b36
commit
bdcdfffe11
@ -196,6 +196,35 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
int getLineSpacing(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the position of the underline
|
||||
///
|
||||
/// Underline position is the vertical offset to apply between the
|
||||
/// baseline and the underline.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Underline position, in pixels
|
||||
///
|
||||
/// \see getUnderlineThickness
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int getUnderlinePosition(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the thickness of the underline
|
||||
///
|
||||
/// Underline thickness is the vertical size of the underline.
|
||||
///
|
||||
/// \param characterSize Reference character size
|
||||
///
|
||||
/// \return Underline thickness, in pixels
|
||||
///
|
||||
/// \see getUnderlinePosition
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
int getUnderlineThickness(unsigned int characterSize) const;
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Retrieve the texture containing the loaded glyphs of a certain size
|
||||
///
|
||||
|
@ -363,6 +363,46 @@ int Font::getLineSpacing(unsigned int characterSize) const
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int Font::getUnderlinePosition(unsigned int characterSize) const
|
||||
{
|
||||
FT_Face face = static_cast<FT_Face>(m_face);
|
||||
|
||||
if (face && setCurrentSize(characterSize))
|
||||
{
|
||||
// Return a fixed position if font is a bitmap font
|
||||
if (!FT_IS_SCALABLE(face))
|
||||
return characterSize / 10;
|
||||
|
||||
return (FT_MulFix(face->underline_position, face->size->metrics.y_scale) >> 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
int Font::getUnderlineThickness(unsigned int characterSize) const
|
||||
{
|
||||
FT_Face face = static_cast<FT_Face>(m_face);
|
||||
|
||||
if (face && setCurrentSize(characterSize))
|
||||
{
|
||||
// Return a fixed thickness if font is a bitmap font
|
||||
if (!FT_IS_SCALABLE(face))
|
||||
return characterSize / 14;
|
||||
|
||||
return (FT_MulFix(face->underline_thickness, face->size->metrics.y_scale) >> 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
const Texture& Font::getTexture(unsigned int characterSize) const
|
||||
{
|
||||
|
@ -262,8 +262,8 @@ void Text::ensureGeometryUpdate() const
|
||||
bool bold = (m_style & Bold) != 0;
|
||||
bool underlined = (m_style & Underlined) != 0;
|
||||
float italic = (m_style & Italic) ? 0.208f : 0.f; // 12 degrees
|
||||
float underlineOffset = m_characterSize * 0.1f;
|
||||
float underlineThickness = m_characterSize * (bold ? 0.1f : 0.07f);
|
||||
float underlineOffset = static_cast<float>(m_font->getUnderlinePosition(m_characterSize));
|
||||
float underlineThickness = static_cast<float>(m_font->getUnderlineThickness(m_characterSize));
|
||||
|
||||
// Precompute the variables needed by the algorithm
|
||||
float hspace = static_cast<float>(m_font->getGlyph(L' ', m_characterSize, bold).advance);
|
||||
|
Loading…
Reference in New Issue
Block a user