From e709ddfa10410f6e042a36fcf7d0cd1a40f84fad Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Tue, 9 Jul 2002 22:08:14 +0000 Subject: [PATCH] Use locale data set FC_LANG by default. Reorder FcPattern and FcValueList to match Xft1. --- src/fcdefault.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ src/fcint.h | 4 ++-- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/src/fcdefault.c b/src/fcdefault.c index 365595d..5208746 100644 --- a/src/fcdefault.c +++ b/src/fcdefault.c @@ -23,6 +23,7 @@ */ #include "fcint.h" +#include 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); + } + } } diff --git a/src/fcint.h b/src/fcint.h index 777b214..750b19c 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -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 {