From 514a8a28638b6a187e840b03f21c9e3b8b76d4d1 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 3 May 2016 08:30:30 +0530 Subject: [PATCH] Patch MathJax so that correct webfont URLs are generated --- setup/mathjax.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/setup/mathjax.py b/setup/mathjax.py index bbdcc07818..1d939acdda 100644 --- a/setup/mathjax.py +++ b/setup/mathjax.py @@ -7,7 +7,7 @@ __license__ = 'GPL v3' __copyright__ = '2012, Kovid Goyal ' __docformat__ = 'restructuredtext en' -import os +import os, re from urllib import urlretrieve from zipfile import ZipFile, ZIP_STORED, ZipInfo from hashlib import sha1 @@ -37,9 +37,20 @@ class MathJax(Command): if os.path.isdir(q): return q + def patch_webfonts(self, raw): + raw = raw.decode('utf-8') + nraw = re.sub(r'font = {[^}]+WOFFDIR[^}]+}', + '''font = {'font-family':family+'w', src:'url(' + AJAX.fileURL(WOFFDIR+'/'+name+'-'+variant+'.woff') + ') format("woff")'}''', raw) + if raw == nraw: + raise SystemExit('Patching of webfonts failed') + return nraw.encode('utf-8') + def add_file(self, zf, path, name): with open(path, 'rb') as f: raw = f.read() + if name == 'jax/output/CommonHTML/fonts/TeX/fontdata.js': + raw = self.patch_webfonts(raw) + self.patched = True self.h.update(raw) zi = ZipInfo(name) zi.external_attr = 0o444 << 16L @@ -56,6 +67,7 @@ class MathJax(Command): return '/fonts/' in name and self.FONT_FAMILY not in name def run(self, opts): + self.patched = False self.h = sha1() src = opts.path_to_mathjax or self.download_mathjax_release() self.info('Compressing MathJax...') @@ -69,6 +81,8 @@ class MathJax(Command): zf.comment = self.h.hexdigest() t.seek(0) + if not self.patched: + raise SystemExit('Could not find fontdata.js to patch') with open(self.j(self.RESOURCES, 'content-server', 'mathjax.zip.xz'), 'wb') as f: compress(t, f, level=9) with open(self.j(self.RESOURCES, 'content-server', 'mathjax.version'), 'wb') as f: