Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Improve usability of dviread.Text by third parties.#22609
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
63 changes: 62 additions & 1 deletionlib/matplotlib/dviread.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -58,10 +58,71 @@ | ||
# The marks on a page consist of text and boxes. A page also has dimensions. | ||
Page = namedtuple('Page', 'text boxes height width descent') | ||
Box = namedtuple('Box', 'x y height width') | ||
# Also a namedtuple, for backcompat. | ||
class Text(namedtuple('Text', 'x y font glyph width')): | ||
""" | ||
A glyph in the dvi file. | ||
The *x* and *y* attributes directly position the glyph. The *font*, | ||
*glyph*, and *width* attributes are kept public for back-compatibility, | ||
but users wanting to draw the glyph themselves are encouraged to instead | ||
load the font specified by `font_path` at `font_size`, warp it with the | ||
effects specified by `font_effects`, and load the glyph specified by | ||
`glyph_name_or_index`. | ||
""" | ||
def _get_pdftexmap_entry(self): | ||
return PsfontsMap(find_tex_file("pdftex.map"))[self.font.texname] | ||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
@property | ||
def font_path(self): | ||
"""The `~pathlib.Path` to the font for this glyph.""" | ||
psfont = self._get_pdftexmap_entry() | ||
if psfont.filename is None: | ||
raise ValueError("No usable font file found for {} ({}); " | ||
"the font may lack a Type-1 version" | ||
.format(psfont.psname.decode("ascii"), | ||
psfont.texname.decode("ascii"))) | ||
return Path(psfont.filename) | ||
@property | ||
def font_size(self): | ||
"""The font size.""" | ||
return self.font.size | ||
@property | ||
def font_effects(self): | ||
""" | ||
The "font effects" dict for this glyph. | ||
This dict contains the values for this glyph of SlantFont and | ||
ExtendFont (if any), read off :file:`pdftex.map`. | ||
""" | ||
return self._get_pdftexmap_entry().effects | ||
@property | ||
def glyph_name_or_index(self): | ||
""" | ||
Either the glyph name or the native charmap glyph index. | ||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
If :file:`pdftex.map` specifies an encoding for this glyph's font, that | ||
is a mapping of glyph indices to Adobe glyph names; use it to convert | ||
dvi indices to glyph names. Callers can then convert glyph names to | ||
glyph indices (with FT_Get_Name_Index/get_name_index), and load the | ||
glyph using FT_Load_Glyph/load_glyph. | ||
If :file:`pdftex.map` specifies no encoding, the indices directly map | ||
to the font's "native" charmap; glyphs should directly loaded using | ||
FT_Load_Char/load_char after selecting the native charmap. | ||
""" | ||
entry = self._get_pdftexmap_entry() | ||
return (_parse_enc(entry.encoding)[self.glyph] | ||
if entry.encoding is not None else self.glyph) | ||
# Opcode argument parsing | ||
# | ||
# Each of the following functions takes a Dvi object and delta, | ||
2 changes: 1 addition & 1 deletionlib/matplotlib/tests/test_usetex.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -131,7 +131,7 @@ def test_missing_psfont(fmt, monkeypatch): | ||
monkeypatch.setattr( | ||
dviread.PsfontsMap, '__getitem__', | ||
lambda self, k: dviread.PsFont( | ||
texname=b'texfont', psname=b'Some Font', | ||
tacaswell marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
effects=None, encoding=None, filename=None)) | ||
mpl.rcParams['text.usetex'] = True | ||
fig, ax = plt.subplots() | ||
84 changes: 30 additions & 54 deletionslib/matplotlib/textpath.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
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.