Skip to content

WIP: New FreeType wrappers #5414

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

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
038cd9c
Remove ft2font
mdboom Nov 5, 2015
5e4c36e
Install freetypy from git
mdboom Nov 5, 2015
0cc61e9
Remove tests and examples that are now obsolete
mdboom Nov 5, 2015
d97def9
Use freetypy in font_manager.py
mdboom Nov 5, 2015
23c2f07
Move from FT2Font to freetypy for all uses
mdboom Nov 5, 2015
c91d988
Update comment
mdboom Nov 5, 2015
440fc51
Move local freetype building resp. to freetypy
mdboom Nov 5, 2015
632a6f6
Bugfix for AFM fonts
mdboom Nov 5, 2015
72cedd3
Remove usage of ttconv, in favor of freetypy.subset
mdboom Nov 18, 2015
4eaa209
Use font config in place of font_manager
mdboom Nov 18, 2015
04c14db
Font layout details
mdboom Nov 18, 2015
d8ca0d5
Bug fixes in new font universe
mdboom Dec 1, 2015
28fb1dc
Build freetypy with specific version of freetype
mdboom Dec 1, 2015
b7d73af
Install fcpy on Travis
mdboom Jan 22, 2016
d45129f
Minor fixes and consistency cleanups
mdboom Jan 22, 2016
cbd59dc
Fix merge
mdboom Jan 22, 2016
19bc0a3
Fix y-alignment
mdboom Apr 11, 2016
2825e44
Fix SVG
mdboom Apr 11, 2016
39a5e79
Fix y-alignment
mdboom Apr 11, 2016
1dfb7b8
Fix rendering of mathtext
mdboom Apr 11, 2016
d2ceb8e
Fix deprecation warnings
mdboom Apr 12, 2016
0208eb5
Remove obsolete test
mdboom Apr 19, 2016
ed07ac8
Fix requirements
mdboom Apr 28, 2016
2261d48
Narrow builds no longer relevant
mdboom Apr 28, 2016
e7e8065
Improve layout-to-bitmap API
mdboom Apr 28, 2016
e3f921e
Fix spacing in PDF
mdboom Apr 28, 2016
6ce033f
Fix slant handling
mdboom Apr 28, 2016
641d2b4
Make single directory font lookup work
mdboom Apr 28, 2016
b55c8eb
Fix deprecated rcParam warnings
mdboom Apr 28, 2016
607767e
Fix font styles test
mdboom Apr 28, 2016
e037636
Fix layout in legends
mdboom Apr 28, 2016
d00777d
Bugfix
mdboom Apr 28, 2016
4c68718
Handle AFM files correctly
mdboom Apr 29, 2016
0d10ec1
Use new layout API
mdboom Apr 29, 2016
9d6632f
Update test images
mdboom Apr 29, 2016
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
Next Next commit
Remove ft2font
  • Loading branch information
mdboom committed Apr 11, 2016
commit 038cd9cfd889349a5a6ca54f04a79b2e5f48cce8
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
setupext.Tornado(),
setupext.Pyparsing(),
setupext.LibAgg(),
setupext.FreeType(),
setupext.FT2Font(),
setupext.Png(),
setupext.Qhull(),
setupext.Image(),
Expand Down
215 changes: 0 additions & 215 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,220 +950,6 @@ def add_flags(self, ext, add_sources=True):
os.path.join('extern', 'agg24-svn', 'src', x) for x in agg_sources)


class FreeType(SetupPackage):
name = "freetype"

def check(self):
if options.get('local_freetype'):
return "Using local version for testing"

if sys.platform == 'win32':
try:
check_include_file(get_include_dirs(), 'ft2build.h', 'freetype')
except CheckFailed:
check_include_file(get_include_dirs(), 'freetype2\\ft2build.h', 'freetype')
return 'Using unknown version found on system.'

status, output = getstatusoutput("freetype-config --ftversion")
if status == 0:
version = output
else:
version = None

# Early versions of freetype grep badly inside freetype-config,
# so catch those cases. (tested with 2.5.3).
if version is None or 'No such file or directory\ngrep:' in version:
version = self.version_from_header()

# pkg_config returns the libtool version rather than the
# freetype version so we need to explicitly pass the version
# to _check_for_pkg_config
return self._check_for_pkg_config(
'freetype2', 'ft2build.h',
min_version='2.3', version=version)

def version_from_header(self):
version = 'unknown'
ext = self.get_extension()
if ext is None:
return version
# Return the first version found in the include dirs.
for include_dir in ext.include_dirs:
header_fname = os.path.join(include_dir, 'freetype.h')
if os.path.exists(header_fname):
major, minor, patch = 0, 0, 0
with open(header_fname, 'r') as fh:
for line in fh:
if line.startswith('#define FREETYPE_'):
value = line.rsplit(' ', 1)[1].strip()
if 'MAJOR' in line:
major = value
elif 'MINOR' in line:
minor = value
else:
patch = value
return '.'.join([major, minor, patch])

def add_flags(self, ext):
if options.get('local_freetype'):
src_path = os.path.join(
'build', 'freetype-{0}'.format(LOCAL_FREETYPE_VERSION))
# Statically link to the locally-built freetype.
# This is certainly broken on Windows.
ext.include_dirs.insert(0, os.path.join(src_path, 'include'))
if sys.platform == 'win32':
libfreetype = 'libfreetype.lib'
else:
libfreetype = 'libfreetype.a'
ext.extra_objects.insert(
0, os.path.join(src_path, 'objs', '.libs', libfreetype))
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'local'))
else:
pkg_config.setup_extension(
ext, 'freetype2',
default_include_dirs=[
'include/freetype2', 'freetype2',
'lib/freetype2/include',
'lib/freetype2/include/freetype2'],
default_library_dirs=[
'freetype2/lib'],
default_libraries=['freetype', 'z'])
ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system'))

def do_custom_build(self):
# We're using a system freetype
if not options.get('local_freetype'):
return

src_path = os.path.join(
'build', 'freetype-{0}'.format(LOCAL_FREETYPE_VERSION))

# We've already built freetype
if sys.platform == 'win32':
libfreetype = 'libfreetype.lib'
else:
libfreetype = 'libfreetype.a'

if os.path.isfile(os.path.join(src_path, 'objs', '.libs', libfreetype)):
return

tarball = 'freetype-{0}.tar.gz'.format(LOCAL_FREETYPE_VERSION)
tarball_path = os.path.join('build', tarball)
try:
tarball_cache_dir = _get_xdg_cache_dir()
tarball_cache_path = os.path.join(tarball_cache_dir, tarball)
except:
# again, do not really care if this fails
tarball_cache_dir = None
tarball_cache_path = None
if not os.path.isfile(tarball_path):
if (tarball_cache_path is not None and
os.path.isfile(tarball_cache_path)):
if get_file_hash(tarball_cache_path) == LOCAL_FREETYPE_HASH:
try:
# fail on Lpy, oh well
os.makedirs('build', exist_ok=True)
shutil.copy(tarball_cache_path, tarball_path)
print('Using cached tarball: {}'
.format(tarball_cache_path))
except:
# If this fails, oh well just re-download
pass

if not os.path.isfile(tarball_path):
url_fmt = (
'http://download.savannah.gnu.org/releases/freetype/{0}')
tarball_url = url_fmt.format(tarball)

print("Downloading {0}".format(tarball_url))
if sys.version_info[0] == 2:
from urllib import urlretrieve
else:
from urllib.request import urlretrieve

if not os.path.exists('build'):
os.makedirs('build')
urlretrieve(tarball_url, tarball_path)
if get_file_hash(tarball_path) == LOCAL_FREETYPE_HASH:
try:
# this will fail on LPy, oh well
os.makedirs(tarball_cache_dir, exist_ok=True)
shutil.copy(tarball_cache_path, tarball_path)
print('Cached tarball at: {}'
.format(tarball_cache_path))
except:
# again, we do not care if this fails, can
# always re download
pass

if get_file_hash(tarball_path) != LOCAL_FREETYPE_HASH:
raise IOError(
"{0} does not match expected hash.".format(tarball))

print("Building {0}".format(tarball))
if sys.platform != 'win32':
# compilation on all other platforms than windows
cflags = 'CFLAGS="{0} -fPIC" '.format(os.environ.get('CFLAGS', ''))

subprocess.check_call(
['tar', 'zxf', tarball], cwd='build')
subprocess.check_call(
[cflags + './configure --with-zlib=no --with-bzip2=no '
'--with-png=no --with-harfbuzz=no'], shell=True, cwd=src_path)
subprocess.check_call(
[cflags + 'make'], shell=True, cwd=src_path)
else:
# compilation on windows
FREETYPE_BUILD_CMD = """\
call "%ProgramFiles%\\Microsoft SDKs\\Windows\\v7.0\\Bin\\SetEnv.Cmd" /Release /{xXX} /xp
call "{vcvarsall}" {xXX}
set MSBUILD=C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe
rd /S /Q %FREETYPE%\\objs
%MSBUILD% %FREETYPE%\\builds\\windows\\{vc20xx}\\freetype.sln /t:Clean;Build /p:Configuration="{config}";Platform={WinXX}
echo Build completed, moving result"
:: move to the "normal" path for the unix builds...
mkdir %FREETYPE%\\objs\\.libs
:: REMINDER: fix when changing the version
copy %FREETYPE%\\objs\\{vc20xx}\\{xXX}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
if errorlevel 1 (
rem This is a py27 version, which has a different location for the lib file :-/
copy %FREETYPE%\\objs\\win32\\{vc20xx}\\freetype261.lib %FREETYPE%\\objs\\.libs\\libfreetype.lib
)
"""
from setup_external_compile import fixproj, prepare_build_cmd, VS2010, X64, tar_extract
# Note: freetype has no build profile for 2014, so we don't bother...
vc = 'vc2010' if VS2010 else 'vc2008'
WinXX = 'x64' if X64 else 'Win32'
tar_extract(tarball_path, "build")
# This is only false for py2.7, even on py3.5...
if not VS2010:
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.sln'), WinXX)
fixproj(os.path.join(src_path, 'builds', 'windows', vc, 'freetype.vcproj'), WinXX)

cmdfile = os.path.join("build", 'build_freetype.cmd')
with open(cmdfile, 'w') as cmd:
cmd.write(prepare_build_cmd(FREETYPE_BUILD_CMD, vc20xx=vc, WinXX=WinXX,
config='Release' if VS2010 else 'LIB Release'))

os.environ['FREETYPE'] = src_path
subprocess.check_call([cmdfile], shell=True)


class FT2Font(SetupPackage):
name = 'ft2font'

def get_extension(self):
sources = [
'src/ft2font.cpp',
'src/ft2font_wrapper.cpp',
'src/mplutils.cpp'
]
ext = make_extension('matplotlib.ft2font', sources)
FreeType().add_flags(ext)
Numpy().add_flags(ext)
return ext


class Png(SetupPackage):
name = "png"

Expand Down Expand Up @@ -1515,7 +1301,6 @@ def get_extension(self):
ext = make_extension('matplotlib.backends._backend_agg', sources)
Numpy().add_flags(ext)
LibAgg().add_flags(ext)
FreeType().add_flags(ext)
return ext


Expand Down
Loading