annotation-xml.js 2.2 KB

12345678910111213141516171819202122232425
  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/SVG/autoload/annotation-xml.js
  6. *
  7. * Implements the SVG output for <annotation-xml> elements.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2013 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. */MathJax.Hub.Register.StartupHook("SVG Jax Ready",function(){var f=MathJax.ElementJax.mml,e=MathJax.OutputJax.SVG,g=e.BBOX;g.FOREIGN=g.Subclass({type:"foreignObject",removeable:!1});f["annotation-xml"].Augment({toSVG:function(){var b=this.SVG();this.SVGhandleSpace(b);for(var d=this.Get("encoding"),c=0,a=this.data.length;c<a;c++)b.Add(this.data[c].toSVG(d),b.w,0);b.Clean();this.SVGhandleColor(b);this.SVGsaveData(b);return b}});f.xml.Augment({toSVG:function(b){var d=e.textSVG.parentNode;e.mathDiv.style.width="auto";d.insertBefore(this.div,e.textSVG);b=this.div.offsetWidth;var c=this.div.offsetHeight,a=MathJax.HTML.addElement(this.div,"span",{style:{display:"inline-block",overflow:"hidden",height:c+"px",width:"1px",marginRight:"-1px"}}),h=this.div.offsetHeight-c,c=c-h;this.div.removeChild(a);d.removeChild(this.div);e.mathDiv.style.width="";for(var d=1E3/e.em,a=g.FOREIGN({y:-c+"px",width:b+"px",height:c+h+"px",transform:"scale("+d+") matrix(1 0 0 -1 0 0)"}),k=0,f=this.data.length;k<f;k++)a.element.appendChild(this.data[k].cloneNode(!0));a.w=b*d;a.h=c*d;a.d=h*d;a.r=a.w;a.l=0;a.Clean();this.SVGsaveData(a);return a}});MathJax.Hub.Startup.signal.Post("SVG annotation-xml Ready");MathJax.Ajax.loadComplete(e.autoloadDir+"/annotation-xml.js")});