annotation-xml.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
  2. /* vim: set ts=2 et sw=2 tw=80: */
  3. /*************************************************************
  4. *
  5. * MathJax/jax/output/CommonHTML/autoload/annotation-xm;l.js
  6. *
  7. * Implements the CommonHTML output for <annotation-xml> elements.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2015-2017 The MathJax Consortium
  12. *
  13. * Licensed under the Apache License, Version 2.0 (the "License");
  14. * you may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at
  16. *
  17. * http://www.apache.org/licenses/LICENSE-2.0
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. */
  25. MathJax.Hub.Register.StartupHook("CommonHTML Jax Ready",function () {
  26. var VERSION = "2.7.2";
  27. var MML = MathJax.ElementJax.mml,
  28. CHTML = MathJax.OutputJax.CommonHTML;
  29. MML["annotation-xml"].Augment({
  30. toCommonHTML: function (node) {
  31. var encoding = this.Get("encoding");
  32. node = this.CHTMLdefaultNode(node,{childOptions:{encoding:encoding}});
  33. if (this.CHTML.rscale !== 1) this.CHTML.rescale(1/this.CHTML.rscale);
  34. return node;
  35. }
  36. });
  37. MML.xml.Augment({
  38. toCommonHTML: function (node,options) {
  39. var bbox = this.CHTML = CHTML.BBOX.zero();
  40. for (var i = 0, m = this.data.length; i < m; i++)
  41. {node.appendChild(this.data[i].cloneNode(true))}
  42. //
  43. // Warning: causes reflow
  44. //
  45. var w = node.offsetWidth, h = node.offsetHeight;
  46. var strut = CHTML.addElement(node,"mjx-hd-test",{style:{height:h+"px"}});
  47. bbox.d = bbox.b = (node.offsetHeight - h)/CHTML.em;
  48. bbox.w = bbox.r = w/CHTML.em; bbox.h = bbox.t = h/CHTML.em - bbox.d;
  49. node.removeChild(strut);
  50. }
  51. });
  52. MathJax.Hub.Startup.signal.Post("CommonHTML annotation-xml Ready");
  53. MathJax.Ajax.loadComplete(CHTML.autoloadDir+"/annotation-xml.js");
  54. });