Commit 5bbdffd2 authored by Behdad Esfahbod's avatar Behdad Esfahbod

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
parent 2a41738f
......@@ -219,6 +219,55 @@ FcCompareRange (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
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
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_FcComparePostScript(n) PRI1(n)
#define PRI_FcCompareRange(n) PRI1(n)
#define PRI_FcCompareSize(n) PRI1(n)
#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 (WEIGHT, FcTypeRange, FcCompareRange)
FC_OBJECT (WIDTH, FcTypeRange, FcCompareRange)
FC_OBJECT (SIZE, FcTypeRange, FcCompareRange)
FC_OBJECT (SIZE, FcTypeRange, FcCompareSize)
FC_OBJECT (ASPECT, FcTypeDouble, NULL)
FC_OBJECT (PIXEL_SIZE, FcTypeDouble, FcCompareNumber)
FC_OBJECT (SPACING, FcTypeInteger, FcCompareNumber)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment