Blame SOURCES/fontconfig-score-fix.patch

142473
From 4d43f84188847a6a77f7259f986fb178c52c1ea7 Mon Sep 17 00:00:00 2001
142473
From: Akira TAGOH <akira@tagoh.org>
142473
Date: Thu, 8 Jul 2021 14:21:50 +0900
142473
Subject: [PATCH 1/2] Do not set different score to non-string values
142473
142473
Non-string values in a cache is supposed to choose one from them.
142473
Due to the change of da1c9f7a, there was a regression on scoring for
142473
matching functions.  So reverting the behavior for evaluating non-string
142473
values to the previous one.
142473
142473
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/286
142473
---
142473
 src/fcmatch.c            |  2 +-
142473
 test/Makefile.am         |  1 +
142473
 test/run-test-conf.sh    |  1 +
142473
 test/test-conf.c         | 71 ++++++++++++++++++++++++++--------------
142473
 test/test-issue-286.json | 35 ++++++++++++++++++++
142473
 5 files changed, 85 insertions(+), 25 deletions(-)
142473
 create mode 100644 test/test-issue-286.json
142473
142473
diff --git a/src/fcmatch.c b/src/fcmatch.c
142473
index c88e3aa..fd43cbd 100644
142473
--- a/src/fcmatch.c
142473
+++ b/src/fcmatch.c
142473
@@ -433,7 +433,7 @@ FcCompareValueList (FcObject	     object,
142473
 		*result = FcResultTypeMismatch;
142473
 		return FcFalse;
142473
 	    }
142473
-	    v = v * 1000 + j * 100 + k;
142473
+	    v = v * 1000 + j * 100 + k * (v2->value.type == FcTypeString ? 1 : 0);
142473
 	    if (v < best)
142473
 	    {
142473
 		if (bestValue)
142473
diff --git a/test/Makefile.am b/test/Makefile.am
142473
index aea8724..d07654b 100644
142473
--- a/test/Makefile.am
142473
+++ b/test/Makefile.am
142473
@@ -47,6 +47,7 @@ TESTDATA =			\
142473
 	test-45-generic.json	\
142473
 	test-60-generic.json	\
142473
 	test-90-synthetic.json	\
142473
+	test-issue-286.json	\
142473
 	test-style-match.json	\
142473
 	$(NULL)
142473
 
142473
diff --git a/test/run-test-conf.sh b/test/run-test-conf.sh
142473
index 0c2bd52..bbb56f4 100644
142473
--- a/test/run-test-conf.sh
142473
+++ b/test/run-test-conf.sh
142473
@@ -49,6 +49,7 @@ for i in \
142473
     $RUNNER $TESTDIR/../conf.d/$i $TESTDIR/$test_json
142473
 done
142473
 for i in \
142473
+	test-issue-286.json \
142473
 	test-style-match.json \
142473
     ; do
142473
     echo $RUNNER $TESTDIR/$i ...
142473
diff --git a/test/test-conf.c b/test/test-conf.c
142473
index e4e9da4..1a52c6e 100644
142473
--- a/test/test-conf.c
142473
+++ b/test/test-conf.c
142473
@@ -207,35 +207,58 @@ build_pattern (json_object *obj)
142473
 		    }
142473
 		}
142473
 	    } else if (type == json_type_double || type == json_type_int) {
142473
+		const FcObjectType *fc_o = FcNameGetObjectType (iter.key);
142473
 		double values[4];
142473
-		if (n != 2 && n != 4) {
142473
-		    fprintf (stderr, "E: array starting with number not range or matrix\n");
142473
+
142473
+		if (fc_o && fc_o->type == FcTypeDouble) {
142473
+		    for (i = 0; i < n; i++)
142473
+		    {
142473
+			o = json_object_array_get_idx (iter.val, i);
142473
+			type = json_object_get_type (o);
142473
+			if (type == json_type_double) {
142473
+			    v.type = FcTypeDouble;
142473
+			    v.u.d = json_object_get_double (o);
142473
+			} else if (type == json_type_int) {
142473
+			    v.type = FcTypeInteger;
142473
+			    v.u.i = json_object_get_int (o);
142473
+			} else {
142473
+			    fprintf (stderr, "E: unable to convert to double\n");
142473
+			    continue;
142473
+			}
142473
+			FcPatternAdd (pat, iter.key, v, FcTrue);
142473
+			v.type = FcTypeVoid;
142473
+		    }
142473
 		    continue;
142473
-		}
142473
-		for (i = 0; i < n; i++) {
142473
-		    o = json_object_array_get_idx (iter.val, i);
142473
-		    type = json_object_get_type (o);
142473
-		    if (type != json_type_double && type != json_type_int) {
142473
-			fprintf (stderr, "E: numeric array entry not a number\n");
142473
+		} else {
142473
+		    if (n != 2 && n != 4) {
142473
+			fprintf (stderr, "E: array starting with number not range or matrix\n");
142473
 			continue;
142473
 		    }
142473
-		    values[i] = json_object_get_double (o);
142473
-		}
142473
-		if (n == 2) {
142473
-		    v.type = FcTypeRange;
142473
-		    v.u.r = FcRangeCreateDouble (values[0], values[1]);
142473
-		    if (!v.u.r) {
142473
-			fprintf (stderr, "E: failed to create range\n");
142473
-			continue;
142473
+		    for (i = 0; i < n; i++) {
142473
+			o = json_object_array_get_idx (iter.val, i);
142473
+			type = json_object_get_type (o);
142473
+			if (type != json_type_double && type != json_type_int) {
142473
+			    fprintf (stderr, "E: numeric array entry not a number\n");
142473
+			    continue;
142473
+			}
142473
+			values[i] = json_object_get_double (o);
142473
+		    }
142473
+		    if (n == 2) {
142473
+			v.type = FcTypeRange;
142473
+			v.u.r = FcRangeCreateDouble (values[0], values[1]);
142473
+			if (!v.u.r) {
142473
+			    fprintf (stderr, "E: failed to create range\n");
142473
+			    continue;
142473
+			}
142473
+			destroy_v = FcTrue;
142473
+		    } else {
142473
+			v.type = FcTypeMatrix;
142473
+			v.u.m = &matrix;
142473
+			matrix.xx = values[0];
142473
+			matrix.xy = values[1];
142473
+			matrix.yx = values[2];
142473
+			matrix.yy = values[3];
142473
 		    }
142473
-		    destroy_v = FcTrue;
142473
-		} else {
142473
-		    v.type = FcTypeMatrix;
142473
-		    v.u.m = &matrix;
142473
-		    matrix.xx = values[0];
142473
-		    matrix.xy = values[1];
142473
-		    matrix.yx = values[2];
142473
-		    matrix.yy = values[3];
142473
 		}
142473
 	    } else {
142473
 		fprintf (stderr, "E: array format not recognized\n");
142473
diff --git a/test/test-issue-286.json b/test/test-issue-286.json
142473
new file mode 100644
142473
index 0000000..a3199fa
142473
--- /dev/null
142473
+++ b/test/test-issue-286.json
142473
@@ -0,0 +1,35 @@
142473
+{
142473
+    "fonts": [
142473
+        {
142473
+            "family": "Foo",
142473
+            "style": "Italic",
142473
+	    "pixelsize": [15, 16, 17, 18],
142473
+            "file": "/path/to/Foo-Italic.ttf",
142473
+            "fontversion": 133365
142473
+        },
142473
+        {
142473
+            "family": "Foo",
142473
+            "style": "Regular",
142473
+	    "pixelsize": [11, 12, 13, 14, 15, 16, 17, 18, 22],
142473
+            "file": "/path/to/Foo-Regular.ttf",
142473
+            "fontversion": 133365
142473
+        }
142473
+    ],
142473
+    "tests": [
142473
+        {
142473
+            "method": "match",
142473
+            "query": {
142473
+                "family": "Foo",
142473
+                "style": "Regular",
142473
+		"pixelsize": 16
142473
+            },
142473
+            "result": {
142473
+                "family": "Foo",
142473
+                "style": "Regular",
142473
+	        "pixelsize": 16,
142473
+                "file": "/path/to/Foo-Regular.ttf",
142473
+                "fontversion": 133365
142473
+            }
142473
+        }
142473
+    ]
142473
+}
142473
-- 
142473
2.31.1
142473