Add separate match compare function for size
Has two distinctions from FcCompareRange(): 1. As best value, it returns query pattern size, even if it's out of font range, 2. Implements semi-closed interval, as that's what OS/2 v5 table defines
This commit is contained in:
parent
2a41738fd7
commit
5bbdffd2c2
|
@ -219,6 +219,55 @@ FcCompareRange (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
FcCompareSize (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
|
||||||
|
{
|
||||||
|
FcValue value1 = FcValueCanonicalize (v1);
|
||||||
|
FcValue value2 = FcValueCanonicalize (v2);
|
||||||
|
double b1, e1, b2, e2;
|
||||||
|
|
||||||
|
switch ((int) value1.type) {
|
||||||
|
case FcTypeInteger:
|
||||||
|
b1 = e1 = value1.u.i;
|
||||||
|
break;
|
||||||
|
case FcTypeDouble:
|
||||||
|
b1 = e1 = value1.u.d;
|
||||||
|
break;
|
||||||
|
case FcTypeRange:
|
||||||
|
abort();
|
||||||
|
b1 = value1.u.r->begin;
|
||||||
|
e1 = value1.u.r->end;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
switch ((int) value2.type) {
|
||||||
|
case FcTypeInteger:
|
||||||
|
b2 = e2 = value2.u.i;
|
||||||
|
break;
|
||||||
|
case FcTypeDouble:
|
||||||
|
b2 = e2 = value2.u.d;
|
||||||
|
break;
|
||||||
|
case FcTypeRange:
|
||||||
|
b2 = value2.u.r->begin;
|
||||||
|
e2 = value2.u.r->end;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bestValue->type = FcTypeDouble;
|
||||||
|
bestValue->u.d = (b1 + e1) * .5;
|
||||||
|
|
||||||
|
/* If the ranges overlap, it's a match, otherwise return closest distance. */
|
||||||
|
if (e1 < b2 || e2 < b1)
|
||||||
|
return FC_MIN (fabs (b2 - e1), fabs (b1 - e2));
|
||||||
|
if (b2 != e2 && b1 == e2) /* Semi-closed interval. */
|
||||||
|
return 1e-15;
|
||||||
|
else
|
||||||
|
return 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
static double
|
static double
|
||||||
FcCompareFilename (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
|
FcCompareFilename (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
|
||||||
{
|
{
|
||||||
|
@ -250,6 +299,7 @@ FcCompareFilename (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
|
||||||
#define PRI_FcCompareLang(n) PRI1(n)
|
#define PRI_FcCompareLang(n) PRI1(n)
|
||||||
#define PRI_FcComparePostScript(n) PRI1(n)
|
#define PRI_FcComparePostScript(n) PRI1(n)
|
||||||
#define PRI_FcCompareRange(n) PRI1(n)
|
#define PRI_FcCompareRange(n) PRI1(n)
|
||||||
|
#define PRI_FcCompareSize(n) PRI1(n)
|
||||||
|
|
||||||
#define FC_OBJECT(NAME, Type, Cmp) PRI_##Cmp(NAME)
|
#define FC_OBJECT(NAME, Type, Cmp) PRI_##Cmp(NAME)
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ FC_OBJECT (FULLNAMELANG, FcTypeString, NULL)
|
||||||
FC_OBJECT (SLANT, FcTypeInteger, FcCompareNumber)
|
FC_OBJECT (SLANT, FcTypeInteger, FcCompareNumber)
|
||||||
FC_OBJECT (WEIGHT, FcTypeRange, FcCompareRange)
|
FC_OBJECT (WEIGHT, FcTypeRange, FcCompareRange)
|
||||||
FC_OBJECT (WIDTH, FcTypeRange, FcCompareRange)
|
FC_OBJECT (WIDTH, FcTypeRange, FcCompareRange)
|
||||||
FC_OBJECT (SIZE, FcTypeRange, FcCompareRange)
|
FC_OBJECT (SIZE, FcTypeRange, FcCompareSize)
|
||||||
FC_OBJECT (ASPECT, FcTypeDouble, NULL)
|
FC_OBJECT (ASPECT, FcTypeDouble, NULL)
|
||||||
FC_OBJECT (PIXEL_SIZE, FcTypeDouble, FcCompareNumber)
|
FC_OBJECT (PIXEL_SIZE, FcTypeDouble, FcCompareNumber)
|
||||||
FC_OBJECT (SPACING, FcTypeInteger, FcCompareNumber)
|
FC_OBJECT (SPACING, FcTypeInteger, FcCompareNumber)
|
||||||
|
|
Loading…
Reference in New Issue