Bug 105415 - fontconfing 2.13 makes bold font when it's not expected to
Summary: fontconfing 2.13 makes bold font when it's not expected to
Status: RESOLVED FIXED
Alias: None
Product: fontconfig
Classification: Unclassified
Component: library (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: fontconfig-bugs
QA Contact: Behdad Esfahbod
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-03-09 11:45 UTC by Jan Palus
Modified: 2018-04-25 11:31 UTC (History)
4 users (show)

See Also:
i915 platform:
i915 features:


Attachments
another patch (1.19 KB, patch)
2018-03-10 07:55 UTC, Akira TAGOH
Details | Splinter Review
another try (1.17 KB, patch)
2018-03-10 08:17 UTC, Akira TAGOH
Details | Splinter Review
proposed patch (1.14 KB, patch)
2018-03-10 08:27 UTC, Akira TAGOH
Details | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Palus 2018-03-09 11:45:46 UTC
Usual way of disabling bold fonts in rxvt-unicode terminal emulator is to define same font for both normal and bold font ie:

URxvt.font: xft:Input Mono Narrow-10:regular
URxvt.boldFont: xft:Input Mono Narrow-10:regular

This setup worked fine until recent upgrade to fontconfig 2.13. No matter what I'm trying bold font remains bold. What I've also tried:
* xft:Input Mono Narrow-10:embolden=false (nothing changes)
* xft:Input Mono Narrow-10:weight=medium (urxvt does not start as fontconfig fails to parse font spec)

Is there anything I am missing?
Comment 1 Akira TAGOH 2018-03-09 12:11:24 UTC
(In reply to Jan Palus from comment #0)
> * xft:Input Mono Narrow-10:weight=medium (urxvt does not start as fontconfig
> fails to parse font spec)

What exactly errors did the application show you? that looks valid to me.

Also try fc-match "Input Mono Narrow-10" and "Input Mono Narrow-10:weight=medium" too maybe.

> 
> Is there anything I am missing?
Comment 2 Jan Palus 2018-03-09 12:51:07 UTC
$ fc-match "Input Mono Narrow-10"              
InputMonoNarrow-Regular.ttf: "Input Mono Narrow" "Regular"

$ fc-match "Input Mono Narrow-10:weight=medium"
Unable to parse the pattern

Note that it works fine with fontconfig 2.12.6:

$ fc-match "Input Mono Narrow-10:weight=medium" 
InputMonoNarrow-Medium.ttf: "Input Mono Narrow" "Medium"
Comment 3 Jan Palus 2018-03-09 14:03:50 UTC
Looks like "Unable to parse the pattern" came with:

commit d3a7c3ce697a8ceb8042bf5bea11c38ac8990553
Author: Behdad Esfahbod <behdad@behdad.org>
Date:   Wed Sep 13 03:31:48 2017 -0400

    [varfonts] Change FC_WEIGHT and FC_WIDTH into ranges

Changing invocation at least gives some result:

$ fc-match 'Input Mono Narrow-10:weight<=medium'
InputMonoNarrow-Regular.ttf: "Input Mono Narrow" "Regular"

but it still has no influence on rxvt-unicode bold font. As far as I can tell above result is also different than the one in 2.12.6 "Regular" vs "Medium"
Comment 4 Akira TAGOH 2018-03-10 06:06:28 UTC
Hm, thanks. well, there are no syntax to set the range in constant names. you have to set like this to obtain the font with the weight medium anyway:

fc-match "Input Mono Narrow-10:weight=[100 100]"
Comment 5 Akira TAGOH 2018-03-10 06:34:05 UTC
For backward compatibility:
diff --git a/src/fcname.c b/src/fcname.c
index 79e413e..b9933df 100644
--- a/src/fcname.c
+++ b/src/fcname.c
@@ -293,6 +293,7 @@ FcNameConvert (FcType type, FcChar8 *string)
     FcMatrix   m;
     double     b, e;
     char       *p;
+    int                i;

     v.type = type;
     switch ((int) v.type) {
@@ -330,13 +331,18 @@ FcNameConvert (FcType type, FcChar8 *string)
     case FcTypeRange:
        if (sscanf ((char *) string, "[%lg %lg]", &b, &e) != 2)
        {
-           v.u.d = strtod ((char *) string, &p);
-           if (p != NULL && p[0] != 0)
+           if (FcNameConstant(string, &i))
            {
-               v.type = FcTypeVoid;
-               break;
+               v.u.r = FcRangeCreateDouble (i, i);
+           } else {
+               v.u.d = strtod ((char *) string, &p);
+               if (p != NULL && p[0] != 0)
+               {
+                   v.type = FcTypeVoid;
+                   break;
+               }
+               v.type = FcTypeDouble;
            }
-           v.type = FcTypeDouble;
        }
        else
            v.u.r = FcRangeCreateDouble (b, e);
Comment 6 Akira TAGOH 2018-03-10 06:34:56 UTC
$ ./build/fc-pattern/fc-pattern "Input Mono Narrow-10:weight=medium"
Pattern has 3 elts (size 16)
        family: "Input Mono Narrow"(s)
        weight: [100 100](s)
        size: 10(f)(s)
Comment 7 Akira TAGOH 2018-03-10 07:55:57 UTC
Created attachment 137956 [details] [review]
another patch

patch to support the ranges of constant names.

$ ./build/fc-pattern/fc-pattern "Input Mono Narrow-10:weight=[medium bold]"
Pattern has 3 elts (size 16)
        family: "Input Mono Narrow"(s)
        weight: [100 200](s)
        size: 10(f)(s)
Comment 8 Akira TAGOH 2018-03-10 08:17:15 UTC
Created attachment 137957 [details] [review]
another try

non-range constant name should be converted to double:

$ ./build/fc-pattern/fc-pattern "Input Mono Narrow-10:weight=medium"
Pattern has 3 elts (size 16)
        family: "Input Mono Narrow"(s)
        weight: 100(f)(s)
        size: 10(f)(s)
$ ./build/fc-pattern/fc-pattern "Input Mono Narrow-10:weight=[medium  bold]"
Pattern has 3 elts (size 16)
        family: "Input Mono Narrow"(s)
        weight: [100 200](s)
        size: 10(f)(s)
Comment 9 Akira TAGOH 2018-03-10 08:27:39 UTC
Created attachment 137958 [details] [review]
proposed patch

fixed leak in the previous patch
Comment 10 Jan Palus 2018-03-10 11:55:29 UTC
Thanks. fontconfig with the patch seems to work fine for me.
Comment 11 Behdad Esfahbod 2018-03-11 20:06:07 UTC
Thanks Akira. Lgtm.
Comment 12 Akira TAGOH 2018-03-12 02:52:45 UTC
Fixed in git. thanks.
Comment 13 Jan Palus 2018-03-13 16:24:35 UTC
Not sure if that's a valid syntax but there's still a slight difference in behavior between 2.12.6 and patched 2.13.0:

# 2.12.6
$ fc-match 'Input Mono Narrow-10:medium'
InputMonoNarrow-Medium.ttf: "Input Mono Narrow" "Medium"

# 2.13.0
$ fc-match 'Input Mono Narrow-10:medium'       
InputMonoNarrow-Regular.ttf: "Input Mono Narrow" "Regular"

so "medium" is ignored if not passed explicitly with attribute name "weight=medium"
Comment 14 Ulrich Müller 2018-03-14 09:07:04 UTC
(In reply to Jan Palus from comment #13)
> Not sure if that's a valid syntax but there's still a slight difference in
> behavior between 2.12.6 and patched 2.13.0:
> 
> # 2.12.6
> $ fc-match 'Input Mono Narrow-10:medium'
> InputMonoNarrow-Medium.ttf: "Input Mono Narrow" "Medium"
> 
> # 2.13.0
> $ fc-match 'Input Mono Narrow-10:medium'       
> InputMonoNarrow-Regular.ttf: "Input Mono Narrow" "Regular"
> 
> so "medium" is ignored if not passed explicitly with attribute name
> "weight=medium"

I see this too:

   $ fc-match 'Droid Sans-10:bold'   # 2.12.6
   DroidSans-Bold.ttf: "Droid Sans" "Bold"
   $ fc-match 'Droid Sans-10:bold'   # 2.13.0 (with or without patch)
   DroidSans.ttf: "Droid Sans" "Regular"

User documentation explictly mentions examples like 'Times-12:bold' so I believe that the above syntax should work.
https://www.freedesktop.org/software/fontconfig/fontconfig-user.html#AEN36

Reopening.
Comment 15 Akira TAGOH 2018-03-14 09:35:46 UTC
(In reply to Jan Palus from comment #13)
> Not sure if that's a valid syntax but there's still a slight difference in
> behavior between 2.12.6 and patched 2.13.0:

Yes, that is a valid syntax. fixed in git.

$ ./build/fc-pattern/fc-pattern :normal:bold
Pattern has 2 elts (size 16)
        weight: 200(i)(s)
        width: 100(i)(s)


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.