Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rounding differences between harfbuzz and cairo #1892

Closed
matthiasclasen opened this issue Aug 7, 2019 · 26 comments
Closed

rounding differences between harfbuzz and cairo #1892

matthiasclasen opened this issue Aug 7, 2019 · 26 comments

Comments

@matthiasclasen
Copy link
Collaborator

In pango 1.44, we've replaced cairo by harfbuzz for getting glyph extents. Some people complain that fonts are 'stretched' now (https://gitlab.gnome.org/GNOME/pango/issues/404).

Comparing 1.43 and 1.44, I find that i get this returned from cairo (note that the values here are rounded to multiples of 1024:

glyph 78 width 3072 
glyph 83 width 8192 
glyph 74 width 8192

And this is what i get from harfbuzz:

glyph 78 width 3652
glyph 83 width 8294
glyph 74 width 7964

the harfbuzz values are not rounded, that is ok. The issue here is that 3652 rounds to 4096, giving us an extra pixel of width for that glyph.

I haven't gotten to the bottom of why these values are different. I did notice that the scales of the font are similar enough to not be the reason: 15024 (with 1.43) vs 15019 (with 1.44).

@behdad
Copy link
Member

behdad commented Aug 7, 2019

What kind of hinting setting is that with?

@matthiasclasen
Copy link
Collaborator Author

everything is default:

font options: antialias 0 subpixel_order 0 hint-style 0 hint-metrics 0

i can turn hint-metrics off if you think it matters for what cairo returns

Look at that, it does:

glyph 78 advance 3652
glyph 83 advance 8294
glyph 74 advance 7964

This is cairo with hint-metrics off

@matthiasclasen
Copy link
Collaborator Author

Where does this leave us ? harfbuzz is giving me the same values are cairo with hint-metrics off.
But rounding those values on the pango side does not reproduce the same values as cairo with hint-metrics on.

@jfkthame
Copy link
Collaborator

jfkthame commented Aug 7, 2019 via email

@mxmilkiib
Copy link

This issue was mentioned in #sway in regard to a font clipping/shrinking issue in sway-bar, but I'd like to confirm if this issue is actually related?

rose_2019-08-14-110559

@bungeman
Copy link
Collaborator

Having read through the chain of issues (arch, two pango issues, and here) it looks like pango has dropped support for metric hinting? Looking through the changes I see where pango_fc_hb_font_get_glyph_advance was no longer set on the hb_font_funcs_t but I don't see where the hinting was restored. It appears the the raw font data is being passed to HarfBuzz, but HarfBuzz doesn't do hinting itself, and don't see a place where pango is creating an FT_Face to pass to HarfBuzz set up to return hinted metrics (I'm pretty sure it isn't doing this, otherwise BDF fonts would still work).

@khaledhosny
Copy link
Collaborator

Yes, Pango uses HarfBuzz OT font function and thus intentionally not using hinted metrics. I don’t think there is any issue to fix here, everything is working as intended.

@bungeman
Copy link
Collaborator

I suppose my point was that pango appears to now be incapable of doing layout with hinted metrics, but users are still drawing with hinted glyphs... leading to less than desirable spacing (Chromium had this issue for a while, I think it's mostly fixed now). HarfBuzz is working as intended, but I'm not sure that pango realized that it was dropping support for hinting here. At the very least the FT_Face returned from pango_fc_font_lock_face may have hinting set (which the user may use to render) which the shaper never used when computing metrics.

I suppose this explanation is getting to the point where it would be better to comment on the upstream issue. I just wanted to explicitly point out here the HarfBuzz behavior around not hinting since the effect of that hadn't yet been explicitly called out (this probably isn't just a rounding issue).

@khaledhosny
Copy link
Collaborator

It is my understanding that the switch to unhinted metrics was intentional , see the last paragraph in https://blogs.gnome.org/mclasen/2019/05/25/pango-future-directions/. But I agree that Pango should then render unhinted glyphs, by setting suitable cairo font options.

@behdad
Copy link
Member

behdad commented Aug 22, 2019

Where does this leave us ? harfbuzz is giving me the same values are cairo with hint-metrics off.
But rounding those values on the pango side does not reproduce the same values as cairo with hint-metrics on.

Right. Also need to turn hinting off, or to 'slight' which disable horizontal hinting.

@matthiasclasen
Copy link
Collaborator Author

Right. Also need to turn hinting off, or to 'slight' which disable horizontal hinting.

Always, you mean ? Or only when we are not rounding glyph positions ?

This
https://gitlab.gnome.org/GNOME/pango/commits/hinting does it only when we are doing subpixel positioning. But I am not sure how it can address the complaints we get now, since subpixel positioning is not turned on currently.

@khaledhosny
Copy link
Collaborator

You don’t want hinting to change the advance width, regardless of whether the positions are rounded or not.

@behdad
Copy link
Member

behdad commented Sep 8, 2019

Right. Also need to turn hinting off, or to 'slight' which disable horizontal hinting.

Always, you mean ? Or only when we are not rounding glyph positions ?

When you and I agreed on a plan, it was to enable subpixel positioning, which lets us disable horizontal hinting, which would enable us using HarfBuzz font funcs.

@matthiasclasen
Copy link
Collaborator Author

Yes, we just need to get on with it, by getting a cairo release out

@Ede123
Copy link

Ede123 commented Sep 11, 2019

So, do I understand correctly that on back-ends that do not support subpixel positioning (notably win32 according to https://gitlab.gnome.org/GNOME/pango/issues/385) we still won't use horizontal hinting anymore and - consequently - will end up with bad font rendering (at least on "normal" displays that not have high DPI)?

Even subpixel positioning is usually a lot less readable compared to a font that's properly hinted for screen display.

I can understand that the general direction outlined in https://blogs.gnome.org/mclasen/2019/05/25/pango-future-directions/ is desirable in the long-term, but it sounds a bit premature, considering high-DPI displays are far from being standard today.

@madig
Copy link
Contributor

madig commented Nov 2, 2019

Side-note:

will end up with bad font rendering [...] Even subpixel positioning is usually a lot less readable compared to a font that's properly hinted for screen display.

All browsers on Windows use DirectWrite, which doesn't do much horizontal grid fitting and uses subpixel positioning, even on today's screens. Most fonts out there don't even have horizontal hinting. It's fine.

@ubitux
Copy link

ubitux commented Nov 12, 2019

This is a followup on the initial pango issue reported (apparently the discussion continues here). The issue was mentioning Roboto, and I can also reproduce it with ProFont (https://tobiasjung.name/profont/ - OTB version, the one released in order to address the PCF/BDF issue):

Using pango-view -q --background=black --foreground=white --font="ProFont 8" /tmp/test.txt between pango-1.43 and pango-1.44.7 leads to the following horizontal spacing issue:

1.43:
pango-1 43 0

1.44:
pango-1 44 7

The 2nd output is definitely not desired.

@tritonas00
Copy link

Yep, another example with the spacing issue (lxpanel)

Before
before
After
after

@epico
Copy link

epico commented Nov 26, 2019

Just checked the original ProFont bitmap fonts and converted ProFont OpenType fonts with ftdump.

Maybe the ppem value is relevant to this issue.

PCF font:
fixed size
     0: height 12, width 8
        size 11.953, x_ppem 11.953, y_ppem 11.953

OTB font:
fixed size
     2: height 12, width 3
        size 12.000, x_ppem 12.000, y_ppem 12.000

@last-partizan
Copy link

Hey, any news on this?

@khaledhosny
Copy link
Collaborator

There is nothing to fix here in HarfBuzz, it is a Pango issue.

@Ede123
Copy link

Ede123 commented Nov 30, 2019

@khaledhosny Which is/are the relevant Pango issue(s) then?

It seems there are multiple downstream issues that depend on this one so we can't just close it without properly tracking it somewhere else:

So apparently at least @matthiasclasen intended to continue the discussion here...

I don't really have enough insight into harfbuzz/pango/cairo to know where the issues need to be tracked (I hope people with more insight can figure out this part and make sure it's tracked properly). There seem to be at least two blocking issues made visible with pango 1.44 which still have no fix:

  • Different subpixel positioning between pango/harfbuzz (for backends that actually support subpixel positioning) which results in different rendering in pango 1.44.
  • Complete loss of hinting in pango 1.44, which is particularly bad for backends that do not support subpixel positioning at all.

@tritonas00
Copy link

tritonas00 commented Nov 30, 2019

Nothing is going to happen until I have time to get back to it or somebody else starts working on this.

¯\_(ツ)_/¯

and i cant even keep pango downgraded on Arch because programs need 1.44 😟

@Ede123
Copy link

Ede123 commented Nov 30, 2019

It's still held back on MSYS2 because of https://gitlab.gnome.org/GNOME/pango/issues/385.

@khaledhosny
Copy link
Collaborator

@khaledhosny Which is/are the relevant Pango issue(s) then?

It seems there are multiple downstream issues that depend on this one so we can't just close it without properly tracking it somewhere else:

* https://gitlab.gnome.org/GNOME/pango/issues/404#note_575986 suggests the downstream issue should be discussed here (it's still open).

* https://gitlab.gnome.org/GNOME/pango/issues/385#note_583927 also refers to this issue and the downstream issue was even closed in favor of the issue here.

So apparently at least @matthiasclasen intended to continue the discussion here...

The discussion here is already resolved, HarfBuzz is working as intended and there is nothing broken in it to fix.

@madig
Copy link
Contributor

madig commented Dec 1, 2019

I believe the current blocker for forward progress is

#1892 (comment)
[...] getting a cairo release out

? I see some commits by @matthiasclasen about subpixel positioning in https://gitlab.freedesktop.org/cairo/cairo/commits/master that are unreleased. Behdad asked for a new release on the mailing list back in August: https://lists.cairographics.org/archives/cairo/2019-August/028910.html. No one responded.

PalinuroSec added a commit to ParrotSec/debian-installer that referenced this issue Jan 7, 2022
debian-installer (20210731+parrot1) lts-updates; urgency=medium
.
  * Import new Debian release.
  * Update bootloader background.
  * Use choose direct downloads from parrot servers.
  * Bump Linux kernel ABI to 5.15.0-5parrot1.
  * Update preseed.
  * Disable secure boot (we don't support it yet).
  * Use Parrot 5.0 repo.
.
debian-installer (20210731+deb11u2) bullseye; urgency=medium
.
  * Bump Linux kernel ABI to 5.10.0-10.
.
debian-installer (20210731+deb11u1) bullseye; urgency=medium
.
  * Set USE_PROPOSED_UPDATES=1 for the bullseye stable branch.
  * Update USE_UDEBS_FROM default from unstable to bullseye, so that
    users don't have to know about the debian/rules heuristics when
    performing manual, local builds.
  * Bump Linux kernel ABI to 5.10.0-9.
.
debian-installer (20210731) unstable; urgency=medium
.
  [ Cyril Brulebois ]
  * Update translation-status for the release.
.
  [ Steve McIntyre ]
  * Make mini.iso work with UEFI boot
  * Bump Linux kernel ABI to 5.10.0-8
.
debian-installer (20210415) unstable; urgency=medium
.
  [ Shawn Guo ]
  * Build in libinput instead of evdev driver for gtk installer.
.
  [ Steve McIntyre ]
  * Bump Linux kernel ABI to 5.10.0-6
.
  [ Holger Wansing ]
  * Add wireless-regdb-udeb to all Linux arch images (#979104).
  * Correct keyword for bootloader arguments in netboot/xen/debian.cfg
    example file. Closes: #904131
  * Update of debian-internals manual to current development state.
.
  [ Vagrant Cascadian ]
  * [arm64] Add support for puma-rk3399.
  * [arm64] Update to use u-boot-install-sunxi.
  * [armhf] Make hd-media and netboot sdcard images start at offset 32768,
    for compatibility with rockchip platforms.
  * [arm64, armhf] Update SD-card-images sizes for netboot, netboot-gtk and hd-media.
.
  [ Samuel Thibault ]
  * On hurd-i386, mips, and powerpc, add debian-ports-archive-keyring-udeb also
    in the monolithic images for bootstraping from debian-ports' unreleased.
  * Update minimum disk and memory sizes.
  * Makefile: Drop libmachuser/libhurduser manual copy, now fixed in glibc.
  * Makefile: Drop /servers manual creation, now done in hurd-udeb package.
.
  [ Cyril Brulebois ]
  * Update translation-status for the release.
.
debian-installer (20201202) unstable; urgency=medium
.
  [ Cyril Brulebois ]
  * Bump Linux kernel ABI to 5.9.0-4
  * Drop fontconfig tweaks introduced in version 20170828 (See: #873462):
     - Full hinting support was removed upstream, in pango 1.44.
     - Forcing truetype:interpreter-version=35 through FREETYPE_PROPERTIES
       now leads to arguably worse rendering than with default settings.
  * With or without the aforementioned changes, the rendering looks much
    worse than it used to (until Debian Installer Bullseye Alpha 3), due
    to a behavioral change in pango. Since it affects default fonts, and
    not only in the installer's context, one might have hoped for a fix
    at some point but that doesn't seem to be happening. We might try to
    use different fonts to try and dodge this issue… Until then, here
    are some pointers to bugtracker entries:
     - https://bugs.debian.org/956612
     - https://gitlab.gnome.org/GNOME/pango/-/issues/404
     - harfbuzz/harfbuzz#1892
  * Convert doc/devel/anna-install.txt to UTF-8.
  * Clean whitespaces in doc/i18n/ChangeLog, making it UTF-8.
  * Update translation-status for the release.
.
  [ Vagrant Cascadian ]
  * Update Firefly-RK3288 image for new u-boot version.
  * [arm64] Add support for firefly-rk3399, pinebook-pro-rk3399,
    rockpro64-rk3399, rock64-rk3328 and rock-pi-4-rk3399 to u-boot images
    and netboot SD card images.
  * [arm64] Make all netboot sdcard images start at offset 32768, for
    compatibility with rockchip platforms.
.
  [ Lubomir Rintel ]
  * Add OLPC XO-1.75 laptop support. Closes: #949306
.
  [ Aurelien Jarno ]
  * Drop build-dependency on libgcc1. It has been renamed and it is not
    needed since r62791.
  * Add libgcc-s1 to the fake packages list as it doesn't have an udeb just
    like libgcc1. Remove libc* and libnewt0.52 from that list.
  * Install kmod-udeb instead of libkmod2-udeb now that the library and the
    binaries are properly packaged in different udebs.
  * Remove the mklibs library reduction pass. Add a hack to copy
    libgcc_s.so.[124] from the host filesystem as it is not done anymore by
    mklibs. This needs to be replaced by a proper udeb.
  * Add explicit build-depends on fdisk on arm64, amd64 and i386 now that
    util-linux doesn't depend on it anymore.
.
  [ Wookey, Steve McIntyre, Alper Nebi Yasak ]
  * Enable gtk build for arm64
.
  [ Domenico Andreoli ]
  * Add support for NanoPi NEO Air. Closes: #928863
.
  [ Holger Wansing]
  * d-i i18n guide: update for util-linux's eject overtaking.
  * Add Occitan as new language for the installer (thanks to Quentin PAGÈS).
.
  [ Steve McIntyre ]
  * Tweaks for efi-image:
    + Improve sizing calculation to reduce wasted space
    + Include DTB files in the ESP for armhf and arm64 systems. Should
      make U-Boot based systems work better when booting via UEFI
  * Fix build failures related to #940056 "fakeroot does not fake
    statx()". Don't use "ls" to check if /dev/console is a character
    device, instead use "file". Thanks to JH Chatenet for helping to
    debug this.
.
  [ Samuel Thibault ]
  * Copy over libmach/hurduser, until the fixed glibc is installed.
  * Fix monolithic hurd build by excluding more packages.
.
  [ Jessica Clarke ]
  * kfreebsd: Update to use debian-ports-archive-keyring.
  * kfreebsd: Don't try to build build_cdrom_gtk on kfreebsd-i386.
.
  [ Julien Cristau ]
  * Add grub2 to built-using (closes: #968998).
.
  [ Ben Hutchings ]
  * Add wireless-regdb-udeb to Linux builds that include nic-wireless-modules
.
  [ Alper Nebi Yasak ]
  * Include a /gtk/initrd.gz in graphical arm mini.iso builds
  * Include fb-modules in non-gtk arm64 cdrom builds as well
  * Build concatenateable images for arm64 netboot-gtk
.
  [ John Paul Adrian Glaubitz ]
  * powerpc: Add cdrom-core-modules and isofs-modules to cdrom pkg-lists
  * ppc64: Add cdrom-core-modules and isofs-modules to cdrom pkg-lists
chearon added a commit to chearon/node-canvas that referenced this issue Jan 2, 2023
Text renders wider or narrower, as if letter-spacing is set, than
it should with newer versions of Pango.

My best understanding of this problem is that around version 1.43
Pango dropped support for subpixel antialiasing because it
switched to Harbuzz for glyph postions instead of Freetype.
For some reason it still rounds the glyph positions by default.

There's no need for node-canvas to support subpixel antialiasing.
The maintainers of the Linux font stack (Behdad and Matthias) have
stated that they wont, and it's subjective, and node-canvas cannot
make any assumptions about DPI anyways.

Reading (warning: lots of drama to wade through):
- https://gitlab.gnome.org/GNOME/pango/-/issues/404
- https://gitlab.gnome.org/GNOME/pango/-/issues/463
- harfbuzz/harfbuzz#1892
- harfbuzz/harfbuzz#2394
chearon added a commit to Automattic/node-canvas that referenced this issue Jan 2, 2023
Text renders wider or narrower, as if letter-spacing is set, than
it should with newer versions of Pango.

My best understanding of this problem is that around version 1.43
Pango dropped support for subpixel antialiasing because it
switched to Harbuzz for glyph postions instead of Freetype.
For some reason it still rounds the glyph positions by default.

There's no need for node-canvas to support subpixel antialiasing.
The maintainers of the Linux font stack (Behdad and Matthias) have
stated that they wont, and it's subjective, and node-canvas cannot
make any assumptions about DPI anyways.

Reading (warning: lots of drama to wade through):
- https://gitlab.gnome.org/GNOME/pango/-/issues/404
- https://gitlab.gnome.org/GNOME/pango/-/issues/463
- harfbuzz/harfbuzz#1892
- harfbuzz/harfbuzz#2394
chearon added a commit to Automattic/node-canvas that referenced this issue Jan 2, 2023
Text renders wider or narrower, as if letter-spacing is set, than
it should with newer versions of Pango.

My best understanding of this problem is that around version 1.43
Pango dropped support for font hinting because it switched to
Harbuzz for glyph postions instead of Freetype. For some reason it
still rounds the glyph positions by default.

There's no need for node-canvas to support font hinting. The
maintainers of the Linux font stack (Behdad and Matthias) have
stated that they wont, and font hinting is subjective, and
browsers have moved to subpixel positioning too.

Reading (warning: lots of drama to wade through):
- https://gitlab.gnome.org/GNOME/pango/-/issues/404
- https://gitlab.gnome.org/GNOME/pango/-/issues/463
- harfbuzz/harfbuzz#1892
- harfbuzz/harfbuzz#2394
chearon added a commit to Automattic/node-canvas that referenced this issue Jan 2, 2023
Text renders wider or narrower, as if letter-spacing is set, than
it should with newer versions of Pango.

My best understanding of this problem is that around version 1.43
Pango dropped support for font hinting because it switched to
Harbuzz for glyph postions instead of Freetype. For some reason it
still rounds the glyph positions by default.

There's no need for node-canvas to support font hinting. The
maintainers of the Linux font stack (Behdad and Matthias) have
stated that they wont, and font hinting is subjective, and
browsers have moved to subpixel positioning too.

Reading (warning: lots of drama to wade through):
- https://gitlab.gnome.org/GNOME/pango/-/issues/404
- https://gitlab.gnome.org/GNOME/pango/-/issues/463
- harfbuzz/harfbuzz#1892
- harfbuzz/harfbuzz#2394
chearon added a commit to Automattic/node-canvas that referenced this issue Jan 3, 2023
Text renders wider or narrower, as if letter-spacing is set, than
it should with newer versions of Pango.

My best understanding of this problem is that around version 1.43
Pango dropped support for font hinting because it switched to
Harbuzz for glyph postions instead of Freetype. For some reason it
still rounds the glyph positions by default.

There's no need for node-canvas to support font hinting. The
maintainers of the Linux font stack (Behdad and Matthias) have
stated that they wont, and font hinting is subjective, and
browsers have moved to subpixel positioning too.

Reading (warning: lots of drama to wade through):
- https://gitlab.gnome.org/GNOME/pango/-/issues/404
- https://gitlab.gnome.org/GNOME/pango/-/issues/463
- harfbuzz/harfbuzz#1892
- harfbuzz/harfbuzz#2394
zbjornson pushed a commit to Automattic/node-canvas that referenced this issue Jan 4, 2023
Text renders wider or narrower, as if letter-spacing is set, than
it should with newer versions of Pango.

My best understanding of this problem is that around version 1.43
Pango dropped support for font hinting because it switched to
Harbuzz for glyph postions instead of Freetype. For some reason it
still rounds the glyph positions by default.

There's no need for node-canvas to support font hinting. The
maintainers of the Linux font stack (Behdad and Matthias) have
stated that they wont, and font hinting is subjective, and
browsers have moved to subpixel positioning too.

Reading (warning: lots of drama to wade through):
- https://gitlab.gnome.org/GNOME/pango/-/issues/404
- https://gitlab.gnome.org/GNOME/pango/-/issues/463
- harfbuzz/harfbuzz#1892
- harfbuzz/harfbuzz#2394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests