Stackedit/lib/MathJax/jax/output/SVG/autoload/mtable.js

17 lines
7.3 KiB
JavaScript
Raw Normal View History

2013-05-12 00:48:25 +00:00
/*
* /MathJax/jax/output/SVG/autoload/mtable.js
*
* Copyright (c) 2012 Design Science, Inc.
*
* Part of the MathJax library.
* See http://www.mathjax.org for details.
*
* Licensed under the Apache License, Version 2.0;
* you may not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
MathJax.Hub.Register.StartupHook("SVG Jax Ready",function(){var c="2.1";var a=MathJax.ElementJax.mml,d=MathJax.OutputJax.SVG,b=d.BBOX;a.mtable.Augment({toSVG:function(U){this.SVGgetStyles();var l=this.SVG();if(this.data.length===0){return l}var aG=this.getValues("columnalign","rowalign","columnspacing","rowspacing","columnwidth","equalcolumns","equalrows","columnlines","rowlines","frame","framespacing","align","useHeight","width","side","minlabelspacing");if(aG.width.match(/%$/)){l.width=aG.width=Math.floor(d.cwidth*parseFloat(aG.width)/100)+"px"}var aj=this.SVGgetScale(),r=this.SVGgetMu(l);var aD=-1;var u=[],B=[],h=[],K=[],E=[],aB,aA,t=-1,ay,q,at,N,ai,w;var aI=d.FONTDATA.baselineskip*aj*aG.useHeight,au,X=d.FONTDATA.lineH*aj,ac=d.FONTDATA.lineD*aj;for(aB=0,ay=this.data.length;aB<ay;aB++){N=this.data[aB];at=(N.type==="mlabeledtr"?aD:0);K[aB]=[];u[aB]=B[aB]=0;for(aA=at,q=N.data.length+at;aA<q;aA++){if(h[aA]==null){if(aA>t){t=aA}E[aA]=b.G();h[aA]=-d.BIGDIMEN}ai=N.data[aA-at];K[aB][aA]=ai.toSVG();if(ai.isEmbellished()){w=ai.CoreMO();var aF=w.Get("minsize",true);if(aF){if(w.SVGcanStretch("Vertical")){au=w.SVGdata.h+w.SVGdata.d;if(au){aF=d.length2em(aF,r,au);if(aF*w.SVGdata.h/au>u[aA]){u[aA]=aF*w.SVGdata.h/au}if(aF*w.SVGdata.d/au>B[aA]){B[aA]=aF*w.SVGdata.d/au}}}else{if(w.SVGcanStretch("Horizontal")){aF=d.length2em(aF,r,w.SVGdata.w);if(aF>h[aA]){h[aA]=aF}}}}}if(K[aB][aA].h>u[aB]){u[aB]=K[aB][aA].h}if(K[aB][aA].d>B[aB]){B[aB]=K[aB][aA].d}if(K[aB][aA].w>h[aA]){h[aA]=K[aB][aA].w}}}if(u[0]+B[0]){u[0]=Math.max(u[0],X)}if(u[K.length-1]+B[K.length-1]){B[K.length-1]=Math.max(B[K.length-1],ac)}var ah=aG.columnspacing.split(/ /),O=aG.rowspacing.split(/ /),ae=aG.columnalign.split(/ /),G=aG.rowalign.split(/ /),I=aG.columnlines.split(/ /),g=aG.rowlines.split(/ /),al=aG.columnwidth.split(/ /),ap=[];for(aB=0,ay=ah.length;aB<ay;aB++){ah[aB]=d.length2em(ah[aB],r)}for(aB=0,ay=O.length;aB<ay;aB++){O[aB]=d.length2em(O[aB],r)}while(ah.length<t){ah.push(ah[ah.length-1])}while(ae.length<=t){ae.push(ae[ae.length-1])}while(I.length<t){I.push(I[I.length-1])}while(al.length<=t){al.push(al[al.length-1])}while(O.length<K.length){O.push(O[O.length-1])}while(G.length<=K.length){G.push(G[G.length-1])}while(g.length<K.length){g.push(g[g.length-1])}if(E[aD]){ae[aD]=(aG.side.substr(0,1)==="l"?"left":"right");ah[aD]=-h[aD]}for(aB=0,ay=K.length;aB<ay;aB++){N=this.data[aB];ap[aB]=[];if(N.rowalign){G[aB]=N.rowalign}if(N.columnalign){ap[aB]=N.columnalign.split(/ /);while(ap[aB].length<=t){ap[aB].push(ap[aB][ap[aB].length-1])}}}if(aG.equalrows){var Q=Math.max.apply(Math,u),ak=Math.max.apply(Math,B);for(aB=0,ay=K.length;aB<ay;aB++){at=((Q+ak)-(u[aB]+B[aB]))/2;u[aB]+=at;B[aB]+=at}}au=u[0]+B[K.length-1];for(aB=0,ay=K.length-1;aB<ay;aB++){au+=Math.max((u[aB]+B[aB]?aI:0),B[aB]+u[aB+1]+O[aB])}var aa=0,V=0,av,aE=au;if(aG.frame!=="none"||(aG.columnlines+aG.rowlines).match(/solid|dashed/)){aa=d.length2em(aG.framespacing.split(/[, ]+/)[0],r);V=d.length2em(aG.framespacing.split(/[, ]+/)[1],r);aE=au+2*V}var e,ar,ax="";if(typeof(aG.align)!=="string"){aG.align=String(aG.align)}if(aG.align.match(/(top|bottom|center|baseline|axis)( +(-?\d+))?/)){ax=RegExp.$3;aG.align=RegExp.$1}else{aG.align=this.defaults.align}if(ax!==""){ax=parseInt(ax);if(ax<0){ax=K.length+1+ax}if(ax<1){ax=1}else{if(ax>K.length){ax=K.length}}e=0;ar=-(au+V)+u[0];for(aB=0,ay=ax-1;aB<ay;aB++){var T=Math.max((u[aB]+B[aB]?aI:0),B[aB]+u[aB+1]+O[aB]);e+=T;ar+=T}}else{e=({top:-(u[0]+V),bottom:au+V-u[0],center:au/2-u[0],baseline:au/2-u[0],axis:au/2+d.TeX.axis_height*aj-u[0]})[aG.align];ar=({top:-(au+2*V),bottom:0,center:-(au/2+V),baseline:-(au/2+V),axis:d.TeX.axis_height*aj-au/2-V})[aG.align]}var am,aq=0,R=0,S=0,aw=0,aC=0,o=[],v=[],af=1;if(aG.equalcolumns&&aG.width!=="auto"){am=d.length2em(aG.width,r);for(aB=0,ay=Math.min(t+1,ah.length);aB<ay;aB++){am-=ah[aB]}am/=t+1;for(aB=0,ay=Math.min(t+1,al.length);aB<ay;aB++){h[aB]=am}}else{for(aB=0,ay=Math.min(t+1,al.length);aB<ay;aB++){if(al[aB]==="auto"){R+=h[aB]}else{if(al[aB]==="fit"){v[aC]=aB;aC++;R+=h[aB]}else{if(al[aB].match(/%$/)){o[aw]=aB;aw++;S+=h[aB];aq+=d.length2em(al[aB