How/where is font hinting performed in libreoffice?
Frank Steiner
fsteiner-mail1 at bio.ifi.lmu.de
Sun Oct 15 22:42:56 UTC 2023
Hi,
Caolán McNamara wrote:
> Not quite, we override these via cairo_font_options_set_* in some
> cases, so you might be looking for
> vcl/unx/generic/gdi/cairotextrender.cxx
> and CairoTextRender::DrawTextLayout wrt CAIRO_HINT_STYLE_SLIGHT
thanks for pointing me to cairotextrender.cxx! I've analyzed the code
and inserted some debugging output and could figure out why fonts like
Arial can no longer be displayed in their slight version but always
look bolder in LO starting with 7.5.x
The relevant code parts in cairotextrender.cxx (current git clone) is
this, I've added the comments to explain what happens.
// always true because pFontOptions is set and bSubpixelPositioning is true
if (pFontOptions || bDisableAA || bSubpixelPositioning)
{
// sets eHintStyle to the value of Xft.hintstyle=... from ~/.Xdefaults
// If none is defined there, pFontOptions has CAIRO_HINT_STYLE_MEDIUM set
cairo_hint_style_t eHintStyle = pFontOptions ? cairo_font_options_get_hint_style(pFontOptions) : CAIRO_HINT_STYLE_DEFAULT;
// with bSubpixelPositioning=true, this is true for Xft.hintstyle=none/slight and false otherwise
bool bAllowedHintStyle = !bSubpixelPositioning || (eHintStyle == CAIRO_HINT_STYLE_NONE || eHintStyle == CAIRO_HINT_STYLE_SLIGHT);
// always true if bSubpixelPositioning=true
if (bDisableAA || !bAllowedHintStyle || bSubpixelPositioning)
{
...
// bAllowedHintStyle is false if Xft.hintstyle=medium/full
if (!bAllowedHintStyle) {
// so Xft.hintstyle=medium/full is reset to slight
cairo_font_options_set_hint_style(pOptions, CAIRO_HINT_STYLE_SLIGHT);
}
bSubpixelPositioning is always true and I have found no way to set this
to false. I didn't find where it is set in LO, so I guess it's a default
from cairo, and there seems to be no way to disable it.
Thus, with bSubpixelPositioning being true, Xft.hintstyle=hintnone/hintslight
will be kept, but Xft.hintstyle=hintmedium/hintfull will be ignored and the
hintstyle will be reset to CAIRO_HINT_STYLE_SLIGHT.
But with CAIRO_HINT_STYLE_SLIGHT and CAIRO_HINT_STYLE_NONE e.g. the
microsoft fonts like Arial are not shown in their thin version, but in
their bolder version (see screenshots at
https://bugs.documentfoundation.org/show_bug.cgi?id=157348)
When I change the last line of the code above to
cairo_font_options_set_hint_style(pOptions, CAIRO_HINT_STYLE_MEDIUM);
(or _FULL) Arial etc. are shown in their thin version again.
In LO 7.4.7, which respects the settings from fontfonfig, Arial is thin
with hinting set to hintslight/medium/full in fontconfig, and only bold
with hintnone (as long as authinting is false).
In LO >= 7.5 there is no way to enforce font hinting medium or full and
therefore these fonts who look better with their integrated hinting, can
no longer be shown in their thin versions.
Maybe someone can help me understand these questions:
1) Why is font hinting explicitely forced to hintslight if
bSubpixelPositioning is true? Why doesn't LO allow people to
force the hinting style they prefer?
2) If bSubpixelPositioning is false (it's a read-only variable, but
I just reverted it with "!"), one can indeed use hintmedium/full
by setting it via .Xdefaults.
So is there any way one can set bSubpixelPositioning to false
via any setting from outside? Some environment variable, some
setting in gtk-3.0/settings.init or fontconfig or .Xdefaults?
3) Why is font hinting no longer taken from fontconfig settings?
The Xft.hinting only allows one setting for all fonts, while
fontconfig allows per-font definitions.
Would you (whoever is responsible for the font rendering code)
consider adding some way to either set bSubpixelPositioning to
false from outside LO, or respecting the font hinting value
(from Xft.hinting or from fontconfig) and not force it to
CAIRO_HINT_STYLE_SLIGHT if bSubpixelPositioning is true?
That would give people back at least some control over hinting
and allow the thin versions of certain fonts.
cu,
Frank
--
Dipl.-Inform. Frank Steiner Web: http://www.bio.ifi.lmu.de/~steiner/
Lehrstuhl f. Bioinformatik Mail: http://www.bio.ifi.lmu.de/~steiner/m/
LMU, Amalienstr. 17 Phone: +49 89 2180-4049
80333 Muenchen, Germany Fax: +49 89 2180-99-4049
* Rekursion kann man erst verstehen, wenn man Rekursion verstanden hat. *
More information about the LibreOffice
mailing list