www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

annotation-xml.js (3136B)


      1 /* -*- Mode: Javascript; indent-tabs-mode:nil; js-indent-level: 2 -*- */
      2 /* vim: set ts=2 et sw=2 tw=80: */
      3 
      4 /*************************************************************
      5  *
      6  *  MathJax/jax/output/SVG/autoload/annotation-xml.js
      7  *  
      8  *  Implements the SVG output for <annotation-xml> elements.
      9  *
     10  *  ---------------------------------------------------------------------
     11  *  
     12  *  Copyright (c) 2013-2015 The MathJax Consortium
     13  * 
     14  *  Licensed under the Apache License, Version 2.0 (the "License");
     15  *  you may not use this file except in compliance with the License.
     16  *  You may obtain a copy of the License at
     17  * 
     18  *      http://www.apache.org/licenses/LICENSE-2.0
     19  * 
     20  *  Unless required by applicable law or agreed to in writing, software
     21  *  distributed under the License is distributed on an "AS IS" BASIS,
     22  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     23  *  See the License for the specific language governing permissions and
     24  *  limitations under the License.
     25  */
     26 
     27 MathJax.Hub.Register.StartupHook("SVG Jax Ready",function () {
     28   var VERSION = "2.6.0";
     29   var MML = MathJax.ElementJax.mml,
     30       SVG = MathJax.OutputJax.SVG;
     31   var BBOX = SVG.BBOX;
     32   
     33   BBOX.FOREIGN = BBOX.Subclass({type: "foreignObject", removeable: false});
     34 
     35   MML["annotation-xml"].Augment({
     36     toSVG: function () {
     37       var svg = this.SVG(); this.SVGhandleSpace(svg);
     38       var encoding = this.Get("encoding");
     39       for (var i = 0, m = this.data.length; i < m; i++)
     40         {svg.Add(this.data[i].toSVG(encoding),svg.w,0)}
     41       svg.Clean();
     42       this.SVGhandleColor(svg);
     43       this.SVGsaveData(svg);
     44       return svg;
     45     }
     46   });
     47   
     48   MML.xml.Augment({
     49     toSVG: function (encoding) {
     50       //
     51       //  Get size of xml content
     52       //
     53       var span = SVG.textSVG.parentNode;
     54       SVG.mathDiv.style.width = "auto";  // Firefox returns offsetWidth = 0 without this
     55       span.insertBefore(this.div,SVG.textSVG);
     56       var w = this.div.offsetWidth, h = this.div.offsetHeight;
     57       var strut = MathJax.HTML.addElement(this.div,"span",{
     58         style:{display:"inline-block", overflow:"hidden", height:h+"px",
     59                width:"1px", marginRight:"-1px"}
     60       });
     61       var d = this.div.offsetHeight - h; h -= d;
     62       this.div.removeChild(strut);
     63       span.removeChild(this.div); SVG.mathDiv.style.width = "";
     64       //
     65       //  Create foreignObject element for the content
     66       //
     67       var scale = 1000/SVG.em;
     68       var svg = BBOX.FOREIGN({
     69         y:(-h)+"px", width:w+"px", height:(h+d)+"px",
     70         transform:"scale("+scale+") matrix(1 0 0 -1 0 0)"
     71       });
     72       //
     73       //  Add the children to the foreignObject
     74       //
     75       for (var i = 0, m = this.data.length; i < m; i++) 
     76         {svg.element.appendChild(this.data[i].cloneNode(true))}
     77       //
     78       //  Set the scale and finish up
     79       //
     80       svg.w = w*scale; svg.h = h*scale; svg.d = d*scale;
     81       svg.r = svg.w; svg.l = 0;
     82       svg.Clean();
     83       this.SVGsaveData(svg);
     84       return svg;
     85     }
     86   });
     87   
     88   MathJax.Hub.Startup.signal.Post("SVG annotation-xml Ready");
     89   MathJax.Ajax.loadComplete(SVG.autoloadDir+"/annotation-xml.js");
     90 
     91 });
     92