#!/usr/bin/python from __future__ import print_function from lxml import etree from utils.misc import downloadWithProgressBar from utils import mathfont import json # Retrieve the unicode.xml file if necessary. unicodeXML = downloadWithProgressBar("http://www.w3.org/2003/entities/2007xml/unicode.xml") # Extract the mathvariants transformation. xsltTransform = etree.XSLT(etree.XML('''\ ''')) # Put the mathvariant transforms into a Python structure. mathvariantTransforms = {} root = xsltTransform(etree.parse(unicodeXML)).getroot() def parseCodePoint(aHexaString): return int("0x%s" % aHexaString[1:], 16) for entry in root: mathvariant = entry.get("mathvariant") baseChar = parseCodePoint(entry.get("baseChar")) transformedChar = parseCodePoint(entry.get("transformedChar")) if mathvariant not in mathvariantTransforms: mathvariantTransforms[mathvariant] = {} mathvariantTransforms[mathvariant][baseChar] = transformedChar # There is no "isolated" mathvariant. del mathvariantTransforms["isolated"] # Create a WOFF font for each mathvariant. for mathvariant in mathvariantTransforms: font = mathfont.create("mathvariant-%s" % mathvariant) for baseChar in mathvariantTransforms[mathvariant]: if baseChar not in font: mathfont.createGlyphFromValue(font, baseChar) transformedChar = mathvariantTransforms[mathvariant][baseChar] mathfont.createGlyphFromValue(font, transformedChar) mathfont.save(font) # Create a test font for each mathvariant. for mathvariant in mathvariantTransforms: print("Generating test for %s..." % mathvariant, end="") reftest = open("../relations/css-styling/mathvariant-%s.html" % mathvariant, "w") reftestReference = open("../relations/css-styling/mathvariant-%s-ref.html" % mathvariant, "w") source = '\ \n\ \n\ \n\ \n\ mathvariant %s\n' reftest.write(source % mathvariant) reftestReference.write(source % ("%s (reference)" % mathvariant)) source ='\ \n\ \n\ \n' reftest.write(source % (mathvariant, mathvariant)) source = '\ \n\ \n\ \n\

Test passes if all the equalities below are true.

\n' % mathvariant reftest.write(source) reftestReference.write(source) charIndex = 0 for baseChar in mathvariantTransforms[mathvariant]: transformedChar = mathvariantTransforms[mathvariant][baseChar] reftest.write(' &#x%0X;=%05X' % (mathvariant, baseChar, transformedChar)) reftestReference.write(' &#x%0X;=%05X' % (transformedChar, transformedChar)) charIndex += 1 if charIndex % 10 == 0: reftest.write('
') reftestReference.write('
') reftest.write('\n') reftestReference.write('\n') source = '\n\n' reftest.write(source) reftestReference.write(source) reftest.close() reftestReference.close() print(" done.")