summaryrefslogtreecommitdiff
path: root/indra/llrender
diff options
context:
space:
mode:
authorErik Kundiman <erik@megapahit.org>2026-09-04 23:09:56 +0800
committerErik Kundiman <erik@megapahit.org>2026-09-04 23:25:54 +0800
commit7f8684301a716d23343cd6e85a4759f3a11546d4 (patch)
tree989df6258c0399431aba03da5805d93542db5317 /indra/llrender
parent0400b6693648c58f901c2b492a78e332815bcaa2 (diff)
parenta4aa5233cad1fb66555e7768750af1b57bc1da7c (diff)
Merge tag 'Second_Life_Release#a4aa523-26.4' into 26.4
Diffstat (limited to 'indra/llrender')
-rw-r--r--indra/llrender/llfontfreetype.cpp18
-rw-r--r--indra/llrender/llfontfreetype.h2
-rw-r--r--indra/llrender/llfontgl.cpp28
3 files changed, 29 insertions, 19 deletions
diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp
index 73540200c9..ab3089a269 100644
--- a/indra/llrender/llfontfreetype.cpp
+++ b/indra/llrender/llfontfreetype.cpp
@@ -115,7 +115,7 @@ LLFontGlyphInfo::LLFontGlyphInfo(U32 index, EFontGlyphType glyph_type)
mChar(0),
mWidth(0), // In pixels
mHeight(0), // In pixels
- mXAdvance(0.f), // In pixels
+ mXAdvanceRaw(0.f), // In pixels
mYAdvance(0.f), // In pixels
mXBitmapOffset(0), // Offset to the origin in the bitmap
mYBitmapOffset(0), // Offset to the origin in the bitmap
@@ -133,7 +133,7 @@ LLFontGlyphInfo::LLFontGlyphInfo(const LLFontGlyphInfo& fgi)
, mChar(fgi.mChar)
, mWidth(fgi.mWidth)
, mHeight(fgi.mHeight)
- , mXAdvance(fgi.mXAdvance)
+ , mXAdvanceRaw(fgi.mXAdvanceRaw)
, mYAdvance(fgi.mYAdvance)
, mXBitmapOffset(fgi.mXBitmapOffset)
, mYBitmapOffset(fgi.mYBitmapOffset)
@@ -356,14 +356,14 @@ F32 LLFontFreetype::getXAdvance(llwchar wch) const
{
return mMaxDigitWidth;
}
- return gi->mXAdvance;
+ return gi->mXAdvanceRaw;
}
else
{
char_glyph_info_map_t::iterator found_it = mCharGlyphInfoMap.find((llwchar)0);
if (found_it != mCharGlyphInfoMap.end())
{
- return found_it->second->mXAdvance;
+ return found_it->second->mXAdvanceRaw;
}
}
@@ -382,7 +382,7 @@ F32 LLFontFreetype::getXAdvance(const LLFontGlyphInfo* glyph) const
return mMaxDigitWidth;
}
- return glyph->mXAdvance;
+ return glyph->mXAdvanceRaw;
}
F32 LLFontFreetype::getXKerning(llwchar char_left, llwchar char_right) const
@@ -637,15 +637,15 @@ LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, l
gi->mLsbDelta = (S32)fontp->mFTFace->glyph->lsb_delta;
gi->mRsbDelta = (S32)fontp->mFTFace->glyph->rsb_delta;
// Convert these from 26.6 units to float pixels.
- gi->mXAdvance = fontp->mFTFace->glyph->advance.x / 64.f;
+ gi->mXAdvanceRaw = fontp->mFTFace->glyph->advance.x / 64.f;
gi->mYAdvance = fontp->mFTFace->glyph->advance.y / 64.f;
if (mWeight > 0 && wch >= '0' && wch <= '9')
{
// Digits are supposed to be preloaded, and buffers
- // refresh when new chars get added, so this lazy load
- // should not cause any issues.
- mMaxDigitWidth = llmax(mMaxDigitWidth, gi->mXAdvance);
+ // refresh when new chars get added (mGeneration),
+ // so this lazy load should not cause any issues.
+ mMaxDigitWidth = llmax(mMaxDigitWidth, gi->mXAdvanceRaw);
}
insertGlyphInfo(wch, gi);
diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h
index 3191ca8df7..608313b4d6 100644
--- a/indra/llrender/llfontfreetype.h
+++ b/indra/llrender/llfontfreetype.h
@@ -83,7 +83,7 @@ struct LLFontGlyphInfo
// Metrics
S32 mWidth; // In pixels
S32 mHeight; // In pixels
- F32 mXAdvance; // In pixels
+ F32 mXAdvanceRaw; // In pixels, don't use directly, use getXAdvance() for tabular numbers to work correctly.
F32 mYAdvance; // In pixels
// Information for actually rendering
diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp
index bb5a12375e..89da15ed43 100644
--- a/indra/llrender/llfontgl.cpp
+++ b/indra/llrender/llfontgl.cpp
@@ -349,8 +349,9 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons
F32 x_offset = 0.0f;
if (mFontFreetype->getFontWeight() > 0 && fgi->mChar >= '0' && fgi->mChar <= '9' && mFontFreetype->getMaxDigitWidth() > 0.0f)
{
- // use mXAdvance directly here, since we don't want to get max width instead.
- x_offset = (mFontFreetype->getMaxDigitWidth() - fgi->mXAdvance) * 0.5f;
+ // getXAdvance will return max digit width.
+ // use mXAdvanceRaw directly here, since we don't want to get max width instead.
+ x_offset = (mFontFreetype->getMaxDigitWidth() - fgi->mXAdvanceRaw) * 0.5f;
}
// Draw the text at the appropriate location
@@ -613,10 +614,15 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
S32 start_of_last_word = 0;
bool in_word = false;
- // avoid S32 overflow when max_pixels == S32_MAX by staying in floating point
F32 scaled_max_pixels = max_pixels * sScaleX;
+ if (scaled_max_pixels >= (F32)S32_MAX)
+ {
+ scaled_max_pixels = (F32)S32_MAX;
+ }
+
F32 width_padding = 0.f;
+ const S32 LAST_CHARACTER = LLFontFreetype::LAST_CHAR_FULL;
LLFontGlyphInfo* next_glyph = NULL;
S32 i;
@@ -673,21 +679,25 @@ S32 LLFontGL::maxDrawableChars(const llwchar* wchars, F32 max_pixels, S32 max_ch
}
}
+ F32 advance = mFontFreetype->getXAdvance(fgi);
+
// account for glyphs that run beyond the starting point for the next glyphs
width_padding = llmax( 0.f, // always use positive padding amount
- width_padding - fgi->mXAdvance, // previous padding left over after advance of current character
- (F32)(fgi->mWidth + fgi->mXBearing) - fgi->mXAdvance); // difference between width of this character and advance to next character
+ width_padding - advance, // previous padding left over after advance of current character
+ (F32)(fgi->mWidth + fgi->mXBearing) - advance); // difference between width of this character and advance to next character
- cur_x += fgi->mXAdvance;
+ cur_x += advance;
- // clip if current character runs past scaled_max_pixels (using width_padding)
+ // Clip if current character runs past scaled_max_pixels (using width_padding)
if (scaled_max_pixels < cur_x + width_padding)
{
clip = true;
break;
}
- if (((i+1) < max_chars) && wchars[i+1])
+ if (((i+1) < max_chars)
+ && wchars[i+1]
+ && (wchars[i + 1] < LAST_CHARACTER))
{
// Kern this puppy.
next_glyph = mFontFreetype->getGlyphInfo(wchars[i+1], EFontGlyphType::Unspecified);
@@ -743,7 +753,7 @@ S32 LLFontGL::firstDrawableChar(const llwchar* wchars, F32 max_pixels, S32 text_
// other characters just use advance
F32 width = (i == start)
? (F32)(fgi->mWidth + fgi->mXBearing) // use actual width for last character
- : fgi->mXAdvance; // use advance for all other characters
+ : mFontFreetype->getXAdvance(fgi); // use advance for all other characters
if( scaled_max_pixels < (total_width + width) )
{