Skip to content

Deprecate setting text kerning factor to any non-None value #30322

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

Open
wants to merge 1 commit into
base: text-overhaul
Choose a base branch
from

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 17, 2025

PR summary

This factor existed only to preserve test images, but as of #29816, it is set to 0 (i.e., disabled and providing default behaviour). In the future, with libraqm, it will have no effect no matter its setting (because we won't be applying kerning ourselves at all.)

Since we seem to have removed most of the rcParam deprecation machinery, instead of warning from there, warn from the FT2Font constructor, which is always passed _kerning_factor in the normal code path (i.e., anywhere outside of direct tests.) This does mean the warning won't occur directly where you set it, nor if you don't use any text, but I think that's a reasonable compromise.

PR checklist

@QuLogic QuLogic added this to the v3.11.0 milestone Jul 17, 2025
@github-actions github-actions bot added topic: rcparams topic: text/fonts Documentation: user guide files in galleries/users_explain or doc/users labels Jul 17, 2025
@QuLogic QuLogic force-pushed the deprecate-kerning branch 2 times, most recently from 76132af to 30280d0 Compare July 17, 2025 01:27
Comment on lines -61 to -71
.. plot::

import matplotlib.pyplot as plt

# Use old kerning values:
plt.rcParams['text.kerning_factor'] = 6
fig, ax = plt.subplots()
ax.text(0.0, 0.05, 'BRAVO\nAWKWARD\nVAT\nW.Test', fontsize=56)
ax.set_title('Before (text.kerning_factor = 6)')

Note how the spacing between characters is uniform between their bounding boxes
Copy link
Member Author

Choose a reason for hiding this comment

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

I decided to remove this plot from the old what's new, as it will no longer show any difference between it and the plot below (with the correct results) once we switch to libraqm, and so it might be misleading.

@@ -188,7 +191,7 @@ def test_ft2font_clear():

def test_ft2font_set_size():
file = fm.findfont('DejaVu Sans')
font = ft2font.FT2Font(file, hinting_factor=1, _kerning_factor=1)
Copy link
Member Author

Choose a reason for hiding this comment

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

This being 1 seems to have been a typo. Since the test checks relative results, it made no difference here.

@github-project-automation github-project-automation bot moved this to Waiting for other PR in Font and text overhaul Jul 17, 2025
@QuLogic QuLogic moved this from Waiting for other PR to Ready for Review in Font and text overhaul Jul 17, 2025
@timhoffm
Copy link
Member

The rcParams depreciation machinery was removed per #29563. But you can still dreprecate rcParams if you want to

just write custom deprecation logic into setitem/getitem and add corresponding tests whenever we want to deprecate a rcparam...

@QuLogic QuLogic force-pushed the deprecate-kerning branch from 30280d0 to 99d357f Compare July 17, 2025 05:36
@QuLogic
Copy link
Member Author

QuLogic commented Jul 17, 2025

OK, I've added a deprecation for the rcParam directly, then.


Due to internal changes to support complex text rendering, the kerning factor on fonts is
no longer used. Setting the ``text.kerning_factor`` rcParam (which existed only for
backwards-compatibility) to any value other than 0 is deprecated, and the rcParam will be
Copy link
Member

Choose a reason for hiding this comment

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

It looks like in the deprecation warning it warns for a value !=None, not a value !=0. Am I missing something, or is this changelog entry wrong with respect to the current code?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, quite right. It originally warned on non-0, but once I added the rcParam as well, I switched to non-None instead.

This factor existed only to preserve test images, but as of matplotlib#29816, it
is set to 0 (i.e., disabled and providing default behaviour). In the
future, with libraqm, it will have no effect no matter its setting
(because we won't be applying kerning ourselves at all.)
@QuLogic QuLogic force-pushed the deprecate-kerning branch from 99d357f to 779af59 Compare July 17, 2025 18:42
@QuLogic QuLogic changed the title Deprecate setting text kerning factor to any non-0 value Deprecate setting text kerning factor to any non-None value Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready for Review
Development

Successfully merging this pull request may close these issues.

3 participants