Bug 152239 - Font hinting does not work as expected inside document view
Summary: Font hinting does not work as expected inside document view
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.4.0.0 alpha1+
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-11-26 16:14 UTC by Radu Rendec
Modified: 2022-11-27 16:25 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
DejaVu Sans font rendering in LibreOffice 7.3 (2.42 KB, image/png)
2022-11-26 16:16 UTC, Radu Rendec
Details
DejaVu Sans font rendering in LibreOffice 7.4 (3.02 KB, image/png)
2022-11-26 16:17 UTC, Radu Rendec
Details
Screenshot including both the document rendering and the preview in font properties (82.39 KB, image/png)
2022-11-26 16:18 UTC, Radu Rendec
Details
sample ~/.config/fontconfig/fonts.conf (796 bytes, text/plain)
2022-11-27 14:38 UTC, Caolán McNamara
Details
zoomed in DejaVu Sans gen above gtk below (8.84 KB, image/png)
2022-11-27 15:07 UTC, Caolán McNamara
Details
better zoom (3.27 KB, image/png)
2022-11-27 15:08 UTC, Caolán McNamara
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Radu Rendec 2022-11-26 16:14:45 UTC
Description:
After upgrading to LibreOffice 7.4, font rendering inside the document view no longer obeys system-wide font hinting settings. The problem exists only in the document view, and does *not* affect the preview inside the Font properties window or the Font Features window.

I noticed the problem after an upgrade from Fedora 35 to Fedora 37, using the distribution LibreOffice packages. But then I was able to reproduce both the old (good) and new (bad) behavior on Fedora 37 by using several different versions of binary RPM packages from libreoffice.org.

Unaffected versions:
7.2.7.2
7.3.7.2

Affected versions:
7.4.0.0.alpha1
7.4.3.2

To enable full hinting, I am using the truetype:interpreter-version=35 option for FreeType. Rendering options are configured through fontconfig like so:
antialias: true
hinting: true
hintstyle: full
rgba: none
autohint: false
lcdfilter: lcdnone

Steps to Reproduce:
1. Configure the system to enable full hinting, as per the description.
2. Open a blank document, type something, and change the font to "DejaVu Sans".


Actual Results:
Font is only partially hinted in the document rendering.

Expected Results:
Font should be fully hinted.


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 7.4.0.0.alpha1 / LibreOffice Community
Build ID: b871abad383583f02eb49c7e49aeae01f6941072
CPU threads: 2; OS: Linux 6.0; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 Radu Rendec 2022-11-26 16:16:25 UTC
Created attachment 183817 [details]
DejaVu Sans font rendering in LibreOffice 7.3
Comment 2 Radu Rendec 2022-11-26 16:17:03 UTC
Created attachment 183818 [details]
DejaVu Sans font rendering in LibreOffice 7.4
Comment 3 Radu Rendec 2022-11-26 16:18:31 UTC
Created attachment 183819 [details]
Screenshot including both the document rendering and the preview in font properties
Comment 4 ⁨خالد حسني⁩ 2022-11-26 23:58:01 UTC
I believe this is intentional because strong hinting modes change glyph advances and we use unhinted glyph advances in text layout so that document does not re-flow due changes in hinting mode, so both are incompatible.

CC’ing Caolán McNamara for a definitive answer.
Comment 5 Radu Rendec 2022-11-27 00:44:26 UTC
I agree, you definitely do not want the document to re-flow due to changes in hinting mode. However, hinting should only affect kerning, not glyph advances. In other words, it should not cause the document to re-flow.

As always with full hinting, I am willing to sacrifice kerning for glyph aspect. I totally understand you cannot have both.

In the meantime, I tried to start LibreOffice with the SAL_USE_VCLPLUGIN environment variable set to "gen", as suggested here: https://wiki.documentfoundation.org/QA/FirstSteps#Rendering_issues_specific_to_Linux. The UI is messed up (which is expected), but font hinting inside the document view works as expected.

I'm not sure if it's relevant, but my desktop environment is MATE.
Comment 6 Caolán McNamara 2022-11-27 14:38:47 UTC
Created attachment 183828 [details]
sample ~/.config/fontconfig/fonts.conf
Comment 7 Caolán McNamara 2022-11-27 15:07:11 UTC
Created attachment 183829 [details]
zoomed in DejaVu Sans gen above gtk below

Yeah, we're explicitly forcing just slight hinting if hinting is enabled. The positions for determining line breaks aren't affected by whatever hinting mode is done, layout is done at printer resolutions where hinting doesn't matter anyway. But with full hinting we can't guarantee that the smaller font used on the lower resolution screen will fit into the space the text in the larger print resolution font occupied when scaled down to the screen resolution. Or at least that's the working assumption. So light/slight/vertical-hinting-only is deliberate.

In LibreOffice 7.4 the various stuff described in this presentation: https://events.documentfoundation.org/media/libreoffice-conference-2022/submissions/B87ZBP/resources/LibreOfficeCon-2022-ResolutionI_2TieDK1.odp is only applied for the main writer window so there indeed is a discrepancy with the preview in the dialog. In 7.5 the preview matches.

I'm surprised to hear that gen vs gtk makes a difference. We render with the same code by default and with the same settings. Locally here, as seen in this screenshot, I get the same pixels for gtk and gen. A difference there in 7.4.3.2 is surprising? Was there a difference with gen in 7.4.3.2 or was it an earlier 7.4 version where there might have been a discrepancy in settings?
Comment 8 Caolán McNamara 2022-11-27 15:08:43 UTC
Created attachment 183830 [details]
better zoom
Comment 9 V Stuart Foote 2022-11-27 16:01:46 UTC
So, by design and => NAB
Comment 10 Radu Rendec 2022-11-27 16:25:11 UTC
Thanks for the detailed input! You are right, in 7.4.3.2 there is no discrepancy between gtk and gen. I was testing 7.4.0.0.alpha1 when I noticed the discrepancy.

Is there an option (setting?) to revert to the old behavior *locally?* I understand why the change was done, but only slight hinting (or no hinting) makes my eyes bleed, and I'm probably not alone. I am ready to accept whatever would presumably break because of full hinting. To be honest, I have lived with full hinting since before LibreOffice was forked from OpenOffice, and haven't had any issues. So, from my perspective, this is a regression that was introduced to fix a problem that didn't exist. And again, I totally understand this is just *my own* perspective, and what works for me doesn't necessarily work for everybody else. I really wish there was a way to tweak it. Thanks!