]> git.wh0rd.org Git - fontconfig.git/commitdiff
Use locale data set FC_LANG by default. Reorder FcPattern and FcValueList
authorKeith Packard <keithp@keithp.com>
Tue, 9 Jul 2002 22:08:14 +0000 (22:08 +0000)
committerKeith Packard <keithp@keithp.com>
Tue, 9 Jul 2002 22:08:14 +0000 (22:08 +0000)
    to match Xft1.

src/fcdefault.c
src/fcint.h

index 365595dfdc3529b1ba6f2cabcbd653edc4eccfbc..5208746d9bd3234ef9a64dd7e9289fb224055b0f 100644 (file)
@@ -23,6 +23,7 @@
  */
 
 #include "fcint.h"
+#include <locale.h>
 
 static struct {
     char       *field;
@@ -84,4 +85,56 @@ FcDefaultSubstitute (FcPattern *pattern)
        size *= dpi / 72.0;
        FcPatternAddDouble (pattern, FC_PIXEL_SIZE, size);
     }
+
+    if (FcPatternGet (pattern, FC_LANG, 0, &v) == FcResultNoMatch)
+    {
+       char    *lang;
+       char    *territory;
+       char    *after;
+       int     lang_len, territory_len;
+       char    lang_local[128];
+       char    *ctype = setlocale (LC_CTYPE, NULL);
+
+       /*
+        * Check if setlocale (LC_ALL, "") has been called
+        */
+       if (!ctype || !strcmp (ctype, "C"))
+       {
+           ctype = getenv ("LC_ALL");
+           if (!ctype)
+           {
+               ctype = getenv ("LC_CTYPE");
+               if (!ctype)
+                   ctype = getenv ("LANG");
+           }
+       }
+       if (ctype)
+       {
+           lang = ctype;
+           territory = strchr (ctype, '_');
+           if (territory)
+           {
+               lang_len = territory - lang;
+               territory = territory + 1;
+               after = strchr (territory, '.');
+               if (!after)
+               {
+                   after = strchr (territory, '@');
+                   if (!after)
+                       after = territory + strlen (territory);
+               }
+               territory_len = after - territory;
+               if (lang_len + 1 + territory_len + 1 <= sizeof (lang_local))
+               {
+                   strncpy (lang_local, lang, lang_len);
+                   lang_local[lang_len] = '-';
+                   strncpy (lang_local + lang_len + 1, territory, territory_len);
+                   lang_local[lang_len + 1 + territory_len] = '\0';
+                   FcPatternAddString (pattern, FC_LANG, (FcChar8 *) lang_local);
+               }
+           }
+           else
+               FcPatternAddString (pattern, FC_LANG, (FcChar8 *) lang);
+       }
+    }
 }
index 777b214e7fdd5e233af0a0fa8becb3f79c1acb6b..750b19ca27d9ea03569e6958aa3d04ef6c81d72f 100644 (file)
@@ -88,8 +88,8 @@ typedef enum _FcValueBinding {
 
 typedef struct _FcValueList {
     struct _FcValueList    *next;
-    FcValueBinding         binding;
     FcValue                value;
+    FcValueBinding         binding;
 } FcValueList;
 
 typedef struct _FcPatternElt {
@@ -100,8 +100,8 @@ typedef struct _FcPatternElt {
 struct _FcPattern {
     int                    num;
     int                    size;
-    int                    ref;
     FcPatternElt    *elts;
+    int                    ref;
 };
 
 typedef enum _FcOp {