mglyph.js 2.8 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/mglyph.js
  6. *
  7. * Implements the SVG output for <mglyph> elements.
  8. *
  9. * ---------------------------------------------------------------------
  10. *
  11. * Copyright (c) 2011-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 d=MathJax.ElementJax.mml,f=MathJax.OutputJax.SVG,e=f.BBOX,m=MathJax.Localization;e.MGLYPH=e.Subclass({type:"image",removeable:!1,Init:function(l,h,b,c,a,g){null==g&&(g={});var d=1E3*l.width/f.em,k=1E3*l.height/f.em,e=0;""!==h&&(d=f.length2em(h,a,d));""!==b&&(k=f.length2em(b,a,k));""!==c&&c.match(/\d/)&&(e=f.length2em(c,a),g.y=-e);g.height=Math.floor(k);g.width=Math.floor(d);g.transform="translate(0,"+k+") matrix(1 0 0 -1 0 0)";g.preserveAspectRatio="none";this.SUPER(arguments).Init.call(this,g);this.element.setAttributeNS("http://www.w3.org/1999/xlink","href",l.src);this.w=this.r=d;this.h=this.H=k+e;this.d=this.D=-e;this.l=0}});d.mglyph.Augment({toSVG:function(f,h){this.SVGgetStyles();var b=this.SVG(),c;this.SVGhandleSpace(b);var a=this.getValues("src","width","height","valign","alt");""===a.src?(a=this.getValues("index","fontfamily"),a.index&&(h||(h=this.SVGgetScale()),c={},a.fontfamily&&(c["font-family"]=a.fontfamily),b.Add(e.TEXT(h,String.fromCharCode(a.index),c)))):(this.img||(this.img=d.mglyph.GLYPH[a.src]),this.img||(this.img=d.mglyph.GLYPH[a.src]={img:new Image,status:"pending"},c=this.img.img,c.onload=MathJax.Callback(["SVGimgLoaded",this]),c.onerror=MathJax.Callback(["SVGimgError",this]),c.src=a.src,MathJax.Hub.RestartAfter(c.onload)),"OK"!==this.img.status?(b=d.merror(m._(["MathML","BadMglyph"],"Bad mglyph: %1",a.src)).With({mathsize:"75%"}),this.Append(b),b=b.toSVG(),this.data.pop()):(c=this.SVGgetMu(b),b.Add(e.MGLYPH(this.img.img,a.width,a.height,a.valign,c,{src:a.src,alt:a.alt,title:a.alt}))));b.Clean();this.SVGhandleColor(b);this.SVGsaveData(b);return b},SVGimgLoaded:function(d,e){"string"===typeof d&&(e=d);this.img.status=e||"OK"},SVGimgError:function(){this.img.img.onload("error")}},{GLYPH:{}});MathJax.Hub.Startup.signal.Post("SVG mglyph Ready");MathJax.Ajax.loadComplete(f.autoloadDir+"/mglyph.js")});