Fix outline thickness.

This commit is contained in:
Martín Lucas Golini
2023-08-07 18:24:21 -03:00
parent 4de6afcbd1
commit 22e83d3da8
8 changed files with 44 additions and 32 deletions

View File

@@ -237,7 +237,7 @@ Glyph FontBMFont::loadGlyph( Uint32 codePoint, unsigned int characterSize, bool,
return glyph;
}
Float FontBMFont::getKerning( Uint32, Uint32, unsigned int, bool, bool ) const {
Float FontBMFont::getKerning( Uint32, Uint32, unsigned int, bool, bool, Float ) const {
return 0;
}

View File

@@ -215,7 +215,7 @@ Glyph FontSprite::loadGlyph( Uint32 codePoint, unsigned int characterSize ) cons
return glyph;
}
Float FontSprite::getKerning( Uint32, Uint32, unsigned int, bool, bool ) const {
Float FontSprite::getKerning( Uint32, Uint32, unsigned int, bool, bool, Float ) const {
return 0;
}

View File

@@ -56,7 +56,7 @@ static inline Uint64 getIndexKey( Uint32 fontInternalId, Uint32 index, bool bold
Float outlineThickness ) {
return ( static_cast<EE::Uint64>( reinterpret<EE::Uint32>( fontInternalId ) ) << 48 ) |
( static_cast<EE::Uint64>(
reinterpret<EE::Uint32>( static_cast<Uint32>( outlineThickness ) * 1000 ) )
reinterpret<EE::Uint32>( static_cast<Uint32>( outlineThickness ) * 100 ) )
<< 34 ) |
( static_cast<EE::Uint64>( bold ) << 33 ) |
( static_cast<EE::Uint64>( italics ) << 32 ) | index;
@@ -310,7 +310,8 @@ const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSiz
FontManager::instance()->getColorEmojiFont()->getType() == FontType::TTF ) {
if ( isMonospace() && maxWidth == 0.f ) {
Glyph monospaceGlyph = getGlyph( ' ', characterSize, bold, outlineThickness );
Glyph monospaceGlyph =
getGlyph( ' ', characterSize, bold, italic, outlineThickness );
maxWidth = monospaceGlyph.advance;
}
@@ -323,7 +324,8 @@ const Glyph& FontTrueType::getGlyph( Uint32 codePoint, unsigned int characterSiz
FontManager::instance()->getEmojiFont()->getType() == FontType::TTF ) {
if ( isMonospace() && maxWidth == 0.f ) {
Glyph monospaceGlyph = getGlyph( ' ', characterSize, bold, outlineThickness );
Glyph monospaceGlyph =
getGlyph( ' ', characterSize, bold, italic, outlineThickness );
maxWidth = monospaceGlyph.advance;
}
@@ -514,7 +516,7 @@ GlyphDrawable* FontTrueType::getGlyphDrawable( Uint32 codePoint, unsigned int ch
}
Float FontTrueType::getKerning( Uint32 first, Uint32 second, unsigned int characterSize, bool bold,
bool italic ) const {
bool italic, Float outlineThickness ) const {
// Special case where first or second is 0 (null character)
if ( first == 0 || second == 0 || isMonospace() )
return 0.f;
@@ -527,10 +529,10 @@ Float FontTrueType::getKerning( Uint32 first, Uint32 second, unsigned int charac
FT_UInt index2 = getGlyphIndex( second );
// Retrieve position compensation deltas generated by FT_LOAD_FORCE_AUTOHINT flag
auto firstRsbDelta =
static_cast<float>( getGlyph( first, characterSize, bold, italic ).rsbDelta );
auto secondLsbDelta =
static_cast<float>( getGlyph( second, characterSize, bold, italic ).lsbDelta );
auto firstRsbDelta = static_cast<float>(
getGlyph( first, characterSize, bold, italic, outlineThickness ).rsbDelta );
auto secondLsbDelta = static_cast<float>(
getGlyph( second, characterSize, bold, italic, outlineThickness ).lsbDelta );
// Get the kerning vector
FT_Vector kerning;

View File

@@ -422,12 +422,13 @@ Float Text::getTextWidth( Font* font, const Uint32& fontSize, const String& stri
Uint32 prevChar = 0;
bool bold = ( style & Text::Bold ) != 0;
bool italic = ( style & Text::Italic ) != 0;
Float hspace = static_cast<Float>( font->getGlyph( L' ', fontSize, bold, italic ).advance );
Float hspace = static_cast<Float>(
font->getGlyph( L' ', fontSize, bold, italic, outlineThickness ).advance );
for ( std::size_t i = 0; i < string.size(); ++i ) {
rune = string.at( i );
Glyph glyph = font->getGlyph( rune, fontSize, bold, italic, outlineThickness );
if ( rune != '\r' && rune != '\t' ) {
width += font->getKerning( prevChar, rune, fontSize, bold, italic );
width += font->getKerning( prevChar, rune, fontSize, bold, italic, outlineThickness );
prevChar = rune;
width += glyph.advance;
} else if ( rune == '\t' ) {
@@ -454,7 +455,8 @@ Vector2f Text::findCharacterPos( std::size_t index, Font* font, const Uint32& fo
// Precompute the variables needed by the algorithm
bool bold = ( style & Text::Bold ) != 0;
bool italic = ( style & Italic ) != 0;
Float hspace = static_cast<Float>( font->getGlyph( L' ', fontSize, bold, italic ).advance );
Float hspace = static_cast<Float>(
font->getGlyph( L' ', fontSize, bold, italic, outlineThickness ).advance );
Float vspace = static_cast<Float>( font->getLineSpacing( fontSize ) );
// Compute the position
@@ -464,7 +466,8 @@ Vector2f Text::findCharacterPos( std::size_t index, Font* font, const Uint32& fo
String::StringBaseType curChar = string[i];
// Apply the kerning offset
position.x += static_cast<Float>( font->getKerning( prevChar, curChar, fontSize, bold, italic ) );
position.x += static_cast<Float>(
font->getKerning( prevChar, curChar, fontSize, bold, italic, outlineThickness ) );
prevChar = curChar;
// Handle special characters
@@ -485,7 +488,7 @@ Vector2f Text::findCharacterPos( std::size_t index, Font* font, const Uint32& fo
// For regular characters, add the advance offset of the glyph
position.x += static_cast<Float>(
font->getGlyph( curChar, fontSize, bold, outlineThickness ).advance );
font->getGlyph( curChar, fontSize, bold, italic, outlineThickness ).advance );
}
return position;
@@ -509,16 +512,17 @@ Int32 Text::findCharacterFromPos( const Vector2i& pos, bool returnNearest, Font*
bool italic = ( style & Italic ) != 0;
Vector2f fpos( pos.asFloat() );
Float hspace = static_cast<Float>( font->getGlyph( L' ', fontSize, bold, italic ).advance );
Float hspace = static_cast<Float>(
font->getGlyph( L' ', fontSize, bold, italic, outlineThickness ).advance );
for ( std::size_t i = 0; i < tSize; ++i ) {
rune = string[i];
Glyph glyph = font->getGlyph( rune, fontSize, bold, outlineThickness );
Glyph glyph = font->getGlyph( rune, fontSize, bold, italic, outlineThickness );
lWidth = width;
if ( rune != '\r' && rune != '\t' ) {
width += font->getKerning( prevChar, rune, fontSize, bold, italic );
width += font->getKerning( prevChar, rune, fontSize, bold, italic, outlineThickness );
prevChar = rune;
width += glyph.advance;
} else if ( rune == '\t' ) {
@@ -579,14 +583,16 @@ void Text::getWidthInfo() {
mLinesStartIndex.push_back( 0 );
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold, italic ).advance );
Float hspace = static_cast<Float>(
mFont->getGlyph( L' ', mRealFontSize, bold, italic, mOutlineThickness ).advance );
for ( std::size_t i = 0; i < mString.size(); ++i ) {
CharID = static_cast<Int32>( mString.at( i ) );
Glyph glyph = mFont->getGlyph( CharID, mRealFontSize, bold, mOutlineThickness );
Glyph glyph = mFont->getGlyph( CharID, mRealFontSize, bold, italic, mOutlineThickness );
if ( CharID != '\r' && CharID != '\t' ) {
Width += mFont->getKerning( prevChar, CharID, mRealFontSize, bold, italic );
Width += mFont->getKerning( prevChar, CharID, mRealFontSize, bold, italic,
mOutlineThickness );
prevChar = CharID;
Width += glyph.advance;
}
@@ -635,10 +641,11 @@ void Text::wrapText( const Uint32& maxWidth ) {
bool bold = ( mStyle & Bold ) != 0;
bool italic = ( mStyle & Italic ) != 0;
Float hspace = static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold, italic ).advance );
Float hspace = static_cast<Float>(
mFont->getGlyph( L' ', mRealFontSize, bold, italic, mOutlineThickness ).advance );
while ( *tChar ) {
Glyph pChar = mFont->getGlyph( *tChar, mRealFontSize, bold, mOutlineThickness );
Glyph pChar = mFont->getGlyph( *tChar, mRealFontSize, bold, italic, mOutlineThickness );
Float fCharWidth = (Float)pChar.advance;
@@ -651,7 +658,8 @@ void Text::wrapText( const Uint32& maxWidth ) {
tWordWidth += fCharWidth;
if ( *tChar != '\r' ) {
tWordWidth += mFont->getKerning( prevChar, *tChar, mRealFontSize, bold, italic );
tWordWidth += mFont->getKerning( prevChar, *tChar, mRealFontSize, bold, italic,
mOutlineThickness );
prevChar = *tChar;
}
@@ -926,8 +934,8 @@ void Text::ensureGeometryUpdate() {
}
// Precompute the variables needed by the algorithm
Float hspace = static_cast<Float>(
mFont->getGlyph( L' ', mRealFontSize, bold, reqItalic ).advance );
Float hspace =
static_cast<Float>( mFont->getGlyph( L' ', mRealFontSize, bold, reqItalic ).advance );
Float vspace = static_cast<Float>( mFont->getLineSpacing( mRealFontSize ) );
Float x = 0.f;
Float y = static_cast<Float>( mRealFontSize );
@@ -957,7 +965,8 @@ void Text::ensureGeometryUpdate() {
Uint32 curChar = mString[i];
// Apply the kerning offset
x += mFont->getKerning( prevChar, curChar, mRealFontSize, bold, reqItalic );
x += mFont->getKerning( prevChar, curChar, mRealFontSize, bold, reqItalic,
mOutlineThickness );
prevChar = curChar;
// If we're using the underlined style and there's a new line, draw a line
@@ -1030,7 +1039,8 @@ void Text::ensureGeometryUpdate() {
// Apply the outline
if ( mOutlineThickness != 0 ) {
const Glyph& glyph = mFont->getGlyph( curChar, mRealFontSize, bold, mOutlineThickness );
const Glyph& glyph =
mFont->getGlyph( curChar, mRealFontSize, bold, italic, mOutlineThickness );
Float left = glyph.bounds.Left;
Float top = glyph.bounds.Top;