[teklib-general] changeset in /hg/teklib/current: kicked FcPatternEqualSubset bac...

Franciska Schulze fschulze at neoscientists.org
Mon Dec 10 19:47:47 CET 2007


changeset 0f8c57042c46 in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=0f8c57042c46
description:
	kicked FcPatternEqualSubset back to the infernal abyss it came from

diffs (276 lines):

diff -r 46d27330c3d2 -r 0f8c57042c46 src/display_x11/display_x11_font.c
--- a/src/display_x11/display_x11_font.c	Mon Nov 19 18:31:39 2007 +0100
+++ b/src/display_x11/display_x11_font.c	Mon Dec 10 19:41:08 2007 +0100
@@ -17,6 +17,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <dlfcn.h>
+#include <ctype.h>
 
 #include <tek/debug.h>
 #include <tek/teklib.h>
@@ -62,20 +63,17 @@ TSTRPTR libfcsyms[LIBFC_NUMSYMS] =
 	"FcDefaultSubstitute",
 	"FcFontSetDestroy",
 	"FcFontSort",
-	"FcObjectSetAdd",
-	"FcObjectSetCreate",
 	"FcPatternAddBool",
 	"FcPatternAddDouble",
 	"FcPatternAddInteger",
 	"FcPatternBuild",
 	"FcPatternDestroy",
-	"FcPatternEqualSubset",
 	"FcPatternPrint",
 	"FcPatternGetString",
 	"FcPatternGetDouble",
 	"FcPatternGetInteger",
 	"FcPatternGetBool",
-	"FcObjectSetDestroy",
+	"FcInit",
 };
 
 /*****************************************************************************/
@@ -98,7 +96,12 @@ initlibxft(TMOD_X11 *mod)
 							(TVOID *)&mod->x11_xftiface, LIBXFT_NUMSYMS);
 
 		if (mod->x11_libxfthandle && !DISABLE_XFT)
-			mod->x11_use_xft = TTRUE;
+		{
+			if((*mod->x11_fciface.FcInit)())
+				mod->x11_use_xft = TTRUE;
+			else
+				TDBPRINTF(10, ("fontconfig init failed\n"));
+		}
 	}
 
 	if (!mod->x11_use_xft)
@@ -600,6 +603,87 @@ fnt_getfitalic(TBOOL fitalic)
 	}
 
 	return TNULL;
+}
+
+/*****************************************************************************/
+/* search pattern for properties specified by flag and compare them with
+** fname and fattr, if properties match, the corresponing bit is set in
+** the flagfield the function returns
+*/
+static TUINT
+fnt_matchfont_xft(TMOD_X11 *mod, FcPattern *pattern, TSTRPTR fname,
+	struct fnt_attr *fattr, TUINT flag)
+{
+	TUINT match = 0;
+	TAPTR exec = TGetExecBase(mod);
+
+	if (flag & FNT_MATCH_NAME)
+	{
+		TINT i, len;
+		FcChar8 *fcfname = NULL;
+		TSTRPTR tempname = TNULL;
+
+		(*mod->x11_fciface.FcPatternGetString)(pattern, FC_FAMILY, 0, &fcfname);
+
+		/* convert fontnames to lower case */
+		len = strlen(fname);
+		for (i = 0; i < len; i++)
+			fname[i] = tolower(fname[i]);
+
+		len = strlen((TSTRPTR)fcfname);
+		tempname = TExecAlloc0(exec, mod->x11_MemMgr, len+1);
+		if (!tempname)
+		{
+			TDBPRINTF(20, ("out of memory :(\n"));
+			return -1;
+		}
+
+		for (i = 0; i < len; i++)
+			tempname[i] = tolower(fcfname[i]);
+
+		/* compare converted fontnames */
+		if (strncmp(fname, tempname, len) == 0)
+			match = FNT_MATCH_NAME;
+
+		TExecFree(exec, tempname);
+	}
+
+	if (flag & FNT_MATCH_SIZE)
+	{
+		double fcsize;
+		(*mod->x11_fciface.FcPatternGetDouble)(pattern, FC_PIXEL_SIZE, 0, &fcsize);
+		if ((TFLOAT)fattr->fpxsize == (TFLOAT)fcsize)
+			match |= FNT_MATCH_SIZE;
+	}
+
+	if (flag & FNT_MATCH_SLANT)
+	{
+		int fcslant;
+		(*mod->x11_fciface.FcPatternGetInteger)(pattern, FC_SLANT, 0, &fcslant);
+		if ((fcslant == FC_SLANT_ITALIC && fattr->fitalic == TTRUE) ||
+			(fcslant == FC_SLANT_ROMAN  && fattr->fitalic == TFALSE))
+			match |= FNT_MATCH_SLANT;
+	}
+
+	if (flag & FNT_MATCH_WEIGHT)
+	{
+		int fcweight;
+		(*mod->x11_fciface.FcPatternGetInteger)(pattern, FC_WEIGHT, 0, &fcweight);
+		if ((fcweight == FC_WEIGHT_BOLD && fattr->fbold == TTRUE) ||
+			(fcweight == FC_WEIGHT_MEDIUM && fattr->fbold == TFALSE))
+			match |= FNT_MATCH_WEIGHT;
+	}
+
+	if (flag & FNT_MATCH_SCALE)
+	{
+		FcBool fcscale;
+		(*mod->x11_fciface.FcPatternGetBool)(pattern, FC_SCALABLE, 0, &fcscale);
+		if ((fcscale == FcTrue && fattr->fscale == TTRUE) ||
+			(fcscale == FcFalse && fattr->fscale == TFALSE))
+			match |= FNT_MATCH_SCALE;
+	}
+
+	return match;
 }
 
 /*****************************************************************************/
@@ -908,9 +992,9 @@ hostqueryfonts_xft(TMOD_X11 *mod, struct
 hostqueryfonts_xft(TMOD_X11 *mod, struct FontQueryHandle *fqh, struct fnt_attr *fattr)
 {
 	FcPattern *pattern = TNULL;
-	FcObjectSet *objset = TNULL;
 	struct TNode *node, *next;
 	TAPTR exec = TGetExecBase(mod);
+	TUINT matchflg = 0;
 
 	for (node = fattr->fnlist.tlh_Head; (next = node->tln_Succ); node = next)
 	{
@@ -931,19 +1015,10 @@ hostqueryfonts_xft(TMOD_X11 *mod, struct
 			continue;
 		}
 
-		/* create object set to filter results */
-		objset = (*mod->x11_fciface.FcObjectSetCreate)();
-		if (!objset)
-		{
-			TDBPRINTF(10, ("X unable to create object set for '%s'\n", fnn->fname));
-			(*mod->x11_fciface.FcPatternDestroy)(pattern);
-			continue;
-		}
-
-		/* add attributes to pattern and object set */
+		/* add attributes to pattern and build matchflag */
 
 		if (strncmp(fnn->fname, FNT_WILDCARD, 1) != 0)
-			(*mod->x11_fciface.FcObjectSetAdd)(objset, FC_FAMILY);
+			matchflg = FNT_MATCH_NAME;
 
 		/* font pxsize attribute is ignored when the scaleable
 			attribute of the font is set, because some scaleable
@@ -952,28 +1027,28 @@ hostqueryfonts_xft(TMOD_X11 *mod, struct
 		{
 			(*mod->x11_fciface.FcPatternAddDouble)
 				(pattern, FC_PIXEL_SIZE, (TFLOAT)fattr->fpxsize);
-			(*mod->x11_fciface.FcObjectSetAdd)(objset, FC_PIXEL_SIZE);
+			matchflg |= FNT_MATCH_SIZE;
 		}
 
 		if (fattr->fitalic != FNTQUERY_UNDEFINED)
 		{
 			(*mod->x11_fciface.FcPatternAddInteger) (pattern, FC_SLANT,
 				(fattr->fitalic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN));
-			(*mod->x11_fciface.FcObjectSetAdd)(objset, FC_SLANT);
+			matchflg |= FNT_MATCH_SLANT;
 		}
 
 		if (fattr->fbold != FNTQUERY_UNDEFINED)
 		{
 			(*mod->x11_fciface.FcPatternAddInteger)(pattern, FC_WEIGHT,
 				(fattr->fbold ? FC_WEIGHT_BOLD : FC_WEIGHT_MEDIUM));
-			(*mod->x11_fciface.FcObjectSetAdd)(objset, FC_WEIGHT);
+			matchflg |= FNT_MATCH_WEIGHT;
 		}
 
 		if (fattr->fscale != FNTQUERY_UNDEFINED)
 		{
 			(*mod->x11_fciface.FcPatternAddBool)(pattern, FC_SCALABLE,
 				fattr->fscale);
-			(*mod->x11_fciface.FcObjectSetAdd)(objset, FC_SCALABLE);
+			matchflg |= FNT_MATCH_SCALE;
 		}
 
 		/* don't call FcConfigSubstitute because matching
@@ -982,7 +1057,7 @@ hostqueryfonts_xft(TMOD_X11 *mod, struct
 		(*mod->x11_fciface.FcDefaultSubstitute)(pattern);
 		TDB(10, ((*mod->x11_fciface.FcPatternPrint)(pattern)));
 
-		fontset = (*mod->x11_fciface.FcFontSort)(TNULL, pattern, FcFalse, TNULL, &result);
+		fontset = (*mod->x11_fciface.FcFontSort)(NULL, pattern, FcFalse, TNULL, &result);
 		if (fontset)
 		{
 			TINT i;
@@ -992,8 +1067,8 @@ hostqueryfonts_xft(TMOD_X11 *mod, struct
 
 			for (i = 0; i < fontset->nfont; i++)
 			{
-				if ((*mod->x11_fciface.FcPatternEqualSubset)
-					(pattern, fontset->fonts[i], objset))
+				if (fnt_matchfont_xft(mod, fontset->fonts[i], fnn->fname,
+					fattr, matchflg) == matchflg)
 				{
 					struct FontQueryNode *fqnode;
 
@@ -1023,7 +1098,6 @@ hostqueryfonts_xft(TMOD_X11 *mod, struct
 		else
 			TDBPRINTF(10, ("X query failed\n"));
 
-		(*mod->x11_fciface.FcObjectSetDestroy)(objset);
 		(*mod->x11_fciface.FcPatternDestroy)(pattern);
 
 	} /* end of fnlist iteration */
diff -r 46d27330c3d2 -r 0f8c57042c46 src/display_x11/display_x11_font.h
--- a/src/display_x11/display_x11_font.h	Mon Nov 19 18:31:39 2007 +0100
+++ b/src/display_x11/display_x11_font.h	Mon Dec 10 19:41:08 2007 +0100
@@ -29,7 +29,8 @@
 #define FNT_MATCH_SIZE		0x2
 #define FNT_MATCH_SLANT		0x4
 #define	FNT_MATCH_WEIGHT	0x8
-#define FNT_MATCH_ALL		0xf
+#define	FNT_MATCH_SCALE		0x10
+#define FNT_MATCH_ALL		0xf		/* all mandatory properties */
 
 /*****************************************************************************/
 
@@ -99,7 +100,7 @@ struct XftInterface
 	void (*XftDrawDestroy)(XftDraw *draw);
 };
 
-#define	LIBFC_NUMSYMS	17
+#define	LIBFC_NUMSYMS	14
 
 struct FcInterface
 {
@@ -107,15 +108,11 @@ struct FcInterface
 	void (*FcFontSetDestroy)(FcFontSet *s);
 	FcFontSet *(*FcFontSort)(FcConfig *config, FcPattern *p, FcBool trim,
 		FcCharSet **csp, FcResult *result);
-	FcBool (*FcObjectSetAdd)(FcObjectSet *os, const char *object);
-	FcObjectSet *(*FcObjectSetCreate)(void);
 	FcBool (*FcPatternAddBool)(FcPattern *p, const char *object, FcBool b);
 	FcBool (*FcPatternAddDouble)(FcPattern *p, const char *object, double d);
 	FcBool (*FcPatternAddInteger)(FcPattern *p, const char *object, int i);
 	FcPattern *(*FcPatternBuild)(FcPattern *orig, ...);
 	void (*FcPatternDestroy)(FcPattern *p);
-	FcBool (*FcPatternEqualSubset)(const FcPattern *pa, const FcPattern *pb,
-		const FcObjectSet *os);
 	void (*FcPatternPrint)(const FcPattern *p);
 	FcResult (*FcPatternGetString)(const FcPattern *p, const char *object,
 		int n, FcChar8 **s);
@@ -125,7 +122,7 @@ struct FcInterface
 		int n, int *i);
 	FcResult (*FcPatternGetBool)(const FcPattern *p, const char *object,
 		int n, FcBool *b);
-	void (*FcObjectSetDestroy)(FcObjectSet *os);
+	FcBool (*FcInit)(void);
 };
 
 /*****************************************************************************/


More information about the teklib-general mailing list