Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb9b8fe

Browse filesBrowse files
dstansbyMeeseeksDev[bot]
authored andcommitted
Backport PR #13582: Cleanup two font-related examples.
1 parent 4b67d40 commit bb9b8fe
Copy full SHA for bb9b8fe

File tree

Expand file treeCollapse file tree

2 files changed

+23
-30
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+23
-30
lines changed

‎examples/misc/font_indexing.py

Copy file name to clipboardExpand all lines: examples/misc/font_indexing.py
+10-14Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
11
"""
22
=============
3-
Font Indexing
3+
Font indexing
44
=============
55
6-
A little example that shows how the various indexing into the font
7-
tables relate to one another. Mainly for mpl developers....
8-
6+
This example shows how the font tables relate to one another.
97
"""
8+
9+
import os
10+
1011
import matplotlib
11-
from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED
12+
from matplotlib.ft2font import (
13+
FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED)
1214

1315

14-
fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans.ttf'
15-
font = FT2Font(fname)
16+
font = FT2Font(
17+
os.path.join(matplotlib.get_data_path(), 'fonts/ttf/DejaVuSans.ttf'))
1618
font.set_charmap(0)
1719

1820
codes = font.get_charmap().items()
19-
#dsu = [(ccode, glyphind) for ccode, glyphind in codes]
20-
#dsu.sort()
21-
#for ccode, glyphind in dsu:
22-
# try: name = font.get_glyph_name(glyphind)
23-
# except RuntimeError: pass
24-
# else: print('% 4d % 4d %s %s' % (glyphind, ccode, hex(int(ccode)), name))
25-
2621

2722
# make a charname to charcode and glyphind dictionary
2823
coded = {}
@@ -31,6 +26,7 @@
3126
name = font.get_glyph_name(glyphind)
3227
coded[name] = ccode
3328
glyphd[name] = glyphind
29+
# print(glyphind, ccode, hex(int(ccode)), name)
3430

3531
code = coded['A']
3632
glyph = font.load_char(code)

‎examples/misc/ftface_props.py

Copy file name to clipboardExpand all lines: examples/misc/ftface_props.py
+13-16Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
"""
2-
============
3-
Ftface Props
4-
============
2+
===============
3+
Font properties
4+
===============
55
6-
This is a demo script to show you how to use all the properties of an
7-
FT2Font object. These describe global font properties. For
8-
individual character metrics, use the Glyph object, as returned by
9-
load_char
6+
This example lists the attributes of an `FT2Font` object, which describe global
7+
font properties. For individual character metrics, use the `Glyph` object, as
8+
returned by `load_char`.
109
"""
10+
11+
import os
12+
1113
import matplotlib
1214
import matplotlib.ft2font as ft
1315

1416

15-
#fname = '/usr/local/share/matplotlib/VeraIt.ttf'
16-
fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans-Oblique.ttf'
17-
#fname = '/usr/local/share/matplotlib/cmr10.ttf'
18-
19-
font = ft.FT2Font(fname)
17+
font = ft.FT2Font(
18+
# Use a font shipped with Matplotlib.
19+
os.path.join(matplotlib.get_data_path(),
20+
'fonts/ttf/DejaVuSans-Oblique.ttf'))
2021

2122
print('Num faces :', font.num_faces) # number of faces in file
2223
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
@@ -61,7 +62,3 @@
6162
'External stream'):
6263
bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
6364
print('%-17s:' % style, bool(font.style_flags & (1 << bitpos)))
64-
65-
print(dir(font))
66-
67-
print(font.get_kerning)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.