]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Bug 23419 - "contains" expression seems not working on the fontconfig rule
[fontconfig.git] / src / fclang.c
index 13f0ca21fb932c232c58a4eecc5ec17b6e769072..6a3b7b5e3dbd44a71d9b54ae44a51561ea5556a0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $RCSId: xc/lib/fontconfig/src/fclang.c,v 1.7 2002/08/26 23:34:31 keithp Exp $
+ * fontconfig/src/fclang.c
  *
  * Copyright © 2002 Keith Packard
  *
@@ -13,9 +13,9 @@
  * representations about the suitability of this software for any purpose.  It
  * is provided "as is" without express or implied warranty.
  *
- * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * THE AUTHOR(S) DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
@@ -23,6 +23,7 @@
  */
 
 #include "fcint.h"
+#include "fcftint.h"
 
 typedef struct {
     const FcChar8      lang[8];
@@ -41,8 +42,8 @@ struct _FcLangSet {
     FcStrSet   *extra;
 };
 
-#define FcLangSetBitSet(ls, id)        ((ls)->map[(id)>>5] |= ((FcChar32) 1 << ((id) & 0x1f)))
-#define FcLangSetBitGet(ls, id) (((ls)->map[(id)>>5] >> ((id) & 0x1f)) & 1)
+#define FcLangSetBitSet(ls, id)        ((ls)->map[(fcLangCharSetIndices[id])>>5] |= ((FcChar32) 1 << ((fcLangCharSetIndices[id]) & 0x1f)))
+#define FcLangSetBitGet(ls, id) (((ls)->map[(fcLangCharSetIndices[id])>>5] >> ((fcLangCharSetIndices[id]) & 0x1f)) & 1)
 
 FcLangSet *
 FcFreeTypeLangSet (const FcCharSet  *charset, 
@@ -54,13 +55,13 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
     FcLangSet      *ls;
 
     if (exclusiveLang)
-       exclusiveCharset = FcCharSetForLang (exclusiveLang);
+       exclusiveCharset = FcLangGetCharSet (exclusiveLang);
     ls = FcLangSetCreate ();
     if (!ls)
        return 0;
     if (FcDebug() & FC_DBG_LANGSET) 
     {
-       printf ("font charset\n");
+       printf ("font charset");
        FcCharSetPrint (charset);
        printf ("\n");
     }
@@ -68,7 +69,7 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
     {
        if (FcDebug() & FC_DBG_LANGSET) 
        {
-           printf ("%s charset\n", fcLangCharSets[i].lang);
+           printf ("%s charset", fcLangCharSets[i].lang);
            FcCharSetPrint (&fcLangCharSets[i].charset);
            printf ("\n");
        }
@@ -150,13 +151,13 @@ FcLangCompare (const FcChar8 *s1, const FcChar8 *s2)
        if (c1 != c2)
        {
            if (FcLangEnd (c1) && FcLangEnd (c2))
-               result = FcLangDifferentCountry;
+               result = FcLangDifferentTerritory;
            return result;
        }
        else if (!c1)
            return FcLangEqual;
        else if (c1 == '-')
-           result = FcLangDifferentCountry;
+           result = FcLangDifferentTerritory;
     }
 }
 
@@ -196,7 +197,7 @@ FcLangContains (const FcChar8 *super, const FcChar8 *sub)
 }
 
 const FcCharSet *
-FcCharSetForLang (const FcChar8 *lang)
+FcLangGetCharSet (const FcChar8 *lang)
 {
     int                i;
     int                country = -1;
@@ -206,7 +207,7 @@ FcCharSetForLang (const FcChar8 *lang)
        switch (FcLangCompare (lang, fcLangCharSets[i].lang)) {
        case FcLangEqual:
            return &fcLangCharSets[i].charset;
-       case FcLangDifferentCountry:
+       case FcLangDifferentTerritory:
            if (country == -1)
                country = i;
        default:
@@ -218,6 +219,22 @@ FcCharSetForLang (const FcChar8 *lang)
     return &fcLangCharSets[country].charset;
 }
 
+FcStrSet *
+FcGetLangs (void)
+{
+    FcStrSet *langs;
+    int        i;
+
+    langs = FcStrSetCreate();
+    if (!langs)
+       return 0;
+
+    for (i = 0; i < NUM_LANG_CHAR_SET; i++)
+       FcStrSetAdd (langs, fcLangCharSets[i].lang);
+
+    return langs;
+}
+
 FcLangSet *
 FcLangSetCreate (void)
 {
@@ -437,7 +454,7 @@ FcLangSetCompare (const FcLangSet *lsa, const FcLangSet *lsb)
            if ((lsa->map[i] & fcLangCountrySets[j][i]) &&
                (lsb->map[i] & fcLangCountrySets[j][i]))
            {
-               best = FcLangDifferentCountry;
+               best = FcLangDifferentTerritory;
                break;
            }
     if (lsa->extra)
@@ -534,27 +551,20 @@ bail0:
 FcBool
 FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls)
 {
-    int                i, bit;
-    FcChar32   bits;
+    int                i;
     FcBool     first = FcTrue;
 
-    for (i = 0; i < NUM_LANG_SET_MAP; i++)
-    {
-       if ((bits = ls->map[i]))
-       {
-           for (bit = 0; bit <= 31; bit++)
-               if (bits & (1 << bit))
-               {
-                   int id = (i << 5) | bit;
-                   if (!first)
-                       if (!FcStrBufChar (buf, '|'))
-                           return FcFalse;
-                   if (!FcStrBufString (buf, fcLangCharSets[id].lang))
+    for (i = 0; i < NUM_LANG_CHAR_SET; i++)
+       if (FcLangSetBitGet (ls, i))
+           {
+               if (!first)
+                   if (!FcStrBufChar (buf, '|'))
                        return FcFalse;
-                   first = FcFalse;
-               }
-       }
-    }
+               if (!FcStrBufString (buf, fcLangCharSets[i].lang))
+                   return FcFalse;
+               first = FcFalse;
+           }
+
     if (ls->extra)
     {
        FcStrList   *list = FcStrListCreate (ls->extra);
@@ -676,10 +686,10 @@ FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb)
                if (missing & (1 << j)) 
                {
                    if (!FcLangSetContainsLang (lsa,
-                                               fcLangCharSets[i*32 + j].lang))
+                                               fcLangCharSets[fcLangCharSetIndicesInv[i*32 + j]].lang))
                    {
                        if (FcDebug() & FC_DBG_MATCHV)
-                           printf ("\tMissing bitmap %s\n", fcLangCharSets[i*32+j].lang);
+                           printf ("\tMissing bitmap %s\n", fcLangCharSets[fcLangCharSetIndicesInv[i*32+j]].lang);
                        return FcFalse;
                    }
                }
@@ -727,6 +737,39 @@ FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l)
     *l_serialize = *l;
     return l_serialize;
 }
+
+FcStrSet *
+FcLangSetGetLangs (const FcLangSet *ls)
+{
+    FcStrSet *langs;
+    int              i;
+
+    langs = FcStrSetCreate();
+    if (!langs)
+       return 0;
+
+    for (i = 0; i < NUM_LANG_CHAR_SET; i++)
+       if (FcLangSetBitGet (ls, i))
+           FcStrSetAdd (langs, fcLangCharSets[i].lang);
+
+    if (ls->extra)
+    {
+       FcStrList       *list = FcStrListCreate (ls->extra);
+       FcChar8         *extra;
+
+       if (list)
+       {
+           while ((extra = FcStrListNext (list)))
+               FcStrSetAdd (langs, extra);
+
+           FcStrListDone (list);
+       }
+    }
+
+    return langs;
+}
+
 #define __fclang__
 #include "fcaliastail.h"
+#include "fcftaliastail.h"
 #undef __fclang__