Blame SOURCES/fontconfig-score-fix.patch

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