-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Update the font_table example. #12943
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
Conversation
This seems OK, but why did you change the name of the file? That will break links to the example... |
Because there's nothing specific to ttf in that example. |
Is that how you wanted it to look? |
I think an empty line after The file is sgskipped because sphinx-gallery can't handle stuff like this (which tries to read from sys.argv) properly, so nothing is rendered in the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the motivation to make this file an executable script? Should users download the file and actually use it as a standalone tool? If so, the sgskip title is really bad.
Is it possible to add a check to see if this was run from the command line or by sphinx galery and run draw_font_table(None)
in the latter case?
Here, we use `~.Axes.table` build a font table that shows the glyphs by Unicode | ||
codepoint, and print the glyphs corresponding to codepoints beyond 0xff. | ||
|
||
Usage:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Usage:: | |
You can download this script and run it to investigate a font by calling:: |
|
||
import unicodedata | ||
|
||
from matplotlib import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that really common style? I would have used
import matplotlib.pyplot as plt
import matplotlib.font_manager as fm
import numpy as np | ||
|
||
|
||
def main(path): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def main(path): | |
def draw_font_table(path): |
While it's technically a main()
the semantic name tells us what the function is actually doing.
Or just run it from the examples folder if they already have a cloned repo.
Likely, but my interest in figuring out how to make s-g play nicely with this is close to non-existent. Other comments are handled. |
Print characters corresponding to codepoints >0xff. Add comments explaining font charmaps (briefly). Don't use pyplot.
import matplotlib.font_manager as fm | ||
from matplotlib.ft2font import FT2Font | ||
import matplotlib.pyplot as plt | ||
import numpy as np |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused import
I have a mild preference to not rename examples to avoid changing the URLs of the example but will not block merging over that. |
If s-g can run this then yes, let's include the table. (In which case we're going to get a rename anyways.) @tacaswell We should really redirect |
I've added the inclusion of the table in the sphinx-gallery output as a separte PR. Should be squashed before merging. |
I've additionally factored out the printing of the glyphs. This makes the table code more readable (and at least part of the motivation of the example is showing how to use |
|
||
|
||
def print_glyphs(font): | ||
"""Print the all the glyphs in the given FT2Font font to stdout.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove "the"
print(f"{glyph_index:>{max_indices_len}} {char} {name}") | ||
|
||
|
||
def draw_font_table(path, print_all=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make print_all kwonly? (Not that it really matters here but it's the kind of arg that should likely be kwonly if this was a general-use function...)
Or perhaps just don't include this functionality at all in draw_font_table and handle it in the if name==main block, i.e. below:
if args.print_all: print_glyphs(...)
draw_font_table(...)
Print characters corresponding to codepoints >0xff.
Add comments explaining font charmaps (briefly).
Don't use pyplot.
PR Summary
PR Checklist