]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Fix FcNameUnparseLangSet()
[fontconfig.git] / src / fclang.c
index 229a13e96d23db1c60b3a7cab6a1b6a6e34d18d3..9d1858de2031dd01afba970ed3e3ddee195c417f 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
@@ -42,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, 
@@ -551,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);
@@ -744,6 +737,38 @@ 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"