Visitar URL original
Use harfbuzz for text layout (proof of concept). by anntzer · Pull Request #14912 · matplotlib/matplotlib · GitHub
The Wayback Machine - https://web.archive.org/web/20260106143418/https://github.com/matplotlib/matplotlib/pull/14912
Skip to content

Conversation

@anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 29, 2019

Support languages requiring complex text layout, e.g. Arabic, Hebrew,
Indic scripts, etc.

Nearly all test images will need to be regenerated. Probably
hinting_factor should be killed at the same time. Alternatively the old
code path could be left just for the purposes of testing and things
could be rcParam-switchable.

For vector output, the functionality implemented here in C will need to
be exposed in Python _text_layout::layout.

Doesn't support bidi (mixed left-to-right and right-to-left) mostly
because the main bidi library (fribidi) is LGPL.

Needs docs.

Test with e.g.

figtext(.5, .5, "العَرَبِيَّة‎")

(I don't speak any of these languages, this is just copy-pasted from
Wikipedia :))

Note that this should improve kerning even for latin-script languages
(even after fixing bugs currently present), because FreeType is unable
to read kerning info for some modern fonts. See notes about 'kern' and
'GPOS' at https://www.freetype.org/freetype2/docs/glyphs/glyphs-4.html.

Closes #5941 and its duplicates (e.g. #8765), #14887.

Mostly needs to decide whether we want to add that dependency...

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Support languages requiring complex text layout, e.g. Arabic, Hebrew,
Indic scripts, etc.

Nearly all test images will need to be regenerated.  Probably
hinting_factor should be killed at the same time.  Alternatively the old
code path could be left just for the purposes of testing and things
could be rcParam-switchable.

For vector output, the functionality implemented here in C will need to
be exposed in Python _text_layout::layout.

Doesn't support bidi (mixed left-to-right and right-to-left) mostly
because the main bidi library (fribidi) is LGPL.

Needs docs.

Test with e.g.
```
figtext(.5, .5, "العَرَبِيَّة‎")
```
(I don't speak any of these languages, this is just copy-pasted from
Wikipedia :))

Note that this should improve kerning even for latin-script languages
(even after fixing bugs currently present), because FreeType is unable
to read kerning info for some modern fonts.  See notes about 'kern' and
'GPOS' at https://www.freetype.org/freetype2/docs/glyphs/glyphs-4.html.
@jklymak
Copy link
Member

jklymak commented Jul 29, 2019

So freetype calls harfbuzz a higher level library. Does that mean it’s here to stay? Would hate for us to depend on a project that is ephemeral.

@jklymak
Copy link
Member

jklymak commented Jul 29, 2019

I guess it’s used by enough big-name projects. https://en.m.wikipedia.org/wiki/HarfBuzz

@anntzer
Copy link
Contributor Author

anntzer commented Jul 29, 2019

I believe it's a very well established project. It's also packaged by conda-forge (https://anaconda.org/conda-forge/harfbuzz) -- realizing this was what made me actually write the PR as this makes it actually realistic to adopt it as a dependency, otherwise I wouldn't even have bothered.

@jklymak
Copy link
Member

jklymak commented Jul 29, 2019

I think we should definitely be willing to re-do the test images if there is a reasonable plus side.

@tacaswell tacaswell added this to the v3.3.0 milestone Jul 29, 2019
@tacaswell
Copy link
Member

I think this is worth looking into more.

@QuLogic
Copy link
Member

QuLogic commented Jul 29, 2019

Any idea how many test images need regenerating? For example, the hinting factor fix is about 1100 of them.
If we're regenerating all of them, it'd be nice to bump bundled FreeType, too.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 29, 2019

Basically all of them -- because the kerning of "0.0"/"1.0" changes (despite the use of hinting_factor=8). I guess this may have something to do with different data in kern and GPOS tables.

In the actual PR I will probably keep the old code around and switch to harfbuzz if e.g. hinting_factor=0 (or some other controlling rcParam), at least until we come up with a reasonable approach (if ever) for the baseline images problem.

@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 2, 2020
@jklymak jklymak marked this pull request as draft July 23, 2020 16:07
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 21, 2021
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Aug 23, 2021
@timhoffm timhoffm modified the milestones: v3.6.0, unassigned Apr 30, 2022
@anntzer
Copy link
Contributor Author

anntzer commented Jun 26, 2022

Ah, I just noticed that there is actually a harfbuzz cython binding on PyPI (uharfbuzz, AFAICT from the harfbuzz team itself), which importantly provides wheels for all three major OSes (https://pypi.org/project/uharfbuzz/#files), which suggests that the problem of packaging and shipping the C-library has been solved there (I haven't actually checked their approach, though).

@tacaswell
Copy link
Member

@story645 story645 modified the milestones: unassigned, needs sorting Oct 6, 2022
@github-actions
Copy link

Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Jun 23, 2023
@anntzer
Copy link
Contributor Author

anntzer commented Jun 23, 2023

I think everyone got the idea.

@anntzer anntzer closed this Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better document how to set font

6 participants