Imported Upstream version 2.14.2
[platform/upstream/fontconfig.git] / src / fcpat.c
index 0861b8f..cdbeec4 100644 (file)
@@ -142,27 +142,7 @@ FcValueListDestroy (FcValueListPtr l)
     FcValueListPtr next;
     for (; l; l = next)
     {
-       switch ((int) l->value.type) {
-       case FcTypeString:
-           FcFree (l->value.u.s);
-           break;
-       case FcTypeMatrix:
-           FcMatrixFree ((FcMatrix *)l->value.u.m);
-           break;
-       case FcTypeCharSet:
-           FcCharSetDestroy
-               ((FcCharSet *) (l->value.u.c));
-           break;
-       case FcTypeLangSet:
-           FcLangSetDestroy
-               ((FcLangSet *) (l->value.u.l));
-           break;
-       case FcTypeRange:
-           FcRangeDestroy ((FcRange *) (l->value.u.r));
-           break;
-       default:
-           break;
-       }
+       FcValueDestroy (l->value);
        next = FcValueListNext(l);
        free(l);
     }
@@ -338,7 +318,7 @@ FcValueHash (const FcValue *v)
     case FcTypeLangSet:
        return FcLangSetHash (FcValueLangSet(v));
     case FcTypeRange:
-       return FcRangeHash (v->u.r);
+       return FcRangeHash (FcValueRange (v));
     }
     return 0;
 }
@@ -553,17 +533,17 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
                p->size++;
            }
        }
-       
+
        e = FcPatternElts(p);
        /* move elts up */
        memmove (e + i + 1,
                 e + i,
                 sizeof (FcPatternElt) *
                 (FcPatternObjectCount (p) - i));
-               
+
        /* bump count */
        p->num++;
-       
+
        e[i].object = object;
        e[i].values = NULL;
     }
@@ -708,30 +688,29 @@ FcPatternObjectAddWithBinding  (FcPattern *p,
     if (!new)
        goto bail0;
 
-    value = FcValueSave (value);
-    if (value.type == FcTypeVoid)
+    new->value = FcValueSave (value);
+    new->binding = binding;
+    new->next = NULL;
+
+    if (new->value.type == FcTypeVoid)
        goto bail1;
 
     /*
      * Make sure the stored type is valid for built-in objects
      */
-    if (!FcObjectValidType (object, value.type))
+    if (!FcObjectValidType (object, new->value.type))
     {
        fprintf (stderr,
                 "Fontconfig warning: FcPattern object %s does not accept value",
                 FcObjectName (object));
-       FcValuePrintFile (stderr, value);
+       FcValuePrintFile (stderr, new->value);
        fprintf (stderr, "\n");
        goto bail1;
     }
 
-    new->value = value;
-    new->binding = binding;
-    new->next = NULL;
-
     e = FcPatternObjectInsertElt (p, object);
     if (!e)
-       goto bail2;
+       goto bail1;
 
     if (append)
     {
@@ -747,10 +726,8 @@ FcPatternObjectAddWithBinding  (FcPattern  *p,
 
     return FcTrue;
 
-bail2:
-    FcValueDestroy (value);
 bail1:
-    free (new);
+    FcValueListDestroy (new);
 bail0:
     return FcFalse;
 }
@@ -914,13 +891,19 @@ FcPatternAddBool (FcPattern *p, const char *object, FcBool b)
 }
 
 FcBool
-FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c)
+FcPatternObjectAddCharSet (FcPattern *p, FcObject object, const FcCharSet *c)
 {
     FcValue    v;
 
     v.type = FcTypeCharSet;
     v.u.c = (FcCharSet *)c;
-    return FcPatternAdd (p, object, v, FcTrue);
+    return FcPatternObjectAdd (p, object, v, FcTrue);
+}
+
+FcBool
+FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c)
+{
+    return FcPatternObjectAddCharSet (p, FcObjectFromName (object), c);
 }
 
 FcBool
@@ -934,13 +917,19 @@ FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f)
 }
 
 FcBool
-FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls)
+FcPatternObjectAddLangSet (FcPattern *p, FcObject object, const FcLangSet *ls)
 {
     FcValue    v;
 
     v.type = FcTypeLangSet;
     v.u.l = (FcLangSet *)ls;
-    return FcPatternAdd (p, object, v, FcTrue);
+    return FcPatternObjectAdd (p, object, v, FcTrue);
+}
+
+FcBool
+FcPatternAddLangSet (FcPattern *p, const char *object, const FcLangSet *ls)
+{
+    return FcPatternObjectAddLangSet (p, FcObjectFromName (object), ls);
 }
 
 FcBool
@@ -1570,7 +1559,7 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
                                                          FcValueList);
        else
            head_serialized = vl_serialized;
-       
+
        vl_serialized->next = NULL;
        vl_serialized->value.type = vl->value.type;
        switch ((int) vl->value.type) {