]> git.wh0rd.org - fontconfig.git/blobdiff - src/fclang.c
Use FcLangDifferentTerritory instead of FcLangDifferentCountry.
[fontconfig.git] / src / fclang.c
index 53f2b5982b47400ca6a2ce986fb91b0953cddb17..361803a60e44a295263626dce35d1396f96abebc 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * $RCSId: xc/lib/fontconfig/src/fclang.c,v 1.7 2002/08/26 23:34:31 keithp Exp $
  *
- * Copyright © 2002 Keith Packard
+ * Copyright Â© 2002 Keith Packard
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -25,8 +25,8 @@
 #include "fcint.h"
 
 typedef struct {
-    FcChar8    *lang;
-    FcCharSet  charset;
+    const FcChar8      lang[8];
+    const FcCharSet    charset;
 } FcLangCharSet;
 
 typedef struct {
@@ -48,29 +48,46 @@ FcLangSet *
 FcFreeTypeLangSet (const FcCharSet  *charset, 
                   const FcChar8    *exclusiveLang)
 {
-    int                    i;
+    int                    i, j;
     FcChar32       missing;
     const FcCharSet *exclusiveCharset = 0;
     FcLangSet      *ls;
-    
 
     if (exclusiveLang)
        exclusiveCharset = FcCharSetForLang (exclusiveLang);
     ls = FcLangSetCreate ();
     if (!ls)
        return 0;
+    if (FcDebug() & FC_DBG_LANGSET) 
+    {
+       printf ("font charset\n");
+       FcCharSetPrint (charset);
+       printf ("\n");
+    }
     for (i = 0; i < NUM_LANG_CHAR_SET; i++)
     {
+       if (FcDebug() & FC_DBG_LANGSET) 
+       {
+           printf ("%s charset\n", fcLangCharSets[i].lang);
+           FcCharSetPrint (&fcLangCharSets[i].charset);
+           printf ("\n");
+       }
+       
        /*
         * Check for Han charsets to make fonts
         * which advertise support for a single language
         * not support other Han languages
         */
        if (exclusiveCharset &&
-           FcFreeTypeIsExclusiveLang (fcLangCharSets[i].lang) &&
-           fcLangCharSets[i].charset.leaves != exclusiveCharset->leaves)
+           FcFreeTypeIsExclusiveLang (fcLangCharSets[i].lang))
        {
-           continue;
+           if (fcLangCharSets[i].charset.num != exclusiveCharset->num)
+               continue;
+
+           for (j = 0; j < fcLangCharSets[i].charset.num; j++)
+               if (FcCharSetLeaf(&fcLangCharSets[i].charset, j) != 
+                   FcCharSetLeaf(exclusiveCharset, j))
+                   continue;
        }
        missing = FcCharSetSubtractCount (&fcLangCharSets[i].charset, charset);
         if (FcDebug() & FC_DBG_SCANV)
@@ -83,7 +100,7 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
                FcChar32    map[FC_CHARSET_MAP_SIZE];
                FcChar32    next;
 
-               printf ("\n%s(%d) ", fcLangCharSets[i].lang, missing);
+               printf ("\n%s(%u) ", fcLangCharSets[i].lang, missing);
                printf ("{");
                for (ucs4 = FcCharSetFirstPage (missed, map, &next);
                     ucs4 != FC_CHARSET_DONE;
@@ -102,7 +119,7 @@ FcFreeTypeLangSet (const FcCharSet  *charset,
                FcCharSetDestroy (missed);
            }
            else
-               printf ("%s(%d) ", fcLangCharSets[i].lang, missing);
+               printf ("%s(%u) ", fcLangCharSets[i].lang, missing);
        }
        if (!missing)
            FcLangSetBitSet (ls, i);
@@ -133,40 +150,44 @@ 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;
     }
 }
 
 /*
- * Return FcTrue when s1 contains s2
+ * Return FcTrue when super contains sub
  *
- * s1 contains s2 if s1 equals s2 or if s1 is a
- * language with a country and s2 is just a language
+ * super contains sub if super and sub have the same
+ * language and either the same country or one
+ * is missing the country
  */
 
 static FcBool
-FcLangContains (const FcChar8 *s1, const FcChar8 *s2)
+FcLangContains (const FcChar8 *super, const FcChar8 *sub)
 {
     FcChar8        c1, c2;
 
     for (;;)
     {
-       c1 = *s1++;
-       c2 = *s2++;
+       c1 = *super++;
+       c2 = *sub++;
        
        c1 = FcToLower (c1);
        c2 = FcToLower (c2);
        if (c1 != c2)
        {
-           /* see if s1 has a country while s2 is mising one */
+           /* see if super has a country while sub is mising one */
            if (c1 == '-' && c2 == '\0')
                return FcTrue;
+           /* see if sub has a country while super is mising one */
+           if (c1 == '\0' && c2 == '-')
+               return FcTrue;
            return FcFalse;
        }
        else if (!c1)
@@ -179,12 +200,13 @@ FcCharSetForLang (const FcChar8 *lang)
 {
     int                i;
     int                country = -1;
+
     for (i = 0; i < NUM_LANG_CHAR_SET; i++)
     {
        switch (FcLangCompare (lang, fcLangCharSets[i].lang)) {
        case FcLangEqual:
            return &fcLangCharSets[i].charset;
-       case FcLangDifferentCountry:
+       case FcLangDifferentTerritory:
            if (country == -1)
                country = i;
        default:
@@ -193,7 +215,7 @@ FcCharSetForLang (const FcChar8 *lang)
     }
     if (country == -1)
        return 0;
-    return &fcLangCharSets[i].charset;
+    return &fcLangCharSets[country].charset;
 }
 
 FcLangSet *
@@ -365,7 +387,6 @@ FcLangSetHasLang (const FcLangSet *ls, const FcChar8 *lang)
     {
        FcStrList       *list = FcStrListCreate (ls->extra);
        FcChar8         *extra;
-       FcLangResult    r;
        
        if (list)
        {
@@ -416,7 +437,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)
@@ -545,11 +566,18 @@ FcNameUnparseLangSet (FcStrBuf *buf, const FcLangSet *ls)
        {
            if (!first)
                if (!FcStrBufChar (buf, '|'))
+                {
+                    FcStrListDone (list);
                    return FcFalse;
+                }
            if (!FcStrBufString (buf, extra))
-               return FcFalse;
+                {
+                    FcStrListDone (list);
+                    return FcFalse;
+                }
            first = FcFalse;
        }
+        FcStrListDone (list);
     }
     return FcTrue;
 }
@@ -680,3 +708,25 @@ FcLangSetContains (const FcLangSet *lsa, const FcLangSet *lsb)
     }
     return FcTrue;
 }
+
+FcBool
+FcLangSetSerializeAlloc (FcSerialize *serialize, const FcLangSet *l)
+{
+    if (!FcSerializeAlloc (serialize, l, sizeof (FcLangSet)))
+       return FcFalse;
+    return FcTrue;
+}
+
+FcLangSet *
+FcLangSetSerialize(FcSerialize *serialize, const FcLangSet *l)
+{
+    FcLangSet  *l_serialize = FcSerializePtr (serialize, l);
+
+    if (!l_serialize)
+       return NULL;
+    *l_serialize = *l;
+    return l_serialize;
+}
+#define __fclang__
+#include "fcaliastail.h"
+#undef __fclang__