[teklib-general] changeset in /hg/teklib/current: xft matching is now ready to us...
Franciska Schulze
fschulze at neoscientists.org
Mon Nov 26 16:25:39 CET 2007
changeset 4e7e2d0a4d79 in /hg/teklib/current
details: http://teklib.org:8001/hg/teklib/current?cmd=changeset;node=4e7e2d0a4d79
description:
xft matching is now ready to use, improved code structure and documentation, pxsize 0 is no longer a wildcard for openfont
diffs (truncated from 933 to 300 lines):
diff -r 94a25454459b -r 4e7e2d0a4d79 src/display_x11/display_x11_font.c
--- a/src/display_x11/display_x11_font.c Sun Sep 30 21:49:04 2007 +0200
+++ b/src/display_x11/display_x11_font.c Sun Sep 30 21:56:45 2007 +0200
@@ -7,10 +7,10 @@
** TODO:
** - implement xft version of drawtext2 (OK)
** - convert pens to xftcolors (OK)
-** - xft font matching (WIP)
+** - xft font matching (OK)
** - dlopen fontconfig and bind symbols (OK)
-** - remove TDBFATAL from closefont
-** - convert utf8 string to iso-irgendwas when using xlib
+** - remove TDBFATAL from closefont (OK)
+** - convert utf8 string to latin when using xlib
*/
#include <math.h>
@@ -25,15 +25,20 @@
#include "display_x11_mod.h"
#include "display_x11_font.h"
-#define DISABLE_XFT TFALSE
+#define DISABLE_XFT TFALSE
+
+struct fnt_attr;
/*****************************************************************************/
static TAPTR hostopenfont_xft(TMOD_X11 *mod, TTAGITEM *tags);
static TAPTR hostopenfont_xlib(TMOD_X11 *mod, TTAGITEM *tags);
-static TAPTR hostqueryfonts_xft(TMOD_X11 *mod, TTAGITEM *tags);
-static TAPTR hostqueryfonts_xlib(TMOD_X11 *mod, TTAGITEM *tags);
+static TVOID hostqueryfonts_xft(TMOD_X11 *mod, struct FontQueryHandle *fqh,
+ struct fnt_attr *fattr);
+static TVOID hostqueryfonts_xlib(TMOD_X11 *mod, struct FontQueryHandle *fqh,
+ struct fnt_attr *fattr);
static TAPTR initlib(TMOD_X11 *mod, TSTRPTR libname, const TSTRPTR *libsyms,
- TAPTR iface, TINT numsyms);
+ TAPTR iface, TINT numsyms);
+
/*****************************************************************************/
static const
TSTRPTR libxftsyms[LIBXFT_NUMSYMS] =
@@ -70,18 +75,20 @@ TSTRPTR libfcsyms[LIBFC_NUMSYMS] =
"FcPatternGetDouble",
"FcPatternGetInteger",
"FcPatternGetBool",
+ "FcObjectSetDestroy",
};
/*****************************************************************************/
/* try to open libfontconfig and libxft and bind all symbols
** if initlibxft() succeeds g->use_xft is set to TTRUE
+** DISABLE_XFT can be used to enforce xlib based font rendering
*/
TBOOL
initlibxft(TMOD_X11 *mod)
{
/* init fontconfig (needed for font matching) */
mod->x11_libfchandle = initlib(mod, "libfontconfig.so", libfcsyms,
- (TVOID *)&mod->x11_fciface, LIBFC_NUMSYMS);
+ (TVOID *)&mod->x11_fciface, LIBFC_NUMSYMS);
if (mod->x11_libfchandle)
{
@@ -90,7 +97,7 @@ initlibxft(TMOD_X11 *mod)
mod->x11_libxfthandle = initlib(mod, "libXft.so", libxftsyms,
(TVOID *)&mod->x11_xftiface, LIBXFT_NUMSYMS);
- if (mod->x11_libxfthandle)
+ if (mod->x11_libxfthandle && !DISABLE_XFT)
mod->x11_use_xft = TTRUE;
}
@@ -101,7 +108,7 @@ initlibxft(TMOD_X11 *mod)
}
/*****************************************************************************/
-/* dlopen the library named libname, bind numsyms symbols named by libsyms[]
+/* dlopen the library named libname, bind numsyms symbols from libsyms[]
** to iface and return the libhandle obtained by dlopen or TNULL
*/
static TAPTR
@@ -238,7 +245,7 @@ fnt_getattr(TMOD_X11 *mod, TTAGITEM *tag
case TVisual_FontName:
{
/* extract name -> 2th and 3th '-' */
- tag->tti_Value = (TTAG)fnt_getsubstring(mod, fstring, 2);
+ tag->tti_Value = (TTAG) fnt_getsubstring(mod, fstring, 2);
break;
}
case TVisual_FontPxSize:
@@ -247,7 +254,7 @@ fnt_getattr(TMOD_X11 *mod, TTAGITEM *tag
TSTRPTR pxsize = fnt_getsubstring(mod, fstring, 7);
if (pxsize)
{
- tag->tti_Value = (TTAG)atoi(pxsize);
+ tag->tti_Value = (TTAG) atoi(pxsize);
TExecFree(exec, pxsize);
}
break;
@@ -260,7 +267,7 @@ fnt_getattr(TMOD_X11 *mod, TTAGITEM *tag
{
/* italic attribute set? */
if (strncmp(FNT_SLANT_I, slant, strlen(FNT_SLANT_I)) == 0)
- tag->tti_Value = (TTAG)TTRUE;
+ tag->tti_Value = (TTAG) TTRUE;
TExecFree(exec, slant);
}
break;
@@ -273,7 +280,7 @@ fnt_getattr(TMOD_X11 *mod, TTAGITEM *tag
{
/* bold attribute set? */
if (strncmp(FNT_WGHT_BOLD, weight, strlen(FNT_WGHT_BOLD)) == 0)
- tag->tti_Value = (TTAG)TTRUE;
+ tag->tti_Value = (TTAG) TTRUE;
TExecFree(exec, weight);
}
break;
@@ -300,7 +307,6 @@ fnt_getfqnode_xft(TMOD_X11 *mod, FcPatte
FcChar8 *fname = TNULL;
/* fquerynode ready - fill in attributes */
-
if ((*mod->x11_fciface.FcPatternGetString)(pattern, FC_FAMILY, 0, &fname)
== FcResultMatch)
{
@@ -325,17 +331,21 @@ fnt_getfqnode_xft(TMOD_X11 *mod, FcPatte
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;
+ fqnode->tags[i].tti_Tag = TVisual_FontPxSize;
+ fqnode->tags[i++].tti_Value = (TTAG) ((TINT)fpxsize);
}
else
{
- /* font pxsize argument got ignored when matching,
- now it is added back */
- fqnode->tags[i++].tti_Value = pxsize;
+ if (pxsize != FNTQUERY_UNDEFINED)
+ {
+ /* font pxsize argument got ignored when matching,
+ now it is added back */
+ fqnode->tags[i].tti_Tag = TVisual_FontPxSize;
+ fqnode->tags[i++].tti_Value = pxsize;
+ }
}
if ((*mod->x11_fciface.FcPatternGetInteger)
@@ -362,13 +372,15 @@ fnt_getfqnode_xft(TMOD_X11 *mod, FcPatte
}
fqnode->tags[i].tti_Tag = TTAG_DONE;
- }
+
+ } /* endif fqnode->tags[0].tti_Value */
else
{
TExecFree(exec, fqnode);
fqnode = TNULL;
}
- }
+
+ } /* endif fqnode */
else
TDBPRINTF(20, ("out of memory :(\n"));
@@ -424,7 +436,7 @@ fnt_getfqnode_xlib(TMOD_X11 *mod, TSTRPT
/*****************************************************************************/
/* check if a font with similar properties is already contained
-** in our resultlist, also fonts with pxsize = 0 are filtered
+** in our resultlist
*/
static TBOOL
fnt_checkfqnode(struct TList *rlist, struct FontQueryNode *fqnode)
@@ -439,12 +451,7 @@ fnt_checkfqnode(struct TList *rlist, str
TBOOL newweight = (TBOOL)fqnode->tags[3].tti_Value;
TINT flen = strlen(newfname);
- /* filter out fonts with pxsize = 0 to keep our api consistent */
- if (newpxsize == 0)
- return TTRUE;
-
- node = rlist->tlh_Head;
- for (; (next = node->tln_Succ); node = next)
+ for (node = rlist->tlh_Head; (next = node->tln_Succ); node = next)
{
struct FontQueryNode *fqn = (struct FontQueryNode *)node;
flags = 0;
@@ -524,17 +531,14 @@ fnt_getfnnodes(TMOD_X11 *mod, struct TLi
if (fname[i] == ',' || lastrun)
{
- TSTRPTR ts;
TINT len = (i > p) ? (lastrun ? (i-p+1) : (i-p)) : fnlen+1;
-
- TDBPRINTF(10, ("i = %d, p = %d, size = %d\n", i, p, len));
- ts = TExecAlloc0(exec, mod->x11_MemMgr, len+1);
+ TSTRPTR ts = TExecAlloc0(exec, mod->x11_MemMgr, len+1);
+
if (ts)
{
struct FnNode *fnn;
TExecCopyMem(exec, fname+p, ts, len);
- TDBPRINTF(10, ("copy: '%s'\n", ts));
fnn = TExecAlloc0(exec, mod->x11_MemMgr, sizeof(struct FnNode));
if (fnn)
@@ -561,6 +565,44 @@ fnt_getfnnodes(TMOD_X11 *mod, struct TLi
}
/*****************************************************************************/
+/* translate user attribute bold to a corresponding xlib string
+*/
+static TSTRPTR
+fnt_getfbold(TBOOL fbold)
+{
+ switch (fbold)
+ {
+ case FNTQUERY_UNDEFINED:
+ return FNT_WILDCARD;
+ case TFALSE:
+ return FNT_WGHT_MEDIUM;
+ case TTRUE:
+ return FNT_WGHT_BOLD;
+ }
+
+ return TNULL;
+}
+
+/*****************************************************************************/
+/* translate user attribute italic to a corresponding xlib string
+*/
+static TSTRPTR
+fnt_getfitalic(TBOOL fitalic)
+{
+ switch (fitalic)
+ {
+ case FNTQUERY_UNDEFINED:
+ return FNT_WILDCARD;
+ case TFALSE:
+ return FNT_SLANT_R;
+ case TTRUE:
+ return FNT_SLANT_I;
+ }
+
+ return TNULL;
+}
+
+/*****************************************************************************/
/* CALL:
** x11_hostopenfont(visualbase, tags)
**
@@ -574,12 +616,12 @@ fnt_getfnnodes(TMOD_X11 *mod, struct TLi
** TVisual_FontPxSize | font size in pixel
** TVisual_FontItalic | enable slant italic
** TVisual_FontBold | enable bold weight
-** TVisual_FontScaleable | prefer truetype font
+** TVisual_FontScaleable | use truetype font
**
** tag name | default¹ | wildcard
** ------------------------+-----------+---------------
** TVisual_FontName | "fixed" | "*"
-** TVisual_FontPxSize | 14 | 0
+** TVisual_FontPxSize | 14 | /
** TVisual_FontItalic | false | /
** TVisual_FontBold | false | /
** TVisual_FontScaleable | false | /
@@ -587,7 +629,7 @@ fnt_getfnnodes(TMOD_X11 *mod, struct TLi
** ¹ the defaults are used when the tag is missing
**
** RETURN:
-** - a pointer to a font ready to be used
+** - a pointer to a font ready to be used or TNULL
**
** EXAMPLES:
** - to open the default font of your platform leave all tags empty
@@ -622,9 +664,9 @@ hostopenfont_xft(TMOD_X11 *mod, TTAGITEM
{
TINT fpxsize;
TBOOL fitalic, fbold, fscale;
- TAPTR font = TNULL;
TSTRPTR fname = TNULL;
struct FontNode *fn;
+ TAPTR font = TNULL;
TAPTR exec = TGetExecBase(mod);
/* fetch user specified attributes */
@@ -636,7 +678,7 @@ hostopenfont_xft(TMOD_X11 *mod, TTAGITEM
if (fname)
{
- /* allocate new font node */
+ /* allocate new fontnode */
More information about the teklib-general
mailing list