Bug 105797 - Changing fonts from Kcontrol will enable hinting and make it default. All this information it writes to ~/.fonts.conf
Summary: Changing fonts from Kcontrol will enable hinting and make it default. All thi...
Status: RESOLVED FIXED
Alias: None
Product: systemsettings
Classification: Applications
Component: kcm_fonts (show other bugs)
Version: unspecified
Platform: RedHat Enterprise Linux Linux
: NOR normal
Target Milestone: ---
Assignee: rik
URL:
Keywords:
: 149455 209841 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-05-17 10:10 UTC by Ankit Patel
Modified: 2014-09-29 09:22 UTC (History)
13 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Do not modify .fonts.conf when loading it. Now nothing is written before the user clicks apply or ok. (1.42 KB, patch)
2011-04-24 01:23 UTC, Nikolaus Waxweiler
Details
Do not modify .fonts.conf when loading it. Now nothing is written before the user clicks apply or ok. (1.42 KB, patch)
2011-04-24 01:27 UTC, Nikolaus Waxweiler
Details
a patch to remove settings when "System defaults" are selected (4.56 KB, patch)
2012-07-08 11:40 UTC, Fuminobu TAKEYAMA
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ankit Patel 2005-05-17 10:10:32 UTC
Version:           3.3.1-2.1 (using KDE KDE 3.3.1)
Installed from:    RedHat RPMs
OS:                Linux

I have tried to change my appearance (spicifically fonts) from the kcontrol. After changing the appearance i have logged into the Gnome session. I surprised to see my hinting is enabled in Gnome, though it was not enabled. I have tried to change the hintings from the Kcontrol and Gnome's Main menu => preferences => Fonts => Details => Hinting. But the result remains the same. After that i have removed ~/.fonts.conf file, and logged into Gnome again. Then only my hinting is disabled.
Comment 1 Ankit Patel 2005-05-17 12:18:32 UTC
Just now i got new thing. Open "kcontrol" (control-center). Click on
"Appearance". Now when you click on "Fonts" in that then only it will create
automatically ~/.fonts.conf automatically. Simply you can say that when you
click on "Fonts" in the "Appearance" tab then "kcontrol" will create
~/.fonts.conf according to the 'configuration' settings of the checkbox "Use sub-pixel hinting for fonts" in the "Fonts" tab whether this checkbox is selected or not and make it default, and it affect Gnome settings also.
Comment 2 Richard Fujimoto 2005-11-30 23:37:19 UTC
Not only does the kcm do that, I find it quite annoying that it decides to reformat my entire file when no changes are made.  I was going to file a new bug, but found this one instead.

Why does the kcm change or alter the file when you've cancelled out of the font dialog?  I have a lot of custom adjustments and I have it formatted so that I can easily read it

By simply opening the kcm, it reformats the entire file inserting anything that it feels is missing.  Even if it's already there.  One example, it will completely ignore this and re-enter the information using a <match> for each <edit> attribute.

<match target="font" >
	<edit mode="assign" name="autohint"><bool>false</bool></edit>
	<edit mode="assign" name="hinting"><bool>true</bool></edit>
<!--	<edit name="hintstyle"><const>hintmedium</const></edit> -->
	<edit mode="assign" name="rgba"><const>none</const></edit>

<!-- Turn on System wide Antialias -->
	<edit mode="assign" name="antialias"><bool>true</bool></edit>
</match>

------------Is Ignored and this is at the bottom----------

<match target="font" >
  <edit mode="assign" name="autohint" >
   <bool>false</bool>
  </edit>
 </match>
 <match target="font" >
  <edit mode="assign" name="hinting" >
   <bool>true</bool>
  </edit>
 </match>
 <match target="font" >
  <edit name="hintstyle" >
   <const>hintmedium</const>
  </edit>
 </match>
 <match target="font" >
  <edit mode="assign" name="rgba" >
   <const>none</const>
  </edit>
 </match>
<!-- Turn on System wide Antialias --> <match target="font" >
  <edit mode="assign" name="antialias" >
   <bool>true</bool>
  </edit>
 </match>

-----------

You'll notice it has decided to add an <edit> for "hintstyle" even though there is no setting in the original file.

Please only write a fonts.conf file if something has changed, nothing should be altered by simply opening a dialog.
Comment 3 Andrey Rakhmatullin 2009-01-26 19:23:35 UTC
The same with KDE4 up to 4.1.96
Comment 4 Andrey Rakhmatullin 2009-03-28 20:22:57 UTC
4.2.1: still here.
After a quick glance at kde4base-workspace/kcontrol/fonts/kxftconfig.cpp I think that file is broken in KXftConfig() -> reset() -> apply().
Comment 5 Dario Andres 2009-10-10 17:20:18 UTC
*** Bug 149455 has been marked as a duplicate of this bug. ***
Comment 6 Dario Andres 2009-10-10 17:20:46 UTC
*** Bug 209841 has been marked as a duplicate of this bug. ***
Comment 7 Nikolaus Waxweiler 2011-03-11 00:45:34 UTC
Still happens in 4.6.0. I've been trying to make sense of the font setting code for a few days and I.. haven't gotten very far. If I'm not mistaken, the code in KXftConfig looks for

 <match target="font">
  <edit mode="assign" name="hintstyle">
   <const>hintSOMETHING</const>
  </edit>
 </match>

as a child of <fontconfig>. If it doesn't find that, it modifies .fonts.conf, adds its' own defaults (hintmedium, ...) and reformats the file in the process, even if you said "Use anti-aliasing -> System Settings" (from a quick glance, KXftConfig doesn't know anything about that option). If you "sudo chattr +i .fonts.conf", the file can't be modified anymore but depending on what's in it, the config options XftSubPixel and others might still be set to whatever in .kde4/share/config/kdeglobals. This also sets "Xft.hintstyle: ..." and others in the X server resource database (see "xrdb -query | grep Xft"). In my case, this usually resulted in un-subpixel-hinted fonts in Plasma applets and all KDE apps.

The whole mechanism seems fragile to me. Users and distributions (like openSUSE) can set up elaborate .fonts.conf files dealing with hinting details (see for example the Infinality FreeType patches) and the fonts configuration dialog simply overrides everything. I still trying to make sense of the code so that I can get the "Please leave my settings alone" option to work (and make it the default if it isn't already). I'm also toying with the idea of rewriting/refactoring the module, since it looks like it hasn't been touched much since ancient times. By the way, what is this Xft configuration (the stuff in "xrdb -query | grep Xft") good for anymore? Afaik this method of font configuration is outdated, even if Qt still deals with it (src/gui/kernel/qapplication_x11.cpp).
Comment 8 Karl Tomlinson 2011-03-11 01:35:02 UTC
(In reply to comment #7)
> By the way, what is this Xft configuration (the stuff
> in "xrdb -query | grep Xft") good for anymore? Afaik this method of font
> configuration is outdated, even if Qt still deals with it
> (src/gui/kernel/qapplication_x11.cpp).

These X resources are screen-specific settings read by libXft.  cairo and Qt also look at these settings to mimic libXft's behaviour.  These are useful for setting the default screen properties, such indicating subpixel order and saying whether the user prefers hinting.

Fontconfig <match target="font" > settings should override the X resource settings.  They provide a means to tailor settings to the font.  For example, preferring a lighter hintstyle for fonts that have bad TrueType instructions.

Beware, however, that fontconfig settings are not only used for screen rendering but font rendering in general so it doesn't make sense, for example, to turn on hinting unconditionally in a fontconfig file.

It probably makes sense to set the X resources if the user changes the corresponding font rendering preferences in Kcontrol (but preferably not if the user merely changes preferred fonts).

It should not be necessary for Kcontrol to add any fontconfig rules at all, because applications take into account the X resources.
Comment 9 Nikolaus Waxweiler 2011-04-24 01:23:56 UTC
Created attachment 59264 [details]
Do not modify .fonts.conf when loading it. Now nothing is written before the user clicks apply or ok.

Thanks for your comment. I'm not sure if I can really remove the fontconfig stuff (I want to!). I tried setting hinting and subpixel hinting via .Xdefaults and removing my user .fonts.conf (openSUSE 11.4) and didn't get what I wanted. Dunno. Maybe I'm overlooking something? Where else is the config used where it doesn't make sense to set things unconditionally? I know that font substitutions take effect in e.g. Okular (poppler), but font hinting is disabled when viewing PDFs.

Anyway, after blankly staring at my monitor for more than a month, I came up with a patch to solve the overwriting problem. Turns out that the file was modified in *loading* routines. Ouch. Now nothing is written before the user clicks apply or ok, the way it should be. Can somebody test this?
Comment 10 Nikolaus Waxweiler 2011-04-24 01:27:39 UTC
Created attachment 59266 [details]
Do not modify .fonts.conf when loading it. Now nothing is written before the user clicks apply or ok.

Thanks for your comment. I'm not sure if I can really remove the fontconfig stuff (I want to!). I tried setting hinting and subpixel hinting via .Xdefaults and removing my user .fonts.conf (openSUSE 11.4) and didn't get what I wanted. Dunno. Maybe I'm overlooking something? Where else is the config used where it doesn't make sense to set things unconditionally? I know that font substitutions take effect in e.g. Okular (poppler), but font hinting is disabled when viewing PDFs.

Anyway, after blankly staring at my monitor for more than a month, I came up with a patch to solve the overwriting problem. Turns out that the file was modified in *loading* routines. Ouch. Now nothing is written before the user clicks apply or ok, the way it should be. Can somebody test this?
Comment 11 Jekyll Wu 2011-07-26 14:43:40 UTC
*** This bug has been confirmed by popular vote. ***
Comment 12 Daniel Eklöf 2011-10-02 11:40:08 UTC
(In reply to comment #10)
> Created an attachment (id=59266) [details]
> Do not modify .fonts.conf when loading it. Now nothing is written before the
> user clicks apply or ok.

I had the same issue as described in bug 245664, and while trying to find a solution for it, I managed to duplicate your patch - down to the last byte :)

So, I can confirm the patch works; not only does it prevent .fonts.conf from being overwritten when loading the fonts kcm, but as a side effect, it also prevents it from being overwritten when applying font changes when "Use anti-aliasing" is set to "System Settings".
Comment 13 Nikolaus Waxweiler 2011-10-02 17:03:14 UTC
Is this patch still not included in mainline?
Comment 14 Daniel Eklöf 2011-10-02 17:47:26 UTC
(In reply to comment #13)
> Is this patch still not included in mainline?

Nope (and I don't have any commit-rights)
Comment 15 Fuminobu TAKEYAMA 2012-07-08 11:40:21 UTC
Created attachment 72365 [details]
a patch to remove settings when "System defaults" are selected

I wrote a patch to resolve problem that "System Settings" does not change any value.

Now when you select "System Settings", the font setting module removes all of values that it appended to ~/.fonts.conf.

If you are using openSUSE and KDE 4.8, you can download patched package from:
https://build.opensuse.org/project/show?project=home%3Aftake%3Abranches%3AKDE%3ADistro%3AFactory

This bug is really annoying. I hope this bug is resolved soon in official release.

See also:
https://bugzilla.novell.com/show_bug.cgi?id=768896
Comment 16 Rex Dieter 2012-07-08 14:52:53 UTC
Mind posting your patch to reviewboard.kde.org for review?
Comment 17 Fuminobu TAKEYAMA 2012-07-09 16:17:28 UTC
No problem.

Has Nikolaus's patch been submitted there?
We need both patches to resolve this problem.
Comment 18 Fuminobu TAKEYAMA 2014-08-14 14:36:11 UTC
I have submitted to the review board:
https://git.reviewboard.kde.org/r/119764/
Comment 19 Eike Hein 2014-09-29 09:22:15 UTC
Git commit f02df03cb87b4bb5724eec668d49126a5f52a1e7 by Eike Hein, on behalf of Fuminobu TAKEYAMA.
Committed on 29/09/2014 at 09:22.
Pushed by hein into branch 'master'.

Fix BUG#105797: inappropriate fontconfig settings are saved when kcontrol/fonts is shown and no way to revert them

Fix kcontrol/fonts saves fontconfig settings when it is opened. Add "System default" to each config. It removes a corresponding fontconfig entry made by this module. "System default" is now default values for sub-pixel rendering and hinting.

Selecting "System default" also reverts Xft configs.

REVIEW: 119764

M  +40   -40   kcms/fonts/fonts.cpp
M  +3    -2    kcms/fonts/fonts.h
M  +67   -43   kcms/fonts/kxftconfig.cpp
M  +16   -9    kcms/fonts/kxftconfig.h

http://commits.kde.org/plasma-desktop/f02df03cb87b4bb5724eec668d49126a5f52a1e7
Comment 20 Eike Hein 2014-09-29 09:22:15 UTC
Git commit f02df03cb87b4bb5724eec668d49126a5f52a1e7 by Eike Hein, on behalf of Fuminobu TAKEYAMA.
Committed on 29/09/2014 at 09:22.
Pushed by hein into branch 'master'.

Fix BUG#105797: inappropriate fontconfig settings are saved when kcontrol/fonts is shown and no way to revert them

Fix kcontrol/fonts saves fontconfig settings when it is opened. Add "System default" to each config. It removes a corresponding fontconfig entry made by this module. "System default" is now default values for sub-pixel rendering and hinting.

Selecting "System default" also reverts Xft configs.

REVIEW: 119764

M  +40   -40   kcms/fonts/fonts.cpp
M  +3    -2    kcms/fonts/fonts.h
M  +67   -43   kcms/fonts/kxftconfig.cpp
M  +16   -9    kcms/fonts/kxftconfig.h

http://commits.kde.org/plasma-desktop/f02df03cb87b4bb5724eec668d49126a5f52a1e7