[teklib-general] changeset in /hg/teklib/current: improved handling of default fo...
Franciska Schulze
fschulze at neoscientists.org
Mon Nov 26 16:22:16 CET 2007
changeset 9aaf3beb7184 in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=9aaf3beb7184
description:
improved handling of default font, added font attributes
diffs (272 lines):
diff -r b16fc54c855e -r 9aaf3beb7184 src/visual/posix/visual_host.c
--- a/src/visual/posix/visual_host.c Sun Sep 02 23:07:05 2007 +0200
+++ b/src/visual/posix/visual_host.c Mon Sep 03 20:15:46 2007 +0200
@@ -28,10 +28,16 @@ static TBOOL shm_available;
#define FNT_DEFPXSIZE 14
#define FNT_DEFREGENC "iso8859-1"
+#define FNT_ITALIC 0x01
+#define FNT_BOLD 0x02
+#define FNT_UNDERLINE 0x04
+
struct FontNode
{
struct TNode node;
XFontStruct *font;
+ TUINT attr;
+ TUINT pxsize;
};
LOCAL TAPTR
@@ -52,7 +58,11 @@ vis_hostopenfont(TMOD_VIS *mod, TTAGITEM
fitalic = (TBOOL) TGetTag(tags, TVisual_FontItalic, (TTAG) TFALSE);
fbold = (TBOOL) TGetTag(tags, TVisual_FontBold, (TTAG) TFALSE);
- fquery = (TSTRPTR) TExecAlloc0(exec, mod->vis_MMU, FNT_LENGTH + strlen(fname));
+ if (fname)
+ fquery = TExecAlloc0(exec, mod->vis_MMU, FNT_LENGTH + strlen(fname));
+ else
+ TDBPRINTF(20, ("invalid fontname '%s' specified\n", fname));
+
if (fquery)
{
TExecLock(exec, g->lock);
@@ -75,6 +85,13 @@ vis_hostopenfont(TMOD_VIS *mod, TTAGITEM
fn->font = XLoadQueryFont(g->display, fquery);
if (fn->font)
{
+ /* save font attributes */
+ fn->pxsize = fpxsize;
+ if (fitalic)
+ fn->attr = FNT_ITALIC;
+ if (fbold)
+ fn->attr |= FNT_BOLD;
+
/* append to the list of open fonts */
TDBPRINTF(10, ("'%s' successfully loaded\n", fname));
TAddTail(&g->fm.openfonts, &fn->node);
@@ -102,12 +119,18 @@ setfont(TMOD_VIS *mod, TAPTR font)
setfont(TMOD_VIS *mod, TAPTR font)
{
VISUAL *v = mod->vis_HostVisual;
- XGCValues gcv;
- struct FontNode *fn = (struct FontNode *) font;
-
- gcv.font = fn->font->fid;
- XChangeGC(v->display, v->gc, GCFont, &gcv);
- v->curfont = font;
+
+ if (font)
+ {
+ XGCValues gcv;
+ struct FontNode *fn = (struct FontNode *) font;
+
+ gcv.font = fn->font->fid;
+ XChangeGC(v->display, v->gc, GCFont, &gcv);
+ v->curfont = font;
+ }
+ else
+ TDBPRINTF(20, ("invalid font specified\n"));
}
LOCAL TVOID
@@ -126,6 +149,7 @@ vis_hostclosefont(TMOD_VIS *mod, TAPTR f
/* prevent freeing of default font if it's */
/* still referenced */
g->fm.defref--;
+ TExecUnlock(exec, g->lock);
return;
}
}
@@ -185,7 +209,20 @@ vis_hostgetfattrfunc(struct THook *hook,
switch (item->tti_Tag)
{
default:
+
return TTRUE;
+
+ case TVisual_FontPxSize:
+ *((TINT *) item->tti_Value) = fn->pxsize;
+ break;
+
+ case TVisual_FontItalic:
+ *((TINT *) item->tti_Value) = (fn->attr & FNT_ITALIC) ? TTRUE : TFALSE;
+ break;
+
+ case TVisual_FontBold:
+ *((TINT *) item->tti_Value) = (fn->attr & FNT_BOLD) ? TTRUE : TFALSE;
+ break;
case TVisual_FontAscent:
*((TINT *) item->tti_Value) = fn->font->ascent;
@@ -196,8 +233,19 @@ vis_hostgetfattrfunc(struct THook *hook,
break;
case TVisual_FontHeight:
- *((TINT *) item->tti_Value) =
- fn->font->ascent + fn->font->descent;
+ *((TINT *) item->tti_Value) = fn->font->ascent + fn->font->descent;
+ break;
+
+ case TVisual_FontUlPosition:
+ if (!XGetFontProperty(fn->font, XA_UNDERLINE_POSITION,
+ (unsigned long *)item->tti_Value))
+ *((TINT *) item->tti_Value) = fn->font->descent / 2;
+ break;
+
+ case TVisual_FontUlThickness:
+ if (!XGetFontProperty(fn->font, XA_UNDERLINE_THICKNESS,
+ (unsigned long *)item->tti_Value))
+ *((TINT *) item->tti_Value) = 1;
break;
/* ... */
@@ -1194,13 +1242,13 @@ LOCAL TBOOL
LOCAL TBOOL
vis_init(TMOD_VIS *mod)
{
- struct FontNode *fn;
TAPTR exec = TGetExecBase(mod);
GLOBAL *g = TExecAlloc0(exec, mod->vis_MMU, sizeof(GLOBAL));
if (g == TNULL) return TFALSE;
for (;;)
{
+ TTAGITEM ftags[3];
TInitList(&g->vlist);
g->lock = TExecCreateLock(exec, TNULL);
@@ -1209,23 +1257,20 @@ vis_init(TMOD_VIS *mod)
g->display = XOpenDisplay(TNULL);
if (g->display == TNULL) break;
+ mod->vis_HostGlobal = g;
+
/* init fontmanager and default font */
TInitList(&g->fm.openfonts);
- fn = TExecAlloc0(exec, mod->vis_MMU, sizeof(struct FontNode));
- if (fn == TNULL) break;
-
- fn->font = XLoadQueryFont(g->display, DEFFONTNAME);
- if (fn->font == TNULL)
- {
- TExecFree(exec, fn);
- break;
- }
-
- TAddTail(&g->fm.openfonts, &fn->node);
- g->fm.deffont = (TAPTR)fn;
-
- mod->vis_HostGlobal = g;
+ ftags[0].tti_Tag = TVisual_FontName;
+ ftags[0].tti_Value = (TTAG) FNT_DEFNAME;
+ ftags[1].tti_Tag = TVisual_FontPxSize;
+ ftags[1].tti_Value = (TTAG) FNT_DEFPXSIZE;
+ ftags[2].tti_Tag = TTAG_DONE;
+
+ g->fm.deffont = vis_hostopenfont(mod, ftags);
+ if (g->fm.deffont == TNULL) break;
+
return TTRUE;
}
@@ -1239,6 +1284,9 @@ vis_exit(TMOD_VIS *mod)
TAPTR exec = TGetExecBase(mod);
GLOBAL *g = mod->vis_HostGlobal;
struct TNode *node, *next;
+
+ /* force closing of default font */
+ g->fm.defref = 0;
/* close all fonts */
node = g->fm.openfonts.tlh_Head;
diff -r b16fc54c855e -r 9aaf3beb7184 src/visual/posix/visual_host.h
--- a/src/visual/posix/visual_host.h Sun Sep 02 23:07:05 2007 +0200
+++ b/src/visual/posix/visual_host.h Mon Sep 03 20:15:46 2007 +0200
@@ -6,6 +6,7 @@
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
+#include <X11/Xatom.h>
#include <sys/shm.h>
#include <X11/extensions/XShm.h>
diff -r b16fc54c855e -r 9aaf3beb7184 src/visual/tests/fonts.c
--- a/src/visual/tests/fonts.c Sun Sep 02 23:07:05 2007 +0200
+++ b/src/visual/tests/fonts.c Mon Sep 03 20:15:46 2007 +0200
@@ -30,7 +30,8 @@ TVOID fonttest(TAPTR v, TVPEN *pentab)
TVOID fonttest(TAPTR v, TVPEN *pentab)
{
TINT fh = 0;
- TAPTR font = TNULL;
+ TAPTR cfont = TNULL;
+ TAPTR dfont = TNULL;
TSTRPTR buf = "hallo";
TTAGITEM ftags[5];
static TBOOL init_done = TFALSE;
@@ -38,30 +39,42 @@ TVOID fonttest(TAPTR v, TVPEN *pentab)
if (!init_done)
{
ftags[0].tti_Tag = TVisual_FontName;
+ ftags[0].tti_Value = (TTAG) "";
+ ftags[1].tti_Tag = TTAG_DONE;
+
+ dfont = TVisualOpenFont(v, ftags);
+
+ ftags[0].tti_Tag = TVisual_FontName;
ftags[0].tti_Value = (TTAG) "helvetica";
ftags[1].tti_Tag = TVisual_FontPxSize;
- ftags[1].tti_Value = (TTAG) 10;
+ ftags[1].tti_Value = (TTAG) 20;
ftags[2].tti_Tag = TVisual_FontItalic;
ftags[2].tti_Value = (TTAG) TFALSE;
ftags[3].tti_Tag = TVisual_FontBold;
ftags[3].tti_Value = (TTAG) TTRUE;
ftags[4].tti_Tag = TTAG_DONE;
- font = TVisualOpenFont(v, ftags);
- if (font)
+ cfont = TVisualOpenFont(v, ftags);
+
+ if (dfont && cfont)
{
- TTAGITEM tags[2];
+ TUINT ul = 0;
+ TTAGITEM tags[4];
tags[0].tti_Tag = TVisual_FontHeight;
tags[0].tti_Value = (TTAG) &fh;
- tags[1].tti_Tag = TTAG_DONE;
+ tags[1].tti_Tag = TVisual_FontUlPosition;
+ tags[1].tti_Value = (TTAG) &ul;
+ tags[2].tti_Tag = TTAG_DONE;
- TVisualGetFAttrs(v, font, tags);
+ TVisualGetFAttrs(v, cfont, tags);
+ printf("UL pos: %d\n", ul);
- TVisualSetFont(v, font);
+ TVisualSetFont(v, cfont);
TVisualText(v, 10, 10, buf, TStrLen(buf), pentab[0], TVPEN_UNDEFINED);
- printf("size of text: %d\n", TVisualTextSize(v, font, buf));
- TVisualCloseFont(v, font);
+ printf("size of text: %d\n", TVisualTextSize(v, cfont, buf));
+ TVisualSetFont(v, dfont);
+ TVisualCloseFont(v, cfont);
}
init_done = TTRUE;
diff -r b16fc54c855e -r 9aaf3beb7184 tek/mod/visual.h
--- a/tek/mod/visual.h Sun Sep 02 23:07:05 2007 +0200
+++ b/tek/mod/visual.h Mon Sep 03 20:15:46 2007 +0200
@@ -50,7 +50,8 @@ typedef TTAG TVPEN;
#define TVisual_FontScaleable (TVISTAGS_ + 18)
#define TVisual_FontAscent (TVISTAGS_ + 19)
#define TVisual_FontDescent (TVISTAGS_ + 20)
-
+#define TVisual_FontUlPosition (TVISTAGS_ + 21)
+#define TVisual_FontUlThickness (TVISTAGS_ + 22)
/*****************************************************************************/
/*
More information about the teklib-general
mailing list