A few extra optimizations.

This commit is contained in:
Martín Lucas Golini
2025-11-20 00:19:45 -03:00
parent b20d1503a6
commit 02cd65eebe
5 changed files with 13 additions and 8 deletions

View File

@@ -40,7 +40,7 @@ class EE_API Text {
static inline bool canSkipShaping( Uint32 textDrawHints ) {
return Text::TextShaperOptimizations &&
( textDrawHints & ( TextHints::AllAscii | TextHints::AllLatin1 ) ) != 0;
( textDrawHints & ( TextHints::AllLatin1 | TextHints::AllAscii ) ) != 0;
}
static Float tabAdvance( Float spaceHorizontalAdvance, Uint32 tabLength,

View File

@@ -131,6 +131,7 @@ class EE_API UITextView : public UIWidget {
Vector2f mRealAlignOffset;
Int32 mSelCurInit;
Int32 mSelCurEnd;
Uint32 mTextDrawHints{ 0 };
struct SelPosCache {
SelPosCache( Vector2f ip, Vector2f ep ) : initPos( ip ), endPos( ep ) {}

View File

@@ -822,7 +822,7 @@ Vector2f Text::findCharacterPos( std::size_t index ) const {
return Text::findCharacterPos( index, mFontStyleConfig.Font, mFontStyleConfig.CharacterSize,
mString, mFontStyleConfig.Style, mTabWidth,
mFontStyleConfig.OutlineThickness );
mFontStyleConfig.OutlineThickness, {}, true, mTextHints );
}
Int32 Text::findCharacterFromPos( const Vector2i& pos, bool nearest ) const {

View File

@@ -92,7 +92,7 @@ DocumentView::computeLineBreaks( const String::View& string, const FontStyleConf
( fontStyle.Font->isMonospace() ||
( fontStyle.Font->getType() == FontType::TTF &&
static_cast<FontTrueType*>( fontStyle.Font )->isIdentifiedAsMonospace() &&
( textDrawHints & TextHints::AllAscii ) ) );
Text::canSkipShaping( textDrawHints ) ) );
size_t lastSpace = 0;
Uint32 prevChar = 0;

View File

@@ -195,6 +195,7 @@ const String& UITextView::getText() const {
UITextView* UITextView::setText( const String& text ) {
if ( mString != text ) {
mString = text;
mTextDrawHints = mString.getTextHints();
mTextCache->setString( mString );
recalculate();
@@ -208,6 +209,7 @@ UITextView* UITextView::setText( const String& text ) {
UITextView* UITextView::setText( String&& text ) {
if ( mString != text ) {
mString = std::move( text );
mTextDrawHints = mString.getTextHints();
mTextCache->setString( mString );
recalculate();
@@ -473,7 +475,7 @@ void UITextView::setTheme( UITheme* Theme ) {
}
Float UITextView::getTextWidth() {
return hasTextOverflow() ? Text::getTextWidth( mString, mFontStyleConfig )
return hasTextOverflow() ? Text::getTextWidth( mString, mFontStyleConfig, 4, mTextDrawHints )
: mTextCache->getTextWidth();
}
@@ -878,16 +880,18 @@ void UITextView::loadFromXmlNode( const pugi::xml_node& node ) {
void UITextView::updateTextOverflow() {
if ( hasTextOverflow() ) {
mTextOverflowWidth = Text::getTextWidth( mTextOverflow, mFontStyleConfig );
mTextOverflowWidth =
Text::getTextWidth( mTextOverflow, mFontStyleConfig, 4, mTextDrawHints );
Float maxWidth = mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right;
std::size_t charPos =
Text::findLastCharPosWithinLength( mString, maxWidth, mFontStyleConfig );
std::size_t charPos = Text::findLastCharPosWithinLength(
mString, maxWidth, mFontStyleConfig, 4, {}, mTextDrawHints );
if ( charPos != mString.size() ) {
maxWidth -= mTextOverflowWidth;
charPos = Text::findLastCharPosWithinLength( mString, maxWidth, mFontStyleConfig );
charPos = Text::findLastCharPosWithinLength( mString, maxWidth, mFontStyleConfig, 4, {},
mTextDrawHints );
mTextCache->setString( mString.view().substr( 0, charPos ) + mTextOverflow );
} else {
if ( mFlags & UI_WORD_WRAP ) {