You are not logged in.

#1 2020-09-02 18:33:44

null1480
Member
Registered: 2020-09-02
Posts: 5

How to apply a "fontconfig" rule to a single program

I've managed to set a bitmap font as the default font for the GUI in Firefox 80.0 by inserting the following in my "fontconfig" configuration file

$ cat ~/.config/fontconfig/fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <selectfont>
    <rejectfont>
      <pattern>
        <patelt name="scalable">
          <bool>true</bool>
        </patelt>
      </pattern>
    </rejectfont>
  </selectfont>

</fontconfig>

You can see how it changed the Firefox GUI in this Imgur album

The problem is: That rule is rejecting all non bitmap fonts system-wide, so it is breaking some applications: The following code block shows how it broke "anki".

$ anki
reverting to stock json
Trace/breakpoint trap (core dumped)
$

The following code block shows how it broke "audacity". "audacity" didn't even exit, it just infinitely printed the message shown below.

$ audacity
...
(audacity:82552): Pango-CRITICAL **: 20:47:08.502: pango_font_description_set_size: assertion 'size >= 0' failed
(audacity:82552): Pango-CRITICAL **: 20:47:08.502: pango_font_description_set_size: assertion 'size >= 0' failed
The question

Is there any way I can make that rule only be applied to "firefox" so that it doesn't break other programs?

I've tried with the "fontconfig" configuration (see code block below). However, the rule seemed to be toggled globally since "anki" and "audacity" still crashed

$ cat ~/.config/fontconfig/fonts.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <match target="pattern">
    
    <test name="prgname">
      <string>firefox</string>
    </test>
    
    <selectfont>
      <rejectfont>
        <pattern>
          <patelt name="scalable">
            <bool>true</bool>
          </patelt>
        </pattern>
      </rejectfont>
    </selectfont>
    
  </match>

</fontconfig>

Last edited by null1480 (2020-09-02 18:40:07)

Offline

#2 2020-09-02 19:09:21

seth
Member
Registered: 2012-09-03
Posts: 51,224

Re: How to apply a "fontconfig" rule to a single program

https://www.freedesktop.org/software/fo … -user.html

Environment variables
FONTCONFIG_FILE is used to override the default configuration file.

FONTCONFIG_PATH is used to override the default configuration directory.

FONTCONFIG_SYSROOT is used to set a default sysroot directory.

FC_DEBUG is used to output the detailed debugging messages. see Debugging Applications section for more details.

FC_DBG_MATCH_FILTER is used to filter out the patterns. this takes a comma-separated list of object names and effects only when FC_DEBUG has MATCH2. see Debugging Applications section for more details.

FC_LANG is used to specify the default language as the weak binding in the query. if this isn't set, the default language will be determined from current locale.

FONTCONFIG_USE_MMAP is used to control the use of mmap(2) for the cache files if available. this take a boolean value. fontconfig will checks if the cache files are stored on the filesystem that is safe to use mmap(2). explicitly setting this environment variable will causes skipping this check and enforce to use or not use mmap(2) anyway.

SOURCE_DATE_EPOCH is used to ensure fc-cache(1) generates files in a deterministic manner in order to support reproducible builds. When set to a numeric representation of UNIX timestamp, fontconfig will prefer this value over using the modification timestamps of the input files in order to identify which cache files require regeneration. If SOURCE_DATE_EPOCH is not set (or is newer than the mtime of the directory), the existing behaviour is unchanged.

Offline

#3 2020-09-02 20:04:47

null1480
Member
Registered: 2020-09-02
Posts: 5

Re: How to apply a "fontconfig" rule to a single program

I read that guide, and I've managed to set the default font to a bitmap font in "obs", "transmission-qt" and "kvirc" by inserting the following in my "fontconfig" configuration file.

$ cat ~/.config/fontconfig/fonts.conf
...
<match>
  <test qual="all" name="prgname" target="pattern" compare="eq">
    <string>obs</string>
  </test>
  <edit mode="assign" name="family">
    <string>Misc Fixed</string>
  </edit>
</match>
... (same with "transmission-qt" and "kvirc")

However, when trying the same in "firefox", the font is not set, so I think I might be missing something.

<match>
  <test qual="all" name="prgname" target="pattern" compare="eq">
    <string>firefox</string>
  </test>
  <edit mode="assign" name="family">
    <string>Misc Fixed</string>
  </edit>
</match>

Last edited by null1480 (2020-09-02 20:05:10)

Offline

#4 2020-09-02 20:17:51

seth
Member
Registered: 2012-09-03
Posts: 51,224

Re: How to apply a "fontconfig" rule to a single program

What in FF do you try to override? The GUI or the webpage rendering?
https://bbs.archlinux.org/viewtopic.php?id=240806

Edit: https://addons.mozilla.org/de/firefox/addon/styl-us/ - stylish has taken a less than benign course and is now more or less malware.

Last edited by seth (2020-09-02 20:19:30)

Offline

#5 2020-09-02 20:29:41

null1480
Member
Registered: 2020-09-02
Posts: 5

Re: How to apply a "fontconfig" rule to a single program

I'm trying to change the font that is used to render text in "about:config", "about:preferences", "about:addons", all text in Developer Tools ("Ctrl + Shift + I"), context menu, etc (Firefox GUI, in general). I can easily accomplished this with a TrueType font, by inserting the following in my "fontconfig" configuration file

$ cat ~/.config/fontconfig/fonts.conf
...
<match>
  <test qual="all" name="prgname" target="pattern" compare="eq">
    <string>firefox</string>
  </test>
  <edit mode="assign" name="family">
    <string>Fira Code</string>
  </edit>
</match>
...

The problem is present when trying this method with a bitmap font. As stated above, I've already managed to use a bitmap font in all the parts of the GUI I mentioned ("about:config", "about:preferences", etc.) but I did it by making "fontconfig" reject all non bitmap fonts (see the "<rejectfont>" part in the first message of this thread). The problem with this approach is that it led some programs to crash or display strange characters.

Last edited by null1480 (2020-09-02 20:37:44)

Offline

#6 2020-09-02 20:46:54

seth
Member
Registered: 2012-09-03
Posts: 51,224

Re: How to apply a "fontconfig" rule to a single program

Did you try a qualified rejection of scalable fonts for FF?

Offline

#7 2020-09-02 21:13:42

null1480
Member
Registered: 2020-09-02
Posts: 5

Re: How to apply a "fontconfig" rule to a single program

I will explain what I want to accomplish just to make things clear. My goal is to make the font "5x7.pcf.gz" (from the "extra/xorg-fonts-misc" package) to be used to render the text from "about:config", "about:preferences", "about:addons", Developer Tools, etc from Firefox 80.0. I don't want this font to affect websites' fonts.

I've already accomplished what I'm requesting by doing some nasty tricks. These are the tricks I performed

  • Reject all non-bitmap fonts system-wide: I accomplished this by specifying a rule in my "fontconfig" configuration file (see configuration below)

  • Delete all bitmap fonts but "5x7.pcf.gz": I first copied "5x7.pcf.gz" from "/usr/share/fonts/misc" to "/home/my/.local/share/fonts" and then I unsinstalled the "extra/xorgs-fonts-misc" package.

<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>

  <selectfont>
    <rejectfont>
      <pattern>
        <patelt name="scalable">
          <bool>true</bool>
        </patelt>
      </pattern>
    </rejectfont>
  </selectfont>

</fontconfig>

Of course I want to find another way of accomplishing this since these two tricks cause two major negative effects. These negative effects are explained below.

  • Reject all non-bitmap fonts system-wide: Some programs such as "anki" and "audacity" doesn't support bitmap fonts so when executed they show an error since the only fonts "fontconfig" accepts now are bitmap fonts.

  • Delete all bitmap fonts but "5x7.pcf.gz": I have some other bitmap fonts which I use in other programs such as "emacs", so by making "5x7.pcf.gz" the only available font, I will not be able to use the other bitmap fonts.

Additional context

Since I'm rejecting all non bitmap fonts and the only installed bitmap font is "5x7.pcf.gz", the output of "fc-list" is a single font (see below)

$ fc-list 
/home/my/.local/share/fonts/5x7.pcf.gz: Misc Fixed:style=Regular
$ fc-list | wc -l 
1

Last edited by null1480 (2020-09-02 21:17:33)

Offline

#8 2020-09-03 06:49:01

seth
Member
Registered: 2012-09-03
Posts: 51,224

Re: How to apply a "fontconfig" rule to a single program

What I meant was sth. like

...
<match>
  <test qual="all" name="prgname" target="pattern" compare="eq">
    <string>firefox</string>
  </test>
  <selectfont>
    <rejectfont>
      <pattern>
        <patelt name="scalable">
          <bool>true</bool>
        </patelt>
      </pattern>
    </rejectfont>
  </selectfont>
</match>
...

You could also invert this and reject them globally but override that w/ special rules for anki, audacity and other clients.

However, there's sth. off here: pango dropped support for pcf bitmap fonts so they should™ cease to work in at least all gtk applications - unless you're using an old version of pango.
https://bbs.archlinux.org/viewtopic.php?id=248032

Offline

Board footer

Powered by FluxBB