GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Apply hinting factor rcParam in all cases. by QuLogic · Pull Request #9481 · matplotlib/matplotlib

Conversation

@QuLogic

@QuLogic QuLogic commented Oct 19, 2017

Copy link
Copy Markdown
Member

This is only explicitly used in Agg, so any other users get the default in the C++ code. Thus if you modify this setting and use some other backend, you get very weird behaviour. Positioning sometimes breaks and glyphs are shrunk or cropped.

@anntzer this is why just changing a random hinting_factor produced super-weird results yesterday.

Don't know if it's worth backporting; I guess no-one ever tried modifying this setting or they would have complained. Also, trying to see if a simple test of some sort can be done.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • [N/A] New features are documented, with examples if plot related
  • [N/A] Documentation is sphinx and numpydoc compliant
  • [N/A] 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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@QuLogic
Apply hinting factor rcParam in all cases.
0f4d99e
This is only explicitly used in Agg, so any other users get the default
in the C++ code. Thus if you modify this setting and use some other
backend, you get very weird behaviour. Positioning sometimes breaks and
glyphs are shrunk or cropped.
anntzer
anntzer previously approved these changes Oct 19, 2017
View reviewed changes

@anntzer anntzer left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

conditional on CI

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@QuLogic

QuLogic commented Oct 19, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Hmm, something might still be cached somewhere as changing the hinting factor in the middle of a script causes all text to be the wrong width.

for hinting_factor in map(int, sys.argv[1:]):
    plt.rcParams['text.hinting_factor'] = hinting_factor
    fig, ax = plt.subplots()
    ax.text(0.5, 0.5, 'text')
    plt.show()

Opens figures with progressively smaller text (or wider depending on what you specify), but it's fine if you specify anything other than 8 in a separate run.

As an example of something this PR does fix, if you add a fig.savefig('test.svg') before show (to switch backends), you get broken text for anything other than 8 on master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

dopplershift
dopplershift approved these changes Oct 19, 2017
View reviewed changes
@anntzer

anntzer commented Oct 19, 2017

Copy link
Copy Markdown
Contributor

@QuLogic but I guess that caching was already present before, in which case this PR does not really make things worse, does it?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic

QuLogic commented Oct 19, 2017

Copy link
Copy Markdown
Member Author

@anntzer True, it just makes it more difficult to write a test.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer dismissed their stale review October 19, 2017 22:25

let me investigate the caching first...

@QuLogic
Un-static-ify FreeType font transforms.
cd37119
Static initializers are only applied the first time, so any subsequent
calls with alternate hinting_factor would use the first value. FreeType
copies the matrix values into an internal structure, so these do not
really need to be static.
@QuLogic

QuLogic commented Oct 20, 2017 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

I think that should fix the caching issue, and it even fixes the SVG+Agg save from above, without the first change. I guess the first change can still go in for consistency.

But thinking about it, SVG and PDF render text externally, so it may be better to have those use hinting_factor=1 since that's the most likely method to be used by external renderers. Maybe can discuss that in a separate issue where we also might decide to turn it off entirely.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented Oct 20, 2017

Copy link
Copy Markdown
Contributor

Ah, the static was tricky...
I would favor moving the discussion of entirely dropping hinting_factor (which I agree with) to a separate issue, not clear there's much gain of doing so in a piecemeal fashion.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented Oct 20, 2017

Copy link
Copy Markdown
Contributor

test failures look real though

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@QuLogic
QuLogic force-pushed the fix-hinting-factor branch 3 times, most recently from b61fbd7 to df5558c Compare October 21, 2017 08:54
@QuLogic
Add tests that hinting_factor works.
6a685d2
@QuLogic
QuLogic force-pushed the fix-hinting-factor branch from df5558c to 6a685d2 Compare October 21, 2017 09:23
@QuLogic

QuLogic commented Oct 22, 2017

Copy link
Copy Markdown
Member Author

Not sure why I needed the clear and set_size as I thought the same stuff is done in the constructor, but it matches what's done in normal rendering code and it works, so...

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Kojoley
Kojoley reviewed Oct 28, 2017
View reviewed changes
Comment thread lib/matplotlib/font_manager.py
def get_font(filename, hinting_factor=None):
if hinting_factor is None:
hinting_factor = rcParams['text.hinting_factor']
return _get_font(filename, hinting_factor)

@Kojoley Kojoley Oct 28, 2017

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Is not it equals to?

@lru_cache(64)
def get_font(filename, hinting_factor=None):
    if hinting_factor is None:
        hinting_factor = rcParams['text.hinting_factor']
    return ft2font.FT2Font(filename, hinting_factor)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@QuLogic QuLogic Oct 29, 2017

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That would cache hinting_factor=None with whatever the value of the rcParam was at first call.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tacaswell tacaswell added this to the v2.2 milestone Oct 29, 2017
@QuLogic QuLogic mentioned this pull request Nov 4, 2017
Determine if hinting_factor setting can be dropped #9681
Closed
@anntzer

anntzer commented Nov 4, 2017

Copy link
Copy Markdown
Contributor

thanks

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer merged commit b2bbbfd into matplotlib:master Nov 4, 2017
@QuLogic
QuLogic deleted the fix-hinting-factor branch November 4, 2017 23:26
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Kojoley Kojoley Kojoley left review comments
@dopplershift dopplershift dopplershift approved these changes
@anntzer anntzer anntzer left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v2.2.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@QuLogic @anntzer @dopplershift @Kojoley @tacaswell
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.