summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2017-09-15 01:51:46 -0400
committerBehdad Esfahbod <behdad@behdad.org>2017-09-20 13:13:35 -0700
commit5bbdffd2c2efcf684ae787bfad9d154b2fe05fb4 (patch)
tree2b016c69d6f36c9ebe2077385594ccc8b6e595a6 /src
parent2a41738fd7c88e2b6977673f91bdb8d1f7224cf1 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/fcmatch.c50
-rw-r--r--src/fcobjs.h2
2 files changed, 51 insertions, 1 deletions
diff --git a/src/fcmatch.c b/src/fcmatch.c
index 03a4e5f1..f2175394 100644
--- a/src/fcmatch.c
+++ b/src/fcmatch.c
@@ -220,6 +220,55 @@ FcCompareRange (const FcValue *v1, const FcValue *v2, FcValue *bestValue)
}
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)
{
const FcChar8 *s1 = FcValueString (v1), *s2 = FcValueString (v2);
@@ -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)
diff --git a/src/fcobjs.h b/src/fcobjs.h
index 81015943..e3926cc3 100644
--- a/src/fcobjs.h
+++ b/src/fcobjs.h
@@ -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)