Skip to content

Unify text layout paths. #14872

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

Merged
merged 2 commits into from
Jul 25, 2019
Merged

Unify text layout paths. #14872

merged 2 commits into from
Jul 25, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jul 23, 2019

PR Summary

... i.e. the logic for advancing one character at a time, positioning
that character and taking kerning between consecutive characters into
account.

Such a factoring would also be useful if we ever get to use a text
layout engine that supports right-to-left languages (we'd just need to
fix layout (and the C-version used by agg)).

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

gind = font.get_char_index(ccode)
for char_idx, newx in _text_layout.layout(
chunk, font, x0=newx, kern_mode=KERNING_UNFITTED):

if mode == 2 and chunk_type == 2:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this section, the newx would originally not use kerning, while it would with this new layout, no? I'm surprised there are no errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous version did use kerning, per newx += kern / 64 + glyph.linearHoriAdvance / 65536

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot it's only used for intra-character adjustments, so it would take effect after the character at play.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, coming back to this again, the new code applies kerning of this-and-last character before yielding, whereas the PDF backend here applies kerning of this-and-last character after using the position (newx) it's found. This seems like a bug in the original, though...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just rewrote the whole thing in #14886...

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS, the code is doing the same as before. Event though, admittedly, I don't fully understand the details of font handling.

... i.e. the logic for advancing one character at a time, positioning
that character and taking kerning between consecutive characters into
account.

Such a factoring would also be useful if we ever get to use a text
layout engine that supports right-to-left languages (we'd just need to
fix `layout` (and the C-version used by agg)).
@QuLogic QuLogic added this to the v3.2.0 milestone Jul 25, 2019
@anntzer
Copy link
Contributor Author

anntzer commented Jul 25, 2019

Actually looking at it again I think the new version for pdf fails to take inter-chunk kerning into account :-( (probably this was never tested) If you agree with that analysis, I'll just revert the changes to backend_pdf for now.

@QuLogic
Copy link
Member

QuLogic commented Jul 25, 2019

lastgind is reset here before every chunk, isn't it (i.e., no inter-chunk kerning)?

@anntzer
Copy link
Contributor Author

anntzer commented Jul 25, 2019

Ah, ok, so it's not worse than before...

@QuLogic
Copy link
Member

QuLogic commented Jul 25, 2019

Maybe open a separate issue for that, then?

@anntzer
Copy link
Contributor Author

anntzer commented Jul 25, 2019

working on fixing that, but that'll be a separate pr

@QuLogic
Copy link
Member

QuLogic commented Jul 25, 2019

Ugh, and there's no coverage link again.

@anntzer
Copy link
Contributor Author

anntzer commented Jul 25, 2019

For some reason codecov very often fails to upload coverage for my PRs (even though they're done, here it's at https://codecov.io/gh/matplotlib/matplotlib/pull/14872), do you have any possible idea why?

@QuLogic
Copy link
Member

QuLogic commented Jul 25, 2019

If you look at the commit, it says it's still waiting for CI, though it's received all the CI notifications that it would have on a working build. I pushed the button to send notifications, so maybe it'll show up now.

@QuLogic QuLogic merged commit eb6664f into matplotlib:master Jul 25, 2019
@anntzer anntzer deleted the text_layout branch July 25, 2019 20:41
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.

3 participants