[sldev] unicode.ttf
Alissa Sabre
alissa_sabre at yahoo.co.jp
Sun May 20 09:22:40 PDT 2007
> the unicode.ttf thing was only ever an interim workaround
> until fontconfig support is implemented.
Hmm. I'm not sure fontconfig is the way to go, but, yes, we can
remove some unicode.ttf related issues by fontconfig.
I talked with Matuu on this, and wrote a quick hack.
This is not yet ready for integration into the source repository, but
if you are interested in the issue, please try it and see whether
fontconfig works as you want.
To use the patch,
- You need a working fontconfig installed on your system and properly
configured.
- You need to modify your settings.xml to include:
<FontSansSerifFallback value="*sans serif"/>
# or you can rewrite your linden/indra/newview/llcontroldefs.cpp :-)
Have fun!
-------------- next part --------------
Index: linden/indra/llrender/llfontgl.cpp
===================================================================
RCS file: /var/cvsroot/sl/linden/indra/llrender/llfontgl.cpp,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 llfontgl.cpp
--- linden/indra/llrender/llfontgl.cpp 19 May 2007 03:39:05 -0000 1.1.1.4
+++ linden/indra/llrender/llfontgl.cpp 20 May 2007 16:01:25 -0000
@@ -29,12 +29,14 @@
#include "linden_common.h"
#include <boost/tokenizer.hpp>
+#include <fontconfig/fontconfig.h>
#include "llfont.h"
#include "llfontgl.h"
#include "llgl.h"
#include "v4color.h"
#include "llstl.h"
+#include "llui.h"
const S32 BOLD_OFFSET = 1;
@@ -228,23 +230,71 @@
for(token_iter = tokens.begin(); token_iter != tokens.end(); ++token_iter)
{
+ if (token_iter->at(0) == '*')
+ {
+ // Use fontconfig to find a suitable font.
+ FcPattern *pattern = FcNameParse((FcChar8 const *)token_iter->substr(1).c_str());
+ if (pattern != NULL)
+ {
+ // Find the user's language preference.
+ // The code is stolen from LLUICtrlFactory::setupPaths().
+ // This should be done in an upper layer. FIXME.
+ LLString language = "en-us";
+ if (LLUI::sConfigGroup)
+ {
+ language = LLUI::sConfigGroup->getString("Language");
+ if(language == "default")
+ {
+ language = LLUI::sConfigGroup->getString("SystemLanguage");
+ }
+ }
+ FcPatternAddString(pattern, FC_LANG, (FcChar8 const *)language.c_str());
+ FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
+ FcConfigSubstitute(0, pattern, FcMatchPattern);
+ FcResult r;
+ FcFontSet *font_set = FcFontSort(0, pattern, FcTrue, NULL, &r);
+ if (font_set)
+ {
+ for (int i = 0; i < font_set->nfont; i++)
+ {
+ FcPattern *font_pattern = font_set->fonts[i];
+ FcBool scalable;
+ if (FcPatternGetBool(font_pattern, FC_SCALABLE, 0, &scalable) != FcResultMatch || !scalable) continue;
+ FcChar8 *filename;
+ if (FcPatternGetString(font_pattern, FC_FILE, 0, &filename) != FcResultMatch || !filename) continue;
+ LLFont *fontp = new LLFont();
+ if (fontp->loadFace((char const *)filename, point_size, sVertDPI, sHorizDPI, 2, TRUE))
+ {
+ fontlistp->addAtEnd(fontp);
+ continue;
+ }
+ delete fontp;
+ }
+ FcFontSetDestroy(font_set);
+ }
+ FcPatternDestroy(pattern);
+ }
+ continue;
+ }
+
LLFont *fontp = new LLFont();
+
LLString font_path = local_path + *token_iter;
- if (!fontp->loadFace(font_path.c_str(), point_size, sVertDPI, sHorizDPI, 2, TRUE))
+ if (fontp->loadFace(font_path.c_str(), point_size, sVertDPI, sHorizDPI, 2, TRUE))
{
- font_path = sys_path + *token_iter;
- if (!fontp->loadFace(font_path.c_str(), point_size, sVertDPI, sHorizDPI, 2, TRUE))
- {
- llwarns << "Couldn't load font " << *token_iter << llendl;
- delete fontp;
- fontp = NULL;
- }
+ fontlistp->addAtEnd(fontp);
+ continue;
}
-
- if(fontp)
+
+ font_path = sys_path + *token_iter;
+ if (fontp->loadFace(font_path.c_str(), point_size, sVertDPI, sHorizDPI, 2, TRUE))
{
fontlistp->addAtEnd(fontp);
+ continue;
}
+
+ llwarns << "Couldn't load font " << *token_iter << llendl;
+ delete fontp;
}
// We want to return true if at least one fallback font loaded correctly.
More information about the SLDev
mailing list