mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-30 02:15:06 +00:00
17 lines
7 KiB
JavaScript
17 lines
7 KiB
JavaScript
/*
|
|
* /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}}else{am=am/R;for(aA=0;aA<=t;aA++){h[aA]*=am}}}if(aF.equalcolumns){var ab=Math.max.apply(Math,h);for(aA=0;aA<=t;aA++){h[aA]=ab}}}var an=e,k,az;at=(E[aD]?aD:0);for(aA=at;aA<=t;aA++){E[aA].w=h[aA];for(aB=0,ay=K.length;aB<ay;aB++){if(K[aB][aA]){at=(this.data[aB].type==="mlabeledtr"?aD:0);var ah=this.data[aB].data[aA-at];if(ah.SVGcanStretch("Horizontal")){K[aB][aA]=ah.SVGstretchH(h[aA])}else{if(ah.SVGcanStretch("Vertical")){var v=ah.CoreMO();var Z=v.symmetric;v.symmetric=false;K[aB][aA]=ah.SVGstretchV(u[aB],B[aB]);v.symmetric=Z}}az=ah.rowalign||this.data[aB].rowalign||G[aB];k=({top:u[aB]-K[aB][aA].h,bottom:K[aB][aA].d-B[aB],center:((u[aB]-B[aB])-(K[aB][aA].h-K[aB][aA].d))/2,baseline:0,axis:0})[az];az=(ah.columnalign||ap[aB][aA]||ae[aA]);E[aA].Align(K[aB][aA],az,0,an+k)}if(aB<K.length-1){an-=Math.max((u[aB]+B[aB]?aH:0),B[aB]+u[aB+1]+O[aB])}}an=e}var ad=1.5*d.em;var ao=aa-ad/2;for(aA=0;aA<=t;aA++){l.Add(E[aA],ao,0);ao+=h[aA]+ai[aA];if(I[aA]!=="none"&&aA<t&&aA!==aD){l.Add(b.VLINE(aE,ad,I[aA]),ao-ai[aA]/2,ar)}}l.w+=aa;l.d=-ar;l.h=aE+ar;av=l.w;if(aF.frame!=="none"){l.Add(b.HLINE(av,ad,aF.frame),0,ar+aE-ad);l.Add(b.HLINE(av,ad,aF.frame),0,ar);l.Add(b.VLINE(aE,ad,aF.frame),0,ar);l.Add(b.VLINE(aE,ad,aF.frame),av-ad,ar)}an=e-ad/2;for(aB=0,ay=K.length-1;aB<ay;aB++){k=Math.max(aH,B[aB]+u[aB+1]+O[aB]);if(g[aB]!=="none"){l.Add(b.HLINE(av,ad,g[aB]),0,an-B[aB]-(k-B[aB]-u[aB+1])/2)}an-=k}l.Clean();this.SVGhandleSpace(l);this.SVGhandleColor(l);if(E[aD]){var L=this.getValues("indentalignfirst","indentshiftfirst","indentalign","indentshift");if(L.indentalignfirst!==a.INDENTALIGN.INDENTALIGN){L.indentalign=L.indentalignfirst}if(L.indentalign===a.INDENTALIGN.AUTO){L.indentalign=this.displayAlign}if(L.indentshiftfirst!==a.INDENTSHIFT.INDENTSHIFT){L.indentshift=L.indentshiftfirst}if(L.indentshift==="auto"){L.indentshift=this.displayIndent}var ag=(L.indentshift?d.length2em(L.indentshift,r):0);var aG=d.length2em(aF.minlabelspacing,r);var z=l;l=this.SVG();if(L.indentalign===a.INDENTALIGN.CENTER){l.w=l.r=d.length2em(d.cwidth+"px");ag=0;l.hasIndent=true}else{if(ae[aD]!==L.indentalign){l.w=l.r=d.length2em(d.cwidth+"px")-ag-aG;ag=aG=0}else{l.w=l.r=z.w+ag;l.hasIndent=true}}l.Align(z,L.indentalign,ag,0);l.Align(E[aD],ae[aD],aG,0)}this.SVGsaveData(l);return l},SVGhandleSpace:function(e){if(!this.hasFrame&&!e.width){e.x=e.X=167}this.SUPER(arguments).SVGhandleSpace.call(this,e)}});a.mtd.Augment({toSVG:function(e,g){var f=this.svg=this.SVG();if(this.data[0]){f.Add(this.SVGdataStretched(0,e,g));f.Clean()}this.SVGhandleColor(f);this.SVGsaveData(f);return f}});MathJax.Hub.Startup.signal.Post("SVG mtable Ready");MathJax.Ajax.loadComplete(d.autoloadDir+"/mtable.js")});
|
|
|