[teklib-general] changeset in /hg/teklib/current: Font include added, drawtext wi...

Timm S. Mueller tmueller at neoscientists.org
Mon Nov 26 16:24:38 CET 2007


changeset 4d4b9408363b in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=4d4b9408363b
description:
	Font include added, drawtext with opaque background added

diffs (157 lines):

diff -r 0bc384ae540d -r 4d4b9408363b src/display_x11/display_x11_api.c
--- a/src/display_x11/display_x11_api.c	Wed Sep 26 00:49:18 2007 +0200
+++ b/src/display_x11/display_x11_api.c	Wed Sep 26 01:01:03 2007 +0200
@@ -554,22 +554,47 @@ x11_drawtext(TMOD_X11 *mod, struct TVReq
 	TINT len = req->tvr_Op.Text.Length;
 	TUINT x = req->tvr_Op.Text.X;
 	TUINT y = req->tvr_Op.Text.Y;
+
 	struct X11Pen *fgpen = (struct X11Pen *) req->tvr_Op.Text.FgPen;
-
-	setfgpen(mod, v, req->tvr_Op.Text.FgPen);
-	setbgpen(mod, v, req->tvr_Op.Text.BgPen);
-
-	if (mod->x11_use_xft == TTRUE)
-	{
-		XftFont *f = ((struct FontNode *) v->curfont)->xftfont;
-		(*mod->x11_xftiface.XftDrawStringUtf8)(v->draw, &fgpen->xftcolor,
-			f, x, y + f->ascent, (FcChar8 *)text, len);
+	struct X11Pen *bgpen = (struct X11Pen *) req->tvr_Op.Text.BgPen;
+
+	setfgpen(mod, v, fgpen);
+	setbgpen(mod, v, bgpen);
+
+	if ((TUINTPTR) bgpen == TVPEN_UNDEFINED)
+	{
+		if (mod->x11_use_xft == TTRUE)
+		{
+			XftFont *f = ((struct FontNode *) v->curfont)->xftfont;
+			(*mod->x11_xftiface.XftDrawStringUtf8)(v->draw, &fgpen->xftcolor,
+				f, x, y + f->ascent, (FcChar8 *)text, len);
+		}
+		else
+		{
+			XFontStruct *f = ((struct FontNode *) v->curfont)->font;
+			XDrawString(mod->x11_Display, v->window, v->gc,
+				x, y + f->ascent, (char *) text, len);
+		}
 	}
 	else
 	{
-		XFontStruct *f = ((struct FontNode *) v->curfont)->font;
-		XDrawString(mod->x11_Display, v->window, v->gc,
-			x, y + f->ascent, (char *) text, len);
+		if (mod->x11_use_xft == TTRUE)
+		{
+			XftFont *f = ((struct FontNode *) v->curfont)->xftfont;
+			TINT w = x11_hosttextsize(mod, v->curfont, text);
+
+			(*g->xftiface.XftDrawRect)(v->draw, &bgpen->xftcolor,
+							x-1, y, w+2, f->ascent + f->descent);
+
+			(*g->xftiface.XftDrawStringUtf8)(v->draw, &fgpen->xftcolor,
+				f, x, y + f->ascent, (FcChar8 *)text, len);
+		}
+		else
+		{
+			XFontStruct *f = ((struct FontNode *) v->curfont)->font;
+			XDrawImageString(mod->x11_Display, v->window, v->gc,
+				x, y + f->ascent, (char *) text, len);
+		}
 	}
 }
 
diff -r 0bc384ae540d -r 4d4b9408363b src/display_x11/display_x11_font.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/display_x11/display_x11_font.h	Wed Sep 26 01:01:03 2007 +0200
@@ -0,0 +1,90 @@
+#ifndef _TEK_DISPLAY_X11_FONT_H
+#define _TEK_DISPLAY_X11_FONT_H
+
+#include <X11/Xft/Xft.h>
+
+#define DEFFONTNAME			"-misc-fixed-medium-r-normal-*-14-*-*-*-*-*-*-*"
+
+/* "-*-fname-medium-r-*-*-xxx-*-*-*-*-*-iso8859-1" */
+#define FNT_LENGTH			41
+#define FNT_DEFNAME			"fixed"
+#define FNT_WGHT_MEDIUM		"medium"
+#define	FNT_WGHT_BOLD		"bold"
+#define FNT_SLANT_R			"r"
+#define FNT_SLANT_I			"i"
+#define FNT_DEFPXSIZE		14
+#define	FNT_DEFREGENC		"iso8859-1"
+
+/* results of a query if TVisual_FontNumResults is not specified */
+#define FNTQUERY_NUMRES		1
+#define FNTQUERY_NUMATTR	(5+1)
+#define	FNTQUERY_UNDEFINED	-1
+
+#define FNT_ITALIC			0x1
+#define	FNT_BOLD			0x2
+#define FNT_UNDERLINE		0x4
+
+#define FNT_MATCH_NAME		0x1
+#define FNT_MATCH_SIZE		0x2
+#define FNT_MATCH_SLANT		0x4
+#define	FNT_MATCH_WEIGHT	0x8
+#define FNT_MATCH_ALL		0xf
+
+
+/*****************************************************************************/
+
+struct FontNode
+{
+	struct THandle handle;
+	XFontStruct *font;
+	XftFont *xftfont;
+	TUINT attr;
+	TUINT pxsize;
+};
+
+struct FontQueryNode
+{
+	struct TNode node;
+	TTAGITEM tags[FNTQUERY_NUMATTR];
+};
+
+struct FontQueryHandle
+{
+	struct THandle handle;
+	struct TList reslist;
+	struct TNode **nptr;
+};
+
+struct FnNode
+{
+	struct TNode node;
+	TSTRPTR fname;
+};
+
+/*****************************************************************************/
+
+#define LIBXFT_NUMSYMS	11
+
+struct XftInterface
+{
+	XftFont *(*XftFontOpen)(Display *dpy, int screen, ...);
+	void (*XftFontClose)(Display *dpy, XftFont *pub);
+	void (*XftTextExtentsUtf8)(Display *dpy, XftFont *pub, _Xconst FcChar8 *string,
+           						int len, XGlyphInfo *extents);
+	void (*XftDrawStringUtf8)(XftDraw *draw, _Xconst XftColor *color, XftFont *pub,
+								int x, int y, _Xconst FcChar8  *string, int len);
+	void (*XftDrawRect)(XftDraw *draw, _Xconst XftColor *color, int x, int y,
+						unsigned int width, unsigned int height);
+	FT_Face (*XftLockFace)(XftFont *pub);
+	void (*XftUnlockFace)(XftFont *pub);
+	Bool (*XftColorAllocValue)(Display *dpy, Visual *visual, Colormap cmap,
+								_Xconst XRenderColor *color, XftColor *result);
+	void (*XftColorFree)(Display *dpy, Visual *visual, Colormap  cmap, XftColor *color);
+	XftDraw *(*XftDrawCreate)(Display *dpy, Drawable  drawable, Visual *visual,
+								Colormap colormap);
+	void (*XftDrawDestroy)(XftDraw *draw);
+};
+
+/*****************************************************************************/
+
+#endif /* _TEK_DISPLAY_X11_FONT_H */


More information about the teklib-general mailing list