From 1c9fdccab95c9c5eebd0f9d8488d3ac7c46cbe53 Mon Sep 17 00:00:00 2001 From: Patrick Lam Date: Thu, 24 Nov 2005 21:40:20 +0000 Subject: [PATCH] Move FC_BANK_DYNAMIC, FC_BANK_FIRST to internal header. Check for type validity during FcPatternAddWithBinding, don't verify type in FcFontMatch, don't call FcCanonicalize here (which always does a deep copy). reviewed by: plam --- ChangeLog | 13 +++++++++++++ fontconfig/fontconfig.h | 3 --- src/fcint.h | 3 +++ src/fcmatch.c | 22 +++++----------------- src/fcpat.c | 22 +++++++++++++++++----- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index bea96dd..2acd9c4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-11-24 Dirk Mueller + 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 reviewed by: plam diff --git a/fontconfig/fontconfig.h b/fontconfig/fontconfig.h index 68b62d2..aae60f4 100644 --- a/fontconfig/fontconfig.h +++ b/fontconfig/fontconfig.h @@ -207,9 +207,6 @@ typedef struct _FcPattern FcPattern; typedef struct _FcLangSet FcLangSet; -#define FC_BANK_DYNAMIC 0 -#define FC_BANK_FIRST 1 - typedef struct _FcValue { FcType type; union { diff --git a/src/fcint.h b/src/fcint.h index 1b545bc..e20589c 100644 --- a/src/fcint.h +++ b/src/fcint.h @@ -100,6 +100,8 @@ #define FC_MEM_NUM 30 +#define FC_BANK_DYNAMIC 0 +#define FC_BANK_FIRST 1 #define FC_BANK_LANGS 0xfcfcfcfc typedef enum _FcValueBinding { @@ -309,6 +311,7 @@ typedef struct _FcCaseFold { #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- file is loaded into diff --git a/src/fcmatch.c b/src/fcmatch.c index 8b0bd01..b0d4bf8 100644 --- a/src/fcmatch.c +++ b/src/fcmatch.c @@ -61,12 +61,7 @@ FcCompareNumber (const char *object, FcValue *value1, FcValue *value2) 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 @@ -74,9 +69,6 @@ FcCompareFamily (const char *object, FcValue *v1, FcValue *v2) { /* 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); @@ -134,21 +126,17 @@ FcCompareLang (const char *object, FcValue *v1, FcValue *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 diff --git a/src/fcpat.c b/src/fcpat.c index c37936f..ad6afc0 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -855,7 +855,8 @@ FcPatternAddWithBinding (FcPattern *p, { FcPatternElt *e; FcValueListPtr new, *prev; - FcValueList * newp; + FcValueList *newp; + FcObjectPtr objectPtr; if (p->ref == FC_REF_CONSTANT) goto bail0; @@ -872,11 +873,22 @@ FcPatternAddWithBinding (FcPattern *p, 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; -- 2.39.2