Do not set different score to non-string values
Non-string values in a cache is supposed to choose one from them.
Due to the change of da1c9f7a
, there was a regression on scoring for
matching functions. So reverting the behavior for evaluating non-string
values to the previous one.
Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/286
This commit is contained in:
parent
fd393c53d8
commit
4d43f84188
|
@ -433,7 +433,7 @@ FcCompareValueList (FcObject object,
|
|||
*result = FcResultTypeMismatch;
|
||||
return FcFalse;
|
||||
}
|
||||
v = v * 1000 + j * 100 + k;
|
||||
v = v * 1000 + j * 100 + k * (v2->value.type == FcTypeString ? 1 : 0);
|
||||
if (v < best)
|
||||
{
|
||||
if (bestValue)
|
||||
|
|
|
@ -47,6 +47,7 @@ TESTDATA = \
|
|||
test-45-generic.json \
|
||||
test-60-generic.json \
|
||||
test-90-synthetic.json \
|
||||
test-issue-286.json \
|
||||
test-style-match.json \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ for i in \
|
|||
$RUNNER $TESTDIR/../conf.d/$i $TESTDIR/$test_json
|
||||
done
|
||||
for i in \
|
||||
test-issue-286.json \
|
||||
test-style-match.json \
|
||||
; do
|
||||
echo $RUNNER $TESTDIR/$i ...
|
||||
|
|
|
@ -207,35 +207,58 @@ build_pattern (json_object *obj)
|
|||
}
|
||||
}
|
||||
} else if (type == json_type_double || type == json_type_int) {
|
||||
const FcObjectType *fc_o = FcNameGetObjectType (iter.key);
|
||||
double values[4];
|
||||
if (n != 2 && n != 4) {
|
||||
fprintf (stderr, "E: array starting with number not range or matrix\n");
|
||||
|
||||
if (fc_o && fc_o->type == FcTypeDouble) {
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
o = json_object_array_get_idx (iter.val, i);
|
||||
type = json_object_get_type (o);
|
||||
if (type == json_type_double) {
|
||||
v.type = FcTypeDouble;
|
||||
v.u.d = json_object_get_double (o);
|
||||
} else if (type == json_type_int) {
|
||||
v.type = FcTypeInteger;
|
||||
v.u.i = json_object_get_int (o);
|
||||
} else {
|
||||
fprintf (stderr, "E: unable to convert to double\n");
|
||||
continue;
|
||||
}
|
||||
FcPatternAdd (pat, iter.key, v, FcTrue);
|
||||
v.type = FcTypeVoid;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
o = json_object_array_get_idx (iter.val, i);
|
||||
type = json_object_get_type (o);
|
||||
if (type != json_type_double && type != json_type_int) {
|
||||
fprintf (stderr, "E: numeric array entry not a number\n");
|
||||
continue;
|
||||
}
|
||||
values[i] = json_object_get_double (o);
|
||||
}
|
||||
if (n == 2) {
|
||||
v.type = FcTypeRange;
|
||||
v.u.r = FcRangeCreateDouble (values[0], values[1]);
|
||||
if (!v.u.r) {
|
||||
fprintf (stderr, "E: failed to create range\n");
|
||||
continue;
|
||||
}
|
||||
destroy_v = FcTrue;
|
||||
} else {
|
||||
v.type = FcTypeMatrix;
|
||||
v.u.m = &matrix;
|
||||
matrix.xx = values[0];
|
||||
matrix.xy = values[1];
|
||||
matrix.yx = values[2];
|
||||
matrix.yy = values[3];
|
||||
if (n != 2 && n != 4) {
|
||||
fprintf (stderr, "E: array starting with number not range or matrix\n");
|
||||
continue;
|
||||
}
|
||||
for (i = 0; i < n; i++) {
|
||||
o = json_object_array_get_idx (iter.val, i);
|
||||
type = json_object_get_type (o);
|
||||
if (type != json_type_double && type != json_type_int) {
|
||||
fprintf (stderr, "E: numeric array entry not a number\n");
|
||||
continue;
|
||||
}
|
||||
values[i] = json_object_get_double (o);
|
||||
}
|
||||
if (n == 2) {
|
||||
v.type = FcTypeRange;
|
||||
v.u.r = FcRangeCreateDouble (values[0], values[1]);
|
||||
if (!v.u.r) {
|
||||
fprintf (stderr, "E: failed to create range\n");
|
||||
continue;
|
||||
}
|
||||
destroy_v = FcTrue;
|
||||
} else {
|
||||
v.type = FcTypeMatrix;
|
||||
v.u.m = &matrix;
|
||||
matrix.xx = values[0];
|
||||
matrix.xy = values[1];
|
||||
matrix.yx = values[2];
|
||||
matrix.yy = values[3];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fprintf (stderr, "E: array format not recognized\n");
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"fonts": [
|
||||
{
|
||||
"family": "Foo",
|
||||
"style": "Italic",
|
||||
"pixelsize": [15, 16, 17, 18],
|
||||
"file": "/path/to/Foo-Italic.ttf",
|
||||
"fontversion": 133365
|
||||
},
|
||||
{
|
||||
"family": "Foo",
|
||||
"style": "Regular",
|
||||
"pixelsize": [11, 12, 13, 14, 15, 16, 17, 18, 22],
|
||||
"file": "/path/to/Foo-Regular.ttf",
|
||||
"fontversion": 133365
|
||||
}
|
||||
],
|
||||
"tests": [
|
||||
{
|
||||
"method": "match",
|
||||
"query": {
|
||||
"family": "Foo",
|
||||
"style": "Regular",
|
||||
"pixelsize": 16
|
||||
},
|
||||
"result": {
|
||||
"family": "Foo",
|
||||
"style": "Regular",
|
||||
"pixelsize": 16,
|
||||
"file": "/path/to/Foo-Regular.ttf",
|
||||
"fontversion": 133365
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue