[teklib-general] changeset in /hg/teklib/current: basic version of xft font match...

Franciska Schulze fschulze at neoscientists.org
Mon Nov 26 16:25:09 CET 2007


changeset 45dc4d743529 in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=45dc4d743529
description:
	basic version of xft font matching added

diffs (210 lines):

diff -r 9dfb79f44af2 -r 45dc4d743529 src/display_x11/display_x11_font.c
--- a/src/display_x11/display_x11_font.c	Thu Sep 27 16:54:53 2007 +0200
+++ b/src/display_x11/display_x11_font.c	Thu Sep 27 16:56:22 2007 +0200
@@ -66,6 +66,10 @@ TSTRPTR libfcsyms[LIBFC_NUMSYMS] =
 	"FcPatternDestroy",
 	"FcPatternEqualSubset",
 	"FcPatternPrint",
+	"FcPatternGetString",
+	"FcPatternGetDouble",
+	"FcPatternGetInteger",
+	"FcPatternGetBool",
 };
 
 /*****************************************************************************/
@@ -281,10 +285,10 @@ fnt_getattr(TMOD_X11 *mod, TTAGITEM *tag
 
 /*****************************************************************************/
 /* allocate a fontquerynode and fill in properties derived from
-** a x11 fontname
+** a FcPattern
 */
 static struct FontQueryNode *
-fnt_getfqnode(TMOD_X11 *mod, TSTRPTR fontname)
+fnt_getfqnode_xft(TMOD_X11 *mod, FcPattern *pattern, TINT pxsize)
 {
 	TAPTR exec = TGetExecBase(mod);
 	struct FontQueryNode *fqnode = TNULL;
@@ -293,6 +297,98 @@ fnt_getfqnode(TMOD_X11 *mod, TSTRPTR fon
 	fqnode = TExecAlloc0(exec, mod->x11_MemMgr, sizeof(struct FontQueryNode));
 	if (fqnode)
 	{
+		FcChar8 *fname = TNULL;
+
+		/* fquerynode ready - fill in attributes */
+
+ 		if ((*mod->x11_fciface.FcPatternGetString)(pattern, FC_FAMILY, 0, &fname)
+ 				== FcResultMatch)
+ 		{
+ 			/* got fontname, now copy it to fqnode */
+ 			TINT flen = strlen((char *)fname);
+			TSTRPTR myfname = TExecAlloc0(exec, mod->x11_MemMgr, flen + 1);
+
+			if (myfname)
+			{
+				TExecCopyMem(exec, fname, myfname, flen);
+ 				fqnode->tags[0].tti_Tag = TVisual_FontName;
+				fqnode->tags[0].tti_Value = (TTAG) myfname;
+			}
+			else
+				TDBPRINTF(20, ("out of memory :(\n"));
+		}
+
+		if (fqnode->tags[0].tti_Value)
+		{
+			double fpxsize;
+			FcBool fscale = TFALSE;
+			TINT fslant, fweight, i = 1;
+			TBOOL fitalic = TFALSE, fbold = TFALSE;
+
+			fqnode->tags[i].tti_Tag = TVisual_FontPxSize;
+			if ((*mod->x11_fciface.FcPatternGetDouble)
+				(pattern, FC_PIXEL_SIZE, 0, &fpxsize) == FcResultMatch)
+			{
+				fqnode->tags[i++].tti_Value = (TINT) fpxsize;
+			}
+			else
+			{
+				/* font pxsize argument got ignored when matching,
+				   now it is added back */
+				fqnode->tags[i++].tti_Value = pxsize;
+			}
+
+			if ((*mod->x11_fciface.FcPatternGetInteger)
+				(pattern, FC_SLANT, 0, &fslant) == FcResultMatch)
+			{
+				if (fslant == FC_SLANT_ITALIC) fitalic = TTRUE;
+				fqnode->tags[i].tti_Tag = TVisual_FontItalic;
+				fqnode->tags[i++].tti_Value = (TTAG) fitalic;
+			}
+
+			if ((*mod->x11_fciface.FcPatternGetInteger)
+				(pattern, FC_WEIGHT, 0, &fweight) == FcResultMatch)
+			{
+				if (fweight == FC_WEIGHT_BOLD) fbold = TTRUE;
+				fqnode->tags[i].tti_Tag = TVisual_FontItalic;
+				fqnode->tags[i++].tti_Value = (TTAG) fbold;
+			}
+
+			if ((*mod->x11_fciface.FcPatternGetBool)
+				(pattern, FC_SCALABLE, 0, &fscale) == FcResultMatch)
+			{
+				fqnode->tags[i].tti_Tag = TVisual_FontScaleable;
+				fqnode->tags[i++].tti_Value = (TTAG) fscale;
+			}
+
+			fqnode->tags[i].tti_Tag = TTAG_DONE;
+		}
+		else
+		{
+			TExecFree(exec, fqnode);
+			fqnode = TNULL;
+		}
+	}
+	else
+		TDBPRINTF(20, ("out of memory :(\n"));
+
+	return fqnode;
+}
+
+/*****************************************************************************/
+/* allocate a fontquerynode and fill in properties derived from
+** a x11 fontname
+*/
+static struct FontQueryNode *
+fnt_getfqnode_xlib(TMOD_X11 *mod, TSTRPTR fontname)
+{
+	TAPTR exec = TGetExecBase(mod);
+	struct FontQueryNode *fqnode = TNULL;
+
+	/* allocate fquery node */
+	fqnode = TExecAlloc0(exec, mod->x11_MemMgr, sizeof(struct FontQueryNode));
+	if (fqnode)
+	{
 		/* fquerynode ready - fill in attributes */
 		fqnode->tags[0].tti_Tag = TVisual_FontName;
 		fnt_getattr(mod, &fqnode->tags[0], fontname);
@@ -308,7 +404,7 @@ fnt_getfqnode(TMOD_X11 *mod, TSTRPTR fon
 			fqnode->tags[3].tti_Tag = TVisual_FontBold;
 			fnt_getattr(mod, &fqnode->tags[3], fontname);
 
-			/* TODO: not yet implemented */
+			/* always false */
 			fqnode->tags[4].tti_Tag = TVisual_FontScaleable;
 			fqnode->tags[4].tti_Value = (TTAG) TFALSE;
 
@@ -772,10 +868,13 @@ hostqueryfonts_xft(TMOD_X11 *mod, TTAGIT
 		FcResult result;
 		FcFontSet *fontset = TNULL;
 
+		/* add attributes to pattern and object set */
+
 		if (strncmp(fname, "*", 1) != 0)
 			(*mod->x11_fciface.FcObjectSetAdd)(objset, FC_FAMILY);
 
-		/* add attributes to pattern and object set */
+		/* font pxsize attribute is ignored when the scaleable
+		   attribute of the font is set */
 		if (fpxsize != FNTQUERY_UNDEFINED && fscale != TTRUE)
 		{
 			(*mod->x11_fciface.FcPatternAddDouble)
@@ -812,23 +911,47 @@ hostqueryfonts_xft(TMOD_X11 *mod, TTAGIT
 		{
 			TINT i;
 
+			if (fontset->nfont == 0)
+				TDBPRINTF(10, ("query returned no results\n"));
+
 			for (i = 0; i < fontset->nfont; i++)
 			{
 				if ((*mod->x11_fciface.FcPatternEqualSubset)
 					(pattern, fontset->fonts[i], objset))
 				{
-					/* ... */
-					(*mod->x11_fciface.FcPatternPrint)(fontset->fonts[i]);
+					struct FontQueryNode *fqnode;
+
+					//(*mod->x11_fciface.FcPatternPrint)(fontset->fonts[i]);
+
+					/* create fqnode and fill in attributes */
+					fqnode = fnt_getfqnode_xft(mod, fontset->fonts[i], fpxsize);
+					if(!fqnode)	break;
+
+					/* compare fqnode with nodes in result list */
+					if (fnt_checkfqnode(&fqh->reslist, fqnode) == 0)
+					{
+						/* fqnode is unique, add to result list */
+						TAddTail(&fqh->reslist, &fqnode->node);
+					}
+					else
+					{
+						/* fqnode is not unique, destroy it */
+						TDBPRINTF(10,("X node is not unique\n"));
+						TExecFree(exec, (TSTRPTR)fqnode->tags[0].tti_Value);
+						TExecFree(exec, fqnode);
+					}
 				}
 			}
 
 			(*mod->x11_fciface.FcFontSetDestroy)(fontset);
 		}
+		else
+			TDBPRINTF(10, ("query failed\n"));
 
 		(*mod->x11_fciface.FcPatternDestroy)(pattern);
 	}
 	else
-		TDBPRINTF(10, ("unable to create pattern\n"));
+		TDBPRINTF(10, ("unable to create pattern for query\n"));
 
 
 	fnt_dumplist(&fqh->reslist);
@@ -960,7 +1083,7 @@ hostqueryfonts_xlib(TMOD_X11 *mod, TTAGI
 				TDBPRINTF(10, ("! %s\n", fontlist[i]));
 
 				/* create fqnode and fill in attributes */
-				fqnode = fnt_getfqnode(mod, fontlist[i]);
+				fqnode = fnt_getfqnode_xlib(mod, fontlist[i]);
 				if(!fqnode)	break;
 
 				/* compare fqnode with nodes in result list */


More information about the teklib-general mailing list