Skip to content

Cleanup two font-related examples. #13582

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
Mar 4, 2019
Merged
Show file tree
Hide file tree
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
24 changes: 10 additions & 14 deletions examples/misc/font_indexing.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
"""
=============
Font Indexing
Font indexing
=============

A little example that shows how the various indexing into the font
tables relate to one another. Mainly for mpl developers....

This example shows how the font tables relate to one another.
"""

import os

import matplotlib
from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED
from matplotlib.ft2font import (
FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED)


fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans.ttf'
font = FT2Font(fname)
font = FT2Font(
os.path.join(matplotlib.get_data_path(), 'fonts/ttf/DejaVuSans.ttf'))
font.set_charmap(0)

codes = font.get_charmap().items()
#dsu = [(ccode, glyphind) for ccode, glyphind in codes]
#dsu.sort()
#for ccode, glyphind in dsu:
# try: name = font.get_glyph_name(glyphind)
# except RuntimeError: pass
# else: print('% 4d % 4d %s %s' % (glyphind, ccode, hex(int(ccode)), name))


# make a charname to charcode and glyphind dictionary
coded = {}
Expand All @@ -31,6 +26,7 @@
name = font.get_glyph_name(glyphind)
coded[name] = ccode
glyphd[name] = glyphind
# print(glyphind, ccode, hex(int(ccode)), name)

code = coded['A']
glyph = font.load_char(code)
Expand Down
29 changes: 13 additions & 16 deletions examples/misc/ftface_props.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
"""
============
Ftface Props
============
===============
Font properties
===============

This is a demo script to show you how to use all the properties of an
FT2Font object. These describe global font properties. For
individual character metrics, use the Glyph object, as returned by
load_char
This example lists the attributes of an `FT2Font` object, which describe global
font properties. For individual character metrics, use the `Glyph` object, as
returned by `load_char`.
"""

import os

import matplotlib
import matplotlib.ft2font as ft


#fname = '/usr/local/share/matplotlib/VeraIt.ttf'
fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans-Oblique.ttf'
#fname = '/usr/local/share/matplotlib/cmr10.ttf'

font = ft.FT2Font(fname)
font = ft.FT2Font(
# Use a font shipped with Matplotlib.
os.path.join(matplotlib.get_data_path(),
'fonts/ttf/DejaVuSans-Oblique.ttf'))

print('Num faces :', font.num_faces) # number of faces in file
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
Expand Down Expand Up @@ -61,7 +62,3 @@
'External stream'):
bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
print('%-17s:' % style, bool(font.style_flags & (1 << bitpos)))

print(dir(font))

print(font.get_kerning)