From 7269f7a3a567f2823b0cca1d0bc716a7a0389ecc Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Tue, 8 Aug 2023 22:16:09 +0300 Subject: [PATCH 1/3] viewer#2023 Google Inter --- autobuild.xml | 34 +++++++ indra/cmake/ViewerMiscLibs.cmake | 1 + indra/llrender/llfontfreetype.cpp | 29 ++++-- indra/llrender/llfontfreetype.h | 11 ++- indra/llrender/llfontgl.cpp | 4 +- indra/llrender/llfontgl.h | 2 +- indra/llrender/llfontregistry.cpp | 50 +++++++++-- indra/llrender/llfontregistry.h | 21 ++++- indra/newview/skins/default/xui/en/fonts.xml | 94 +++++++++++--------- indra/newview/skins/default/xui/ja/fonts.xml | 94 ++++++++++---------- 10 files changed, 231 insertions(+), 109 deletions(-) diff --git a/autobuild.xml b/autobuild.xml index 95ee34439b0..1fa5182ef5e 100644 --- a/autobuild.xml +++ b/autobuild.xml @@ -2554,6 +2554,40 @@ Copyright (c) 2012, 2014, 2015, 2016 nghttp2 contributors description Viewer fonts + google-fonts + + copyright + Copyright 2020 The Inter Project Authors (https://github.com/rsms/inter) + description + Google fonts + license + SIL Open Font License, Version 1.1 + license_file + LICENSES/google_inter.txt + name + google-fonts + platforms + + common + + archive + + creds + github + hash + 22bcc72ed59926f00ed58a57f5e3cd3d9d82595f + hash_algorithm + sha1 + url + https://api.github.com/repos/secondlife/3p-google-fonts/releases/assets/195509500 + + name + common + + + version + 1.0.0.11083103671 + viewer-manager platforms diff --git a/indra/cmake/ViewerMiscLibs.cmake b/indra/cmake/ViewerMiscLibs.cmake index cae68fbc119..ee679777152 100644 --- a/indra/cmake/ViewerMiscLibs.cmake +++ b/indra/cmake/ViewerMiscLibs.cmake @@ -20,4 +20,5 @@ use_prebuilt_binary(slvoice) use_prebuilt_binary(nanosvg) use_prebuilt_binary(viewer-fonts) +use_prebuilt_binary(google-fonts) use_prebuilt_binary(emoji_shortcodes) diff --git a/indra/llrender/llfontfreetype.cpp b/indra/llrender/llfontfreetype.cpp index 62b551f1e0a..9a3ae6c55f0 100644 --- a/indra/llrender/llfontfreetype.cpp +++ b/indra/llrender/llfontfreetype.cpp @@ -144,6 +144,7 @@ LLFontFreetype::LLFontFreetype() pFtStream(NULL), #endif mIsFallback(false), + mHinting(EFontHinting::FORCE_AUTOHINT), mFTFace(NULL), mRenderGlyphCount(0), mStyle(0), @@ -186,7 +187,7 @@ void ft_close_cb(FT_Stream stream) { } #endif -bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 vert_dpi, F32 horz_dpi, bool is_fallback, S32 face_n) +bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 vert_dpi, F32 horz_dpi, bool is_fallback, S32 face_n, EFontHinting hinting, S32 flags) { // Don't leak face objects. This is also needed to deal with // changed font file names. @@ -215,6 +216,8 @@ bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 v } mIsFallback = is_fallback; + mHinting = hinting; + mFontFlags = flags; F32 pixels_per_em = (point_size / 72.f)*vert_dpi; // Size in inches * dpi error = FT_Set_Char_Size(mFTFace, /* handle to face object */ @@ -272,6 +275,12 @@ bool LLFontFreetype::loadFace(const std::string& filename, F32 point_size, F32 v { mStyle |= LLFontGL::BOLD; } + else if (flags & LLFontGL::BOLD) + { + // FontGL applies programmatic bolding to fonts that are a part of 'bold' descriptor but don't have the bold style set. + // Ex: Inter SemiBold doesn't have FT_STYLE_FLAG_BOLD and without this style it would be bolded programmatically. + mStyle |= LLFontGL::BOLD; + } if(mFTFace->style_flags & FT_STYLE_FLAG_ITALIC) { @@ -422,7 +431,12 @@ F32 LLFontFreetype::getXKerning(llwchar char_left, llwchar char_right) const llverify(!FT_Get_Kerning(mFTFace, left_glyph, right_glyph, ft_kerning_unfitted, &delta)); - return delta.x*(1.f/64.f); + if (mFTFace->face_flags & FT_FACE_FLAG_SCALABLE) + { + // Return the X advance + return (F32)(delta.x * (1.0 / 64.0)); + } + return (F32)delta.x; } F32 LLFontFreetype::getXKerning(const LLFontGlyphInfo* left_glyph_info, const LLFontGlyphInfo* right_glyph_info) const @@ -437,7 +451,12 @@ F32 LLFontFreetype::getXKerning(const LLFontGlyphInfo* left_glyph_info, const LL llverify(!FT_Get_Kerning(mFTFace, left_glyph, right_glyph, ft_kerning_unfitted, &delta)); - return delta.x*(1.f/64.f); + if (mFTFace->face_flags & FT_FACE_FLAG_SCALABLE) + { + // Return the X advance + return (F32)(delta.x * (1.0 / 64.0)); + } + return (F32)delta.x; } bool LLFontFreetype::hasGlyph(llwchar wch) const @@ -700,7 +719,7 @@ void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, ll if (mFTFace == NULL) return; - FT_Int32 load_flags = FT_LOAD_FORCE_AUTOHINT; + FT_Int32 load_flags = (FT_Int32)mHinting; if (EFontGlyphType::Color == bitmap_type) { // We may not actually get a color render so our caller should always examine mFTFace->glyph->bitmap.pixel_mode @@ -743,7 +762,7 @@ void LLFontFreetype::renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, ll void LLFontFreetype::reset(F32 vert_dpi, F32 horz_dpi) { resetBitmapCache(); - loadFace(mName, mPointSize, vert_dpi ,horz_dpi, mIsFallback, 0); + loadFace(mName, mPointSize, vert_dpi ,horz_dpi, mIsFallback, 0, mHinting, mFontFlags); if (!mIsFallback) { // This is the head of the list - need to rebuild ourself and all fallbacks. diff --git a/indra/llrender/llfontfreetype.h b/indra/llrender/llfontfreetype.h index 783bf4a4b30..0045768d540 100644 --- a/indra/llrender/llfontfreetype.h +++ b/indra/llrender/llfontfreetype.h @@ -42,6 +42,7 @@ struct FT_FaceRec_; typedef struct FT_FaceRec_* LLFT_Face; struct FT_StreamRec_; typedef struct FT_StreamRec_ LLFT_Stream; +enum class EFontHinting : S32; class LLFontManager { @@ -86,7 +87,7 @@ class LLFontFreetype : public LLRefCount // is_fallback should be true for fallback fonts that aren't used // to render directly (Unicode backup, primarily) - bool loadFace(const std::string& filename, F32 point_size, F32 vert_dpi, F32 horz_dpi, bool is_fallback, S32 face_n); + bool loadFace(const std::string& filename, F32 point_size, F32 vert_dpi, F32 horz_dpi, bool is_fallback, S32 face_n, EFontHinting hinting, S32 flags); S32 getNumFaces(const std::string& filename); @@ -155,7 +156,11 @@ class LLFontFreetype : public LLRefCount bool setSubImageBGRA(U32 x, U32 y, U32 bitmap_num, U16 width, U16 height, const U8* data, U32 stride) const; bool hasGlyph(llwchar wch) const; // Has a glyph for this character LLFontGlyphInfo* addGlyph(llwchar wch, EFontGlyphType glyph_type) const; // Add a new character to the font if necessary - LLFontGlyphInfo* addGlyphFromFont(const LLFontFreetype *fontp, llwchar wch, U32 glyph_index, EFontGlyphType bitmap_type) const; // Add a glyph from this font to the other (returns the glyph_index, 0 if not found) + LLFontGlyphInfo* addGlyphFromFont( + const LLFontFreetype *fontp, + llwchar wch, + U32 glyph_index, + EFontGlyphType bitmap_type) const; // Add a glyph from this font to the other (returns the glyph_index, 0 if not found) void renderGlyph(EFontGlyphType bitmap_type, U32 glyph_index, llwchar wch) const; void insertGlyphInfo(llwchar wch, LLFontGlyphInfo* gi) const; @@ -176,6 +181,8 @@ class LLFontFreetype : public LLRefCount #endif bool mIsFallback; + EFontHinting mHinting; + S32 mFontFlags; typedef std::pair, char_functor_t> fallback_font_t; typedef std::vector fallback_font_vector_t; fallback_font_vector_t mFallbackFonts; // A list of fallback fonts to look for glyphs in (for Unicode chars) diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 16eec1fdd24..d95eea526bb 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -90,14 +90,14 @@ void LLFontGL::destroyGL() mFontFreetype->destroyGL(); } -bool LLFontGL::loadFace(const std::string& filename, F32 point_size, const F32 vert_dpi, const F32 horz_dpi, bool is_fallback, S32 face_n) +bool LLFontGL::loadFace(const std::string& filename, F32 point_size, const F32 vert_dpi, const F32 horz_dpi, bool is_fallback, S32 face_n, EFontHinting hinting, S32 flags) { if(mFontFreetype == reinterpret_cast(NULL)) { mFontFreetype = new LLFontFreetype; } - return mFontFreetype->loadFace(filename, point_size, vert_dpi, horz_dpi, is_fallback, face_n); + return mFontFreetype->loadFace(filename, point_size, vert_dpi, horz_dpi, is_fallback, face_n, hinting, flags); } S32 LLFontGL::getNumFaces(const std::string& filename) diff --git a/indra/llrender/llfontgl.h b/indra/llrender/llfontgl.h index 1c8e036f58d..652cec8e5bd 100644 --- a/indra/llrender/llfontgl.h +++ b/indra/llrender/llfontgl.h @@ -87,7 +87,7 @@ class LLFontGL void destroyGL(); - bool loadFace(const std::string& filename, F32 point_size, const F32 vert_dpi, const F32 horz_dpi, bool is_fallback, S32 face_n); + bool loadFace(const std::string& filename, F32 point_size, const F32 vert_dpi, const F32 horz_dpi, bool is_fallback, S32 face_n, EFontHinting hinting, S32 flags); S32 getNumFaces(const std::string& filename); S32 getCacheGeneration() const; diff --git a/indra/llrender/llfontregistry.cpp b/indra/llrender/llfontregistry.cpp index c48a389f6a5..777bba3f250 100644 --- a/indra/llrender/llfontregistry.cpp +++ b/indra/llrender/llfontregistry.cpp @@ -181,16 +181,16 @@ LLFontDescriptor LLFontDescriptor::normalize() const return LLFontDescriptor(new_name,new_size,new_style, getFontFiles(), getFontCollectionFiles()); } -void LLFontDescriptor::addFontFile(const std::string& file_name, const std::string& char_functor) +void LLFontDescriptor::addFontFile(const std::string& file_name, EFontHinting hinting, S32 flags, const std::string& char_functor) { char_functor_map_t::const_iterator it = mCharFunctors.find(char_functor); - mFontFiles.push_back(LLFontFileInfo(file_name, (mCharFunctors.end() != it) ? it->second : nullptr)); + mFontFiles.push_back(LLFontFileInfo(file_name, hinting, flags, (mCharFunctors.end() != it) ? it->second : nullptr)); } -void LLFontDescriptor::addFontCollectionFile(const std::string& file_name, const std::string& char_functor) +void LLFontDescriptor::addFontCollectionFile(const std::string& file_name, EFontHinting hinting, S32 flags, const std::string& char_functor) { char_functor_map_t::const_iterator it = mCharFunctors.find(char_functor); - mFontCollectionFiles.push_back(LLFontFileInfo(file_name, (mCharFunctors.end() != it) ? it->second : nullptr)); + mFontCollectionFiles.push_back(LLFontFileInfo(file_name, hinting, flags, (mCharFunctors.end() != it) ? it->second : nullptr)); } LLFontRegistry::LLFontRegistry(bool create_gl_textures) @@ -289,23 +289,57 @@ bool font_desc_init_from_xml(LLXMLNodePtr node, LLFontDescriptor& desc) { std::string font_file_name = child->getTextContents(); std::string char_functor; + EFontHinting hinting = EFontHinting::FORCE_AUTOHINT; + S32 flags = 0; if (child->hasAttribute("functor")) { child->getAttributeString("functor", char_functor); } + if (child->hasAttribute("font_hinting")) + { + std::string attr_hinting; + child->getAttributeString("font_hinting", attr_hinting); + LLStringUtil::toLower(attr_hinting); + + if (attr_hinting == "default") + { + hinting = EFontHinting::DEFAULT; + } + else if (attr_hinting == "force_auto") + { + hinting = EFontHinting::FORCE_AUTOHINT; + } + else if (attr_hinting == "no_hinting") + { + hinting = EFontHinting::NO_HINTING; + } + } + + if (child->hasAttribute("flags")) + { + std::string attr_flags; + child->getAttributeString("flags", attr_flags); + LLStringUtil::toLower(attr_flags); + + if (attr_flags == "bold") + { + flags |= LLFontGL::BOLD; + } + } + if (child->hasAttribute("load_collection")) { bool col = false; child->getAttributeBOOL("load_collection", col); if (col) { - desc.addFontCollectionFile(font_file_name, char_functor); + desc.addFontCollectionFile(font_file_name, hinting, flags, char_functor); } } - desc.addFontFile(font_file_name, char_functor); + desc.addFontFile(font_file_name, hinting, flags, char_functor); } else if (child->hasName("os")) { @@ -462,7 +496,7 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) // Add ultimate fallback list - generated dynamically on linux, // null elsewhere. std::transform(getUltimateFallbackList().begin(), getUltimateFallbackList().end(), std::back_inserter(font_files), - [](const std::string& file_name) { return LLFontFileInfo(file_name); }); + [](const std::string& file_name) { return LLFontFileInfo(file_name, EFontHinting::FORCE_AUTOHINT, 0); }); // Load fonts based on names. if (font_files.empty()) @@ -518,7 +552,7 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) fontp = new LLFontGL; } if (fontp->loadFace(font_path, point_size_scale, - LLFontGL::sVertDPI, LLFontGL::sHorizDPI, is_fallback, i)) + LLFontGL::sVertDPI, LLFontGL::sHorizDPI, is_fallback, i, font_file_it->mHinting, font_file_it->mFlags)) { is_font_loaded = true; if (is_first_found) diff --git a/indra/llrender/llfontregistry.h b/indra/llrender/llfontregistry.h index 8bbf5aa30c5..bf190d903c9 100644 --- a/indra/llrender/llfontregistry.h +++ b/indra/llrender/llfontregistry.h @@ -34,22 +34,35 @@ class LLFontGL; typedef std::vector string_vec_t; +enum class EFontHinting : S32 +{ + DEFAULT = 0, + NO_HINTING = 0x8000U, + FORCE_AUTOHINT = 0x20, +}; + struct LLFontFileInfo { - LLFontFileInfo(const std::string& file_name, const std::function& char_functor = nullptr) + LLFontFileInfo(const std::string& file_name, EFontHinting hinting, S32 flags, const std::function& char_functor = nullptr) : FileName(file_name) , CharFunctor(char_functor) + , mHinting(hinting) + , mFlags(flags) { } - LLFontFileInfo(const LLFontFileInfo& ffi) + LLFontFileInfo(const LLFontFileInfo& ffi, EFontHinting hinting, S32 flags) : FileName(ffi.FileName) , CharFunctor(ffi.CharFunctor) + , mHinting(hinting) + , mFlags(flags) { } std::string FileName; std::function CharFunctor; + EFontHinting mHinting; + S32 mFlags; }; typedef std::vector font_file_info_vec_t; @@ -71,10 +84,10 @@ class LLFontDescriptor const std::string& getSize() const { return mSize; } void setSize(const std::string& size) { mSize = size; } - void addFontFile(const std::string& file_name, const std::string& char_functor = LLStringUtil::null); + void addFontFile(const std::string& file_name, EFontHinting hinting, S32 flags, const std::string& char_functor = LLStringUtil::null); const font_file_info_vec_t & getFontFiles() const { return mFontFiles; } void setFontFiles(const font_file_info_vec_t& font_files) { mFontFiles = font_files; } - void addFontCollectionFile(const std::string& file_name, const std::string& char_functor = LLStringUtil::null); + void addFontCollectionFile(const std::string& file_name, EFontHinting hinting, S32 flags, const std::string& char_functor = LLStringUtil::null); const font_file_info_vec_t& getFontCollectionFiles() const { return mFontCollectionFiles; } void setFontCollectionFiles(const font_file_info_vec_t& font_collection_files) { mFontCollectionFiles = font_collection_files; } diff --git a/indra/newview/skins/default/xui/en/fonts.xml b/indra/newview/skins/default/xui/en/fonts.xml index 45ec1e27f1a..fafe6a3ebcc 100644 --- a/indra/newview/skins/default/xui/en/fonts.xml +++ b/indra/newview/skins/default/xui/en/fonts.xml @@ -1,8 +1,10 @@ - - DejaVuSans.ttf + + Inter_18pt-Regular.ttf TwemojiSVG.ttf meiryo.TTC @@ -31,9 +33,10 @@ - - DejaVuSans-Bold.ttf + + Inter_18pt-SemiBold.ttf arialbd.ttf @@ -42,8 +45,10 @@ - - DejaVuSans.ttf + + Inter_18pt-Regular.ttf arial.ttf @@ -52,31 +57,35 @@ - - DejaVuSans-Bold.ttf + + Inter_18pt-SemiBold.ttf - - DejaVuSans-Oblique.ttf + + Inter_18pt-Italic.ttf - - DejaVuSans-BoldOblique.ttf + + Inter_18pt-BoldItalic.ttf TwemojiSVG.ttf - - + + DejaVuSansMono.ttf @@ -103,9 +112,10 @@ DejaVuSans-BoldOblique.ttf - - DejaVuSans.ttf + + Inter_18pt-Regular.ttf arial.ttf @@ -114,10 +124,11 @@ - - DejaVuSans-Bold.ttf + + Inter_18pt-SemiBold.ttf arialbd.ttf @@ -126,10 +137,11 @@ - - DejaVuSans-Oblique.ttf + + Inter_18pt-Italic.ttf ariali.ttf @@ -138,10 +150,11 @@ - - DejaVuSans-BoldOblique.ttf + + Inter_18pt-BoldItalic.ttf arialbi.ttf @@ -150,10 +163,11 @@ - + times.ttf - DejaVuSans.ttf + Inter_18pt-Regular.ttf - NotoSansCJKjp-Medium.otf - - - DejaVuSans.ttf + NotoSansCJKjp-SemiBold.otf + + Inter_18pt-Regular.ttf + YuGothM.ttc @@ -41,7 +41,7 @@ - YuGothic-Medium.otf + YuGothic-SemiBold.otf ヒラギノ角ゴシック W3.ttc @@ -82,9 +82,9 @@ NotoSansCJKjp-Bold.otf - - DejaVuSans-Bold.ttf - + + Inter_18pt-SemiBold.ttf + YuGothB.ttc @@ -106,9 +106,9 @@ NotoSansCJKjp-Bold.otf - - DejaVuSans.ttf - + + Inter_18pt-Regular.ttf + arial.ttf @@ -121,19 +121,19 @@ - - DejaVuSans-Bold.ttf - + + Inter_18pt-SemiBold.ttf + - - DejaVuSans-Oblique.ttf - + + Inter_18pt-Italic.ttf + - - DejaVuSans-BoldOblique.ttf - + + Inter_18pt-SemiBoldItalic.ttf + @@ -144,29 +144,29 @@ - - DejaVuSans.ttf - + + Inter_18pt-Regular.ttf + - - DejaVuSans-Bold.ttf - + + Inter_18pt-SemiBold.ttf + - - DejaVuSans-Oblique.ttf - + + Inter_18pt-Italic.ttf + - - DejaVuSans-BoldOblique.ttf - + + Inter_18pt-SemiBoldItalic.ttf + - - DejaVuSans.ttf - + + Inter_18pt-Regular.ttf + arial.ttf @@ -179,9 +179,9 @@ - - DejaVuSans-Bold.ttf - + + Inter_18pt-SemiBold.ttf + arialbd.ttf @@ -194,9 +194,9 @@ - - DejaVuSans-Oblique.ttf - + + Inter_18pt-Italic.ttf + ariali.ttf @@ -209,9 +209,9 @@ - - DejaVuSans-BoldOblique.ttf - + + Inter_18pt-SemiBoldItalic.ttf + arialbi.ttf @@ -227,9 +227,9 @@ times.ttf - - DejaVuSans.ttf - + + Inter_18pt-Regular.ttf + From ce45474f0ab3c0eb89d6a2cd92d1fc4ef356fa0a Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Mon, 17 Feb 2025 18:03:34 +0200 Subject: [PATCH 2/3] viewer#2023 Google Inter #2 Bums sizes up because Inter is smaller than our old font --- indra/newview/skins/default/xui/ja/fonts.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/newview/skins/default/xui/ja/fonts.xml b/indra/newview/skins/default/xui/ja/fonts.xml index 465131499eb..874f530f17c 100644 --- a/indra/newview/skins/default/xui/ja/fonts.xml +++ b/indra/newview/skins/default/xui/ja/fonts.xml @@ -233,7 +233,7 @@ - - - + + + From 624eaf59a02dbd2f002fb45af01bbc17f04f8331 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev <117672381+akleshchev@users.noreply.github.com> Date: Fri, 19 Sep 2025 17:24:01 +0300 Subject: [PATCH 3/3] viewer#2023 Google Inter #3 Size increase shouldn't have been specific for ja, it was meant to be universal. --- indra/newview/skins/default/xui/en/fonts.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/indra/newview/skins/default/xui/en/fonts.xml b/indra/newview/skins/default/xui/en/fonts.xml index fafe6a3ebcc..de8e6404553 100644 --- a/indra/newview/skins/default/xui/en/fonts.xml +++ b/indra/newview/skins/default/xui/en/fonts.xml @@ -180,15 +180,15 @@ />