mediawiki-extensions-Math/modules/MathJax/jax/output/SVG/autoload/mtable.js

17 lines
7 KiB
JavaScript
Raw Normal View History

/*
* /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.0";var a=MathJax.ElementJax.mml,d=MathJax.OutputJax.SVG,b=d.BBOX;a.mtable.Augment({toSVG:function(U){var l=this.SVG();if(this.data.length===0){return l}var aF=this.getValues("columnalign","rowalign","columnspacing","rowspacing","columnwidth","equalcolumns","equalrows","columnlines","rowlines","frame","framespacing","align","useHeight","width","side","minlabelspacing");if(aF.width.match(/%$/)){l.width=aF.width=Math.floor(d.cwidth*parseFloat(aF.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;var aH=d.FONTDATA.baselineskip*aj*aF.useHeight,V=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}K[aB][aA]=N.data[aA-at].toSVG();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],V)}if(u[K.length-1]+B[K.length-1]){B[K.length-1]=Math.max(B[K.length-1],ac)}var ai=aF.columnspacing.split(/ /),O=aF.rowspacing.split(/ /),ae=aF.columnalign.split(/ /),G=aF.rowalign.split(/ /),I=aF.columnlines.split(/ /),g=aF.rowlines.split(/ /),al=aF.columnwidth.split(/ /),ap=[];for(aB=0,ay=ai.length;aB<ay;aB++){ai[aB]=d.length2em(ai[aB],r)}for(aB=0,ay=O.length;aB<ay;aB++){O[aB]=d.length2em(O[aB],r)}while(ai.length<t){ai.push(ai[ai.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]=(aF.side.substr(0,1)==="l"?"left":"right");ai[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(aF.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}}var au=u[0]+B[K.length-1];for(aB=0,ay=K.length-1;aB<ay;aB++){au+=Math.max((u[aB]+B[aB]?aH:0),B[aB]+u[aB+1]+O[aB])}var aa=0,X=0,av,aE=au;if(aF.frame!=="none"||(aF.columnlines+aF.rowlines).match(/solid|dashed/)){aa=d.length2em(aF.framespacing.split(/[, ]+/)[0],r);X=d.length2em(aF.framespacing.split(/[, ]+/)[1],r);aE=au+2*X}var e,ar,ax="";if(typeof(aF.align)!=="string"){aF.align=String(aF.align)}if(aF.align.match(/(top|bottom|center|baseline|axis)( +(-?\d+))?/)){ax=RegExp.$3;aF.align=RegExp.$1}else{aF.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+X)+u[0];for(aB=0,ay=ax-1;aB<ay;aB++){var T=Math.max((u[aB]+B[aB]?aH:0),B[aB]+u[aB+1]+O[aB]);e+=T;ar+=T}}else{e=({top:-(u[0]+X),bottom:au+X-u[0],center:au/2-u[0],baseline:au/2-u[0],axis:au/2+d.TeX.axis_height*aj-u[0]})[aF.align];ar=({top:-(au+2*X),bottom:0,center:-(au/2+X),baseline:-(au/2+X),axis:d.TeX.axis_height*aj-au/2-X})[aF.align]}var am,aq=0,R=0,S=0,aw=0,aC=0,o=[],w=[],af=1;if(aF.equalcolumns&&aF.width!=="auto"){am=d.length2em(aF.width,r);for(aB=0,ay=Math.min(t+1,ai.length);aB<ay;aB++){am-=ai[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"){w[aC]=aB;aC++;R+=h[aB]}else{if(al[aB].match(/%$/)){o[aw]=aB;aw++;S+=h[aB];aq+=d.length2em(al[aB],r,1)}else{h[aB]=d.length2em(al[aB],r);R+=h[aB]}}}}if(aF.width==="auto"){if(aq>0.98){af=S/(R+S);am=R+S}else{am=R/(1-aq)}}else{am=d.length2em(aF.width,r);for(aB=0,ay=Math.min(t+1,ai.length);aB<ay;aB++){am-=ai[aB]}}for(aB=0,ay=o.length;aB<ay;aB++){h[o[aB]]=d.length2em(al[o[aB]],r,am*af);R+=h[o[aB]]}if(Math.abs(am-R)>0.01){if(aC&&am>R){am=(am-R)/aC;for(aB=0,ay=w.length;aB<ay;aB++){h[w[aB]]+=am}}e