From 25e64d972829a4be5aedeeed105c4c40081dc474 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 10 Sep 2010 14:39:00 -0500 Subject: Added the concept of font size multiplier (size_mult). This compensates for inherent size differences in each font family, so that UI text is a consistent size, no matter which font you use. --- linden/indra/llrender/llfontregistry.cpp | 35 ++++++++++++++-------- linden/indra/llrender/llfontregistry.h | 4 +++ .../newview/skins/default/xui/en-us/fonts.xml | 18 ++++++----- 3 files changed, 38 insertions(+), 19 deletions(-) (limited to 'linden') diff --git a/linden/indra/llrender/llfontregistry.cpp b/linden/indra/llrender/llfontregistry.cpp index cbd0d5a..b1d8c5c 100644 --- a/linden/indra/llrender/llfontregistry.cpp +++ b/linden/indra/llrender/llfontregistry.cpp @@ -48,7 +48,8 @@ using std::map; bool fontDescInitFromXML(LLXMLNodePtr node, LLFontDescriptor& desc); LLFontDescriptor::LLFontDescriptor(): - mStyle(0) + mStyle(0), + mSizeMult(1.0) { } @@ -59,7 +60,8 @@ LLFontDescriptor::LLFontDescriptor(const std::string& name, mName(name), mSize(size), mStyle(style), - mFileNames(file_names) + mFileNames(file_names), + mSizeMult(1.0) { } @@ -68,7 +70,8 @@ LLFontDescriptor::LLFontDescriptor(const std::string& name, const U8 style): mName(name), mSize(size), - mStyle(style) + mStyle(style), + mSizeMult(1.0) { } @@ -165,7 +168,9 @@ LLFontDescriptor LLFontDescriptor::normalize() const if (removeSubString(new_name,"Italic")) new_style |= LLFontGL::ITALIC; - return LLFontDescriptor(new_name,new_size,new_style,getFileNames()); + LLFontDescriptor norm(new_name,new_size,new_style,getFileNames()); + norm.setSizeMult(mSizeMult); + return norm; } LLFontRegistry::LLFontRegistry(const string_vec_t& xui_paths) @@ -255,6 +260,12 @@ bool fontDescInitFromXML(LLXMLNodePtr node, LLFontDescriptor& desc) } desc.setSize(s_template_string); + + F32 attr_size_mult; + if (node->getAttributeF32("size_mult",attr_size_mult)) + { + desc.setSizeMult(attr_size_mult); + } } LLXMLNodePtr child; @@ -363,7 +374,6 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) return NULL; } llinfos << "createFont " << norm_desc.getName() << " size " << norm_desc.getSize() << " style " << ((S32) norm_desc.getStyle()) << llendl; - F32 fallback_scale = 1.0; // Find corresponding font template (based on same descriptor with no size specified) LLFontDescriptor template_desc(norm_desc); @@ -431,13 +441,13 @@ LLFontGL *LLFontRegistry::createFont(const LLFontDescriptor& desc) LLFontGL *fontp = new LLFontGL; std::string font_path = local_path + *file_name_it; BOOL is_fallback = !is_first_found; - F32 extra_scale = (is_fallback)?fallback_scale:1.0; - if (!fontp->loadFace(font_path, extra_scale * point_size, + F32 size_mult = (is_fallback ? 1 : match_desc->getSizeMult()); + if (!fontp->loadFace(font_path, point_size * size_mult, LLFontGL::sVertDPI, LLFontGL::sHorizDPI, 2, is_fallback)) { font_path = sys_path + *file_name_it; - if (!fontp->loadFace(font_path, extra_scale * point_size, + if (!fontp->loadFace(font_path, point_size * size_mult, LLFontGL::sVertDPI, LLFontGL::sHorizDPI, 2, is_fallback)) { LL_INFOS_ONCE("LLFontRegistry") << "Couldn't load font " << *file_name_it << LL_ENDL; @@ -526,12 +536,12 @@ LLFontGL *LLFontRegistry::getFont(const LLFontDescriptor& orig_desc) return it->second; else { - LLFontGL *fontp = createFont(orig_desc); + LLFontGL *fontp = createFont(norm_desc); if (!fontp) { - llwarns << "getFont failed, name " << orig_desc.getName() - <<" style=[" << ((S32) orig_desc.getStyle()) << "]" - << " size=[" << orig_desc.getSize() << "]" << llendl; + llwarns << "getFont failed, name " << norm_desc.getName() + <<" style=[" << ((S32) norm_desc.getStyle()) << "]" + << " size=[" << norm_desc.getSize() << "]" << llendl; } return fontp; } @@ -649,6 +659,7 @@ void LLFontRegistry::dump() llinfos << "Font: name=" << desc.getName() << " style=[" << ((S32)desc.getStyle()) << "]" << " size=[" << desc.getSize() << "]" + << " size_mult=[" << desc.getSizeMult() << "]" << " fileNames=" << llendl; for (string_vec_t::const_iterator file_it=desc.getFileNames().begin(); diff --git a/linden/indra/llrender/llfontregistry.h b/linden/indra/llrender/llfontregistry.h index 0add372..67a529f 100644 --- a/linden/indra/llrender/llfontregistry.h +++ b/linden/indra/llrender/llfontregistry.h @@ -56,6 +56,9 @@ public: void setName(const std::string& name) { mName = name; } const std::string& getSize() const { return mSize; } void setSize(const std::string& size) { mSize = size; } + F32 getSizeMult() const { return mSizeMult; } + void setSizeMult(F32 size_mult) { mSizeMult = size_mult; } + const std::vector& getFileNames() const { return mFileNames; } std::vector& getFileNames() { return mFileNames; } const U8 getStyle() const { return mStyle; } @@ -64,6 +67,7 @@ public: private: std::string mName; std::string mSize; + F32 mSizeMult; string_vec_t mFileNames; U8 mStyle; }; diff --git a/linden/indra/newview/skins/default/xui/en-us/fonts.xml b/linden/indra/newview/skins/default/xui/en-us/fonts.xml index df1356b..1aa44fb 100644 --- a/linden/indra/newview/skins/default/xui/en-us/fonts.xml +++ b/linden/indra/newview/skins/default/xui/en-us/fonts.xml @@ -26,25 +26,29 @@ + comment="Name of DejaVu font" + size_mult="1.00"> DejaVuSansCondensed.ttf + comment="Name of DejaVu font (bold)" + size_mult="1.00" + font_style="BOLD"> DejaVuSansCondensed-Bold.ttf + comment="Name of DejaVu font (italic)" + size_mult="1.00" + font_style="ITALIC"> DejaVuSansCondensed-Oblique.ttf + comment="Name of DejaVu font (bold italic)" + size_mult="1.00" + font_style="BOLD|ITALIC"> DejaVuSansCondensed-BoldOblique.ttf -- cgit v1.1