Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 728308 - x11-apps/fonttosfnt: fonts spacing issues
Summary: x11-apps/fonttosfnt: fonts spacing issues
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo X packagers
URL: https://gitlab.freedesktop.org/xorg/a...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-06-15 01:23 UTC by Alexander Tsoy
Modified: 2020-11-03 03:51 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
bad.png (bad.png,1.16 KB, image/png)
2020-06-15 01:24 UTC, Alexander Tsoy
Details
good.png (good.png,1.13 KB, image/png)
2020-06-15 01:25 UTC, Alexander Tsoy
Details
terminus-font-4.48-r1.ebuild.patch (terminus-font-4.48-r1.ebuild.patch,866 bytes, text/plain)
2020-06-15 22:15 UTC, Alexander Tsoy
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Tsoy 2020-06-15 01:23:10 UTC
fonttosfnt incorrectly calculates some metrics, which causes fonts spacing issues. This can be reproduced with x11-libs/pango-1.44* + media-fonts/terminus-font-4.48-r1[otf]. See attached screenshots.

The fix is available, but not merged yet:
https://gitlab.freedesktop.org/xorg/app/fonttosfnt/-/merge_requests/7
Comment 1 Alexander Tsoy 2020-06-15 01:24:01 UTC
Created attachment 644766 [details]
bad.png
Comment 2 Alexander Tsoy 2020-06-15 01:25:12 UTC
Created attachment 644768 [details]
good.png

This is after applying patches from MR and rebuilding terminus-font.
Comment 3 Alexander Tsoy 2020-06-15 01:35:04 UTC
Forgot to add that this is with font size 12. Other sizes may not be affected.
https://bugzilla.redhat.com/show_bug.cgi?id=1753295#c92
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2020-06-15 07:44:49 UTC
Also https://gitlab.gnome.org/GNOME/pango/-/issues/386#note_567758 coaims something was fixed in cairo master. Don't know if gentoo/upstream has it in 1.16.0.
Comment 5 Sergei Trofimovich (RETIRED) gentoo-dev 2020-06-15 21:19:20 UTC
I also asked Dimitar (Terminus fonts author) over email if it's expected for Terminus to have artifacts like that in a way we convert terminus.

    Tl;DR: yes, it's expected and we can somewhat improve our conversion logic.

Pasting Dimitar's explanation:

"""
...
> Linux GUI font rendering libraries like pango are moving away from
> freetype to harfbuzz. One of the side-effects is that pango stops
> loading bitmap fonts in non-OpenType format:
>      https://gitlab.gnome.org/GNOME/pango/-/issues/386
>      https://bugzilla.redhat.com/show_bug.cgi?id=1753295  

[...]

What is even worse, Pango 1.44 now returns floating point ascent and 
descent, instead of integer. The functions were always returning float, 
all right... but so far, without a fractional part. Which makes problems 
too, for example in Scintilla based editors such as SciTE and Geany 
(there is a quick and dirty fix).

[...]

> Currently Gentoo follows Fedora's suggestion and converts BDF to
> OpenType as:
>     $ fonttosfnt -v -b -c -g 2 -m 2 -o Terminus.otb      ter-u*n.bdf
>     $ fonttosfnt -v -b -c -g 2 -m 2 -o Terminus-Bold.otb ter-u*b.bdf
> Done in https://bugs.gentoo.org/717206
> Fedora's suggestion: https://fedoraproject.org/wiki/BitmapFontConversion#Steps
>
> People report that fonttosfnt does not do a perfect job at that
> and introduces unexpected spacing in some applications (gvim?):
>      https://bugs.gentoo.org/728308  

1. fonttosfnt adds 0.5 to at least the logical (OpenType-scaled) 
character width, ascent and height. Haven't checked the physical (pixel) 
metrics yet. With some sizes/applications, the fonttosfnt converted 
fonts do indeed have extra wrong spacing, 1 pixel horizontal or 
vertical. It has other bugs too, but they don't seem important.

2. If you pack 2+ terminus sizes into a single .otb font file, KDE will 
(may? YMMV) use *only the first size*.

3. OTB has a single set of logical metrics. So, for example, the logical 
character width (which is relative to height) can never be correct for 
an .otb file including both 8x14 and 8x16.

[...]

> I'm not sure if it's an effect of application/harfbuzz bug (or
> user misconfiguration, like extra hinting).  

fonttosfnt bug(s) plus Pango returning floating point metrics.

[...]

> Q 2. Would it be feasible for terminus package to also provide fonts in
>         OpenType format?  (Worth adding to the F.A.Q?)  

Well I'll have to release OTB-s sooner or later. So yes.

> Q 3. What is the best way to convert terminus to OpenType container
>         format today? Does 'fonttosfnt' do something sensible? [...]

For each source file:

fontforge -lang=ff -c "Open($1); ScaleToEm(1024); Generate($2)" 
source.bdf target.otb

1024 may or may not avoid Pango fractioning, don't know for sure.
But it should be better that the default EM-s of FontForge (1000) and 
fonttosfnt (2048).

For (non-terminus) Italic/Oblique fonts, insert "SetItalicAngle(...);" 
after ScaleToEm.
"""

I'll try the 'fontforge' conversion suggested by Dimitar on terminus. Quite a heavyweight dependency. Let's see if it gets better.
Comment 6 Alexander Tsoy 2020-06-15 21:37:13 UTC
(In reply to Sergei Trofimovich from comment #5)
> 1. fonttosfnt adds 0.5 to at least the logical (OpenType-scaled) 
> character width, ascent and height. Haven't checked the physical (pixel) 
> metrics yet. With some sizes/applications, the fonttosfnt converted 
> fonts do indeed have extra wrong spacing, 1 pixel horizontal or 
> vertical. It has other bugs too, but they don't seem important.
This should be fixed by the MR I mentioned in comment 0
Comment 7 Larry the Git Cow gentoo-dev 2020-06-15 22:04:50 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=98a92c85d431a70f660f9dbd43b148e7c2afae2f

commit 98a92c85d431a70f660f9dbd43b148e7c2afae2f
Author:     Sergei Trofimovich <slyfox@gentoo.org>
AuthorDate: 2020-06-15 22:03:31 +0000
Commit:     Sergei Trofimovich <slyfox@gentoo.org>
CommitDate: 2020-06-15 22:04:44 +0000

    media-fonts/terminus-font: use fontforge for rescaling
    
    We tackle a few issues at once here:
    
    1. Avoid 'fonttosfnt' when converting to .otb and use fontforge instead.
    2. Use one .otb file per font
    3. Attempt to avoid Pango's fractioning by using 1024 em
    
    Reported-by: Alexander Tsoy
    Bug: https://bugs.gentoo.org/728308
    Package-Manager: Portage-2.3.101, Repoman-2.3.22
    Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>

 .../terminus-font/terminus-font-4.48-r2.ebuild     | 128 +++++++++++++++++++++
 1 file changed, 128 insertions(+)
Comment 8 Sergei Trofimovich (RETIRED) gentoo-dev 2020-06-15 22:06:04 UTC
(In reply to Larry the Git Cow from comment #7)
> The bug has been referenced in the following commit(s):
> 
> https://gitweb.gentoo.org/repo/gentoo.git/commit/
> ?id=98a92c85d431a70f660f9dbd43b148e7c2afae2f
> 
> commit 98a92c85d431a70f660f9dbd43b148e7c2afae2f
> Author:     Sergei Trofimovich <slyfox@gentoo.org>
> AuthorDate: 2020-06-15 22:03:31 +0000
> Commit:     Sergei Trofimovich <slyfox@gentoo.org>
> CommitDate: 2020-06-15 22:04:44 +0000
> 
>     media-fonts/terminus-font: use fontforge for rescaling
>     
>     We tackle a few issues at once here:
>     
>     1. Avoid 'fonttosfnt' when converting to .otb and use fontforge instead.
>     2. Use one .otb file per font
>     3. Attempt to avoid Pango's fractioning by using 1024 em
>     
>     Reported-by: Alexander Tsoy
>     Bug: https://bugs.gentoo.org/728308
>     Package-Manager: Portage-2.3.101, Repoman-2.3.22
>     Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
> 
>  .../terminus-font/terminus-font-4.48-r2.ebuild     | 128

Alexander, can you give 4.48-r2 a try? I wonder if it changes anything for you.
Comment 9 Alexander Tsoy 2020-06-15 22:15:14 UTC
Created attachment 644936 [details]
terminus-font-4.48-r1.ebuild.patch

Attached patch fixed the issue for me.
Comment 10 Alexander Tsoy 2020-06-15 22:16:37 UTC
(In reply to Sergei Trofimovich from comment #8)
> Alexander, can you give 4.48-r2 a try? I wonder if it changes anything for
> you.
Ooops, I missed new replies in this bug. =/ I'll give it a try shortly,
Comment 11 Alexander Tsoy 2020-06-15 22:19:58 UTC
(In reply to Alexander Tsoy from comment #9)
> Created attachment 644936 [details]
> terminus-font-4.48-r1.ebuild.patch
> 
> Attached patch fixed the issue for me.
But it still needs patched fonttosfnt, of course.
Comment 12 Alexander Tsoy 2020-06-15 22:32:18 UTC
(In reply to Sergei Trofimovich from comment #8)
> Alexander, can you give 4.48-r2 a try? I wonder if it changes anything for
> you.
It works for me. Thanks!
Comment 13 Matt Turner gentoo-dev 2020-11-03 03:51:18 UTC
Should be in x11-apps/fonttosfnt-1.2.0.