[teklib-general] changeset in /hg/teklib/current: fixed compiler warnings, improv...

Franciska Schulze fschulze at neoscientists.org
Mon Nov 26 16:24:17 CET 2007


changeset 43aaf0aaab32 in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=43aaf0aaab32
description:
	fixed compiler warnings, improved doc

diffs (251 lines):

diff -r e93c87bf27b6 -r 43aaf0aaab32 src/visual/posix/visual_font.c
--- a/src/visual/posix/visual_font.c	Tue Sep 18 17:55:29 2007 +0200
+++ b/src/visual/posix/visual_font.c	Mon Sep 24 12:30:47 2007 +0200
@@ -2,22 +2,131 @@
 **	$Id: visual_font.c,v 1.3 2006/09/10 14:38:04 fschulze Exp $
 **	teklib/src/visual/posix/visual_font.c - x11 based font management
 **
+**  Written by Franciska Schulze <fschulze at schulze-mueller.de>
+**
 **	TODO:
-**	- implement xft version of drawtext2
-**	- convert pens to xftcolors
+**	- implement xft version of drawtext2	(OK)
+**	- convert pens to xftcolors				(OK)
+**	- xft font matching
 */
 
 #include <math.h>
 #include <stdio.h>
 #include <string.h>
+#include <dlfcn.h>
 
 #include <tek/debug.h>
 #include <tek/teklib.h>
 #include <tek/proto/hal.h>
+
 #include "visual_mod.h"
-
 #include "visual_host.h"
 #include "visual_font.h"
+
+#define DISABLE_XFT		TFALSE
+
+/*****************************************************************************/
+/* try to open libxft and bind all symbols listed in libxftsyms
+** if initlibxft() succeeds g->use_xft is set to TTRUE
+*/
+TSTRPTR libxftsyms[LIBXFT_NUMSYMS] =
+{
+	"XftFontOpen",
+	"XftFontClose",
+	"XftTextExtentsUtf8",
+	"XftDrawStringUtf8",
+	"XftDrawRect",
+	"XftLockFace",
+	"XftUnlockFace",
+	"XftColorAllocValue",
+	"XftColorFree",
+	"XftDrawCreate",
+	"XftDrawDestroy",
+};
+
+TBOOL
+initlibxft(TMOD_VIS *mod)
+{
+	GLOBAL *g = mod->vis_HostGlobal;
+
+	/* try to open libXft, if it fails, there
+	   will be no font antialiasing at all :( */
+	g->libxfthandle = dlopen("libXft.so", RTLD_NOW);
+	if (g->libxfthandle)
+	{
+		TINT i;
+		TVOID *p = (TVOID *)&g->xftiface;
+
+		/* clear any old error conditions */
+		dlerror();
+
+		for (i = 0; i < LIBXFT_NUMSYMS; i++)
+		{
+			//((void **) &g->xftiface)[i] = dlsym(g->libxfthandle, libxftsyms[i]);
+			((TVOID **)p)[i] = dlsym(g->libxfthandle, libxftsyms[i]);
+			if (dlerror())	break;
+		}
+
+		if (i == LIBXFT_NUMSYMS && DISABLE_XFT != TTRUE)
+		{
+			g->use_xft = TTRUE;
+			TDBPRINTF(10, ("libXft successfully initialised\n"));
+		}
+		else
+		{
+			/* missing symbols */
+			TDBPRINTF(10, ("libXft initialisation failed\n"));
+			TDBPRINTF(10, ("defaulting to xlib based font rendering\n"));
+		}
+	}
+	else
+	{
+		/* lib not found */
+		TDBPRINTF(10, ("failed to open libXft\n"));
+		TDBPRINTF(10, ("defaulting to xlib based font rendering\n"));
+	}
+
+	return g->use_xft;
+}
+
+/*****************************************************************************/
+/* FontQueryHandle destructor
+** free all memory associated with a fontqueryhandle including
+** all fontquerynodes, a fontqueryhandle is obtained by calling
+** vis_hostqueryfonts()
+*/
+THOOKENTRY TTAG
+fqhdestroy(struct THook *hook, TAPTR obj, TTAG msg)
+{
+	if (msg == TMSG_DESTROY)
+	{
+		struct FontQueryHandle *fqh = obj;
+		TMOD_VIS *mod = fqh->handle.thn_Owner;
+		TAPTR exec = TGetExecBase(mod);
+		struct TNode *node, *next;
+
+		node = fqh->reslist.tlh_Head;
+		for (; (next = node->tln_Succ); node = next)
+		{
+			struct FontQueryNode *fqn = (struct FontQueryNode *)node;
+
+			/* remove from resultlist */
+			TRemove(&fqn->node);
+
+			/* destroy fontname */
+			if (fqn->tags[0].tti_Value)
+				TExecFree(exec, (TAPTR)fqn->tags[0].tti_Value);
+
+			/* destroy node */
+			TExecFree(exec, fqn);
+		}
+
+		/* destroy queryhandle */
+		TExecFree(exec, fqh);
+	}
+
+	return 0;
+}
 
 /*****************************************************************************/
 /* extract a substring from an x11 font
@@ -116,45 +225,6 @@ fnt_getattr(TMOD_VIS *mod, TTAGITEM *tag
 		default:
 			break;
 	}
-}
-
-/*****************************************************************************/
-/* FontQueryHandle destructor
-** free all memory associated with a fontqueryhandle including
-** all fontquerynodes, a fontqueryhandle is obtained by calling
-** vis_hostqueryfonts()
-*/
-THOOKENTRY TTAG
-fqhdestroy(struct THook *hook, TAPTR obj, TTAG msg)
-{
-	if (msg == TMSG_DESTROY)
-	{
-		struct FontQueryHandle *fqh = obj;
-		TMOD_VIS *mod = fqh->handle.thn_Owner;
-		TAPTR exec = TGetExecBase(mod);
-		struct TNode *node, *next;
-
-		node = fqh->reslist.tlh_Head;
-		for (; (next = node->tln_Succ); node = next)
-		{
-			struct FontQueryNode *fqn = (struct FontQueryNode *)node;
-
-			/* remove from resultlist */
-			TRemove(&fqn->node);
-
-			/* destroy fontname */
-			if (fqn->tags[0].tti_Value)
-				TExecFree(exec, (TAPTR)fqn->tags[0].tti_Value);
-
-			/* destroy node */
-			TExecFree(exec, fqn);
-		}
-
-		/* destroy queryhandle */
-		TExecFree(exec, fqh);
-	}
-
-	return 0;
 }
 
 /*****************************************************************************/
@@ -288,7 +358,7 @@ fnt_dumplist(struct TList *rlist)
 }
 
 /*****************************************************************************/
-/* parses a single fontname or a comma seperated list of fontnames
+/* parses a single fontname or a comma separated list of fontnames
 ** and returns a list of fontnames, spaces are NOT filtered, so
 ** "helvetica, fixed" will result in "helvetica" and " fixed"
 */
@@ -445,7 +515,7 @@ hostopenfont_xft(TMOD_VIS *mod, TTAGITEM
 					fn->attr |= FNT_BOLD;
 
 				/* append to the list of open fonts */
-				TDBPRINTF(10, ("O '%s'\n", fname));
+				TDBPRINTF(10, ("O '%s' %dpx\n", fname, fpxsize));
 				TAddTail(&g->fm.openfonts, &fn->node);
 				font = (TAPTR)fn;
 			}
@@ -584,7 +654,7 @@ hostopenfont_xlib(TMOD_VIS *mod, TTAGITE
 ** - to match all available fonts, use wildcards for TVisual_FontName,
 **   TVisual_FontPxSize, TVisual_FontItalic, TVisual_FontBold and set
 **   TVisual_FontNumResults to a big value (propably > 3000)
-** - to match more than one specific font, use a coma seperated list
+** - to match more than one specific font, use a coma separated list
 **   for TVisual_FontName, e.g. "helvetica,utopia,fixed", note that
 **   spaces are not filtered
 **
@@ -778,7 +848,7 @@ setfont(TMOD_VIS *mod, TAPTR font)
 **  vis_hostgetnextfont(visualbase, fontqueryhandle)
 **
 ** USE:
-**  iterates a the list of taglists, returning the next taglist
+**  iterates a list of taglists, returning the next taglist
 **  pointer or TNULL
 **
 ** INPUT:
@@ -879,8 +949,8 @@ vis_hostclosefont(TMOD_VIS *mod, TAPTR f
 		   references, this yields to fonts being freed twice and
 		   the X server answers with a RenderBadGlyphSet */
 
-		//(*g->xftiface.XftFontClose)(g->display, fn->xftfont);
-		//fn->xftfont = TNULL;
+		(*g->xftiface.XftFontClose)(g->display, fn->xftfont);
+		fn->xftfont = TNULL;
 	}
 
 	/* remove from openfonts list */
@@ -946,8 +1016,8 @@ vis_hosttextsize(TMOD_VIS *mod, TAPTR fo
 **  tag name				| description
 **	------------------------+---------------------------
 **  TVisual_FontPxSize		| font size in pixel
-**	TVisual_FontItalic		| true if slant = italic
-**	TVisual_FontBold		| true if weight = bold
+**	TVisual_FontItalic		| true if slant == italic
+**	TVisual_FontBold		| true if weight == bold
 ** 	TVisual_FontAscent		| the font ascent in pixel
 **	TVisual_FontDescent		| the font descent in pixel
 **  TVisual_FontHeight		| height in pixel
@@ -996,7 +1066,7 @@ vis_hostgetfattrfunc(struct THook *hook,
 
 		case TVisual_FontDescent:
 			*((TINT *) item->tti_Value) = g->use_xft ?
-				fn->xftfont->descent : fn->xftfont->descent;
+				fn->xftfont->descent : fn->font->descent;
 			break;
 
 		case TVisual_FontHeight:


More information about the teklib-general mailing list