Fix weird first/not-first lameness in font matches, replacing with target

qualifiers on test elements. Update library manual page.
This commit is contained in:
Keith Packard 2002-08-11 18:11:04 +00:00
parent 80a7d66439
commit 938bc63358
13 changed files with 510 additions and 156 deletions

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/fontconfig/fcprivate.h,v 1.2 2002/02/15 06:01:27 keithp Exp $
* $XFree86: xc/lib/fontconfig/fontconfig/fcprivate.h,v 1.3 2002/05/31 23:21:24 keithp Exp $
*
* Copyright Š 2001 Keith Packard, member of The XFree86 Project, Inc.
*
@ -72,6 +72,9 @@
break; \
case FcTypeFTFace: \
__v__.u.f = va_arg (va, FT_Face); \
break; \
case FcTypePattern: \
__v__.u.p = va_arg (va, FcPattern *); \
} \
if (!FcPatternAdd (__p__, __o__, __v__, FcTrue)) \
goto _FcPatternVapBuild_bail1; \

View File

@ -71,6 +71,7 @@ typedef int FcBool;
#define FC_SOURCE "source" /* String (X11, freetype) */
#define FC_CHARSET "charset" /* CharSet */
#define FC_LANG "lang" /* String OS/2 CodePageRange */
#define FC_PATTERN "pattern" /* FcPattern */
#define FC_DIR_CACHE_FILE "fonts.cache"
#define FC_USER_CACHE_FILE ".fonts.cache"
@ -109,7 +110,8 @@ typedef enum _FcType {
FcTypeBool,
FcTypeMatrix,
FcTypeCharSet,
FcTypeFTFace
FcTypeFTFace,
FcTypePattern
} FcType;
typedef struct _FcMatrix {
@ -141,6 +143,8 @@ typedef enum _FcResult {
FcResultMatch, FcResultNoMatch, FcResultTypeMismatch, FcResultNoId
} FcResult;
typedef struct _FcPattern FcPattern;
typedef struct _FcValue {
FcType type;
union {
@ -151,11 +155,10 @@ typedef struct _FcValue {
const FcMatrix *m;
const FcCharSet *c;
void *f;
const FcPattern *p;
} u;
} FcValue;
typedef struct _FcPattern FcPattern;
typedef struct _FcFontSet {
int nfont;
int sfont;
@ -336,13 +339,13 @@ FcCharSetNextPage (const FcCharSet *a,
/* fcdbg.c */
void
FcValuePrint (FcValue v);
FcValuePrint (const FcValue v);
void
FcPatternPrint (FcPattern *p);
FcPatternPrint (const FcPattern *p);
void
FcFontSetPrint (FcFontSet *s);
FcFontSetPrint (const FcFontSet *s);
/* fcdefault.c */
void
@ -602,6 +605,9 @@ FcPatternAddCharSet (FcPattern *p, const char *object, const FcCharSet *c);
FcBool
FcPatternAddBool (FcPattern *p, const char *object, FcBool b);
FcBool
FcPatternAddPattern (FcPattern *p, const char *object, const FcPattern *pp);
FcResult
FcPatternGetInteger (FcPattern *p, const char *object, int n, int *i);
@ -620,6 +626,9 @@ FcPatternGetCharSet (FcPattern *p, const char *object, int n, FcCharSet **c);
FcResult
FcPatternGetBool (FcPattern *p, const char *object, int n, FcBool *b);
FcResult
FcPatternGetPattern (FcPattern *p, const char *object, int n, FcPattern **pp);
FcPattern *
FcPatternVaBuild (FcPattern *orig, va_list va);

View File

@ -127,6 +127,11 @@
-->
<include ignore_missing="yes">~/.fonts.conf</include>
<!--
Load local system customization file
-->
<include ignore_missing="yes">local.conf</include>
<!--
Alias well known font names to available TrueType fonts
-->
@ -197,11 +202,11 @@
<match target="font">
<!-- check to see if the font is roman -->
<test qual="first" name="slant">
<test name="slant">
<const>roman</const>
</test>
<!-- check to see if the pattern requested non-roman -->
<test qual="not_first" name="slant" compare="not_eq">
<test target="pattern" name="slant" compare="not_eq">
<const>roman</const>
</test>
<!-- multiply the matrix to slant the font -->

View File

@ -112,11 +112,15 @@
if 'qual' is 'first', then the match succeeds only if the first value matches.
if 'qual' is 'not_first', then the match succeeds only if any value other than
the first matches.
For match elements with target=font, if test 'target' is 'pattern',
then the test is applied to the pattern used in matching rather than
to the resulting font.
-->
<!ELEMENT test (%expr;)*>
<!ATTLIST test
qual (any|all|first|not_first) "any"
name CDATA #REQUIRED
target (pattern|font|default) "default"
compare (eq|not_eq|less|less_eq|more|more_eq) "eq">
<!--

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/src/fccfg.c,v 1.15 2002/06/21 06:14:45 keithp Exp $
* $XFree86: xc/lib/fontconfig/src/fccfg.c,v 1.18 2002/07/31 01:36:37 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
@ -438,16 +438,20 @@ FcConfigAddEdit (FcConfig *config,
subst->next = 0;
subst->test = test;
subst->edit = edit;
num = 0;
for (t = test; t; t = t->next)
{
if (t->kind == FcMatchDefault)
t->kind = kind;
num++;
}
if (config->maxObjects < num)
config->maxObjects = num;
if (FcDebug () & FC_DBG_EDIT)
{
printf ("Add Subst ");
FcSubstPrint (subst);
}
num = 0;
for (t = test; t; t = t->next)
num++;
if (config->maxObjects < num)
config->maxObjects = num;
return FcTrue;
}
@ -483,7 +487,6 @@ FcConfigCompareValue (FcValue m,
v = FcConfigPromote (v, m);
if (m.type == v.type)
{
ret = FcFalse;
switch (m.type) {
case FcTypeInteger:
break; /* FcConfigPromote prevents this from happening */
@ -588,6 +591,19 @@ FcConfigCompareValue (FcValue m,
default:
break;
}
break;
case FcTypePattern:
switch (op) {
case FcOpEqual:
ret = FcPatternEqual (m.u.p, v.u.p);
break;
case FcOpNotEqual:
ret = !FcPatternEqual (m.u.p, v.u.p);
break;
default:
break;
}
break;
}
}
else
@ -658,15 +674,22 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
v.type = FcTypeVoid;
FcValueDestroy (vl);
break;
case FcOpOr:
case FcOpAnd:
case FcOpEqual:
case FcOpContains:
case FcOpNotEqual:
case FcOpLess:
case FcOpLessEqual:
case FcOpMore:
case FcOpMoreEqual:
vl = FcConfigEvaluate (p, e->u.tree.left);
vr = FcConfigEvaluate (p, e->u.tree.right);
v.type = FcTypeBool;
v.u.b = FcConfigCompareValue (vl, e->op, vr);
FcValueDestroy (vl);
FcValueDestroy (vr);
break;
case FcOpOr:
case FcOpAnd:
case FcOpEqual:
case FcOpPlus:
case FcOpMinus:
case FcOpTimes:
@ -696,31 +719,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
v.type = FcTypeDouble;
v.u.d = vl.u.d / vr.u.d;
break;
case FcOpEqual:
case FcOpContains:
v.type = FcTypeBool;
v.u.b = vl.u.d == vr.u.d;
break;
case FcOpNotEqual:
v.type = FcTypeBool;
v.u.b = vl.u.d != vr.u.d;
break;
case FcOpLess:
v.type = FcTypeBool;
v.u.b = vl.u.d < vr.u.d;
break;
case FcOpLessEqual:
v.type = FcTypeBool;
v.u.b = vl.u.d <= vr.u.d;
break;
case FcOpMore:
v.type = FcTypeBool;
v.u.b = vl.u.d > vr.u.d;
break;
case FcOpMoreEqual:
v.type = FcTypeBool;
v.u.b = vl.u.d >= vr.u.d;
break;
default:
v.type = FcTypeVoid;
break;
@ -742,15 +740,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
v.type = FcTypeBool;
v.u.b = vl.u.b && vr.u.b;
break;
case FcOpEqual:
case FcOpContains:
v.type = FcTypeBool;
v.u.b = vl.u.b == vr.u.b;
break;
case FcOpNotEqual:
v.type = FcTypeBool;
v.u.b = vl.u.b != vr.u.b;
break;
default:
v.type = FcTypeVoid;
break;
@ -758,15 +747,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
break;
case FcTypeString:
switch (e->op) {
case FcOpEqual:
case FcOpContains:
v.type = FcTypeBool;
v.u.b = FcStrCmpIgnoreCase (vl.u.s, vr.u.s) == 0;
break;
case FcOpNotEqual:
v.type = FcTypeBool;
v.u.b = FcStrCmpIgnoreCase (vl.u.s, vr.u.s) != 0;
break;
case FcOpPlus:
v.type = FcTypeString;
v.u.s = FcStrPlus (vl.u.s, vr.u.s);
@ -780,15 +760,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
break;
case FcTypeMatrix:
switch (e->op) {
case FcOpEqual:
case FcOpContains:
v.type = FcTypeBool;
v.u.b = FcMatrixEqual (vl.u.m, vr.u.m);
break;
case FcOpNotEqual:
v.type = FcTypeBool;
v.u.b = FcMatrixEqual (vl.u.m, vr.u.m);
break;
case FcOpTimes:
v.type = FcTypeMatrix;
m = malloc (sizeof (FcMatrix));
@ -808,26 +779,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e)
break;
}
break;
case FcTypeCharSet:
switch (e->op) {
case FcOpContains:
/* vl contains vr if vr is a subset of vl */
v.type = FcTypeBool;
v.u.b = FcCharSetIsSubset (vr.u.c, vl.u.c);
break;
case FcOpEqual:
v.type = FcTypeBool;
v.u.b = FcCharSetEqual (vl.u.c, vr.u.c);
break;
case FcOpNotEqual:
v.type = FcTypeBool;
v.u.b = !FcCharSetEqual (vl.u.c, vr.u.c);
break;
default:
v.type = FcTypeVoid;
break;
}
break;
default:
v.type = FcTypeVoid;
break;
@ -1068,6 +1019,8 @@ FcConfigSubstitute (FcConfig *config,
FcTest *t;
FcEdit *e;
FcValueList *l;
FcPattern *p_pat = 0;
FcPattern *m;
if (!config)
{
@ -1089,7 +1042,10 @@ FcConfigSubstitute (FcConfig *config,
if (kind == FcMatchPattern)
s = config->substPattern;
else
{
s = config->substFont;
(void) FcPatternGetPattern (p, FC_PATTERN, 0, &p_pat);
}
for (; s; s = s->next)
{
/*
@ -1103,7 +1059,15 @@ FcConfigSubstitute (FcConfig *config,
printf ("FcConfigSubstitute test ");
FcTestPrint (t);
}
st[i].elt = FcPatternFindElt (p, t->field);
st[i].elt = 0;
if (kind == FcMatchFont && t->kind == FcMatchPattern)
m = p_pat;
else
m = p;
if (m)
st[i].elt = FcPatternFindElt (m, t->field);
else
st[i].elt = 0;
/*
* If there's no such field in the font,
* then FcQualAll matches while FcQualAny does not
@ -1122,7 +1086,7 @@ FcConfigSubstitute (FcConfig *config,
* Check to see if there is a match, mark the location
* to apply match-relative edits
*/
st[i].value = FcConfigMatchValueList (p, t, st[i].elt->values);
st[i].value = FcConfigMatchValueList (m, t, st[i].elt->values);
if (!st[i].value)
break;
if (t->qual == FcQualFirst && st[i].value != st[i].elt->values)
@ -1148,11 +1112,17 @@ FcConfigSubstitute (FcConfig *config,
*/
l = FcConfigValues (p, e->expr, e->binding);
/*
* Locate any test associated with this field
* Locate any test associated with this field, skipping
* tests associated with the pattern when substituting in
* the font
*/
for (t = s->test, i = 0; t; t = t->next, i++)
if (!FcStrCmpIgnoreCase ((FcChar8 *) t->field, (FcChar8 *) e->field))
{
if ((t->kind == FcMatchFont || kind == FcMatchPattern) &&
!FcStrCmpIgnoreCase ((FcChar8 *) t->field,
(FcChar8 *) e->field))
break;
}
switch (e->op) {
case FcOpAssign:
/*

View File

@ -27,7 +27,7 @@
#include "fcint.h"
void
FcValuePrint (FcValue v)
FcValuePrint (const FcValue v)
{
switch (v.type) {
case FcTypeVoid:
@ -54,18 +54,23 @@ FcValuePrint (FcValue v)
case FcTypeFTFace:
printf (" face");
break;
case FcTypePattern:
printf (" pattern {");
FcPatternPrint (v.u.p);
printf (" } ");
break;
}
}
void
FcValueListPrint (FcValueList *l)
FcValueListPrint (const FcValueList *l)
{
for (; l; l = l->next)
FcValuePrint (l->value);
}
void
FcPatternPrint (FcPattern *p)
FcPatternPrint (const FcPattern *p)
{
int i;
FcPatternElt *e;
@ -126,7 +131,7 @@ FcOpPrint (FcOp op)
}
void
FcExprPrint (FcExpr *expr)
FcExprPrint (const FcExpr *expr)
{
switch (expr->op) {
case FcOpInteger: printf ("%d", expr->u.ival); break;
@ -206,8 +211,16 @@ FcExprPrint (FcExpr *expr)
}
void
FcTestPrint (FcTest *test)
FcTestPrint (const FcTest *test)
{
switch (test->kind) {
case FcMatchPattern:
printf ("pattern ");
break;
case FcMatchFont:
printf ("font ");
break;
}
switch (test->qual) {
case FcQualAny:
printf ("any ");
@ -230,7 +243,7 @@ FcTestPrint (FcTest *test)
}
void
FcEditPrint (FcEdit *edit)
FcEditPrint (const FcEdit *edit)
{
printf ("Edit %s ", edit->field);
FcOpPrint (edit->op);
@ -239,7 +252,7 @@ FcEditPrint (FcEdit *edit)
}
void
FcSubstPrint (FcSubst *subst)
FcSubstPrint (const FcSubst *subst)
{
FcEdit *e;
FcTest *t;
@ -261,7 +274,7 @@ FcSubstPrint (FcSubst *subst)
}
void
FcFontSetPrint (FcFontSet *s)
FcFontSetPrint (const FcFontSet *s)
{
int i;

View File

@ -138,8 +138,11 @@ typedef enum _FcQual {
FcQualAny, FcQualAll, FcQualFirst, FcQualNotFirst
} FcQual;
#define FcMatchDefault ((FcMatchKind) -1)
typedef struct _FcTest {
struct _FcTest *next;
FcMatchKind kind;
FcQual qual;
const char *field;
FcOp op;
@ -429,22 +432,22 @@ FcFreeTypeGetPrivateMap (FT_Encoding encoding);
/* fcdbg.c */
void
FcValueListPrint (FcValueList *l);
FcValueListPrint (const FcValueList *l);
void
FcOpPrint (FcOp op);
void
FcTestPrint (FcTest *test);
FcTestPrint (const FcTest *test);
void
FcExprPrint (FcExpr *expr);
FcExprPrint (const FcExpr *expr);
void
FcEditPrint (FcEdit *edit);
FcEditPrint (const FcEdit *edit);
void
FcSubstPrint (FcSubst *subst);
FcSubstPrint (const FcSubst *subst);
int
FcDebug (void);
@ -477,7 +480,11 @@ char *
FcConfigSaveField (const char *field);
FcTest *
FcTestCreate (FcQual qual, const FcChar8 *field, FcOp compare, FcExpr *expr);
FcTestCreate (FcMatchKind kind,
FcQual qual,
const FcChar8 *field,
FcOp compare,
FcExpr *expr);
void
FcTestDestroy (FcTest *test);

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/src/fclist.c,v 1.5 2002/06/03 08:31:15 keithp Exp $
* $XFree86: xc/lib/fontconfig/src/fclist.c,v 1.7 2002/06/19 20:08:22 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
@ -247,6 +247,8 @@ FcListValueHash (FcValue v)
return FcCharSetCount (v.u.c);
case FcTypeFTFace:
return (FcChar32) v.u.f;
case FcTypePattern:
return (FcChar32) v.u.p->num;
}
return 0;
}

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/src/fcmatch.c,v 1.15 2002/06/29 20:31:02 keithp Exp $
* $XFree86: xc/lib/fontconfig/src/fcmatch.c,v 1.16 2002/07/06 23:47:44 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
@ -384,26 +384,12 @@ FcFontRenderPrepare (FcConfig *config,
pe = FcPatternFindElt (pat, fe->object);
if (pe)
{
int j;
double score[NUM_MATCH_VALUES];
for (j = 0; j < NUM_MATCH_VALUES; j++)
score[j] = 0;
if (!FcCompareValueList (pe->object, pe->values,
fe->values, &v, score, &result))
fe->values, &v, 0, &result))
{
FcPatternDestroy (new);
return 0;
}
for (j = 0; j < NUM_MATCH_VALUES; j++)
if (score[j] >= 100.0)
{
FcValueList *pv;
for (pv = pe->values; pv; pv = pv->next)
FcPatternAdd (new, fe->object, pv->value, FcTrue);
break;
}
}
else
v = fe->values->value;
@ -416,6 +402,7 @@ FcFontRenderPrepare (FcConfig *config,
if (!fe)
FcPatternAdd (new, pe->object, pe->values->value, FcTrue);
}
FcPatternAddPattern (new, FC_PATTERN, pat);
FcConfigSubstitute (config, new, FcMatchFont);
return new;
}

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/src/fcname.c,v 1.9 2002/06/26 22:14:08 keithp Exp $
* $XFree86: xc/lib/fontconfig/src/fcname.c,v 1.10 2002/06/29 20:31:02 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
@ -472,6 +472,8 @@ FcNameUnparseValue (FcStrBuf *buf,
return FcNameUnparseCharSet (buf, v.u.c);
case FcTypeFTFace:
return FcTrue;
case FcTypePattern:
return FcTrue;
}
return FcFalse;
}

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/src/fcpat.c,v 1.11 2002/07/06 23:47:44 keithp Exp $
* $XFree86: xc/lib/fontconfig/src/fcpat.c,v 1.12 2002/08/07 01:45:59 keithp Exp $
*
* Copyright © 2000 Keith Packard, member of The XFree86 Project, Inc.
*
@ -55,6 +55,9 @@ FcValueDestroy (FcValue v)
case FcTypeCharSet:
FcCharSetDestroy ((FcCharSet *) v.u.c);
break;
case FcTypePattern:
FcPatternDestroy ((FcPattern *) v.u.p);
break;
default:
break;
}
@ -79,6 +82,9 @@ FcValueSave (FcValue v)
if (!v.u.c)
v.type = FcTypeVoid;
break;
case FcTypePattern:
FcPatternReference ((FcPattern *) v.u.p);
break;
default:
break;
}
@ -101,6 +107,9 @@ FcValueListDestroy (FcValueList *l)
case FcTypeCharSet:
FcCharSetDestroy ((FcCharSet *) l->value.u.c);
break;
case FcTypePattern:
FcPatternDestroy ((FcPattern *) l->value.u.p);
break;
default:
break;
}
@ -145,6 +154,8 @@ FcValueEqual (FcValue va, FcValue vb)
return FcCharSetEqual (va.u.c, vb.u.c);
case FcTypeFTFace:
return va.u.f == vb.u.f;
case FcTypePattern:
return FcPatternEqual (va.u.p, vb.u.p);
}
return FcFalse;
}
@ -195,6 +206,8 @@ FcValueHash (FcValue v)
case FcTypeFTFace:
return FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->family_name) ^
FcStringHash ((const FcChar8 *) ((FT_Face) v.u.f)->style_name);
case FcTypePattern:
return (FcChar32) v.u.p->num;
}
return FcFalse;
}
@ -446,6 +459,9 @@ bail2:
case FcTypeCharSet:
FcCharSetDestroy ((FcCharSet *) value.u.c);
break;
case FcTypePattern:
FcPatternDestroy ((FcPattern *) value.u.p);
break;
default:
break;
}
@ -563,6 +579,16 @@ FcPatternAddFTFace (FcPattern *p, const char *object, const FT_Face f)
return FcPatternAdd (p, object, v, FcTrue);
}
FcBool
FcPatternAddPattern (FcPattern *p, const char *object, const FcPattern *pp)
{
FcValue v;
v.type = FcTypePattern;
v.u.p = pp;
return FcPatternAdd (p, object, v, FcTrue);
}
FcResult
FcPatternGet (FcPattern *p, const char *object, int id, FcValue *v)
{
@ -704,6 +730,21 @@ FcPatternGetFTFace (FcPattern *p, const char *object, int id, FT_Face *f)
return FcResultMatch;
}
FcResult
FcPatternGetPattern (FcPattern *p, const char *object, int id, FcPattern **pp)
{
FcValue v;
FcResult r;
r = FcPatternGet (p, object, id, &v);
if (r != FcResultMatch)
return r;
if (v.type != FcTypePattern)
return FcResultTypeMismatch;
*pp = (FcPattern *) v.u.p;
return FcResultMatch;
}
FcPattern *
FcPatternDuplicate (FcPattern *orig)
{

View File

@ -1,5 +1,5 @@
/*
* $XFree86: xc/lib/fontconfig/src/fcxml.c,v 1.16 2002/07/12 19:19:16 keithp Exp $
* $XFree86: xc/lib/fontconfig/src/fcxml.c,v 1.17 2002/07/31 01:36:37 keithp Exp $
*
* Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
*
@ -49,13 +49,18 @@
#endif
FcTest *
FcTestCreate (FcQual qual, const FcChar8 *field, FcOp compare, FcExpr *expr)
FcTestCreate (FcMatchKind kind,
FcQual qual,
const FcChar8 *field,
FcOp compare,
FcExpr *expr)
{
FcTest *test = (FcTest *) malloc (sizeof (FcTest));
if (test)
{
test->next = 0;
test->kind = kind;
test->qual = qual;
test->field = (char *) FcStrCopy (field);
test->op = compare;
@ -1204,7 +1209,8 @@ FcParseAlias (FcConfigParse *parse)
}
if (edit)
{
test = FcTestCreate (FcQualAny,
test = FcTestCreate (FcMatchPattern,
FcQualAny,
(FcChar8 *) FC_FAMILY,
FcOpEqual,
family);
@ -1358,6 +1364,8 @@ FcConfigLexCompare (const FcChar8 *compare)
static void
FcParseTest (FcConfigParse *parse)
{
const FcChar8 *kind_string;
FcMatchKind kind;
const FcChar8 *qual_string;
FcQual qual;
const FcChar8 *name;
@ -1366,6 +1374,23 @@ FcParseTest (FcConfigParse *parse)
FcExpr *expr;
FcTest *test;
kind_string = FcConfigGetAttribute (parse, "target");
if (!kind_string)
kind = FcMatchDefault;
else
{
if (!strcmp ((char *) kind_string, "pattern"))
kind = FcMatchPattern;
else if (!strcmp ((char *) kind_string, "font"))
kind = FcMatchFont;
else if (!strcmp ((char *) kind_string, "default"))
kind = FcMatchDefault;
else
{
FcConfigMessage (parse, FcSevereWarning, "invalid test target \"%s\"", kind_string);
return;
}
}
qual_string = FcConfigGetAttribute (parse, "qual");
if (!qual_string)
qual = FcQualAny;
@ -1409,7 +1434,7 @@ FcParseTest (FcConfigParse *parse)
FcConfigMessage (parse, FcSevereWarning, "missing test expression");
return;
}
test = FcTestCreate (qual, name, compare, expr);
test = FcTestCreate (kind, qual, name, compare, expr);
if (!test)
{
FcConfigMessage (parse, FcSevereError, "out of memory");

View File

@ -1,5 +1,5 @@
.\"
.\" $XFree86: fontconfig.man,v 1.2 2000/11/30 06:59:45 keithp Exp $
.\" $XFree86: xc/lib/fontconfig/src/fontconfig.man,v 1.2 2002/08/06 19:54:10 keithp Exp $
.\"
.\" Copyright © 2002 Keith Packard, member of The XFree86 Project, Inc.
.\"
@ -166,6 +166,22 @@ first is to modify how fonts are selected; aliasing families and adding
suitable defaults. The second is to modify how the selected fonts are
rasterized. Those must apply to the selected font, not the original pattern
as false matches will often occur.
.SS FONT LIST MATCHING
.P
While many applications want to locate a single font best matching their
search criteria, other applications need to build a set of fonts which can
be used to present any Unicode data. Fontconfig provides an API to generate
a list sorted by the nearness of each font to the pattern. Every font in
the system is considered, the best matching fonts are placed first. The
application then can select whether the remaining fonts are unconditionally
included in the list, or whether they are included only if they cover
portions of Unicode not covered by any of the preceeding fonts.
.P
The list resulting from this match is represented by references to the
original font patterns and so consumes very little memory. Using a list
entry involves creating a pattern which combines the information from the
font with the information from the original pattern and executing the font
substitutions.
.SS FONT NAMES
Fontconfig provides a textual representation for patterns that the library
can both accept and generate. The representation is in three parts, first a
@ -200,8 +216,8 @@ by the ISO 3166 country code. The hyphen and country code may be elided.
.P
Fontconfig has orthographies for several languages built into the library.
No provision has been made for adding new ones aside from rebuilding the
library. It currently supports 104 of the 139 languages named in ISO 639-1,
117 of the languages with two-letter codes from ISO 639-2 and another 24
library. It currently supports 122 of the 139 languages named in ISO 639-1,
141 of the languages with two-letter codes from ISO 639-2 and another 30
languages with only three-letter codes.
.SH DATATYPES
@ -295,6 +311,15 @@ results of listing fonts in this format. 'nfont' holds the number of
patterns in the 'fonts' array; 'sfont' is used to indicate the size of that
array.
.TP
.B FcStrSet
.B FcStrList
FcStrSet holds a list of strings that can be appended to and enumerated.
Its unique characteristic is that the enumeration works even while strings
are appended during enumeration. FcStrList is used during enumeration to
safely and correctly walk the list of strings even while that list is edited
in the middle of enumeration.
.TP
.B FcObjectSet
.sp
@ -305,9 +330,34 @@ array.
const char **objects;
} FcObjectSet;
.fi
.sp
holds a set of names and is used to specify which fields from fonts are
placed in the the list of returned patterns when listing fonts.
.TP
.B FcObjectType
.sp
typedef struct _FcObjectType {
const char *object;
FcType type;
} FcObjectType;
.fi
marks the type of a pattern element generated when parsing font names.
Applications can add new object types so that font names may contain the new
elements.
.TP
.B FcConstant
.sp
typedef struct _FcConstant {
const FcChar8 *name;
const char *object;
int value;
} FcConstant;
.fi
Provides for symbolic constants for new pattern elements. When 'name' is
seen in a font name, an 'object' element is created with value 'value'.
.TP
.B FcBlanks
holds a list of Unicode chars which are expected to be blank; unexpectedly
@ -357,6 +407,11 @@ Used as a return type for functions manipulating FcPattern objects.
.br
.DT
.TP
.B FcAtomic
Used for locking access to config files. Provides a safe way to update
configuration files.
.SH FUNCTIONS
.SS FcMatrix
@ -450,6 +505,18 @@ Returns the number of chars that are in both 'a' and 'b'.
FcChar32 FcCharSetSubtractCount (const FcCharSet *a, const FcCharSet *b)
Returns the number of chars that are in 'a' but not in 'b'.
.TP
FcBool FcCharSetIsSubset (const FcCharSet *a, const FcCharSet *b)
Returns whether 'a' is a subset of 'b'.
.TP FcChar32 FcCharSetFirstPage (const FcCharSet *a, FcChar32 [FC_CHARSET_MAP_SIZE], FcChar32 *next)
Builds an array of bits marking the first page of Unicode coverage of 'a'.
Returns the base of the array. 'next' contains the next page in the font.
.TP FcChar32 FcCharSetNextPage (const FcCharSet *a, FcChar32 [FC_CHARSET_MAP_SIZE], FcChar32 *next)
Builds an array of bits marking the Unicode coverage of 'a' for page '*next'.
Returns the base of the array. 'next' contains the next page in the font.
.SS FcValue
FcValue is a structure containing a type tag and a union of all possible
datatypes. The tag is an enum of type
@ -479,6 +546,20 @@ Creates a pattern with no properties; used to build patterns from scratch.
void FcPatternDestroy (FcPattern *p)
Destroys a pattern, in the process destroying all related values.
.TP
FcBool FcPatternEqual (const FcPattern *pa, const FcPattern *pb);
Returns whether 'pa' and 'pb' are exactly alike.
.TP
FcBool FcPatternEqualSubset (const FcPattern *pa, const FcPattern *pb, const FcObjectSet *os)
Returns whether 'pa' and 'pb' have exactly the same values for all of the
objects in 'os'.
.TP
FcChar32 FcPatternHash (const FcPattern *p)
Returns a 32-bit number which is the same for any two patterns which are
exactly alike.
.TP
FcBool FcPatternAdd (FcPattern *p, const char *object, FcValue value, FcBool append)
Adds a single value to the list of values associated with the property named
@ -565,7 +646,7 @@ Deletes all values associated with the property `object', returning
whether the property existed or not.
.TP
void FcPatternPrint (FcPattern *p)
void FcPatternPrint (const FcPattern *p)
Prints an easily readable version of the pattern to stdout. There is
no provision for reparsing data in this format, it's just for diagnostics
and debugging.
@ -635,6 +716,41 @@ FcObjectSet *FcObjectSetBuild (const char *first, ...)
FcObjectSet *FcObjectSetVaBuild (const char *first, va_list va)
These build an object set from a null-terminated list of property names.
.SS FcObjectType
Provides for applcation-specified font name object types so that new
pattern elements can be generated from font names.
.TP FcBool FcNameRegisterObjectTypes (const FcObjectType *types, int ntype)
Register 'ntype' new object types.
.TP
FcBool FcNameUnregisterObjectTypes (const FcObjectType *types, int ntype)
Unregister 'ntype' object types.
.TP
const FcObjectType *FcNameGetObjectType (const char *object)
Return the object type for the pattern element named 'object'.
.SS FcConstant
Provides for application-specified symbolic constants for font names.
.TP
FcBool FcNameRegisterConstants (const FcConstant *consts, int nconsts)
Register 'nconsts' new symbolic constants.
.TP
FcBool FcNameUnregisterConstants (const FcConstant *consts, int nconsts)
Unregister 'nconsts' symbolic constants.
.TP
const FcConstant *FcNameGetConstant (FcChar8 *string)
Return the FcConstant structure related to symbolic constant 'string'.
.TP
FcBool FcNameConstant (FcChar8 *string, int *result);
Returns whether a symbolic constant with name 'string' is registered,
placing the value of the constant in 'result' if present.
.SS FcBlanks
An FcBlanks object holds a list of Unicode chars which are expected to
be blank when drawn. When scanning new fonts, any glyphs which are
@ -684,6 +800,11 @@ FcConfigBuildFonts if necessary, returning FcFalse if that call fails.
FcConfig *FcConfigGetCurrent (void)
Returns the current default configuration.
.TP
FcBool FcConfigUptoDate (FcConfig *config)
Checks all of the files related to 'config' and returns whether the
in-memory version is in sync with the disk version.
.TP
FcBool FcConfigBuildFonts (FcConfig *config)
Builds the set of available fonts for the given configuration. Note that
@ -691,11 +812,18 @@ any changes to the configuration after this call have indeterminate effects.
Returns FcFalse if this operation runs out of memory.
.TP
char **FcConfigGetDirs (FcConfig *config)
Returns the list of font directories specified in 'config'.
FcStrList *FcConfigGetConfigDirs (FcConfig *config)
Returns the list of font directories specified in the configuration files
for 'config'. Does not include any subdirectories.
.TP
char **FcConfigGetConfigFiles (FcConfig *config)
FcStrList *FcConfigGetFontDirs (FcConfig *config)
Returns the list of font directories in 'config'. This includes the
configured font directories along with any directories below those in the
filesystem.
.TP
FcStrList *FcConfigGetConfigFiles (FcConfig *config)
Returns the list of known configuration files used to generate 'config'.
Note that this will not include any configuration done with FcConfigParse.
@ -713,6 +841,16 @@ FcBlanks *FcConfigGetBlanks (FcConfig *config)
Returns the FcBlanks object associated with the given configuration, if no
blanks were present in the configuration, this function will return 0.
.TP
int FcConfigGetRescanInverval (FcConfig *config)
Returns the interval between automatic checks of the configuration (in
seconds) specified in 'config'. The configuration is checked during
a call to FcFontList when this interval has passed since the last check.
.TP
FcBool FcConfigSetRescanInverval (FcConfig *config, int rescanInterval)
Sets the rescan interval; returns FcFalse if an error occurred.
.TP
FcBool FcConfigAppFontAddFile (FcConfig *config, const char *file)
Adds an application-specific font to the configuration.
@ -736,7 +874,30 @@ if 'kind' is FcMatchFont, those tagged as font operations are applied.
FcPattern *FcFontMatch (FcConfig *config, FcPattern *p, FcResult *result)
Returns the font in 'config' most close matching 'p'. This function
should be called only after FcConfigSubstitute and FcDefaultSubstitute have
been called; otherwise the results will be less useful.
been called for 'p'; otherwise the results will not be correct.
.TP
FcFontSet *FcFontSort (FcConfig *config, FcPattern *p, FcBool trim, FcCharSet **csp, FcResult *result) Returns the list of fonts sorted by
closeness to 'p'. If 'trim' is FcTrue, elements in the list which don't
include Unicode coverage not provided by earlier elements in the list are
elided. The union of Unicode coverage of all of the fonts is returned in
'csp', if 'csp' is not NULL. This function should be called only after
FcConfigSubstitute and FcDefaultSubstitute have been called for 'p';
otherwise the results will not be correct.
.P
The returned FcFontSet references FcPattern structures which may be shared
by the return value from multiple FcFontSort calls, applications must not
modify these patterns. Instead, they should be passed, along with 'p' to
FcFontRenderPrepare which combines them into a complete pattern.
.P
The FcFontSet returned by FcFontSort is destroyed by caling FcFontSetDestroy.
.TP
FcPattern *FcFontRenderPrepare (FcConfig *config, FcPattern *pat, FcPattern *font)
Creates a new pattern consisting of elements of 'font' not appearing in
'pat', elements of 'pat' not appearing in 'font' and the best matching value
from 'pat' for elements appearing in both. The result is passed to
FcConfigSubstitute with 'kind' FcMatchFont and then returned.
.TP
FcFontSet *FcFontList (FcConfig *config, FcPattern *p, FcObjectSet *os)
@ -761,18 +922,80 @@ FC_CONFIG_DIR environment variable.
These functions provide some control over how the library is initialized.
.TP
FcBool FcInitConfig (void)
Initializes the default configuration using the default configuration file
FcConfig *FcInitLoadConfig (void)
Loads the default configuration file and returns the resulting configuration.
Does not load any font information.
.TP
FcBool FcInitFonts (void)
Initializes the set of fonts available in the default configuration
FcConfig *FcInitLoadConfigAndFonts (void)
Loads the default configuration file and builds information about the
available fonts. Returns the resulting configuration.
.TP
FcBool FcInit (void)
Calls FcInitConfig and FcInitFonts to completely initialize the default
Loads the default configuration file and the fonts referenced therein and
sets the default configuration to that result. Returns whether this
process succeeded or not. If the default configuration has already
been loaded, this routine does nothing and returns FcTrue.
.TP
int FcGetVersion (void)
Returns the version number of the library.
.TP
FcBool FcInitReinitialize (void)
Forces the default configuration file to be reloaded and resets the default
configuration.
.TP
FcBool FcInitBringUptoDate (void)
Checks the rescan interval in the default configuration, checking the
configuration if the interval has passed and reloading the configuration if
when any changes are detected.
.SS FcAtomic
These functions provide a safe way to update config files, allowing ongoing
reading of the old config file while locked for writing and ensuring that a
consistent and complete version of the config file is always available.
.TP
FcAtomic * FcAtomicCreate (const FcChar8 *file)
Creates a data structure containing data needed to control access to 'file'.
Writing is done to a separate file. Once that file is complete, the original
configuration file is atomically replaced so that reading process always see
a consistent and complete file without the need to lock for reading.
.TP
FcBool FcAtomicLock (FcAtomic *atomic)
Attempts to lock the file referenced by 'atomic'. Returns FcFalse if the
file is locked by another process, else returns FcTrue and leaves the file
locked.
.TP
FcChar8 *FcAtomicNewFile (FcAtomic *atomic)
Returns the filename for writing a new version of the file refernced by
'atomic'.
.TP
FcChar8 *FcAtomicOrigFile (FcAtomic *atomic)
Returns the file refernced by 'atomic'.
.TP
FcBool FcAtomicReplaceOrig (FcAtomic *atomic)
Replaces the original file referenced by 'atomic' with the new file.
.TP
void FcAtomicDeleteNew (FcAtomic *atomic)
Deletes the new file.
.TP
void FcAtomicUnlock (FcAtomic *atomic)
Unlocks the file.
.TP
void FcAtomicDestroy (FcAtomic *atomic)
Destroys 'atomic'.
.SS FreeType specific functions
.nf
.B #include <fontconfig/fcfreetype.h>
@ -814,28 +1037,78 @@ FcConfigFilename. This doesn't load a complete configuration as any
include files referenced from 'file' will not be loaded.
.TP
FcBool FcConfigParse (FcConfig *config, xmlDocPtr doc)
Walks the given configuration and constructs the internal representation in
'config'. Any include files referenced from within 'doc' will be loaded
with FcConfigLoad and also parsed.
FcBool FcConfigParseAndLoad (FcConfig *config, const FcChar8 *file, FcBool complain)
Walks the configuration in 'file' and constructs the internal representation in
'config'. Any include files referenced from within 'file' will be loaded
with FcConfigLoad and also parsed. If 'complain' is FcFalse, no warning
will be displayed if 'file' does not exist.
.SS File and Directory routines
.TP
FcBool FcFileScan (FcFontSet *set, FcFileCache *cache, FcBlanks *blanks, const char *file, FcBool force)
FcBool FcFileScan (FcFontSet *set, FcStrSet *dirs, FcFileCache *cache, FcBlanks *blanks, const char *file, FcBool force)
Scans a single file and adds all fonts found to 'set'. If 'force' is FcTrue,
then the file is scanned even if associated information is found in 'cache'.
If 'file' is a directory, it is added to 'dirs'.
.TP
FcBool FcDirScan (FcFontSet *set, FcFileCache *cache, FcBlanks *blanks, const char *dir, FcBool force)
FcBool FcDirScan (FcFontSet *set, FcStrSet *dirs, FcFileCache *cache, FcBlanks *blanks, const char *dir, FcBool force)
Scans an entire directory and adds all fonts found to 'set'. If 'force' is
FcTrue, then the directory and all files within it are scanned even if
information is present in the per-directory cache file or 'cache'.
information is present in the per-directory cache file or 'cache'. Any
subdirectories found are added to 'dirs'.
.TP
FcBool FcDirSave (FcFontSet *set, const char *dir)
FcBool FcDirSave (FcFontSet *set, FcStrSet *dirs, const char *dir)
Creates the per-directory cache file for 'dir' and populates it with the
fonts in 'set'.
fonts in 'set' and subdirectories in 'dirs'.
.TP
FcBool FcDirCacheValid (const FcChar8 *cache_file)
Returns FcTrue if 'cache_file' is no older than the directory containing it,
else FcFalse.
.SS FcStrSet and FcStrList
A data structure for enumerating strings, used to list directories while
scanning the configuration as directories are added while scanning.
.TP
FcStrSet *FcStrSetCreate (void)
Create an empty set.
.TP
FcBool FcStrSetMember (FcStrSet *set, const FcChar8 *s)
Returns whether 's' is a member of 'set'.
.TP
FcBool FcStrSetAdd (FcStrSet *set, const FcChar8 *s)
Adds a copy of 's' to 'set'.
.TP
FcBool FcStrSetAddFilename (FcStrSet *set, const FcChar8 *s)
Adds a copy 's' to 'set', The copy is created with FcStrCopyFilename
so that leading '~' values are replaced with the value of the HOME
environment variable.
.TP
FcBool FcStrSetDel (FcStrSet *set, const FcChar8 *s)
Removes 's' from 'set', returning FcTrue if 's' was a member else FcFalse.
.TP
void FcStrSetDestroy (FcStrSet *set)
Destroys 'set'.
.TP
FcStrList *FcStrListCreate (FcStrSet *set)
Creates an enumerator to list the strings in 'set'.
.TP
FcChar8 *FcStrListNext (FcStrList *list)
Returns the next string in 'set'.
.TP
void FcStrListDone (FcStrList *list)
Destroys the enumerator 'list'.
.SS String utilities
@ -871,16 +1144,29 @@ bytes needed to hold the largest unicode char counted. The return value
indicates whether 'string' is a well-formed UTF16 string.
.TP
char *FcStrCopy (const char *s)
FcChar8 *FcStrCopy (const FcChar8 *s)
Allocates memory, copies 's' and returns the resulting buffer. Yes, this is
'strdup', but that function isn't available on every platform.
.TP
FcChar8 *FcStrCopyFilename (const FcChar8 *s)
Just like FcStrCopy except that it converts any leading '~' characters in
's' to the value of the HOME environment variable.
.TP
int FcStrCmpIgnoreCase (const char *s1, const char *s2)
Returns the usual <0, 0, >0 result of comparing 's1' and 's2'. This test
is case-insensitive in the ASCII range and will operate properly with UTF8
encoded strings, although it does not check for well formed strings.
.TP
FcChar8 *FcStrDirname (const FcChar8 *file)
Returns the directory containing 'file'.
.TP
FcChar8 *FcStrBasename (const FcChar8 *file)
Returns the filename of 'file' stripped of any leading directory names.
.SH CONFIGURATION FILE FORMAT
Configuration files for fontconfig are stored in XML format; this
format makes external configuration tools easier to write and ensures that