[teklib-general] changeset in /hg/teklib/current: font support moved to separate ...
Franciska Schulze
fschulze at neoscientists.org
Mon Nov 26 16:22:27 CET 2007
changeset a8f2c81c5191 in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=a8f2c81c5191
description:
font support moved to separate file
diffs (254 lines):
diff -r 7095b8a540ff -r a8f2c81c5191 src/visual/posix/visual_host.c
--- a/src/visual/posix/visual_host.c Wed Sep 05 21:17:38 2007 +0200
+++ b/src/visual/posix/visual_host.c Tue Sep 11 19:04:46 2007 +0200
@@ -1,4 +1,3 @@
-
/*
** $Id: visual_host.c,v 1.3 2006/09/10 14:38:04 tmueller Exp $
** teklib/src/visual/posix/visual_host.c - X11 implementation
@@ -15,244 +14,9 @@
#include <stdio.h>
#include <string.h>
#include "visual_host.h"
+#include "visual_font.h"
static TBOOL shm_available;
-
-/*****************************************************************************/
-#define FNT_LENGTH 41 /* "-*-fname-medium-r-*-*-xxx-*-*-*-*-*-iso8859-1" */
-#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"
-
-#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
-vis_hostopenfont(TMOD_VIS *mod, TTAGITEM *tags)
-{
- GLOBAL *g = mod->vis_HostGlobal;
- TINT fpxsize;
- TBOOL fitalic, fbold;
- TAPTR font = TNULL;
- TSTRPTR fname = TNULL;
- TSTRPTR fquery = TNULL;
- struct FontNode *fn;
- TAPTR exec = TGetExecBase(mod);
-
- /* fetch user specified attributes */
- fname = (TSTRPTR) TGetTag(tags, TVisual_FontName, (TTAG) FNT_DEFNAME);
- fpxsize = (TINT) TGetTag(tags, TVisual_FontPxSize, (TTAG) FNT_DEFPXSIZE);
- fitalic = (TBOOL) TGetTag(tags, TVisual_FontItalic, (TTAG) TFALSE);
- fbold = (TBOOL) TGetTag(tags, TVisual_FontBold, (TTAG) TFALSE);
-
- 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);
-
- /* build fontquery name */
- sprintf(fquery, "-*-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
- fname,
- fbold ? FNT_WGHT_BOLD : FNT_WGHT_MEDIUM,
- fitalic ? FNT_SLANT_I : FNT_SLANT_R,
- fpxsize,
- FNT_DEFREGENC
- );
-
- TDBPRINTF(10, ("fquery = %s\n", fquery));
-
- /* allocate new font node */
- fn = TExecAlloc0(exec, mod->vis_MMU, sizeof(struct FontNode));
- if (fn)
- {
- 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);
- font = (TAPTR)fn;
- }
- else
- {
- /* query failed, return pointer to default font */
- TDBPRINTF(10, ("unable to load '%s'\n", fname));
- TDBPRINTF(10, ("defaulting to '%s'\n", DEFFONTNAME));
- TExecFree(exec, fn);
- font = g->fm.deffont;
- g->fm.defref++;
- }
- }
-
- TExecUnlock(exec, g->lock);
- TExecFree(exec, fquery);
- }
-
- return font;
-}
-
-static TVOID
-setfont(TMOD_VIS *mod, TAPTR font)
-{
- VISUAL *v = mod->vis_HostVisual;
-
- 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
-vis_hostclosefont(TMOD_VIS *mod, TAPTR font)
-{
- GLOBAL *g = mod->vis_HostGlobal;
- struct FontNode *fn = (struct FontNode *) font;
- TAPTR exec = TGetExecBase(mod);
-
- TExecLock(exec, g->lock);
-
- if (font == g->fm.deffont)
- {
- if (g->fm.defref)
- {
- /* prevent freeing of default font if it's */
- /* still referenced */
- g->fm.defref--;
- TExecUnlock(exec, g->lock);
- return;
- }
- }
- else
- {
- struct TNode *node, *next;
- node = g->vlist.tlh_Head;
- for (; (next = node->tln_Succ); node = next)
- {
- /* the font is currently used by another visual */
- VISUAL *v = (VISUAL *) node;
-
- if (font == v->curfont)
- {
- TDBPRINTF(20, ("attempt to close font which is currently in use\n"));
- TDBFATAL();
- }
- }
- }
-
- /* free xfont */
- if (fn->font)
- {
- XFreeFont(g->display, fn->font);
- fn->font = TNULL;
- }
-
- /* remove from openfonts list */
- TRemove(&fn->node);
-
- TExecUnlock(exec, g->lock);
-
- /* free fontnode itself */
- TExecFree(exec, fn);
-}
-
-LOCAL TINT
-vis_hosttextsize(TMOD_VIS *mod, TAPTR font, TSTRPTR text)
-{
- TINT len;
- TAPTR exec = TGetExecBase(mod);
- GLOBAL *g = mod->vis_HostGlobal;
- struct FontNode *fn = (struct FontNode *) font;
- TExecLock(exec, g->lock);
- len = XTextWidth(fn->font, text, strlen(text));
- TExecUnlock(exec, g->lock);
- return len;
-}
-
-LOCAL THOOKENTRY TTAG
-vis_hostgetfattrfunc(struct THook *hook, TAPTR obj, TTAG msg)
-{
- struct attrdata *data = hook->thk_Data;
- TTAGITEM *item = obj;
- struct FontNode *fn = (struct FontNode *) data->font;
-
- 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;
- break;
-
- case TVisual_FontDescent:
- *((TINT *) item->tti_Value) = fn->font->descent;
- break;
-
- case TVisual_FontHeight:
- *((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;
-
- /* ... */
- }
- data->num++;
- return TTRUE;
-}
/*****************************************************************************/
More information about the teklib-general
mailing list