Skip to content

Update docs of type1font #15942

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 1 commit into from
Dec 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions lib/matplotlib/type1font.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ class Type1Font:

def __init__(self, input):
"""
Initialize a Type-1 font. *input* can be either the file name of
a pfb file or a 3-tuple of already-decoded Type-1 font parts.
Initialize a Type-1 font.

Parameters
----------
input : str or 3-tuple
Either a pfb file name, or a 3-tuple of already-decoded Type-1
font `~.Type1Font.parts`.
"""
if isinstance(input, tuple) and len(input) == 3:
self.parts = input
Expand All @@ -67,9 +72,7 @@ def __init__(self, input):
self._parse()

def _read(self, file):
"""
Read the font from a file, decoding into usable parts.
"""
"""Read the font from a file, decoding into usable parts."""
rawdata = file.read()
if not rawdata.startswith(b'\x80'):
return rawdata
Expand Down Expand Up @@ -306,12 +309,23 @@ def suppress(tokens):

def transform(self, effects):
"""
Transform the font by slanting or extending. *effects* should
be a dict where ``effects['slant']`` is the tangent of the
angle that the font is to be slanted to the right (so negative
values slant to the left) and ``effects['extend']`` is the
multiplier by which the font is to be extended (so values less
than 1.0 condense). Returns a new :class:`Type1Font` object.
Return a new font that is slanted and/or extended.

Parameters
----------
effects : dict
A dict with optional entries:

- 'slant' : float, default: 0
Tangent of the angle that the font is to be slanted to the
right. Negative values slant to the left.
- 'extend' : float, default: 1
Scaling factor for the font width. Values less than 1 condense
the glyphs.

Returns
-------
font : `Type1Font`
"""
tokenizer = self._tokens(self.parts[0])
transformed = self._transformer(tokenizer,
Expand Down