instiki/public/MathJax/jax/output/HTML-CSS/autoload/mtable.js

17 lines
9.5 KiB
JavaScript
Raw Normal View History

/*
2011-01-28 02:12:00 +01:00
* /MathJax/jax/output/HTML-CSS/autoload/mtable.js
*
* Copyright (c) 2010 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
*/
2011-06-01 21:35:18 +02:00
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){var c="1.1";var a=MathJax.ElementJax.mml,b=MathJax.OutputJax["HTML-CSS"];a.mtable.Augment({toHTML:function(X){X=this.HTMLcreateSpan(X);if(this.data.length===0){return X}var aJ=this.getValues("columnalign","rowalign","columnspacing","rowspacing","columnwidth","equalcolumns","equalrows","columnlines","rowlines","frame","framespacing","align","useHeight","width","side","minlabelspacing");var r=aJ.width.match(/%$/);var ag=b.createStack(X);var am=this.HTMLgetScale();var aH=-1;var w=[],I=[],l=[],O=[],K=[],aF,aE,v=-1,aC,t,ay,R;var aL=b.FONTDATA.baselineskip*am*aJ.useHeight,Z=b.FONTDATA.lineH*am,af=b.FONTDATA.lineD*am;for(aF=0,aC=this.data.length;aF<aC;aF++){R=this.data[aF];ay=(R.type==="mlabeledtr"?aH:0);O[aF]=[];w[aF]=I[aF]=0;for(aE=ay,t=R.data.length+ay;aE<t;aE++){if(l[aE]==null){if(aE>v){v=aE}K[aE]=b.createStack(b.createBox(ag));l[aE]=-b.BIGDIMEN}O[aF][aE]=b.createBox(K[aE]);b.Measured(R.data[aE-ay].toHTML(O[aF][aE]),O[aF][aE]);if(R.data[aE-ay].isMultiline){O[aF][aE].style.width="100%"}if(O[aF][aE].bbox.h>w[aF]){w[aF]=O[aF][aE].bbox.h}if(O[aF][aE].bbox.d>I[aF]){I[aF]=O[aF][aE].bbox.d}if(O[aF][aE].bbox.w>l[aE]){l[aE]=O[aF][aE].bbox.w}}}if(w[0]+I[0]){w[0]=Math.max(w[0],Z)}if(w[O.length-1]+I[O.length-1]){I[O.length-1]=Math.max(I[O.length-1],af)}var al=aJ.columnspacing.split(/ /),S=aJ.rowspacing.split(/ /),ah=aJ.columnalign.split(/ /),L=aJ.rowalign.split(/ /),N=aJ.columnlines.split(/ /),k=aJ.rowlines.split(/ /),ap=aJ.columnwidth.split(/ /),au=[];for(aF=0,aC=al.length;aF<aC;aF++){al[aF]=b.length2em(al[aF])}for(aF=0,aC=S.length;aF<aC;aF++){S[aF]=b.length2em(S[aF])}while(al.length<v){al.push(al[al.length-1])}while(ah.length<=v){ah.push(ah[ah.length-1])}while(N.length<v){N.push(N[N.length-1])}while(ap.length<=v){ap.push(ap[ap.length-1])}while(S.length<O.length){S.push(S[S.length-1])}while(L.length<=O.length){L.push(L[L.length-1])}while(k.length<O.length){k.push(k[k.length-1])}if(K[aH]){ah[aH]=(aJ.side.substr(0,1)==="l"?"left":"right");al[aH]=-l[aH]}for(aF=0,aC=O.length;aF<aC;aF++){R=this.data[aF];au[aF]=[];if(R.rowalign){L[aF]=R.rowalign}if(R.columnalign){au[aF]=R.columnalign.split(/ /);while(au[aF].length<=v){au[aF].push(au[aF][au[aF].length-1])}}}var az=w[0]+I[O.length-1];for(aF=0,aC=O.length-1;aF<aC;aF++){az+=Math.max((w[aF]+I[aF]?aL:0),I[aF]+w[aF+1]+S[aF])}var ac=0,aa=0,aA,aI=az;if(aJ.frame!=="none"||(aJ.columnlines+aJ.rowlines).match(/solid|dashed/)){ac=b.length2em(aJ.framespacing.split(/[, ]+/)[0]);aa=b.length2em(aJ.framespacing.split(/[, ]+/)[1]);aI=az+2*aa}var h,ax;if(String(aJ.align).match(/^\d+$/)){h=az/2+b.TeX.axis_height*am-w[0];ax=-(az/2+aa)}else{h=({top:-(w[0]+aa),bottom:az+aa-w[0],center:az/2-w[0],baseline:az/2-w[0],axis:az/2+b.TeX.axis_height*am-w[0]})[aJ.align];ax=({top:-(az+2*aa),bottom:0,center:-(az/2+aa),baseline:-(az/2+aa),axis:b.TeX.axis_height*am-az/2-aa})[aJ.align]}var aq,aw=0,U=0,V=0,aB=0,aG=0,o=[],B=[],ai=1;if(aJ.equalcolumns&&aJ.width!=="auto"){if(r){aq=(100/(v+1)).toFixed(2).replace(/\.?0+$/,"")+"%";for(aF=0,aC=Math.min(v+1,ap.length);aF<aC;aF++){ap[aF]=aq}aq=0;aw=1;aG=v+1;for(aF=0,aC=Math.min(v+1,al.length);aF<aC;aF++){aq+=al[aF]}}else{aq=b.length2em(aJ.width);for(aF=0,aC=Math.min(v+1,al.length);aF<aC;aF++){aq-=al[aF]}aq/=v+1;for(aF=0,aC=Math.min(v+1,ap.length);aF<aC;aF++){l[aF]=aq}}}else{for(aF=0,aC=Math.min(v+1,ap.length);aF<aC;aF++){if(ap[aF]==="auto"){U+=l[aF]}else{if(ap[aF]==="fit"){B[aG]=aF;aG++;U+=l[aF]}else{if(ap[aF].match(/%$/)){o[aB]=aF;aB++;V+=l[aF];aw+=b.length2em(ap[aF],1)}else{l[aF]=b.length2em(ap[aF]);U+=l[aF]}}}}if(r){aq=0;for(aF=0,aC=Math.min(v,al.length);aF<aC;aF++){aq+=al[aF]}if(aw>0.98){ai=0.98/aw;aw=0.98}}else{if(aJ.width==="auto"){if(aw>0.98){ai=V/(U+V);aq=U+V}else{aq=U/(1-aw)}}else{aq=b.length2em(aJ.width);for(aF=0,aC=Math.min(v+1,al.length);aF<aC;aF++){aq-=al[aF]}}for(aF=0,aC=o.length;aF<aC;aF++){l[o[aF]]=b.length2em(ap[o[aF]],aq*ai);U+=l[o[aF]]}if(Math.abs(aq-U)>0.01){if(aG&&aq>U){aq=(aq-U)/aG;for(aF=0,aC=B.length;aF<aC;aF++){l[B[aF]]+=aq}}else{aq=aq/U;for(aE=0;aE<=v;aE++){l[aE]*=aq}}}if(aJ.equalcolumns){var ad=Mat