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

Skip to content

Update afm docs and internal data structures #10692

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 2 commits into from
Mar 28, 2018

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Mar 5, 2018

PR Summary

Improve afm docstrings and cleanup the internal data structures.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • Documentation is sphinx and numpydoc compliant

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.

This seems fine though I'm not quite grokking all the namedtupple stuff. However, the test coverage is good...

@QuLogic QuLogic added this to the v3.0 milestone Mar 16, 2018
the character, values are a (*wx*, *name*, *bbox*) tuple, where
*wx* is the character width, *name* is the postscript language
name, and *bbox* is a (*llx*, *lly*, *urx*, *ury*) tuple.
Parse the given filehandle for character metrics information and returns
Copy link
Member

Choose a reason for hiding this comment

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

Some tense inconsistency: Parse vs returns

composites. Values are a num parts list of composite information,
with each element being a (*name*, *dx*, *dy*) tuple. Thus a
composites line reading:
Parse the given filehandle for composites information returns it as a dict.
Copy link
Member

Choose a reason for hiding this comment

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

Same tense inconsistency.

The fields do currently only describe a subset of character metrics
information defined in the AFM standard.
"""
CharMetrics.width.__doc__ = "The character width (WX)."
Copy link
Member

Choose a reason for hiding this comment

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

Why no triple-quotes (like the other one-line named tuples)?

Parse the given filehandle for character metrics information and returns
the information as dicts.

It is assumed that the file cursor is on the line behind
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure I understand this "behind" business. Should the file cursor not be pointing at the 'S'?

Copy link
Member Author

Choose a reason for hiding this comment

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

_parse_header consumes lines up to and including StartCharMetrics. It then returns and the file handle is passed on to _parse_char_metrics. The latter interprets the contents of a char metrics block, but not the StartCharMetrics command itself.

This is maybe not 100% clean and intuitive, but good enough for the internal parser functions. The docstring just describes what the code is doing/expecting.

Copy link
Member

Choose a reason for hiding this comment

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

OK, I think I understand now. When I saw 'line behind something', I thought it was a different line from 'something'. I also don't think 'behind' is the right word here.

Since the cursor is in the middle of a line anyway, I would not mention a line, just: 'the file cursor is pointing after "StartCharMetrics".'

composites line reading:
Parse the given filehandle for composites information returns it as a dict.

It is assumed that the file cursor is on the line behind 'StartComposites'.
Copy link
Member

Choose a reason for hiding this comment

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

Same question about 'behind'.

Copy link
Member Author

Choose a reason for hiding this comment

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

Same answer. parse_composites interprets the contents of a composites block, but not the initial StartComposites, which is already consumed by the previous parser function.

from :func:`_parse_char_metrics`,
*dkernpairs* is a :func:`_parse_kern_pairs` dict (possibly {}) and
*dcomposite* is a :func:`_parse_composites` dict (possibly {})
Parse the Adobe Font Metics file in file handle *fh*.
Copy link
Member

Choose a reason for hiding this comment

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

Metrics

From :func:`_parse_char_metrics`.
cmetrics_by_name : dict
From :func:`_parse_char_metrics`.
dkernpairs : dict
Copy link
Member

Choose a reason for hiding this comment

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

I think this 'd' in the front stood for dict, so it's probably not needed with the type now explicitly named.

ascii_d[num] = (wx, name, bbox)
name_d[name] = (wx, bbox)
ascii_d[num] = metrics
name_d[name] = metrics
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is technically a backcompat break? (someone could have been doing wx, bbox = name_d[name].)
It would not have been a problem if parse_afm was private (... as it probably should have been) but a note is probably useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we are at it, shouldn't we just make parse_afm private? After all, parse_afm is not something I would want to maintain as part of the public matplotlib API in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with deprecating it.

self._metrics = dcmetrics_ascii
self._metrics_by_name = dcmetrics_name
self._composite = dcomposite
(header,
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you're here you may as well write

(self._header,
 ...,
 self._composite) = parse_afm(fh)


def get_height_char(self, c, isord=False):
"""
Get the height of character *c* from the bounding box. This
is the ink height (space is 0)
is the ink height (space is 0).
Copy link
Contributor

Choose a reason for hiding this comment

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

Get the bounding box (ink) height of character c (space is 0).


def get_kern_dist(self, c1, c2):
"""
Return the kerning pair distance (possibly 0) for chars *c1*
and *c2*
and *c2*.
Copy link
Contributor

Choose a reason for hiding this comment

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

fits in a line

@timhoffm timhoffm force-pushed the doc-afm branch 2 times, most recently from 87f2304 to 2e18e7a Compare March 21, 2018 22:40
@timhoffm
Copy link
Member Author

rebased to fix conflict with master

Copy link
Contributor

@anntzer anntzer left a comment

Choose a reason for hiding this comment

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

feel free to dismiss this once the backcompat issue is fixed

@anntzer anntzer dismissed their stale review March 25, 2018 19:23

comments handled

@timhoffm
Copy link
Member Author

@anntzer is this approved then, or should still someone else approve?

@anntzer anntzer merged commit c8fd779 into matplotlib:master Mar 28, 2018
@timhoffm timhoffm deleted the doc-afm branch March 28, 2018 11:27
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.

5 participants