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

horizontal font extent disagreements between ft/ot funcs for mongolian/phags pa. #1262

Closed
HinTak opened this issue Oct 17, 2018 · 15 comments
Closed

Comments

@HinTak
Copy link
Contributor

HinTak commented Oct 17, 2018

The font extents reported by the ft/ot versions don't agree:

db3fff0f1319dbf4c5bd06b549c98775 monbaiti.ttf

ft:

ascender/descender/line_gap= 1792 -512 64
h ascender/descender/line_gap= 1792 -512 64

ot:

ascender/descender/line_gap= 1729 -449 184
h ascender/descender/line_gap= 1729 -449 184
e06492ecfcdc5990647fb2c4058778f5  phagspa.ttf

ft:

ascender/descender/line_gap= 2176 -512 -64
h ascender/descender/line_gap= 2176 -512 -64

ot:

ascender/descender/line_gap= 2138 -482 0
h ascender/descender/line_gap= 2138 -482 0

In both of these cases, hb-view seems to be using the ot numbers, although I cannot seem to find out where it switches. At line 690 of util/options.cc, it defaults to the first entry, which is ft if harfbuzz can find freetype.

    set_font_funcs = supported_font_funcs[0].func;
@HinTak
Copy link
Contributor Author

HinTak commented Oct 17, 2018

Supposedly both get the values from hhea. I decompiled the hhea table from the first font, and the ot values are there. So somehow the ft version is returns values not from hhea.

@HinTak
Copy link
Contributor Author

HinTak commented Oct 17, 2018

It appeared the FT values has been moved down or up to the next multiple of 64

@behdad
Copy link
Member

behdad commented Oct 17, 2018

Yeah this is a known issue. I thought we didn't hinting and that should do it. Are you testing with recent FreeType?

@HinTak
Copy link
Contributor Author

HinTak commented Oct 17, 2018

I am using ft 2.9.1 (the current latest release).

Were you asking if I am testing against freetype git head? I am staying off freetype git head until GSoC wrapped up and settling, I think.

@khaledhosny
Copy link
Collaborator

Check the OS/2 table, it is possible that FreeType or HarfBuzz is reading the values from it rather than from hhea. Last I checked, FreeType had some heuristics to decide which table and which set of values to use, not sure of OT functions use the same heuristics or any at all.

@HinTak
Copy link
Contributor Author

HinTak commented Oct 17, 2018

I looked at the FreeType side - it is supposedly hhea then OS/2. The values look like they were clipped to one direction to multiple of 64, so I am inclined to think Behdad is right in saying it is probably some sort of hinting, or "fit to grid" issue somewhere.

@behdad
Copy link
Member

behdad commented Oct 17, 2018

In both of these cases, hb-view seems to be using the ot numbers, although I cannot seem to find out where it switches.

hb-view uses cairo's numbers, which are proper numbers, not hacked-up use of FreeType.

@behdad
Copy link
Member

behdad commented Oct 17, 2018

I looked at the FreeType side - it is supposedly hhea then OS/2. The values look like they were clipped to one direction to multiple of 64, so I am inclined to think Behdad is right in saying it is probably some sort of hinting, or "fit to grid" issue somewhere.

Yeah, I'm certain that's what's happening. Never figured out why even though we turn all hinting off. Maybe FreeType always rounds font extents?

@lemzwerg

@HinTak
Copy link
Contributor Author

HinTak commented Oct 30, 2018

The two sets of font extent functions also do wildly different things for ukai from freedesktop.org .

@behdad
Copy link
Member

behdad commented Oct 30, 2018

The two sets of font extent functions also do wildly different things for ukai from freedesktop.org .

Care to paste numbers? And link to font?!

@KrasnayaPloshchad
Copy link

The links to font are available here:
https://www.freedesktop.org/wiki/Software/CJKUnifonts/Download/
However all download links were no longer works. But I saw ReactOS Forum has a topic for this, so I think you are able to get and test:
https://www.reactos.org/forum/viewtopic.php?f=30&t=15793&sid=5859b3899e47ddf36b0ab0f9f82759ad

HinTak added a commit to HinTak/harfbuzz that referenced this issue Nov 7, 2018
See freetype/src/base/ftobjs.c:ft_recompute_scaled_metrics() and
the usage of GRID_FIT_METRICS inside.

Fixes harfbuzz#1262
@HinTak
Copy link
Contributor Author

HinTak commented Nov 7, 2018

@behdad : heehee, I found that you were in the last discussion about metrics rounding in freetype in 2006 and its effect on pango. You just forgot :-). It is #327852 on Gnome Bugzilla.

If you pull

#1363

You can close this.

@lemzwerg
Copy link
Contributor

lemzwerg commented Nov 7, 2018

Since the issue obviously caused confusion it's probably necessary to improve FreeType's documentation. Any patches are highly welcomed!

@HinTak
Copy link
Contributor Author

HinTak commented Nov 7, 2018

The issue is just that harfbuzz does not consider entities as F26.6's. It sets FT_Char_Size to (F26.6) upem and hopes mistakenly that everything is then in upem. Some FT values are rounded to whole pixels in F26.6. Back in 2006 somebody wanted those numbers in fractional pixels. Pango broke, and it was reverted back to rounding to whole pixels. I suppose FT documentation could emphasize that some numbers are in whole pixels in F26.6 ... I'll think about where that can go.

@HinTak
Copy link
Contributor Author

HinTak commented Nov 7, 2018

The FT documentation did say they are rounded. Also src/hb-ft.cc near the top mentions that harfbuzz is abusing this... ... such that no rounding etc happens was a wrong assumption:


 *   - FreeType works in 26.6 mode.  Clients can decide to use that mode, and everything
 *     would work fine.  However, we also abuse this API for performing in font-space,
 *     but don't pass the correct flags to FreeType.  We just abuse the no-hinting mode
 *     for that, such that no rounding etc happens.  As such, we don't set ppem, and
 *     pass NO_HINTING as load_flags.  Would be much better to use NO_SCALE, and scale
 *     ourselves.

I'd say just pull #1363 and be done.

behdad pushed a commit that referenced this issue Nov 7, 2018
* Use non-GRID-fitted values for metrics

See freetype/src/base/ftobjs.c:ft_recompute_scaled_metrics() and
the usage of GRID_FIT_METRICS inside.

Fixes #1262

* Update hb-ft.cc
ebraminio pushed a commit to ebraminio/harfbuzz that referenced this issue Nov 24, 2018
* Use non-GRID-fitted values for metrics

See freetype/src/base/ftobjs.c:ft_recompute_scaled_metrics() and
the usage of GRID_FIT_METRICS inside.

Fixes harfbuzz#1262

* Update hb-ft.cc
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

5 participants