+2005-11-24 Dirk Mueller <dmueller@suse.com>
+ reviewed by: plam
+
+ * src/fcint.h, fontconfig/fontconfig.h:
+
+ Move FC_BANK_DYNAMIC, FC_BANK_FIRST to internal header.
+
+ * src/fcpat.c, src/fcint.h, src/fcname.c:
+
+ Check for type validity during FcPatternAddWithBinding, don't
+ verify type in FcFontMatch, don't call FcCanonicalize here
+ (which always does a deep copy).
+
2005-11-24 Dirk Mueller <dmueller@suse.com>
reviewed by: plam
typedef struct _FcLangSet FcLangSet;
-#define FC_BANK_DYNAMIC 0
-#define FC_BANK_FIRST 1
-
typedef struct _FcValue {
FcType type;
union {
#define FC_MEM_NUM 30
+#define FC_BANK_DYNAMIC 0
+#define FC_BANK_FIRST 1
#define FC_BANK_LANGS 0xfcfcfcfc
typedef enum _FcValueBinding {
#define fc_value_string(v) (((v)->type & FC_STORAGE_STATIC) ? ((FcChar8 *) v) + (v)->u.s_off : (v) -> u.s)
#define fc_value_charset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcCharSet *)(((char *) v) + (v)->u.c_off) : (v) -> u.c)
#define fc_value_langset(v) (((v)->type & FC_STORAGE_STATIC) ? (const FcLangSet *)(((char *) v) + (v)->u.l_off) : (v) -> u.l)
+#define fc_storage_type(v) ((v)->type & ~FC_STORAGE_STATIC)
/*
* The per-user ~/.fonts.cache-<version> file is loaded into
static double
FcCompareString (const char *object, FcValue *v1, FcValue *v2)
{
- FcValue value1, value2;
- if ((v2->type & ~FC_STORAGE_STATIC) != FcTypeString ||
- (v1->type & ~FC_STORAGE_STATIC) != FcTypeString)
- return -1.0;
- value1 = FcValueCanonicalize(v1); value2 = FcValueCanonicalize(v2);
- return (double) FcStrCmpIgnoreCase (value1.u.s, value2.u.s) != 0;
+ return (double) FcStrCmpIgnoreCase (fc_value_string(v1), fc_value_string(v2)) != 0;
}
static double
{
/* rely on the guarantee in FcPatternAddWithBinding that
* families are always FcTypeString. */
-
- /* assert ((v2->type & ~FC_STORAGE_STATIC) == FcTypeString &&
- (v1->type & ~FC_STORAGE_STATIC) == FcTypeString); */
const FcChar8* v1_string = fc_value_string(v1);
const FcChar8* v2_string = fc_value_string(v2);
}
static double
-FcCompareBool (const char *object, FcValue *value1, FcValue *value2)
+FcCompareBool (const char *object, FcValue *v1, FcValue *v2)
{
- if (value2->type != FcTypeBool || value1->type != FcTypeBool)
+ if (fc_storage_type(v2) != FcTypeBool || fc_storage_type(v1) != FcTypeBool)
return -1.0;
- return (double) value2->u.b != value1->u.b;
+ return (double) v2->u.b != v1->u.b;
}
static double
FcCompareCharSet (const char *object, FcValue *v1, FcValue *v2)
{
- FcValue value1 = FcValueCanonicalize(v1), value2 = FcValueCanonicalize(v2);
-
- if (value2.type != FcTypeCharSet || value1.type != FcTypeCharSet)
- return -1.0;
- return (double) FcCharSetSubtractCount (value1.u.c, value2.u.c);
+ return (double) FcCharSetSubtractCount (fc_value_charset(v1), fc_value_charset(v2));
}
static double
{
FcPatternElt *e;
FcValueListPtr new, *prev;
- FcValueList * newp;
+ FcValueList *newp;
+ FcObjectPtr objectPtr;
if (p->ref == FC_REF_CONSTANT)
goto bail0;
if (value.type == FcTypeVoid)
goto bail1;
- /* quick and dirty hack to enable FcCompareFamily speedup:
- * only allow strings to be added under the FC_FAMILY key.
+ /* quick and dirty hack to enable FcCompareFamily/FcCompareString
+ * speedup: only allow strings to be added under the FC_FAMILY,
+ * FC_FOUNDRY, FC_STYLE, FC_RASTERIZER keys.
+ * and charsets under FC_CHARSET key.
+ * This is slightly semantically different from the old behaviour,
+ * but fonts shouldn't be getting non-strings here anyway.
* a better hack would use FcBaseObjectTypes to check all objects. */
- if (FcObjectToPtr(object) == FcObjectToPtr(FC_FAMILY) &&
- value.type != FcTypeString)
+ objectPtr = FcObjectToPtr(object);
+ if ((objectPtr == FcObjectToPtr(FC_FAMILY)
+ || objectPtr == FcObjectToPtr(FC_FOUNDRY)
+ || objectPtr == FcObjectToPtr(FC_STYLE)
+ || objectPtr == FcObjectToPtr(FC_RASTERIZER))
+ && value.type != FcTypeString)
+ goto bail1;
+ if (objectPtr == FcObjectToPtr(FC_CHARSET)
+ && value.type != FcTypeCharSet)
goto bail1;
FcValueListPtrU(new)->value = value;