/*
 source : nehan2.js
 version : 1.23
 site : http://tategakibunko.mydns.jp/
 blog : http://tategakibunko.blog83.fc2.com/

 Copyright (c) 2010, Watanabe Masaki <lambda.watanabe@gmail.com>
 licenced under MIT licence.

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.
*/
var Nehan;Nehan||(Nehan={});
(function(){function o(a,b,c){this.text=a;this.length=b;this.eof=c;this.pos=0}function p(a){this.stream=a}function q(a){h.readOption(this,{direction:"vertical",width:400,height:300,fontSize:16,fontColor:"000000",linkColor:"0000FF",charImgRoot:"http://nehan.googlecode.com/hg/char-img/",nextLineOffsetRate:1.8},a);this.init()}function s(a){this.lineTokens=[];this.nextLineTokens=[];this.rubyTokens=[];this.nextRubyTokens=[];this.activeTags={};this.tagStack=[];this.fontStack=[];this.indentStack=[];this.dotTokens=
[];this.repushTokenStack=[];this.curFontScale=1;this.curFontColor=a.fontColor;this.curFontSize=a.fontSize;this.curFontSizeHalf=a.fontSizeHalf;this.curIndent={before:0,after:0};this.seekNextChar=this.seekNextLine=this.curCharCount=this.saveSeekPos=this.curPageNo=this.curBorderSize=0;this.pageHtml="";this.pageHeadPos=0}function g(a,b){this.lexer=a;this.layout=b;this.context=new s(b);this.parseEnd=false;this.elementHandler=[];this.tocTable=[]}function n(a,b,c){this.layout=a;this.lexer=b;this.parser=
c;this.stream=this.lexer.stream}function k(a,b,c){this.layout=new q(a);this.lexer=c?new p(new o(b,c,b.length>=c)):new p(new o(b,b.length,true));this.parser=new g(this.lexer,this.layout);this.parserProxy=new n(this.layout,this.lexer,this.parser);this.pageHeadPos=[{spos:0,cpos:0}];this.resuming=false;this.cache=[];this.restoreContext=null}function u(a,b){this.node=a;this.nodeNo=b;this.groupName="nehan-layout-group-"+b;this.order=0;this.isEnd=false;this.direction="vertical";this.fontSize=16;this.fontColor=
"000000";this.linkColor="0000FF";this.width=400;this.height=300;this.init(a.className)}function t(a,b){this.grids=[];this.groupName=a;this.opt=b}var v={init:function(){this.browser=this.searchString(this.dataBrowser)||"An unknown browser";this.version=this.searchVersion(navigator.userAgent)||this.searchVersion(navigator.appVersion)||"an unknown version";this.OS=this.searchString(this.dataOS)||"an unknown OS"},searchString:function(a){for(var b=0;b<a.length;b++){var c=a[b].string,d=a[b].prop;this.versionSearchString=
a[b].versionSearch||a[b].identity;if(c){if(c.indexOf(a[b].subString)!=-1)return a[b].identity}else if(d)return a[b].identity}},searchVersion:function(a){var b=a.indexOf(this.versionSearchString);if(b!=-1)return parseFloat(a.substring(b+this.versionSearchString.length+1))},dataBrowser:[{string:navigator.userAgent,subString:"Chrome",identity:"Chrome"},{string:navigator.userAgent,subString:"OmniWeb",versionSearch:"OmniWeb/",identity:"OmniWeb"},{string:navigator.vendor,subString:"Apple",identity:"Safari",
versionSearch:"Version"},{prop:window.opera,identity:"Opera"},{string:navigator.vendor,subString:"iCab",identity:"iCab"},{string:navigator.vendor,subString:"KDE",identity:"Konqueror"},{string:navigator.userAgent,subString:"Firefox",identity:"Firefox"},{string:navigator.vendor,subString:"Camino",identity:"Camino"},{string:navigator.userAgent,subString:"Netscape",identity:"Netscape"},{string:navigator.userAgent,subString:"MSIE",identity:"Explorer",versionSearch:"MSIE"},{string:navigator.userAgent,subString:"Gecko",
identity:"Mozilla",versionSearch:"rv"},{string:navigator.userAgent,subString:"Mozilla",identity:"Netscape",versionSearch:"Mozilla"}],dataOS:[{string:navigator.platform,subString:"Win",identity:"Windows"},{string:navigator.platform,subString:"Mac",identity:"Mac"},{string:navigator.userAgent,subString:"iPhone",identity:"iPhone/iPod"},{string:navigator.platform,subString:"Linux",identity:"Linux"}]};v.init();var r={init:function(){var a=v.browser.toLowerCase(),b=v.version,c=v.OS;this.isIE=a=="explorer";
this.isWin=c=="Windows";this.isMac=c=="Mac";this.isIPhone=navigator.platform=="iPhone";this.isIPad=navigator.platform=="iPad";this.isIPod=navigator.platform=="iPod";this.isMobileSafari=this.isIPhone||this.isIPad||this.isIPod;this.canTransform=a=="chrome"?true:a=="safari"?true:a=="firefox"&&b>=3.5?true:a=="opera"?true:this.isIE&&b>=6?true:false}};r.init();var x={RG:[0,36,73,109,146,182,219,255],B:[0,85,170,255],getRGB:function(a){return{r:parseInt(a.substring(0,2),16),g:parseInt(a.substring(2,4),16),
b:parseInt(a.substring(4,6),16)}},findNear:function(a,b){if(a==0||a==255)return a;for(var c=256,d=0,e=0;e<b.length;e++){var f=Math.abs(a-b[e]);if(f<c){c=f;d=b[e]}}return d},get:function(a){var b=this.getRGB(a.replace("#","")),c=function(e){return e.length<=1?"0"+e:e};a=c(this.findNear(b.r,this.RG).toString(16));var d=c(this.findNear(b.g,this.RG).toString(16));b=c(this.findNear(b.b,this.B).toString(16));return(a+d+b).toUpperCase()}},h={filenameConcat:function(a,b){a=a==""?"":a.slice(-1)=="/"?a:a+"/";
b=b==""?"":b[0]=="/"?b.substring(1,b.length):b;return a+b},readOption:function(a,b,c){for(prop in b)a[prop]=typeof c[prop]=="undefined"?b[prop]:c[prop]},deepCopy:function(a){var b;if(typeof a=="object")if(a instanceof Array){b=[];for(var c=0;c<a.length;c++)b[c]=this.deepCopy(a[c])}else{b={};for(prop in a)b[prop]=this.deepCopy(a[prop])}else b=a;return b},cutQuote:function(a){return a.replace(/\"/g,"").replace(/\'/g,"")},inlineAttr:function(a){var b="";for(prop in a)if(a[prop]!="")b+=" "+prop+"='"+
a[prop]+"'";return b},inlineCss:function(a){var b="";for(prop in a)b+=prop+":"+a[prop]+";";return b},tagStart:function(a,b,c){a="<"+a;if(b)a+=this.inlineAttr(b);a+=c?"/>":">";return a},tagWrap:function(a,b,c){return this.tagStart(a,b,false)+c+"</"+a+">"},setRadius:function(a,b,c,d){c=c+"px";d["-moz-border-radius-"+a+b]=c;d["-khtml-border-radius-"+a+b]=c;d["-webkit-border-"+a+"-"+b+"-radius"]=c}},z={get:function(a){switch(a){case "\u300c":case "\uff62":return{imgname:"kakko1",hscale:0.5,kind:"img-char"};
case "\u300d":case "\uff63":return{imgname:"kakko2",hscale:0.5,kind:"img-char"};case "\u300e":return{imgname:"kakko3",hscale:0.5,kind:"img-char"};case "\u300f":return{imgname:"kakko4",hscale:0.5,kind:"img-char"};case "\uff08":case "(":case "\uff5b":case "{":return{imgname:"kakko5",hscale:0.5,kind:"img-char"};case "\uff09":case ")":case "\uff5d":case "}":return{imgname:"kakko6",hscale:0.5,kind:"img-char"};case "\uff1c":case "<":case "\u3008":return{imgname:"kakko7",hscale:0.5,kind:"img-char"};case "\uff1e":case ">":case "\u3009":return{imgname:"kakko8",
hscale:0.5,kind:"img-char"};case "\u300a":case "\u226a":return{imgname:"kakko9",hscale:0.5,kind:"img-char"};case "\u300b":case "\u226b":return{imgname:"kakko10",hscale:0.5,kind:"img-char"};case "\uff3b":case "\u3014":case "[":return{imgname:"kakko11",hscale:0.5,kind:"img-char"};case "\uff3d":case "\u3015":case "]":return{imgname:"kakko12",hscale:0.5,kind:"img-char"};case "\u3010":return{imgname:"kakko17",hscale:0.5,kind:"img-char"};case "\u3011":return{imgname:"kakko18",hscale:0.5,kind:"img-char"};
case "\uff1a":case ":":return{imgname:"tenten",hscale:0.5,kind:"img-char"};case "\u3002":case "\uff61":return{imgname:"kuten",hscale:0.5,kind:"img-char"};case "\uff0e":case ".":return{imgname:"period",hscale:1,kind:"img-char"};case "\u3001":case "\uff64":case ",":case "\uff0c":return{imgname:"touten",hscale:0.5,kind:"img-char"};case "\uff5e":case "\u301c":return{imgname:"kara",hscale:1,kind:"img-char"};case "\u2026":return{imgname:"mmm",hscale:1,kind:"img-char"};case "\u2025":return{imgname:"mm",
hscale:1,kind:"img-char"};case "\u301d":return{imgname:"dmn1",hscale:1,kind:"img-char"};case "\u301f":return{imgname:"dmn2",hscale:1,kind:"img-char"};case "\uff1d":case "=":return{imgname:"equal",hscale:1,kind:"img-char"};case "\u30fc":return{imgname:"onbiki",hscale:1,kind:"img-char"};case "-":case "\u2015":case "\uff0d":case "\u2500":return{data:"\uff5c",kind:"cnv-char"};case "\u2191":return{data:"\u2192",kind:"cnv-char"};case "\u2192":case "\u21d2":return{data:"\u2193",kind:"cnv-char"};case "\u2193":return{data:"\u2190",
kind:"cnv-char"};case "\u2190":return{data:"\u2191",kind:"cnv-char"};default:return null}}},y={h1:{scale:3,family:"Meiryo",weight:"bold"},h2:{scale:2,family:"Meiryo",weight:"bold"},h3:{scale:1.5,family:"Meiryo"},h4:{scale:1.2,family:"Meiryo"},h5:{scale:1,family:"Meiryo",weight:"bold"}};o.prototype.lookChar=function(){if(this.pos==this.length)return"\n";if(this.pos>this.length)throw"BufferEnd";if(this.pos>=this.text.length)throw"BufferShort";return this.text.charAt(this.pos)};o.prototype.readUntil=
function(a){var b=this.pos;a=this.text.indexOf(a,b+1);if(a<0)throw"BufferShort";this.pos=a+1;return this.text.substring(b,a+1)};o.prototype.readMatch=function(a){var b=this.pos;a=this.text.substring(b).match(a).toString();if(a!="")this.pos=b+a.length;return this.text.substring(b,b+a.length)};o.prototype.stepSeekPos=function(){this.pos++};o.prototype.getSeekPos=function(){return this.pos};o.prototype.setSeekPos=function(a){if(a<this.length)this.pos=a};o.prototype.setText=function(a){this.text=a;this.length=
a.length;this.eof=true};o.prototype.getText=function(){return this.text};o.prototype.addText=function(a){this.text+=a;this.eof=this.text.length>=this.length};o.prototype.getSeekPercent=function(){return Math.floor(100*this.pos/this.length)};o.prototype.setEOF=function(a){return this.eof=a};o.prototype.isEOF=function(){return this.eof};p.prototype.getStream=function(){return this.stream};p.prototype.tag=function(a,b){var c=b.replace("<","").replace("/>","").replace(">","").split(/[\s\t\u3000]+/),d=
{};d.src=b;d.name=c[0].toLowerCase();d.attr={};for(var e=0;e<c.length;e++)(function(f){if(f.match(/([^=]+)=(.+)/)){f=RegExp.$1;var j=h.cutQuote(RegExp.$2);d.attr[f]=j}})(c[e],e);return{type:"tag",data:d,pos:a}};p.prototype.character=function(a,b){var c=z.get(b);if(c){c.type="char";c.half=false;c.pos=a;if(c.kind=="img-char")c.data=b;else if(c.kind=="cnv-char")c.fromdata=b;return c}if(b.match(/[\u3041\u30a1\u3043\u30a3\u3045\u30a5\u3047\u30a7\u3049\u30a9\u30f5\u30f6\u3063\u30c3\u3083\u30e3\u3085\u30e5\u3087\u30e7\u308e\u30ee]/))return{type:"char",
half:false,kind:"small-kana",data:b,pos:a};if(b.charAt(0)=="&")return{type:"char",half:true,kind:"special-char",data:b,pos:a};if(escape(b).charAt(1)=="u")return{type:"char",half:false,kind:"zen",data:b,pos:a};return{type:"char",half:true,kind:"small",data:b,pos:a}};p.prototype.word=function(a,b){return{type:"word",data:b,pos:a}};p.prototype.tcy=function(a,b){return{type:"tcy",data:b,pos:a}};p.prototype.getNext=function(){var a=this.stream.getSeekPos(),b=this.stream.lookChar();if(b=="<")return this.tag(a,
this.stream.readUntil(">"));else if(b=="&")return this.character(a,this.stream.readUntil(";"));else if(r.canTransform&&b.match(/[0-9a-zA-Z!\.\?\/\_:#]/)){b=this.stream.readMatch(/[0-9a-zA-Z!\.\?\/\_:#]+/);return b.length<=2&&!isNaN(b)||b=="!?"||b=="!!"||b=="??"?this.tcy(a,b):this.word(a,b)}else{this.stream.stepSeekPos();return this.character(a,b)}};p.prototype.lookNextStr=function(){for(var a=this.stream.getSeekPos(),b=null;;){var c=this.getNext();if(c.type=="char"||c.type=="tcy"||c.type=="word"){b=
c;break}}this.stream.setSeekPos(a);return b};p.prototype.skipUntilTag=function(a){for(;;){var b=this.getNext();if(b.type=="tag"&&b.data.name==a)break}};p.prototype.skipCRLF=function(a){for(var b=0;;){var c=this.getNext();if(c.type!="char"||c.type=="char"&&c.data!="\r"&&c.data!="\n"){this.stream.setSeekPos(c.pos);break}c.data=="\n"&&b++;if(a&&b>=a)break}};q.prototype.init=function(){this.direction=this.direction.toLowerCase();this.isV=this.direction.match(/vertical/i)?true:false;this.baseNextLineSize=
Math.floor(this.nextLineOffsetRate*this.fontSize);this.baseRubyFontSize=this.fontSizeHalf=Math.floor(this.fontSize/2);this.baseExtraLineSize=this.baseNextLineSize-this.fontSize;if(this.isV){this.invDirection="horizontal";this.extraFontSize=this.fontSizeHalf;this.width=Math.max(this.baseNextLineSize,this.width);this.height=Math.max(this.fontSize+this.extraFontSize,this.height);this.lineEndSize=this.height-this.extraFontSize;this.nextCharMaxSize=this.height;this.nextLineMaxSize=this.width}else{this.invDirection=
"vertical";this.extraFontSize=this.fontSize;this.width=Math.max(this.fontSize+this.extraFontSize,this.width);this.height=Math.max(this.baseNextLineSize,this.height);this.nextCharMaxSize=this.width-this.extraFontSize;this.nextLineMaxSize=this.height}this.linkColor=x.get(this.linkColor)};q.prototype.getIndentCount=function(a){return a.before+a.after};q.prototype.getIndentSize=function(a){return this.fontSize*a};q.prototype.getNextCharMaxSize=function(a){return this.nextCharMaxSize-this.getIndentSize(this.getIndentCount(a.curIndent))};
q.prototype.getAlignSpaceSize=function(a,b){return{width:this.isV?a+this.baseExtraLineSize:this.width-a-this.baseExtraLineSize,height:this.isV?this.height-b-this.baseExtraLineSize:b+this.baseExtraLineSize}};q.prototype.isAlignEnable=function(a,b){return this.isV?b*2>this.height:a*2>this.width};s.prototype.setActiveTag=function(a){this.activeTags[a.replace("/","")]=a.substring(0,1)!="/"};s.prototype.isActiveTag=function(a){return this.activeTags[a]||false};s.prototype.setFontScale=function(a,b){this.curFontScale=
b;this.curFontSize=Math.floor(a.fontSize*b);this.curFontSizeHalf=Math.floor(this.curFontSize/2)};s.prototype.inheritLine=function(){this.lineTokens=this.nextLineTokens;this.nextLineTokens=[];this.rubyTokens=this.nextRubyTokens;this.nextRubyTokens=[]};g.prototype.hasNextPage=function(){return this.parseEnd==false};g.prototype.getLexer=function(){return this.lexer};g.prototype.getTocTable=function(){return this.tocTable};g.prototype.isHeadNg=function(a){if(a.match(/[\uff09\)\u300d\u3011\u3015\uff3d\]\u3002\u300f\uff1e\u3009\u300b\u3001\uff0e\.,]/))return true;
return false};g.prototype.isHeadNgToken=function(a){if(a.type!="char")return false;return this.isHeadNg(a.data)};g.prototype.isTailNg=function(a){if(a.match(/[\uff08\(\u300c\u3010\uff3b\u3014\u300e\uff1c\u3008\u300a]/))return true;return false};g.prototype.isTailNgToken=function(a){if(a.type!="char")return false;return this.isTailNg(a.data)};g.prototype.isTextToken=function(a){return a.type=="char"||a.type=="word"||a.type=="tcy"};g.prototype.isTailConnectiveChar=function(a){return a.type=="char"&&
a.data.match(/[\u3001\u3002\.\uff0e,\uff0c]/)};g.prototype.isKakkoStartChar=function(a){if(a.match(/[\u300c\u300e\u3010\uff3b\uff08\u300a\u3008\u226a\uff1c\[\(]/))return true;return false};g.prototype.isKakkoEndChar=function(a){if(a.match(/[\u300d\u300f\u3011\uff3d\uff09\u300b\u3009\u226b\uff1e\]\)]/))return true;return false};g.prototype.isParserEnd=function(){return this.parseEnd};g.prototype.isNextCharOver=function(a,b,c){return b.seekNextChar+c.nextOffset>a.getNextCharMaxSize(b)};g.prototype.isNextLineOver=
function(a,b,c){return b.seekNextLine+c>a.nextLineMaxSize};g.prototype.isLineOverflow=function(a,b){return b.seekNextChar>a.getNextCharMaxSize(b)};g.prototype.setFont=function(a,b,c){c.scale&&this.setFontScale(a,b,parseFloat(c.scale));if(c["border-width"])b.curBorderSize=parseInt(c["border-width"]);if(c.color)b.curFontColor=x.get(c.color)};g.prototype.setFontScale=function(a,b,c){b.setFontScale(a,c)};g.prototype.resetFont=function(a,b){b.curFontScale=1;b.curFontColor=a.fontColor;b.curFontSize=a.fontSize;
b.curFontSizeHalf=a.baseRubyFontSize;b.curBorderSize=0};g.prototype.popFont=function(a,b){b.tagStack.pop();b.fontStack.pop();var c=b.fontStack.length;c>0?this.setFont(a,b,b.fontStack[c-1]):this.resetFont(a,b)};g.prototype.popIndent=function(a,b){var c=b.indentStack.pop();if(c){b.curIndent.before-=c.before;b.curIndent.after-=c.after}};g.prototype.getFontCss=function(a,b,c){b={};for(prop in c)if(prop=="scale"){var d=parseFloat(c.scale);b["font-size"]=Math.floor(a.fontSize*d)+"px";if(a.isV)b["line-height"]=
Math.floor(a.fontSize*d)+"px"}else if(prop=="family")b["font-family"]=c[prop];else if(prop=="weight")b["font-weight"]=c[prop];else if(prop=="color")b.color=c[prop];else if(prop=="bgcolor")b["background-color"]=c[prop];else if(prop=="border-radius-tl")h.setRadius("top","left",parseInt(c[prop]),b);else if(prop=="border-radius-tr")h.setRadius("top","right",parseInt(c[prop]),b);else if(prop=="border-radius-bl")h.setRadius("bottom","left",parseInt(c[prop]),b);else if(prop=="border-radius-br")h.setRadius("bottom",
"right",parseInt(c[prop]),b);else if(prop=="border-radius"){d=parseInt(c[prop]);h.setRadius("top","left",d,b);h.setRadius("top","right",d,b);h.setRadius("bottom","left",d,b);h.setRadius("bottom","right",d,b)}else if(prop=="border-width")b["border-width"]=parseInt(c[prop])+"px";else if(prop=="border-color")b["border-color"]=c[prop];else if(prop=="border-style")b["border-style"]=c[prop];return b};g.prototype.tagFontStart=function(a,b,c){return h.tagStart(a.isV?"div":"span",{style:h.inlineCss(this.getFontCss(a,
b,c))},false)};g.prototype.tagFontEnd=function(a){return a.isV?"</div>":"</span>"};g.prototype.getMaxFontScale=function(a){for(var b=1,c=0;c<a.length;c++){var d=a[c];if(d.type=="tag"){d=d.data;if(d.name=="font"&&d.attr.scale){d=parseFloat(d.attr.scale);if(d>b)for(var e=c+1;e<a.length;e++)if(this.isTextToken(a[e]))b=d}}}return b};g.prototype.getLineTextLength=function(a){for(var b=0,c=0;c<a.length;c++){var d=a[c];if(this.isTextToken(d))b+=d.nextOffset}return b};g.prototype.getTokenLength=function(a){if(a.type==
"tag")return a.data.src.length;return a.data.length};g.prototype.getLineTailStr=function(a){for(var b=a.lineTokens.length-1;b>=0;b--){var c=a.lineTokens[b];if(this.isTextToken(c))return c}return null};g.prototype.getRubyToken=function(a,b,c,d){return{pos:c,yomi:d,fontSize:b.curFontSizeHalf,nextOffset:b.curFontSizeHalf,requireSpaceSize:b.curFontSize}};g.prototype.getRubyCss=function(a,b,c,d,e){b={position:"absolute","font-size":d+"px"};var f=e>1?Math.floor((e-1)*a.baseExtraLineSize/2):0;if(a.isV){b["margin-top"]=
c+"px";b["line-height"]=r.isMobileSafari?"0.9em":"1.1em";if(e>1&&d<=a.baseRubyFontSize){b["margin-left"]="-"+f+"px";b["float"]="left"}}else{b["margin-left"]=c+"px";if(e>1&&d<=a.baseRubyFontSize)b["padding-top"]=f+f+f+"px"}return b};g.prototype.getDotToken=function(a,b,c,d){var e=a.nextLineOffsetRate-1;a=Math.floor(b.curFontSize*e);e=Math.floor(b.curFontSize*(1-e)/2);return{pos:c+e,count:d,fontSize:a,nextOffset:b.curFontSize,requireSpaceSize:b.curFontSize,offsetHead:e,hspace:b.curFontSize-a}};g.prototype.getDotCss=
function(a,b,c){return a.isV?{position:"absolute","margin-top":c.pos,"font-size":c.fontSize+"px","line-height":c.nextOffset+"px","font-weight":"bold"}:{position:"absolute","margin-left":c.pos,"font-size":c.fontSize,"letter-spacing":c.hspace+"px","font-weight":"bold"}};g.prototype.getTailCharToken=function(a){for(var b=a.length-1;b>=0;b--)if(this.isTextToken(a[b]))return a[b];return null};g.prototype.isTailNgLine=function(a){if((a=this.getTailCharToken(a))&&a.type=="char")return this.isTailNgToken(a);
return false};g.prototype.sweepOverflowTokens=function(a,b){for(var c=b.lineTokens.length,d=a.getNextCharMaxSize(b),e=0,f=0;f<c;f++){var j=b.lineTokens[f];if(this.isTextToken(j)){e+=j.nextOffset;if(e>d)break}}if(0<f&&f<c){b.nextLineTokens=b.lineTokens.slice(f).concat(b.nextLineTokens);b.lineTokens=b.lineTokens.slice(0,f)}};g.prototype.sweepWhileMatch=function(a,b,c,d,e){for(var f=false;a.length>0;){var j=a.pop();if(c(j)){b.push(j);f=true}else if(e(j)){b.push(j);f=true;break}else if(d(j)){a.push(j);
break}}return f};g.prototype.fixLineEnd=function(a,b,c){var d=this;(a=this.getTailCharToken(b))&&this.isTailNgToken(a)&&this.sweepWhileMatch(b,c,function(e){return d.isTailNgToken(e)},function(e){return!d.isTailNgToken(e)},function(){return false})&&c.sort(function(e,f){return e.pos-f.pos});this.isHeadNgToken(c[0])&&this.sweepWhileMatch(b,c,function(){return false},function(){return false},function(e){return!d.isHeadNgToken(e)})&&c.sort(function(e,f){return e.pos-f.pos})};g.prototype.parseTag=function(a,
b,c,d,e){var f=d.data;c.setActiveTag(f.name);if(this.elementHandler[f.name])this.elementHandler[f.name](this,a,b,c,d);else if(f.name=="a")this.parseStraightForwardTagStart(a,b,c,d);else if(f.name=="/a")this.parseStraightForwardTagEnd(a,b,c,d);else if(f.name=="b"||f.name=="strong")this.parseStraightForwardTagStart(a,b,c,d);else if(f.name=="/b"||f.name=="/strong")this.parseStraightForwardTagEnd(a,b,c,d);else if(f.name=="ruby")this.parseRuby(a,b,c,d);else if(f.name=="rt")a.skipUntilTag("/rt");else if(f.name==
"rp")a.skipUntilTag("/rp");else if(f.name=="font")this.parseFontStart(a,b,c,d);else if(f.name=="/font")this.parseFontEnd(a,b,c,d);else if(f.name=="img")this.parseImg(a,b,c,d);else if(f.name=="end-page")this.parseEndPage(a,b,c,d,e);else if(f.name=="dot")this.parseDot(a,b,c,d);else if(f.name=="indent")this.parseIndentStart(a,b,c,d);else if(f.name=="/indent")this.parseIndentEnd(a,b,c,d);else if(f.name=="toc")this.parseToc(a,b,c,d);else if(f.name=="pack")this.parsePack(a,b,c,d);else if(f.name=="h1"||
f.name=="h2"||f.name=="h3"||f.name=="h4"||f.name=="h5")this.parseHeaderStart(a,b,c,d);else if(f.name=="/h1"||f.name=="/h2"||f.name=="/h3"||f.name=="/h4"||f.name=="/h5")this.parseHeaderEnd(a,b,c,d);else if(f.name=="blockquote")this.parseBlockquoteStart(a,b,c,d);else if(f.name=="/blockquote")this.parseBlockquoteEnd(a,b,c,d);else if(f.name=="layout")this.parseInlineLayoutStart(a,b,c,d);else f.name=="/layout"&&this.parseInlineLayoutEnd(a,b,c,d)};g.prototype.parseInlineLayoutStart=function(a,b,c,d){if(this.getLineTextLength(c.lineTokens)>
0){a.skipCRLF();this.pushLine(a,b,c,false)}this.setMetricsLayout(a,b,c,d);this.pushInlineLayout(a,b,c,d)};g.prototype.parseInlineLayoutEnd=function(a,b,c,d){a.skipCRLF();this.pushLine(a,b,c,d,false);throw"PageEnd";};g.prototype.parseStraightForwardTagStart=function(a,b,c,d){c.lineTokens.push(d);c.tagStack.push(d)};g.prototype.parseStraightForwardTagEnd=function(a,b,c,d){c.lineTokens.push(d);c.tagStack.pop()};g.prototype.parseIndentStart=function(a,b,c,d){d=d.data.attr;a=d.before?parseInt(d.before):
0;b=d.after?parseInt(d.after):0;d=d.count?parseInt(d.count):0;if(d>0)a=b=d;if(a>0||b>0){c.indentStack.push({before:a,after:b});c.curIndent.before+=a;c.curIndent.after+=b}};g.prototype.parseIndentEnd=function(a,b,c){a.skipCRLF();try{this.pushLine(a,b,c,false)}finally{this.popIndent(b,c)}};g.prototype.parseFontStart=function(a,b,c,d){c.lineTokens.push(d);c.tagStack.push(d);c.fontStack.push(d.data.attr);this.setFont(b,c,d.data.attr)};g.prototype.parseFontEnd=function(a,b,c,d){c.lineTokens.push(d);this.popFont(b,
c)};g.prototype.parseEndPage=function(a,b,c,d,e){if(e)a.getStream().setSeekPos(d.pos);else{a.skipCRLF();this.pushLine(a,b,c,d,false)}throw"PageEnd";};g.prototype.parseHeaderStart=function(a,b,c,d){this.parseFontStart(a,b,c,{type:"tag",data:{name:"font",attr:y[d.data.name]},pos:-1})};g.prototype.parseHeaderEnd=function(a,b,c,d){d=y[d.data.name.replace("/","")].scale;d=Math.floor(b.baseExtraLineSize*d);this.parseFontEnd(a,b,c,{type:"tag",data:{name:"/font",attr:{}},pos:-1});this.pushLine(a,b,c,false);
a.skipCRLF();this.pushSpaceLine(a,b,c,d)};g.prototype.parseBlockquoteStart=function(a,b,c){a.skipCRLF();this.parseIndentStart(a,b,c,{type:"tag",data:{name:"indent",attr:{count:2}},pos:-1});this.parseFontStart(a,b,c,{type:"tag",data:{name:"font",attr:{scale:0.8}},pos:-1})};g.prototype.parseBlockquoteEnd=function(a,b,c){this.parseIndentEnd(a,b,c,{type:"tag",data:{name:"/indent"},pos:-1});this.parseFontEnd(a,b,c,{type:"tag",data:{name:"/font"},pos:-1});a.skipCRLF();this.pushLine(a,b,c,false)};g.prototype.parseRuby=
function(a,b,c,d){var e="",f="ruby",j=c.seekNextChar,i=0;d=d.pos+this.getTokenLength(d);for(var l=b.getNextCharMaxSize(c);;){var m=a.getNext();if(m.type=="tag"){f=m.data.name;if(f=="/ruby"){a.getStream().setSeekPos(d);break}else if(f=="rb")d=m.pos+this.getTokenLength(m);else if(f=="/rt"){if(j+c.curFontSize>=l){j=0;c.nextRubyTokens.push(this.getRubyToken(b,c,j,e))}else{c.rubyTokens.push(this.getRubyToken(b,c,j,e));j+=i}e=""}}else if(this.isTextToken(m)&&m.kind!="img-char")if(f=="rt")e+=m.data;else if(f!=
"rp"){this.setMetricsStr(a,b,c,m);i+=m.nextOffset}}};g.prototype.parseDot=function(a,b,c,d){for(var e=c.seekNextChar,f=-1,j=0;;){d=a.getNext();if(d.type=="tag"&&d.data.name=="/dot"&&j>0){c.dotTokens.push(this.getDotToken(b,c,e,j));f>=0&&a.getStream().setSeekPos(f);break}else if(d.type=="char"){if(f<0)f=d.pos;j++}}};g.prototype.parseToc=function(a,b,c){b="";for(var d=a.getStream().getSeekPos();;){var e=a.getNext();if(e.type=="tag"&&e.data.name=="/toc"){this.tocTable.push({title:b,pageNo:c.curPageNo});
a.getStream().setSeekPos(d);break}else if(this.isTextToken(e))b+=e.data}};g.prototype.parsePack=function(a,b,c,d){var e="";for(a.getStream().getSeekPos();;){var f=a.getNext();if(f.type=="tag"&&f.data.name=="/pack"){e!=""&&this.parseTcy(a,b,c,a.tcy(d.pos,e));break}else if(this.isTextToken(f))e+=f.data}};g.prototype.parseChar=function(a,b,c,d){if(d.data!="\r")if(d.data=="\n")this.pushLine(a,b,c,false);else{this.setMetricsChar(a,b,c,d);this.pushChar(a,b,c,d)}};g.prototype.parseWord=function(a,b,c,d){this.setMetricsWord(a,
b,c,d);this.pushWord(a,b,c,d)};g.prototype.parseTcy=function(a,b,c,d){if(b.isV){this.setMetricsTcy(a,b,c,d);this.pushTcy(a,b,c,d)}else{d.type="word";this.parseWord(a,b,c,d)}};g.prototype.parseImg=function(a,b,c,d){this.getLineTextLength(this.context.lineTokens)>0&&this.pushLine(a,b,c,false);this.setMetricsImg(a,b,c,d);this.pushImg(a,b,c,d)};g.prototype.setMetricsStr=function(a,b,c,d){if(d.type=="char")this.setMetricsChar(a,b,c,d);else if(d.type=="word")this.setMetricsWord(a,b,c,d);else d.type=="tcy"&&
this.setMetricsTcy(a,b,c,d)};g.prototype.setMetricsChar=function(a,b,c,d){if(d.kind=="small-kana")this.setMetricsSmallKana(a,b,c,d);else if(d.kind=="img-char")this.setMetricsImgChar(a,b,c,d);else d.half?this.setMetricsHalfChar(a,b,c,d):this.setMetricsFullChar(a,b,c,d)};g.prototype.setMetricsSmallKana=function(a,b,c,d){d.nextOffset=c.curFontSize;d.fontSize=c.curFontSize};g.prototype.setMetricsImgChar=function(a,b,c,d){var e=d.data,f=d.imgname;d.height=d.nextOffset=d.hscale==1?c.curFontSize:d.hscale==
0.5?c.curFontSizeHalf:Math.floor(c.curFontSize*d.hscale);d.fontSize=c.curFontSize;d.color=c.isActiveTag("a")?b.linkColor:c.curFontColor;if(this.isKakkoStartChar(e)){if((a=this.getLineTailStr(c))&&!this.isKakkoStartChar(a.data)){d.nextOffset+=c.curFontSizeHalf;d.marginTop=c.curFontSizeHalf}}else if(this.isKakkoEndChar(e)){if(b=a.lookNextStr()){a=b.data;b=b.imgname;if(!this.isKakkoEndChar(a)&&b!="tenten"&&b!="kuten"&&b!="touten"&&a!="\u30fb")d.nextOffset=c.curFontSize}}else if(f=="kuten"||f=="touten")if(b=
a.lookNextStr()){a=b.data;if(!this.isKakkoEndChar(a))d.nextOffset=c.curFontSize}};g.prototype.setMetricsHalfChar=function(a,b,c,d){d.nextOffset=r.canTransform||!b.isV?c.curFontSizeHalf:c.curFontSize;d.fontSize=c.curFontSize};g.prototype.setMetricsFullChar=function(a,b,c,d){d.nextOffset=c.curFontSize;d.fontSize=c.curFontSize};g.prototype.setMetricsTcy=function(a,b,c,d){d.fontSize=c.curFontSize;d.nextOffset=c.curFontSize};g.prototype.setMetricsWord=function(a,b,c,d){d.fontSize=c.curFontSize;d.fontWidth=
c.curFontSizeHalf;d.nextOffset=d.data.length*c.curFontSizeHalf};g.prototype.setMetricsImg=function(a,b,c,d){c=d.data.attr;a=parseInt(c.width);c=parseInt(c.height);if(a>b.width){var e=b.width-b.fontSize,f=Math.floor(c*(e/a));a=e;c=f}if(c>b.height){f=b.height-b.fontSize;a=e=Math.floor(a*(f/c));c=f}d.width=a;d.height=c;d.nextOffset=(b.isV?a:c)+b.baseExtraLineSize};g.prototype.setMetricsLayout=function(a,b,c,d){a=d.data.attr;d.width=parseInt(a.width);d.height=parseInt(a.height);d.nextOffset=b.isV?d.width:
d.height};g.prototype.pushLine=function(a,b,c,d){var e=this.getMaxFontScale(c.lineTokens),f=c.curBorderSize+c.curBorderSize,j=Math.floor(b.baseNextLineSize*e);j+=f;if(this.isNextLineOver(b,c,j)){d||c.repushTokenStack.push({type:"char",half:true,kind:"small",data:"\n",pos:-1});throw"PageEnd";}d=Math.floor(b.fontSize*e)+f;f=j-d;var i=this.makeMainText(b,c,e),l=this.makeRubyText(a,b,c,e);e=this.makeDotText(b,c,e);c.pageHtml+=this.makeExtraLine(b,c,l+e,f);c.pageHtml+=this.makeTextLine(b,c,i,d);c.pageHeadPos=
a.getStream().getSeekPos();c.seekNextLine+=j;c.seekNextChar=this.getLineTextLength(c.nextLineTokens);c.inheritLine()};g.prototype.pushSpaceLine=function(a,b,c,d){if(!this.isNextLineOver(b,c,d))if(c.seekNextLine!=0)if(c.seekNextChar==0){c.pageHtml+=this.makeTextLine(b,c,"&nbsp;",d);c.seekNextLine+=d;c.pageHeadPos=a.getStream().getSeekPos()}};g.prototype.pushChar=function(a,b,c,d){c.curCharCount++;if(this.isNextCharOver(b,c,d)){this.isLineOverflow(b,c)&&this.sweepOverflowTokens(b,c);if(this.isTailConnectiveChar(d)&&
c.nextLineTokens.length==0){d.fontSize=b.fontSize;d.height=b.fontSizeHalf;c.lineTokens.push(d);a.skipCRLF(1)}else{c.nextLineTokens.push(d);this.fixLineEnd(b,c.lineTokens,c.nextLineTokens)}this.pushLine(a,b,c,true)}else{c.lineTokens.push(d);c.seekNextChar+=d.nextOffset}};g.prototype.pushWord=function(a,b,c,d){c.curCharCount+=d.data.length;var e=b.getNextCharMaxSize(c),f=e-c.seekNextChar;if(f<d.nextOffset)if(d.nextOffset>e&&f>d.fontWidth){d.data=d.data.substring(0,Math.floor(f/d.fontWidth));d.nextOffset=
f;c.lineTokens.push(d);this.pushLine(a,b,c,true);a.getStream().setSeekPos(d.pos+d.data.length)}else{c.nextLineTokens.push(d);this.pushLine(a,b,c,true)}else{c.lineTokens.push(d);c.seekNextChar+=d.nextOffset}};g.prototype.pushTcy=function(a,b,c,d){c.curCharCount++;if(b.height-c.seekNextChar<d.nextOffset){c.nextLineTokens.push(d);this.pushLine(a,b,c,true)}else{c.lineTokens.push(d);c.seekNextChar+=d.nextOffset}};g.prototype.pushImg=function(a,b,c,d){if(b.nextLineMaxSize-c.seekNextLine<d.nextOffset){a.getStream().setSeekPos(d.pos);
throw"PageEnd";}a.skipCRLF();c.seekNextLine+=d.nextOffset;c.pageHtml+=this.makeImgText(a,b,c,d);c.pageHeadPos=a.getStream().getSeekPos()};g.prototype.pushInlineLayout=function(a,b,c,d){if(!(d.width>b.width||d.height>b.height)){if(this.isNextLineOver(b,c,d.nextOffset))throw"PageEnd";c.seekNextLine+=d.nextOffset;c.pageHtml+=this.makeInlineLayoutText(a,b,c,d);c.pageHeadPos=a.getStream().getSeekPos()}};g.prototype.makeTokenText=function(a,b,c,d){if(c.type=="tag"){c=c.data;if(c.name=="font")return this.tagFontStart(a,
b,c.attr);if(c.name=="/font")return this.tagFontEnd(a);if(c.name=="indent"||c.name=="/indent")return"";return h.tagStart(c.name,c.attr,false)}if(!a.isV){if(c.type=="char"&&c.kind=="cnv-char")return c.fromdata;return c.data}if(c.type=="word")return this.makeWordText(a,b,c,d);if(c.type=="tcy")return this.makeTcyText(a,b,c);return this.makeCharText(a,b,c)};g.prototype.makeCharText=function(a,b,c){if(!a.isV)return c.data;return c.kind=="small-kana"?this.makeSmallKanaText(a,b,c):c.kind=="img-char"?this.makeImgCharText(a,
b,c):c.half?this.makeHalfCharText(a,b,c):this.makeFullCharText(a,b,c)};g.prototype.makeFullCharText=function(a,b,c){return c.data+"<br />"};g.prototype.makeImgCharText=function(a,b,c){a=h.tagStart("img",{src:h.filenameConcat(a.charImgRoot,c.imgname+"/"+c.color+".png"),width:c.fontSize,height:c.height,style:c.marginTop?"margin-top:"+c.marginTop+"px":""},true);return h.tagWrap("div",{"class":"img-char",style:h.inlineCss({clear:"both","line-height":c.nextOffset+"px",height:c.nextOffset+"px"})},a)};g.prototype.makeSmallKanaText=
function(a,b,c){return h.tagWrap("div",{style:h.inlineCss({overflow:"visible",position:"relative",top:r.isMobileSafari?"-0.22em":"-0.12em",right:"-0.12em",height:c.nextOffset+"px","line-height":c.nextOffset+"px"})},c.data)};g.prototype.makeHalfCharText=function(a,b,c){return h.tagWrap("div",{style:h.inlineCss({height:c.nextOffset+"px","line-height":c.nextOffset+"px"})},c.data)};g.prototype.makeWordText=function(a,b,c,d){b=c.data.length<=2?0:c.nextOffset-c.fontSize;a=d>1?a.fontSize*d:a.fontSize;if(c.data.length>
2&&d>1)b=c.nextOffset-a;return r.isIE?h.tagWrap("div",{style:h.inlineCss({"line-height":a+"px","writing-mode":"tb-rl"})},c.data):h.tagWrap("div",{style:h.inlineCss({width:a+"px","line-height":a+"px","margin-bottom":b+"px","-webkit-transform":"rotate(90deg)","-webkit-transform-origin":"50% 50%","-moz-transform":"rotate(90deg)","-moz-transform-origin":"50% 50%","-o-transform":"rotate(90deg)","-o-transform-origin":"50% 50%"})},c.data)};g.prototype.makeTcyText=function(a,b,c){return c.data+"<br />"};
g.prototype.makeImgAlignText=function(a,b,c,d,e){var f=d.data.attr.align;f=f=="top"||f=="left";var j={src:d.data.attr.src,width:d.width,height:d.height},i=b.baseExtraLineSize+"px";if(b.isV)i=f?{margin:[0,i,i,0].join(" ")}:{margin:[i,i,0,0].join(" ")};else{i=f?{margin:[i,i,0,0].join(" ")}:{margin:[i,0,0,i].join(" ")};i["float"]="left"}j.style=h.inlineCss(i);i="";i+=this.makeLineTokensText(b,c,1);i+=h.tagStart("img",j,true);i+=this.makeTagStackCloseText(b,c);c.inheritLine();a=this.makeInlinePageText(a,
b,c,e.width,e.height);b.isV||(a=h.tagWrap("div",{style:"float:left"},a));a=f?i+a:a+i;return h.tagWrap("div",{style:h.inlineCss(b.isV?{"float":"right"}:{width:b.width+"px",height:d.nextOffset+"px"})},a)};g.prototype.makeImgLineText=function(a,b,c,d){a="";d=h.tagStart("img",{src:d.data.attr.src,width:d.width,height:d.height,style:h.inlineCss(b.isV?{"margin-right":b.baseExtraLineSize+"px","float":"right"}:{"margin-bottom":b.baseExtraLineSize+"px"})},true);a+=this.makeLineTokensText(b,c,1);a+=d;a+=this.makeTagStackCloseText(b,
c);c.inheritLine();return a};g.prototype.makeImgText=function(a,b,c,d){if(d.data.attr.align){var e=b.getAlignSpaceSize(d.width,d.height);return b.isAlignEnable(e.width,e.height)?this.makeImgAlignText(a,b,c,d,e):this.makeImgLineText(a,b,c,d)}else return this.makeImgLineText(a,b,c,d)};g.prototype.makeInlineLayoutText=function(a,b,c,d){var e=d.data.attr,f=b.direction;b.direction=e.direction||b.invDirection;b.init();var j=this.makeInlinePageText(a,b,c,d.width,d.height);c.lineTokens=[];c.nextLineTokens=
[];b.direction=f;b.init();if(e.align){e=e.align=="top"||e.align=="left";a=this.makeInlinePageText(a,b,c,b.isV?d.width:b.width-d.width,b.isV?b.height-d.height:d.height);if(b.isV){b=e?j+a:a+j;return h.tagWrap("div",{style:"float:right"},b)}else{b=h.tagWrap("div",{style:"float:left"},j);j=h.tagWrap("div",{style:"float:left"},a);b=e?b+j:j+b;return h.tagWrap("div",{},b)+"<div style='clear:both; line-height:0;'></div>"}}else return tagWrap("div",{style:"float:"+(b.isV?"right":"left")},j)};g.prototype.makeTextLine=
function(a,b,c,d){return a.isV?h.tagWrap("div",{"class":"nehan-vertical-text-line",style:h.inlineCss({"float":"right","text-align":"center","line-height":r.isMobileSafari?"0.9em":a.fontSize+"px",width:d+"px",height:a.height+"px"})},c):h.tagWrap("div",{"class":"nehan-horizontal-text-line",style:h.inlineCss({width:a.width+"px",height:d+"px","text-align":"left","line-height":d+"px"})},c)};g.prototype.makeExtraLine=function(a,b,c,d){if(a.isV){c=c==""?"&nbsp;":c;return h.tagWrap("div",{"class":"nehan-vertical-extra-line",
style:h.inlineCss({"float":"right","text-align":"left",width:d+"px",height:a.height+"px","line-height":r.isMobileSafari?"0.9em":"1em"})},c)}else return h.tagWrap("div",{"class":"nehan-horizontal-extra-line",style:h.inlineCss({width:a.width+"px",height:d+"px","line-height":d+"px"})},c)};g.prototype.makeLineTokensText=function(a,b,c){for(var d="",e=0;e<b.lineTokens.length;e++)d+=this.makeTokenText(a,b,b.lineTokens[e],c);return d};g.prototype.makeMainText=function(a,b,c){c=this.makeLineTokensText(a,
b,c);c=this.makeIndentStackWrapText(a,b,c);c+=this.makeTagStackCloseText(a,b,c);return c};g.prototype.makeIndentStackWrapText=function(a,b,c){for(var d="",e=0;e<b.curIndent.before;e++)d+=this.makeTokenText(a,b,{type:"char",half:false,kind:"zen",data:"\u3000"},1);d+=c;for(e=0;e<b.curIndent.after;e++)d+=this.makeTokenText(a,b,{type:"char",half:false,kind:"zen",data:"\u3000"},1);return d};g.prototype.makeTagStackCloseText=function(a,b){for(var c="",d=b.tagStack.length-1;d>=0;d--){var e=b.tagStack[d];
c+=this.makeTagCloseText(a,e);b.nextLineTokens.unshift(e)}return c};g.prototype.makeTagCloseText=function(a,b){if(b.data.name=="font")return this.tagFontEnd(a);return"</"+b.data.name+">"};g.prototype.makeDotText=function(a,b,c){for(var d="",e=[],f=a.getNextCharMaxSize(b),j=0;j<b.dotTokens.length;j++){for(var i=b.dotTokens[j],l=i.pos,m="";i.count>0;){if(f-l<i.requireSpaceSize){l=h.deepCopy(i);l.pos=i.offsetHead;e.push(l);break}m+=this.makeCharText(a,b,{type:"char",half:false,kind:"zen",data:"\u30fb",
fontSize:i.fontSize});l+=i.nextOffset;i.count--}if(m!=""){i=this.getDotCss(a,b,i,c);d+=h.tagWrap("span",{style:h.inlineCss(i)},m)}}b.dotTokens=e;return d};g.prototype.makeRubyText=function(a,b,c,d){a="";var e=b.getIndentSize(c.curIndent.before);b.getIndentSize(c.curIndent.after);for(var f=b.getNextCharMaxSize(c)+e,j=0;j<c.rubyTokens.length;j++){for(var i=c.rubyTokens[j],l=i.pos+e,m="",w=0;w<i.yomi.length;w++){c1=i.yomi.charAt(w);if(f-l<i.requireSpaceSize){l=h.deepCopy(i);l.pos=0;l.yomi=i.yomi.substring(w);
c.nextRubyTokens.push(l);break}m+=this.makeCharText(b,c,{type:"char",half:false,kind:"zen",data:c1,fontSize:i.fontSize});l+=i.nextOffset}if(m!=""){i=this.getRubyCss(b,c,i.pos+e,i.fontSize,d);a+=h.tagWrap("span",{style:h.inlineCss(i)},m)}}return a};g.prototype.makeInlinePageText=function(a,b,c,d,e){a=b.width;var f=b.height,j=c.seekNextLine,i=c.pageHtml;b.width=d;b.height=e;b.init();c.seekNextLine=0;c.seekNextChar=0;c.pageHtml="";d=this.outputPage(true);if(c.nextLineTokens.length>0){for(e=0;e<c.nextLineTokens.length;e++)(function(l){c.lineTokens.push(l);
c.seekNextChar+=l.nextOffset})(c.nextLineTokens[e]);c.nextLineTokens=[]}b.width=a;b.height=f;b.init();c.seekNextLine=j;c.pageHtml=i;return d};g.prototype.makePageText=function(a,b,c,d){a=h.tagWrap("div",{"class":d?"nehan-page nehan-page-inline":"nehan-page",style:h.inlineCss({width:b.width+"px",height:b.height+"px","font-size":b.fontSize+"px","white-space":"nowrap"})},c.pageHtml);c.pageHtml="";c.seekNextLine=0;d||c.curPageNo++;return a};g.prototype.setElementHandler=function(a,b){this.elementHandler[a]=
b};g.prototype.getNextToken=function(a,b){if(b.repushTokenStack.length>0)return b.repushTokenStack.pop();return a.getNext()};g.prototype.reset=function(a){this.lexer.getStream().setSeekPos(0);this.layout=a;this.context=new s(a);this.tocTable=[];this.parseEnd=false};g.prototype.outputPage=function(a){for(;;)try{var b=this.getNextToken(this.lexer,this.context);if(b.type=="char")this.parseChar(this.lexer,this.layout,this.context,b);else if(b.type=="word")this.parseWord(this.lexer,this.layout,this.context,
b);else if(b.type=="tcy")this.parseTcy(this.lexer,this.layout,this.context,b);else b.type=="tag"&&this.parseTag(this.lexer,this.layout,this.context,b,a)}catch(c){if(c=="BufferEnd"){this.parseEnd=true;if(this.context.lineTokens.length>0)try{this.pushLine(this.lexer,this.layout,this.context,false)}catch(d){if(d=="PageEnd")this.parseEnd=false}return this.makePageText(this.lexer,this.layout,this.context,a)}else if(c=="PageEnd")return this.makePageText(this.lexer,this.layout,this.context,a);else throw c;
}};n.prototype.getContext=function(){return this.parser.context};n.prototype.getLayout=function(){return this.layout};n.prototype.createTagToken=function(a,b){return{type:"tag",data:{name:a,attr:b},pos:-1}};n.prototype.skipCRLF=function(){this.lexer.skipCRLF()};n.prototype.pushLine=function(){this.parser.pushLine(this.lexer,this.layout,this.parser.context,false)};n.prototype.pushSpaceLine=function(a){this.parser.pushSpaceLine(this.lexer,this.layout,this.parser.context,a)};n.prototype.startFont=function(a){this.parser.parseFontStart(this.lexer,
this.layout,this.parser.context,this.createTagToken("font",a))};n.prototype.endFont=function(){this.parser.parseFontEnd(this.lexer,this.layout,this.parser.context,this.createTagToken("/font",{}))};n.prototype.startIndent=function(a,b){this.parser.parseIndentStart(this.lexer,this.layout,this.parser.context,this.createTagToken("indent",{before:a,after:b}))};n.prototype.endIndent=function(){this.parser.parseIndentEnd(this.lexer,this.layout,this.parser.context,this.createTagToken("/indent",{}))};n.prototype.pushImg=
function(a){this.parser.parseImg(this.lexer,this.layout,this.parser.context,this.createTagToken("img",a))};n.prototype.pushChar=function(a){this.parser.parseChar(this.lexer,this.layout,this.parser.context,this.lexer.character(-1,a))};n.prototype.pushWord=function(a){this.parser.parseWord(this.lexer,this.layout,this.parser.context,this.lexer.word(-1,a))};n.prototype.pushTcy=function(a){this.parser.parseTcy(this.lexer,this.layout,this.parser.context,this.lexer.tcy(-1,a))};k.prototype.reset=function(a){this.layout=
new q(a);this.parser.reset(this.layout);this.cache=[]};k.prototype.hasNextPage=function(){return this.parser.hasNextPage()};k.prototype.isEnablePage=function(a){if(a==0)return true;if(this.cache[a])return true;if(this.cache.length==a&&this.parser.hasNextPage())return true;return false};k.prototype.getLayout=function(){return this.layout};k.prototype.getText=function(){return this.lexer.getStream().getText()};k.prototype.setText=function(a){return this.lexer.getStream().setText(a)};k.prototype.addText=
function(a){return this.lexer.getStream().addText(a)};k.prototype.isEOF=function(){return this.lexer.getStream().isEOF()};k.prototype.getTocTable=function(){return this.parser.getTocTable()};k.prototype.getTocCount=function(){return this.parser.getTocTable().length};k.prototype.getPageCount=function(){return this.parser.context.curPageNo};k.prototype.setElementHandler=function(a,b){var c=this;this.parser.setElementHandler(a,function(d,e,f,j,i){b(c.parserProxy,i.data)})};k.prototype.setPageHeadPos=
function(a,b,c){this.pageHeadPos[a]={spos:b,cpos:c}};k.prototype.getPageHeadPos=function(a){return this.pageHeadPos[a]};k.prototype.setPageCache=function(a,b){this.cache[a]=b};k.prototype.getPageSourceText=function(a){if(a+1<this.getPageCount()){var b=this.getPageHeadPos(a).spos;a=this.getPageHeadPos(a+1).spos;return this.lexer.getStream().getText().substring(b,a)}return""};k.prototype.getPageNoFromSeekPos=function(a){for(var b=0;b<this.pageHeadPos.length-1;b++)if(this.pageHeadPos[b].spos<=a&&a<this.pageHeadPos[b+
1].spos)return b;if(this.pageHeadPos[b].spos<=a&&a<=this.lexer.getStream().getText().length)return b;return-1};k.prototype.outputPage=function(a){if(this.cache[a])return this.cache[a];if(!this.resuming&&!this.lexer.getStream().isEOF())this.restoreContext=h.deepCopy(this.parser.context);var b=this.getPageHeadPos(a);try{var c=this.parser.outputPage(false),d=this.lexer.getStream().getSeekPercent(),e=this.parser.context.pageHeadPos,f=this.parser.context.curCharCount;if(!this.parser.hasNextPage())this.pageCount=
a+1;this.resuming=false;this.setPageHeadPos(a+1,e,f);this.cache[a]={html:c,percent:d,spos:b.spos,cpos:b.cpos};return this.cache[a]}catch(j){if(j=="BufferShort"){this.resuming=true;this.parser.context=h.deepCopy(this.restoreContext);this.parser.lexer.getStream().setSeekPos(b.spos)}throw j;}};u.prototype.init=function(a){a=a.split(/[\s\t]/);for(var b=0;b<a.length;b++){var c=a[b];if(c=="lp-vertical")this.direction="vertical";else if(c=="lp-horizontal")this.direction="horizontal";else if(c.match(/span-([0-9]+)/))this.width=
parseInt(RegExp.$1)*40-10;else if(c.match(/lp-width-([0-9]+)/))this.width=parseInt(RegExp.$1);else if(c.match(/lp-height-([0-9]+)/))this.height=parseInt(RegExp.$1);else if(c.match(/lp-font-size-([0-9]+)/))this.fontSize=parseInt(RegExp.$1);else if(c.match(/lp-font-color-(.+)/))this.fontColor=RegExp.$1.toUpperCase();else if(c.match(/lp-link-color-(.+)/))this.linkColor=RegExp.$1.toUpperCase();else if(c.match(/lp-group-([a-zA-Z0-9\-_]+)/))this.groupName=RegExp.$1;else if(c.match(/lp-order-([0-9]+)/))this.order=
parseInt(RegExp.$1);else if(c=="lp-end")this.isEnd=true}a=this.node.style;a.width=this.width+"px";a.height=this.height+"px"};u.prototype.getLayout=function(){return new q({direction:this.direction,width:this.width,height:this.height,fontSize:this.fontSize,fontColor:this.fontColor,linkColor:this.linkColor})};u.prototype.getText=function(a){var b=this.node.innerHTML;if(a)return b.replace(/<br>/gi,"\n").replace(/<br \/>/gi,"\n");return b.replace(/<br>/gi,"").replace(/<br \/>/gi,"")};t.prototype.init=
function(){this.grids.sort(function(a,b){return a.order-b.order});this.provider=new k(this.grids[0].getLayout(),this.grids[0].getText(this.opt.convBR||true));this.rootNode=document.createElement("div");return this};t.prototype.append=function(a){this.grids.push(a)};t.prototype.renderGrid=function(a,b){this.provider.layout.width=a.width;this.provider.layout.height=a.height;this.provider.layout.direction=a.direction;this.provider.layout.fontColor=a.fontColor;this.provider.layout.init();this.provider.parser.context.curFontColor=
a.fontColor;a.node.innerHTML=this.provider.outputPage(b).html};t.prototype.appendRestGrid=function(a,b){var c=document.createElement("div");c.innerHTML=this.provider.outputPage(b).html;c.className="nehan-rest-grid";a.node.appendChild(c)};t.prototype.render=function(){for(var a=0;a<this.grids.length;a++){var b=this.grids[a];if(!this.provider.hasNextPage())break;this.renderGrid(b,a);if(b.isEnd)return}b=this.grids[a-1];for(b.node.style.height="auto";this.provider.hasNextPage();)this.appendRestGrid(b,
a++)};Nehan.Util=h;Nehan.Env=r;Nehan.Layout=q;Nehan.TextStream=o;Nehan.StreamLexer=p;Nehan.StreamParser=g;Nehan.PageProvider=k;Nehan.ParserProxy=n;Nehan.LayoutMapper={start:function(a){a=a||{};for(var b={},c=document.getElementsByTagName("pre"),d=0;d<c.length;d++)(function(e){var f=e.className;if(f.match(/lp-vertical/i)||f.match(/lp-horizontal/i)){e=new u(e,d);b[e.groupName]||(b[e.groupName]=new t(e.groupName,a));b[e.groupName].append(e)}})(c[d]);for(groupName in b)b[groupName].init().render()}}})();
