layout/mathml/MathJaxFonts.html
author Mike Shal <mshal@mozilla.com>
Fri, 16 May 2014 14:37:31 -0400
changeset 210584 c0efa7f1e54c2dfbc9dfa77c49bf0411bc8b891d
parent 108856 f9094ef74bf369e3112887164afc9e8a6fdfb799
permissions -rw-r--r--
Bug 978211 - add an automation/build target for post-build steps; r=glandium

<!-- -*- mode: HTML; tab-width: 2; indent-tabs-mode: nil; -*- -->
<!-- vim: set tabstop=2 expandtab shiftwidth=2 textwidth=80:  -->
<!-- This Source Code Form is subject to the terms of the Mozilla Public
   - License, v. 2.0. If a copy of the MPL was not distributed with this
   - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<!DOCTYPE html>
<html>
  <head>
    <title>MathJax fonts</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <script type="text/x-mathjax-config">
      MathJax.Hub.Config({
        jax: ["output/HTML-CSS"],
        "HTML-CSS": { availableFonts: ["TeX"] }
      });
    </script>
    <script type="text/javascript"
            src="http://cdn.mathjax.org/mathjax/latest/unpacked/MathJax.js">
    </script>
    <script type="text/javascript">
      var fontList = [
        "MathJax_Main",
        "MathJax_Size1",
        "MathJax_Size2",
        "MathJax_Size3",
        "MathJax_Size4",
        "MathJax_AMS",
        "MathJax_Main-bold"
      ];

      var noChar = codePoint();

      function codePoint(aValue, aFont)
      {
        var v = 0xFFFD;
        if (aValue) {
          v = aValue;
        }
        var f = "";
        if (aFont) {
          var i = fontList.indexOf(aFont);
          if (i > 0) {
            f = "@" + i;
          }
        }
        var hexacode = Number(v).toString(16).toUpperCase();
        while (hexacode.length < 4) {
          hexacode = "0" + hexacode;
        }
        return "\\u" + hexacode + f;
      }

      function codePoint2(aList)
      {
        if (aList) {
          return codePoint(aList[0], aList[1]);
        } else {
          return noChar;
        }
      }

      function isSupported(aStretch)
      {
        for (var x in aStretch) {
          var part = aStretch[x];
          if (part[0] instanceof Array) {
            // Composite char
            return false;
          } else if (part.length > 2) {
            // Part has scale factor
            return false;
          }
        }
        return true;
      }

      MathJax.Hub.Queue(
      ["Require", MathJax.Ajax, "[MathJax]/jax/element/mml/jax.js"],
      ["Require", MathJax.Ajax, "[MathJax]/jax/output/HTML-CSS/jax.js"],
      ["Require", MathJax.Ajax, "[MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata-extra.js"],
      function () {

      var t = document.getElementById("output");
      t.value = "";

      var fontData = MathJax.OutputJax["HTML-CSS"].FONTDATA;

      t.value += "# Content below is generated from MathJaxFonts.html. Do not edit.\n";
      t.value += "\n";

      // Generate the list of external fonts
      for (var i = 1; i < fontList.length; i++) {
        t.value += "external." + i + " = " + fontList[i] + "\n";
      }
      t.value += "\n";

      // Generate stretchy table for delimiters
      var delimiters = fontData.DELIMITERS;
      for (var u in delimiters) {

        var v = delimiters[u];

        if (v.load) {
          // These characters are already handled when we load fontdata-extra.js
          continue;
        }

        if (v.alias) {
          if (delimiters.hasOwnProperty(v.alias)) {
            // use data from the char pointed by this alias
            v = delimiters[v.alias];
          } else {
            // It is an alias to a non-stretchy char. Ignore it.
            continue;
          }
        }

        if (v.stretch && !isSupported(v.stretch)) {
          // This construction is not supported.
          t.value += "# " + codePoint(u) + " = [not supported]\n";
          continue;
        }

        t.value += codePoint(u);
        t.value += " = ";
        if (v.stretch) {
          if (v.dir == "V") {
            t.value += codePoint2(v.stretch.top);
            t.value += codePoint2(v.stretch.mid);
            t.value += codePoint2(v.stretch.bot);
            t.value += codePoint2(v.stretch.ext);
          } else {
            t.value += codePoint2(v.stretch.left);
            t.value += codePoint2(v.stretch.mid);
            t.value += codePoint2(v.stretch.right);
            t.value += codePoint2(v.stretch.rep);
          }
        } else {
          t.value += noChar + noChar + noChar + noChar;
        }

        for (var i in v.HW) {
            t.value += codePoint(u, v.HW[i][1]);
        }

        t.value += "\n";
      }

      // Generate table for large operators
      var fonts1 = fontData.FONTS[fontList[1]];
      var fonts2 = fontData.FONTS[fontList[2]];
      for (var u in fonts1) {
        if (delimiters.hasOwnProperty(u) || // already listed above
            u == "version" || u == "available" ||
            u == "directory" ||  u == "family" || u == "testString") {
          // Ignore these properties
          continue;
        }
        t.value += codePoint(u);
        t.value += " = ";
        t.value += noChar + noChar + noChar + noChar;
        t.value += codePoint(u, fontList[1]);
        if (fonts2.hasOwnProperty(u)) {
          t.value += codePoint(u, fontList[2]);
        }
        t.value += "\n";
       }
 
     });
    </script>
  </head>

  <body>

    <textarea id="output" cols="80" rows="20"></textarea>

  </body>
</html>