Thanks to visit codestin.com
Credit goes to github.com

Skip to content

textpath encoding #12928

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 4 commits into from
Apr 2, 2019
Merged

textpath encoding #12928

merged 4 commits into from
Apr 2, 2019

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Dec 3, 2018

PR Summary

Consider the following example.

import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True
plt.rcParams['text.latex.preamble'] = r'\usepackage{siunitx}'
plt.rcParams['text.hinting_factor'] = 1
plt.text(.5, .5, r'$\si{\degree}$')
plt.text(.5, .4, r'ff\textwon')
plt.gca().set_axis_off()
plt.savefig('/tmp/plot.svg')
plt.savefig('/tmp/plot.pdf')
plt.savefig('/tmp/plot.png')
plt.show()

In the svg output, one sees that the \degree and \textwon characters
(which come from a different font that the ff ligature) are now
correctly loaded, but at a too small size -- this still needs to be
fixedn but is already better than not loading the glyphs at all.
(pdf and png output are unaffected.)
screenshot_20181203_174540

Supersedes #8286, #8415 (from which a test is taken).
Fixes part of #8068, #8280 (the glyph-loading part; the sizing issue is a bug this PR newly exposes).

Likely the bad font sizing has something to do with the use, in textpath.py of self.FONT_SCALE rather than prop.get_size_in_points()/dvifont.size...

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

@anntzer anntzer added this to the v3.1 milestone Dec 3, 2018
@anntzer anntzer force-pushed the textpath-encoding branch 2 times, most recently from 04dfa60 to 83f2d64 Compare December 3, 2018 20:41
# If psfonts.map specifies no encoding, the indices directly map to
# the font's builtin charmap (see the pdftex manual, section 6.1
# -- Map files); so don't use the FreeType-synthesized charmap but
# the native ones (we can't directly identify it but it's typically
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@anntzer
Copy link
Contributor Author

anntzer commented Dec 6, 2018

Very empirically, it looks like glyphs are correctly sized (across multiple of font sizes) with

diff --git i/lib/matplotlib/textpath.py w/lib/matplotlib/textpath.py
index 8ef6187bd..d306e82c8 100644
--- i/lib/matplotlib/textpath.py
+++ w/lib/matplotlib/textpath.py
@@ -315,7 +315,7 @@ class TextToPath(object):
 
             if char_id not in glyph_map:
                 font.clear()
-                font.set_size(self.FONT_SCALE, self.DPI)
+                font.set_size(self.FONT_SCALE ** 2 / dvifont.size, self.DPI)
                 # See comments in _get_ps_font_and_encoding.
                 if enc is not None:
                     index = font.get_name_index(enc[glyph])

which doesn't look completely nuts, but I haven't tracked down all the resizings either.

@anntzer anntzer force-pushed the textpath-encoding branch 2 times, most recently from 533b875 to 2077dc9 Compare December 7, 2018 14:57
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

Not clear on all details, but this seems to work...

@anntzer
Copy link
Contributor Author

anntzer commented Mar 4, 2019

rebased

@anntzer anntzer force-pushed the textpath-encoding branch from 2077dc9 to 976e779 Compare March 4, 2019 20:57
glyph0 = font.load_char(charcode, flags=ft2font_flag)
# See comments in _get_ps_font_and_encoding.
if enc is not None:
index = font.get_name_index(enc[glyph])
Copy link
Member

Choose a reason for hiding this comment

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

this used to handle the case where glyph not in enc where as this looks like it will now raise KeyError. Is this a change we want to make?

Copy link
Contributor Author

@anntzer anntzer Apr 2, 2019

Choose a reason for hiding this comment

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

Restored handling of glyph not in enc (in the last commit). Not sure why I removed this in the first place.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

modulo the question about changing .get -> [].

@anntzer anntzer force-pushed the textpath-encoding branch from 976e779 to 51436bf Compare April 2, 2019 09:35
anntzer and others added 4 commits April 2, 2019 13:54
Consider the following example.

    import matplotlib.pyplot as plt
    plt.rcParams['text.usetex'] = True
    plt.rcParams['text.latex.preamble'] = r'\usepackage{siunitx}'
    plt.rcParams['text.hinting_factor'] = 1
    plt.text(.5, .5, r'$\si{\degree}$')
    plt.text(.5, .4, r'ff\textwon')
    plt.gca().set_axis_off()
    plt.savefig('/tmp/plot.svg')
    plt.savefig('/tmp/plot.pdf')
    plt.savefig('/tmp/plot.png')
    plt.show()

In the svg output, one sees that the \degree and \textwon characters
(which come from a different font that the ff ligature) are now
correctly loaded, *but* at a too small size -- this still needs to be
fixed.
(pdf and png output are unaffected.)
@anntzer anntzer force-pushed the textpath-encoding branch from 51436bf to 722de6f Compare April 2, 2019 11:54
@tacaswell tacaswell merged commit a2277af into matplotlib:master Apr 2, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 2, 2019
@anntzer anntzer deleted the textpath-encoding branch April 2, 2019 13:25
dstansby added a commit that referenced this pull request Apr 2, 2019
…928-on-v3.1.x

Backport PR #12928 on branch v3.1.x (textpath encoding)
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