Skip to content

Commit 13c2a88

Browse files
committed
New FreeType wrapper.
TODO: ttc support violates the assumption that the filename suffices to identify the face (when caching). We need to generate a uniquer id or just key off the face object.
1 parent ef5d01a commit 13c2a88

24 files changed

Lines changed: 1464 additions & 515 deletions

.appveyor.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ environment:
2626
CONDA_INSTALL_LOCN: "C:\\Miniconda36-x64"
2727
TEST_ALL: "no"
2828

29+
image: Visual Studio 2017
30+
2931
# We always use a 64-bit machine, but can build x86 distributions
3032
# with the PYTHON_ARCH variable
3133
platform:
@@ -42,6 +44,7 @@ init:
4244
- echo %PYTHON_VERSION% %CONDA_INSTALL_LOCN%
4345

4446
install:
47+
- call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
4548
- set PATH=%CONDA_INSTALL_LOCN%;%CONDA_INSTALL_LOCN%\scripts;%PATH%;
4649
- set PYTHONUNBUFFERED=1
4750
# for msinttypes and newer stuff

.circleci/config.yml

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,24 @@ apt-run: &apt-install
1313
command: |
1414
sudo apt-get -qq update
1515
sudo apt-get install -y \
16+
cm-super \
17+
dvipng \
18+
graphviz \
1619
inkscape \
1720
libav-tools \
18-
dvipng \
19-
pgf \
21+
libgeos-dev \
2022
lmodern \
21-
cm-super \
23+
otf-freefont \
24+
pgf \
25+
software-properties-common \
26+
texlive-fonts-recommended \
2227
texlive-latex-base \
2328
texlive-latex-extra \
24-
texlive-fonts-recommended \
2529
texlive-latex-recommended \
26-
texlive-xetex \
27-
graphviz \
28-
libgeos-dev \
29-
otf-freefont
30+
texlive-xetex
31+
sudo add-apt-repository 'deb http://ftp.us.debian.org/debian testing main'
32+
sudo apt-get update
33+
sudo apt-get install g++-7
3034
3135
fonts-run: &fonts-install
3236
name: Install custom fonts
@@ -64,7 +68,10 @@ deps-run: &deps-install
6468
6569
mpl-run: &mpl-install
6670
name: Install Matplotlib
67-
command: pip install --user -ve .
71+
command: |
72+
ls /usr/include/freetype2
73+
cat /usr/include/freetype2/ft2build.h
74+
CC=gcc-7 CXX=g++-7 pip install --user -ve .
6875
6976
doc-run: &doc-build
7077
name: Build documentation

.travis.yml

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sudo: false
55

66
branches:
77
except:
8-
- /^auto-backport-of-pr-\d*/
8+
- /^auto-backport-of-pr-\d*/
99

1010
cache:
1111
pip: true
@@ -16,11 +16,14 @@ cache:
1616
addons:
1717
artifacts:
1818
paths:
19-
- result_images.tar.bz2
19+
- result_images.tar.bz2
2020
apt:
21+
sources:
22+
- ubuntu-toolchain-r-test
2123
packages:
2224
- cm-super
2325
- dvipng
26+
- g++-7
2427
- gdb
2528
- gir1.2-gtk-3.0
2629
- graphviz
@@ -68,6 +71,8 @@ matrix:
6871
- python: 3.5
6972
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124.
7073
env:
74+
- CC=gcc-7
75+
- CXX=g++-7
7176
- CYCLER=cycler==0.10
7277
- DATEUTIL=python-dateutil==2.1
7378
- NOSE=nose
@@ -78,14 +83,30 @@ matrix:
7883
- PYTEST_COV=pytest-cov==2.3.1
7984
- SPHINX=sphinx==1.3
8085
- python: 3.5
81-
env: PYTHON_ARGS=-OO
86+
env:
87+
- CC=gcc-7
88+
- CXX=g++-7
89+
- PYTHON_ARGS=-OO
8290
- python: 3.6
83-
env: DELETE_FONT_CACHE=1 PANDAS='pandas<0.21.0' PYTEST_PEP8=pytest-pep8 RUN_PEP8=--pep8
91+
env:
92+
- CC=gcc-7
93+
- CXX=g++-7
94+
- DELETE_FONT_CACHE=1
95+
- PANDAS='pandas<0.21.0'
96+
- PYTEST_PEP8=pytest-pep8
97+
- RUN_PEP8=--pep8
8498
- python: "nightly"
85-
env: PRE=--pre
99+
env:
100+
- CC=gcc-7
101+
- CXX=g++-7
102+
- PRE=--pre
86103
- os: osx
87104
language: generic # https://github.com/travis-ci/travis-ci/issues/2312
88105
only: master
106+
env:
107+
- PATH="/usr/local/opt/llvm/bin:$PATH"
108+
- CPPFLAGS=-L/usr/local/opt/llvm/include
109+
- LDFLAGS='-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib'
89110
cache:
90111
# As for now travis caches only "$HOME/.cache/pip"
91112
# https://docs.travis-ci.com/user/caching/#pip-cache
@@ -108,7 +129,9 @@ before_install:
108129
else
109130
ci/travis/silence brew update
110131
brew upgrade python
111-
brew install ffmpeg imagemagick mplayer ccache
132+
brew install ccache llvm
133+
brew info llvm
134+
brew install ffmpeg imagemagick mplayer
112135
hash -r
113136
which python
114137
python --version

examples/misc/font_indexing.py

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,27 @@
44
=============
55
66
A little example that shows how the various indexing into the font
7-
tables relate to one another. Mainly for mpl developers....
7+
tables relate to one another. Mainly for Matplotlib developers...
88
99
"""
10-
import matplotlib
11-
from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, KERNING_UNFITTED, KERNING_UNSCALED
10+
11+
from matplotlib._ft2 import Kerning
12+
import matplotlib.font_manager
1213

1314

1415
fname = matplotlib.get_data_path() + '/fonts/ttf/DejaVuSans.ttf'
15-
font = FT2Font(fname)
16-
font.set_charmap(0)
17-
18-
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-
26-
27-
# make a charname to charcode and glyphind dictionary
28-
coded = {}
29-
glyphd = {}
30-
for ccode, glyphind in codes:
31-
name = font.get_glyph_name(glyphind)
32-
coded[name] = ccode
33-
glyphd[name] = glyphind
34-
35-
code = coded['A']
36-
glyph = font.load_char(code)
37-
print(glyph.bbox)
38-
print(glyphd['A'], glyphd['V'], coded['A'], coded['V'])
39-
print('AV', font.get_kerning(glyphd['A'], glyphd['V'], KERNING_DEFAULT))
40-
print('AV', font.get_kerning(glyphd['A'], glyphd['V'], KERNING_UNFITTED))
41-
print('AV', font.get_kerning(glyphd['A'], glyphd['V'], KERNING_UNSCALED))
42-
print('AV', font.get_kerning(glyphd['A'], glyphd['T'], KERNING_UNSCALED))
16+
font = matplotlib.font_manager.get_font(fname)
17+
18+
# This assumes FreeType>=2.8.1, which automatically picks or synthesizes a
19+
# Unicode charmap.
20+
21+
def get_kerning(c1, c2, mode):
22+
i1 = font.get_char_index(ord(c1))
23+
i2 = font.get_char_index(ord(c2))
24+
return font.get_kerning(i1, i2, mode)
25+
26+
27+
print('AV default ', get_kerning('A', 'V', Kerning.DEFAULT))
28+
print('AV unfitted', get_kerning('A', 'V', Kerning.UNFITTED))
29+
print('AT default ', get_kerning('A', 'T', Kerning.DEFAULT))
30+
print('AT unfitted', get_kerning('A', 'T', Kerning.UNFITTED))

examples/misc/ftface_props.py

Lines changed: 50 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,53 @@
11
"""
2-
============
3-
Ftface Props
4-
============
5-
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
2+
===============
3+
Face properties
4+
===============
5+
6+
This is a demo script to show you how to use all the properties of a Face
7+
object. These describe global font properties. For individual character
8+
metrics, use the Glyph object, as loaded from the glyph attribute after calling
9+
load_char.
1010
"""
1111
import matplotlib
12-
import matplotlib.ft2font as ft
13-
14-
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)
20-
21-
print('Num faces :', font.num_faces) # number of faces in file
22-
print('Num glyphs :', font.num_glyphs) # number of glyphs in the face
23-
print('Family name :', font.family_name) # face family name
24-
print('Style name :', font.style_name) # face style name
25-
print('PS name :', font.postscript_name) # the postscript name
26-
print('Num fixed :', font.num_fixed_sizes) # number of embedded bitmap in face
27-
28-
# the following are only available if face.scalable
29-
if font.scalable:
30-
# the face global bounding box (xmin, ymin, xmax, ymax)
31-
print('Bbox :', font.bbox)
32-
# number of font units covered by the EM
33-
print('EM :', font.units_per_EM)
34-
# the ascender in 26.6 units
35-
print('Ascender :', font.ascender)
36-
# the descender in 26.6 units
37-
print('Descender :', font.descender)
38-
# the height in 26.6 units
39-
print('Height :', font.height)
40-
# maximum horizontal cursor advance
41-
print('Max adv width :', font.max_advance_width)
42-
# same for vertical layout
43-
print('Max adv height :', font.max_advance_height)
44-
# vertical position of the underline bar
45-
print('Underline pos :', font.underline_position)
46-
# vertical thickness of the underline
47-
print('Underline thickness :', font.underline_thickness)
48-
49-
for style in ('Italic',
50-
'Bold',
51-
'Scalable',
52-
'Fixed sizes',
53-
'Fixed width',
54-
'SFNT',
55-
'Horizontal',
56-
'Vertical',
57-
'Kerning',
58-
'Fast glyphs',
59-
'Multiple masters',
60-
'Glyph names',
61-
'External stream'):
62-
bitpos = getattr(ft, style.replace(' ', '_').upper()) - 1
63-
print('%-17s:' % style, bool(font.style_flags & (1 << bitpos)))
64-
65-
print(dir(font))
66-
67-
print(font.get_kerning)
12+
from matplotlib import font_manager, _ft2
13+
14+
15+
fname = matplotlib.get_data_path() + "/fonts/ttf/DejaVuSans-Oblique.ttf"
16+
font = font_manager.get_font(fname)
17+
18+
print("Faces in file :", font.num_faces)
19+
print("Glyphs in face :", font.num_glyphs)
20+
print("Family name :", font.family_name)
21+
print("Style name :", font.style_name)
22+
print("Postscript name :", font.get_postscript_name())
23+
print("Embedded bitmap strikes:", font.num_fixed_sizes)
24+
25+
if font.face_flags & _ft2.FACE_FLAG_SCALABLE:
26+
print('Global bbox (xmin, ymin, xmax, ymax):', font.bbox)
27+
print('Font units per EM :', font.units_per_EM)
28+
print('Ascender (pixels) :', font.ascender)
29+
print('Descender (pixels) :', font.descender)
30+
print('Height (pixels) :', font.height)
31+
print('Max horizontal advance :', font.max_advance_width)
32+
print('Max vertical advance :', font.max_advance_height)
33+
print('Underline position :', font.underline_position)
34+
print('Underline thickness :', font.underline_thickness)
35+
36+
for style in ['Style flag italic',
37+
'Style flag bold']:
38+
flag = getattr(_ft2, style.replace(' ', '_').upper()) - 1
39+
print('%-26s:' % style, bool(font.style_flags & flag))
40+
41+
for style in ['Face flag scalable',
42+
'Face flag fixed sizes',
43+
'Face flag fixed width',
44+
'Face flag SFNT',
45+
'Face flag horizontal',
46+
'Face flag vertical',
47+
'Face flag kerning',
48+
'Face flag fast glyphs',
49+
'Face flag multiple masters',
50+
'Face flag glyph names',
51+
'Face flag external stream']:
52+
flag = getattr(_ft2, style.replace(' ', '_').upper())
53+
print('%-26s:' % style, bool(font.face_flags & flag))

examples/text_labels_and_annotations/font_table_ttf_sgskip.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import os
1616

1717
import matplotlib
18-
from matplotlib.ft2font import FT2Font
18+
from matplotlib import _ft2
1919
from matplotlib.font_manager import FontProperties
2020
import matplotlib.pyplot as plt
2121

@@ -32,8 +32,8 @@
3232
fontname = os.path.join(matplotlib.get_data_path(),
3333
'fonts', 'ttf', 'DejaVuSans.ttf')
3434

35-
font = FT2Font(fontname)
36-
codes = sorted(font.get_charmap().items())
35+
font = _ft2.Face(fontname)
36+
codes = sorted(font.get_charmap().items()) # FIXME
3737

3838
# a 16,16 array of character strings
3939
chars = [['' for c in range(16)] for r in range(16)]

0 commit comments

Comments
 (0)