From 97b0c99e29a60e858f7328094de7e59e5ad02278 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Thu, 9 Jul 2026 21:08:09 +0300 Subject: #5966 Fixed width font's numbers Dejavu used fixed width numbers by default, tweaked fonts to do the same for inter (when weight > 0). --- indra/llrender/llfontfreetype.cpp | 48 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'indra/llrender/llfontfreetype.cpp') diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp index 3c5682dfc9..bc4020a06b 100644 --- a/indra/llrender/llfontfreetype.cpp +++ b/indra/llrender/llfontfreetype.cpp @@ -109,6 +109,7 @@ LLFontManager::~LLFontManager() LLFontGlyphInfo::LLFontGlyphInfo(U32 index, EFontGlyphType glyph_type) : mGlyphIndex(index), mGlyphType(glyph_type), + mChar(0), mWidth(0), // In pixels mHeight(0), // In pixels mXAdvance(0.f), // In pixels @@ -126,6 +127,7 @@ LLFontGlyphInfo::LLFontGlyphInfo(U32 index, EFontGlyphType glyph_type) LLFontGlyphInfo::LLFontGlyphInfo(const LLFontGlyphInfo& fgi) : mGlyphIndex(fgi.mGlyphIndex) , mGlyphType(fgi.mGlyphType) + , mChar(fgi.mChar) , mWidth(fgi.mWidth) , mHeight(fgi.mHeight) , mXAdvance(fgi.mXAdvance) @@ -150,7 +152,8 @@ LLFontFreetype::LLFontFreetype() mFTFace(nullptr), mRenderGlyphCount(0), mStyle(0), - mPointSize(0) + mPointSize(0), + mMaxDigitWidth(0.0f) { } @@ -343,6 +346,10 @@ F32 LLFontFreetype::getXAdvance(llwchar wch) const LLFontGlyphInfo* gi = getGlyphInfo(wch, EFontGlyphType::Unspecified); if (gi) { + if (wch >= '0' && wch <= '9' && mMaxDigitWidth > 0.0f) + { + return mMaxDigitWidth; + } return gi->mXAdvance; } else @@ -363,6 +370,12 @@ F32 LLFontFreetype::getXAdvance(const LLFontGlyphInfo* glyph) const if (mFTFace == nullptr) return 0.0; + // Use max digit width for tabular numbers + if (mWeight > 0 && glyph->mChar >= '0' && glyph->mChar <= '9' && mMaxDigitWidth > 0.0f) + { + return mMaxDigitWidth; + } + return glyph->mXAdvance; } @@ -384,8 +397,27 @@ F32 LLFontFreetype::getXKerning(const LLFontGlyphInfo* left_glyph_info, const LL if (mFTFace == nullptr) return 0.0; - U32 left_glyph = left_glyph_info ? left_glyph_info->mGlyphIndex : 0; - U32 right_glyph = right_glyph_info ? right_glyph_info->mGlyphIndex : 0; + U32 left_glyph = 0; + U32 right_glyph = 0; + + if (left_glyph_info) + { + if (mWeight > 0 && left_glyph_info->mChar >= '0' && left_glyph_info->mChar <= '9') + { + // Disable kerning for digits when using tabular numbers + return 0.0; + } + left_glyph = left_glyph_info->mGlyphIndex; + } + if (right_glyph_info) + { + if (mWeight > 0 && right_glyph_info->mChar >= '0' && right_glyph_info->mChar <= '9') + { + // Disable kerning for digits when using tabular numbers + return 0.0; + } + right_glyph = right_glyph_info->mGlyphIndex; + } FT_Vector delta; @@ -548,6 +580,7 @@ LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, l mFontBitmapCachep->nextOpenPos(width, pos_x, pos_y, bitmap_glyph_type, bitmap_num); LLFontGlyphInfo* gi = new LLFontGlyphInfo(glyph_index, requested_glyph_type); + gi->mChar = wch; gi->mXBitmapOffset = pos_x; gi->mYBitmapOffset = pos_y; gi->mBitmapEntry = std::make_pair(bitmap_glyph_type, bitmap_num); @@ -564,6 +597,14 @@ LLFontGlyphInfo* LLFontFreetype::addGlyphFromFont(const LLFontFreetype *fontp, l gi->mXAdvance = 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); + } + insertGlyphInfo(wch, gi); if (requested_glyph_type != bitmap_glyph_type) @@ -799,6 +840,7 @@ void LLFontFreetype::resetBitmapCache() } mCharGlyphInfoMap.clear(); mFontBitmapCachep->reset(); + mMaxDigitWidth = 0.0f; // Adding default glyph is skipped for fallback fonts here as well as in loadFace(). // This if was added as fix for EXT-4971. -- cgit v1.3