Keith Packard <[EMAIL PROTECTED]> writes:

> Much as I hate the C locale model, I'm wondering if I shouldn't use the 
> current locale as a language hint where applications don't provide 
> explicit language information when selecting fonts.  This would make
> the generic aliases (like "sans-serif") pick a font appropriate for the 
> locale instead of some random font most likely suitable for Latin 
> languages.
> 
> Or would this only lead to confusion and chaos?

I think this is right; it's the only way that we'll get reasonably
consistent font choice between places where there is a heavyweight
system on top of Xft. (Pango, Mozilla, etc) and places that are
using Xft directly.

My "language" hack did this; feel free to use the code below if
it helps. 

Regards,
                                        Owen


--- fontconfig/src/fccfg.c.langtag      Fri Jun 21 02:14:45 2002
+++ fontconfig/src/fccfg.c      Mon Jun 24 14:09:35 2002
@@ -23,6 +23,7 @@
  */
 
 #include "fcint.h"
+#include <locale.h>
 
 FcConfig    *_fcConfig;
 
@@ -1059,6 +1060,50 @@
        FcPatternDel (p, object);
 }
 
+static const FcChar8 canon_map[256] = {
+   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,   0,   0,   0, 
+   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,   0,   0,   0, 
+   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,  '-',  0,   0, 
+   0,   0,   0,   0,   0,   0,   0,   0,    0,   0,   0,   0,   0,   0,   0,   0, 
+   0,  'a', 'b', 'c', 'd', 'e', 'f', 'g',  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',  'x', 'y', 'z',  0,   0,   0,   0,  '-',
+   0,  'a', 'b', 'c', 'd', 'e', 'f', 'g',  'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
+  'p', 'q', 'r', 's', 't', 'u', 'v', 'w',  'x', 'y', 'z',  0,   0,   0,   0,   0
+};
+   
+static FcChar8 *
+FcGetDefaultLanguage (void)
+{
+    FcChar8 *locale;
+    FcChar8 *result;
+    FcChar8 *p, *q;
+
+    locale = (FcChar8 *)setlocale (LC_CTYPE, NULL);
+    result = malloc (strlen (locale + 1));
+    if (!result)
+       return 0;
+    
+    p = locale;
+    q = result;
+    while (*p)
+    {
+       FcChar8 value;
+
+       if (*p == '.' || *p == '@')
+           break;
+
+       value = canon_map[*p];
+       if (value)
+           *(q++) = value;
+
+       p++;
+    }
+
+    *q = 0;
+    
+    return result;
+}
+
 FcBool
 FcConfigSubstitute (FcConfig   *config,
                    FcPattern   *p,
@@ -1070,7 +1115,8 @@
     FcTest         *t;
     FcEdit         *e;
     FcValueList            *l;
-
+    FcValue         v;
+    
     if (!config)
     {
        config = FcConfigGetCurrent ();
@@ -1078,6 +1124,18 @@
            return FcFalse;
     }
 
+    if (FcPatternGet (p, "language", 0, &v) == FcResultNoMatch)
+    {
+       FcChar8 *language;
+
+       language = FcGetDefaultLanguage ();
+       if (!language)
+           return FcFalse;
+       
+       FcPatternAddString (p, "language", language);
+       free (language);
+    }
+
     st = (FcSubState *) malloc (config->maxObjects * sizeof (FcSubState));
     if (!st && config->maxObjects)
        return FcFalse;
_______________________________________________
I18n mailing list
[EMAIL PROTECTED]
http://XFree86.Org/mailman/listinfo/i18n

Reply via email to