Stackedit/public/libs/MathJax/jax/output/HTML-CSS/autoload/multiline.js

20 lines
12 KiB
JavaScript
Raw Normal View History

2013-10-09 01:15:00 +00:00
/*
* /MathJax/jax/output/HTML-CSS/autoload/multiline.js
2013-11-19 22:02:44 +00:00
*
2013-10-09 01:15:00 +00:00
* Copyright (c) 2009-2013 The MathJax Consortium
*
2013-11-19 22:02:44 +00:00
* Licensed under the Apache License, Version 2.0 (the "License");
2013-10-09 01:15:00 +00:00
* you may not use this file except in compliance with the License.
2013-11-19 22:02:44 +00:00
* You may obtain a copy of the License at
2013-10-09 01:15:00 +00:00
*
* http://www.apache.org/licenses/LICENSE-2.0
2013-11-19 22:02:44 +00:00
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
2013-10-09 01:15:00 +00:00
*/
2013-11-19 22:02:44 +00:00
MathJax.Hub.Register.StartupHook("HTML-CSS Jax Ready",function(){var d="2.3";var a=MathJax.ElementJax.mml,b=MathJax.OutputJax["HTML-CSS"];var e={newline:0,nobreak:1000000,goodbreak:[-200],badbreak:[+200],auto:[0],toobig:800,nestfactor:400,spacefactor:-100,spaceoffset:2,spacelimit:1,fence:500,close:500};var c={linebreakstyle:"after"};a.mbase.Augment({HTMLlinebreakPenalty:e,HTMLmultiline:function(n){var o=this;while(o.inferred||(o.parent&&o.parent.type==="mrow"&&o.parent.data.length===1)){o=o.parent}var l=((o.type==="math"&&o.Get("display")==="block")||o.type==="mtd");o.isMultiline=true;var p=this.getValues("linebreak","linebreakstyle","lineleading","linebreakmultchar","indentalign","indentshift","indentalignfirst","indentshiftfirst","indentalignlast","indentshiftlast");if(p.linebreakstyle===a.LINEBREAKSTYLE.INFIXLINEBREAKSTYLE){p.linebreakstyle=this.Get("infixlinebreakstyle")}p.lineleading=b.length2em(p.lineleading,1,0.5);this.HTMLremoveColor(n);var m=b.createStack(n);var f={n:0,Y:0,scale:this.HTMLgetScale(),isTop:l,values:{},VALUES:p},k=this.HTMLgetAlign(f,{}),h=this.HTMLgetShift(f,{},k),g=[],i={index:[],penalty:e.nobreak,w:0,W:h,shift:h,scanW:h,nest:0},j=false;while(this.HTMLbetterBreak(i,f)&&(i.scanW>=b.linebreakWidth||i.penalty==e.newline)){this.HTMLaddLine(m,g,i.index,f,i.values,j);g=i.index.slice(0);j=true;k=this.HTMLgetAlign(f,i.values);h=this.HTMLgetShift(f,i.values,k);if(k===a.INDENTALIGN.CENTER){h=0}i.W=i.shift=i.scanW=h;i.penalty=e.nobreak}f.isLast=true;this.HTMLaddLine(m,g,[],f,c,j);if(l){m.style.width="100%";if(o.type==="math"){n.bbox.width="100%"}}this.HTMLhandleSpace(n);this.HTMLhandleColor(n);n.bbox.isMultiline=true;return n},HTMLbetterBreak:function(h,f){if(this.isToken){return false}if(this.isEmbellished()){h.embellished=this;return this.CoreMO().HTMLbetterBreak(h,f)}if(this.linebreakContainer){return false}var p=h.index.slice(0),n=h.index.shift(),l=this.data.length,k,q,j,o=(h.index.length>0),g=false;if(n==null){n=-1}if(!o){n++;h.W+=h.w;h.w=0}j=h.scanW=h.W;h.nest++;while(n<l&&h.scanW<1.33*b.linebreakWidth){if(this.data[n]){if(this.data[n].HTMLbetterBreak(h,f)){g=true;p=[n].concat(h.index);k=h.W;q=h.w;if(h.penalty===e.newline){h.index=p;if(h.nest){h.nest--}return true}}j=(o?h.scanW:this.HTMLaddWidth(n,h,j))}h.index=[];n++;o=false}if(h.nest){h.nest--}h.index=p;if(g){h.W=k;h.w=q}return g},HTMLaddWidth:function(f,j,h){if(this.data[f]){var g=this.data[f].HTMLspanElement();h+=g.bbox.w;if(g.style.paddingLeft){h+=b.unEm(g.style.paddingLeft)}if(g.style.paddingRight){h+=b.unEm(g.style.paddingRight)}j.W=j.scanW=h;j.w=0}return h},HTMLaddLine:function(n,g,j,f,o,l){line=b.createBox(n);line.bbox=this.HTMLemptyBBox({});f.first=l;f.last=true;this.HTMLmoveLine(g,j,line,f,o);this.HTMLcleanBBox(line.bbox);var m=this.HTMLgetAlign(f,o),h=this.HTMLgetShift(f,o,m);if(h){b.createBlank(line,h,(m!==a.INDENTALIGN.RIGHT));line.bbox.w+=h;line.bbox.rw+=h}if(f.n>0){var k=b.FONTDATA.baselineskip*f.scale;var i=(f.values.lineleading==null?f.VALUES:f.values).lineleading;f.Y-=Math.max(k,f.d+line.bbox.h+i)}b.alignBox(line,m,f.Y);f.d=line.bbox.d;f.values=o;f.n++},HTMLgetAlign:function(i,f){var j=f,g=i.values,h=i.VALUES,k;if(i.n===0){k=j.indentalignfirst||g.indentalignfirst||h.indentalignfirst}else{if(i.isLast){k=g.indentalignlast||h.indentalignlast}else{k=g.indentalign||h.indentalign}}if(k===a.INDENTALIGN.INDENTALIGN){k=g.indentalign||h.indentalign}if(k===a.INDENTALIGN.AUTO){k=(i.isTop?this.displayAlign:a.INDENTALIGN.LEFT)}return k},HTMLgetShift:function(j,g,l){if(l===a.INDENTALIGN.CENTER){return 0}var k=g,h=j.values,i=j.VALUES,f;if(j.n===0){f=k.indentshiftfirst||h.indentshiftfirst||i.indentshiftfirst}else{if(j.isLast){f=h.indentshiftlast||i.indentshiftlast}else{f=h.indentshift||i.indentshift}}if(f===a.INDENTSHIFT.INDENTSHIFT){f=h.indentshift||i.indentshift}if(f==="auto"||f===""){f=(j.isTSop?this.displayIndent:"0")}return b.length2em(f,0)},HTMLmoveLine:function(o,f,l,n,g){var k=o[0],h=f[0];if(k==null){k=-1}if(h==null){h=this.data.length-1}if(k===h&&o.length>1){this.data[k].HTMLmoveSlice(o.slice(1),f.slice(1),l,n,g,"paddingLeft")}else{var m=n