/*!
 * Zfont v1.2.7
 * Text plugin for Zdog
 * 2019 James Daniel
 * MIT Licensed 
 * github.com/jaames/zfont
 */
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(r=r||self).Zfont=t()}(this,function(){"use strict";var V={parse:function(r){var t=V._bin,e=new Uint8Array(r),a=0;t.readFixed(e,a);a+=4;var n=t.readUshort(e,a);a+=2;t.readUshort(e,a);a+=2;t.readUshort(e,a);a+=2;t.readUshort(e,a);a+=2;for(var o=["cmap","head","hhea","maxp","hmtx","name","OS/2","post","loca","glyf","kern","CFF ","GPOS","GSUB","SVG "],i={_data:e},s={},h=0;h<n;h++){var f=t.readASCII(e,a,4);a+=4;t.readUint(e,a);a+=4;var l=t.readUint(e,a);a+=4;var u=t.readUint(e,a);a+=4,s[f]={offset:l,length:u}}for(h=0;h<o.length;h++){var d=o[h];s[d]&&(i[d.trim()]=V[d.trim()].parse(e,s[d].offset,s[d].length,i))}return i},_tabOffset:function(r,t){for(var e=V._bin,a=e.readUshort(r,4),n=12,o=0;o<a;o++){var i=e.readASCII(r,n,4);n+=4;e.readUint(r,n);n+=4;var s=e.readUint(r,n);n+=4;e.readUint(r,n);if(n+=4,i==t)return s}return 0}};V._bin={readFixed:function(r,t){return(r[t]<<8|r[t+1])+(r[t+2]<<8|r[t+3])/65540},readF2dot14:function(r,t){var e=V._bin.readShort(r,t);return e/16384},readInt:function(r,t){var e=V._bin.t.uint8;return e[0]=r[t+3],e[1]=r[t+2],e[2]=r[t+1],e[3]=r[t],V._bin.t.int32[0]},readInt8:function(r,t){return V._bin.t.uint8[0]=r[t],V._bin.t.int8[0]},readShort:function(r,t){var e=V._bin.t.uint8;return e[1]=r[t],e[0]=r[t+1],V._bin.t.int16[0]},readUshort:function(r,t){return r[t]<<8|r[t+1]},readUshorts:function(r,t,e){for(var a=[],n=0;n<e;n++)a.push(V._bin.readUshort(r,t+2*n));return a},readUint:function(r,t){var e=V._bin.t.uint8;return e[3]=r[t],e[2]=r[t+1],e[1]=r[t+2],e[0]=r[t+3],V._bin.t.uint32[0]},readUint64:function(r,t){return 4294967296*V._bin.readUint(r,t)+V._bin.readUint(r,t+4)},readASCII:function(r,t,e){for(var a="",n=0;n<e;n++)a+=String.fromCharCode(r[t+n]);return a},readUnicode:function(r,t,e){for(var a="",n=0;n<e;n++){var o=r[t++]<<8|r[t++];a+=String.fromCharCode(o)}return a},_tdec:window.TextDecoder?new window.TextDecoder:null,readUTF8:function(r,t,e){var a=V._bin._tdec;return a&&0==t&&e==r.length?a.decode(r):V._bin.readASCII(r,t,e)},readBytes:function(r,t,e){for(var a=[],n=0;n<e;n++)a.push(r[t+n]);return a},readASCIIArray:function(r,t,e){for(var a=[],n=0;n<e;n++)a.push(String.fromCharCode(r[t+n]));return a}},V._bin.t={buff:new ArrayBuffer(8)},V._bin.t.int8=new Int8Array(V._bin.t.buff),V._bin.t.uint8=new Uint8Array(V._bin.t.buff),V._bin.t.int16=new Int16Array(V._bin.t.buff),V._bin.t.uint16=new Uint16Array(V._bin.t.buff),V._bin.t.int32=new Int32Array(V._bin.t.buff),V._bin.t.uint32=new Uint32Array(V._bin.t.buff),V._lctf={},V._lctf.parse=function(r,t,e,a,n){var o=V._bin,i={},s=t;o.readFixed(r,t);t+=4;var h=o.readUshort(r,t);t+=2;var f=o.readUshort(r,t);t+=2;var l=o.readUshort(r,t);return t+=2,i.scriptList=V._lctf.readScriptList(r,s+h),i.featureList=V._lctf.readFeatureList(r,s+f),i.lookupList=V._lctf.readLookupList(r,s+l,n),i},V._lctf.readLookupList=function(r,t,e){var a=V._bin,n=t,o=[],i=a.readUshort(r,t);t+=2;for(var s=0;s<i;s++){var h=a.readUshort(r,t);t+=2;var f=V._lctf.readLookupTable(r,n+h,e);o.push(f)}return o},V._lctf.readLookupTable=function(r,t,e){var a=V._bin,n=t,o={tabs:[]};o.ltype=a.readUshort(r,t),t+=2,o.flag=a.readUshort(r,t),t+=2;var i=a.readUshort(r,t);t+=2;for(var s=0;s<i;s++){var h=a.readUshort(r,t);t+=2;var f=e(r,o.ltype,n+h);o.tabs.push(f)}return o},V._lctf.numOfOnes=function(r){for(var t=0,e=0;e<32;e++)0!=(r>>>e&1)&&t++;return t},V._lctf.readClassDef=function(r,t){var e=V._bin,a=[],n=e.readUshort(r,t);if(t+=2,1==n){var o=e.readUshort(r,t);t+=2;var i=e.readUshort(r,t);t+=2;for(var s=0;s<i;s++)a.push(o+s),a.push(o+s),a.push(e.readUshort(r,t)),t+=2}if(2==n){var h=e.readUshort(r,t);t+=2;for(s=0;s<h;s++)a.push(e.readUshort(r,t)),t+=2,a.push(e.readUshort(r,t)),t+=2,a.push(e.readUshort(r,t)),t+=2}return a},V._lctf.getInterval=function(r,t){for(var e=0;e<r.length;e+=3){var a=r[e],n=r[e+1];r[e+2];if(a<=t&&t<=n)return e}return-1},V._lctf.readValueRecord=function(r,t,e){var a=V._bin,n=[];return n.push(1&e?a.readShort(r,t):0),t+=1&e?2:0,n.push(2&e?a.readShort(r,t):0),t+=2&e?2:0,n.push(4&e?a.readShort(r,t):0),t+=4&e?2:0,n.push(8&e?a.readShort(r,t):0),t+=8&e?2:0,n},V._lctf.readCoverage=function(r,t){var e=V._bin,a={};a.fmt=e.readUshort(r,t),t+=2;var n=e.readUshort(r,t);return t+=2,1==a.fmt&&(a.tab=e.readUshorts(r,t,n)),2==a.fmt&&(a.tab=e.readUshorts(r,t,3*n)),a},V._lctf.coverageIndex=function(r,t){var e=r.tab;if(1==r.fmt)return e.indexOf(t);if(2==r.fmt){var a=V._lctf.getInterval(e,t);if(-1!=a)return e[a+2]+(t-e[a])}return-1},V._lctf.readFeatureList=function(r,t){var e=V._bin,a=t,n=[],o=e.readUshort(r,t);t+=2;for(var i=0;i<o;i++){var s=e.readASCII(r,t,4);t+=4;var h=e.readUshort(r,t);t+=2,n.push({tag:s.trim(),tab:V._lctf.readFeatureTable(r,a+h)})}return n},V._lctf.readFeatureTable=function(r,t){var e=V._bin;e.readUshort(r,t);t+=2;var a=e.readUshort(r,t);t+=2;for(var n=[],o=0;o<a;o++)n.push(e.readUshort(r,t+2*o));return n},V._lctf.readScriptList=function(r,t){var e=V._bin,a=t,n={},o=e.readUshort(r,t);t+=2;for(var i=0;i<o;i++){var s=e.readASCII(r,t,4);t+=4;var h=e.readUshort(r,t);t+=2,n[s.trim()]=V._lctf.readScriptTable(r,a+h)}return n},V._lctf.readScriptTable=function(r,t){var e=V._bin,a=t,n={},o=e.readUshort(r,t);t+=2,n.default=V._lctf.readLangSysTable(r,a+o);var i=e.readUshort(r,t);t+=2;for(var s=0;s<i;s++){var h=e.readASCII(r,t,4);t+=4;var f=e.readUshort(r,t);t+=2,n[h.trim()]=V._lctf.readLangSysTable(r,a+f)}return n},V._lctf.readLangSysTable=function(r,t){var e=V._bin,a={};e.readUshort(r,t);t+=2,a.reqFeature=e.readUshort(r,t),t+=2;var n=e.readUshort(r,t);return t+=2,a.features=e.readUshorts(r,t,n),a},V.CFF={},V.CFF.parse=function(r,t,e){var a=V._bin;(r=new Uint8Array(r.buffer,t,e))[t=0],r[++t],r[++t],r[++t];t++;var n=[];t=V.CFF.readIndex(r,t,n);for(var o=[],i=0;i<n.length-1;i++)o.push(a.readASCII(r,t+n[i],n[i+1]-n[i]));t+=n[n.length-1];var s=[];t=V.CFF.readIndex(r,t,s);var h=[];for(i=0;i<s.length-1;i++)h.push(V.CFF.readDict(r,t+s[i],t+s[i+1]));t+=s[s.length-1];var f=h[0],l=[];t=V.CFF.readIndex(r,t,l);var u=[];for(i=0;i<l.length-1;i++)u.push(a.readASCII(r,t+l[i],l[i+1]-l[i]));if(t+=l[l.length-1],V.CFF.readSubrs(r,t,f),f.CharStrings){t=f.CharStrings;l=[];t=V.CFF.readIndex(r,t,l);var d=[];for(i=0;i<l.length-1;i++)d.push(a.readBytes(r,t+l[i],l[i+1]-l[i]));f.CharStrings=d}f.Encoding&&(f.Encoding=V.CFF.readEncoding(r,f.Encoding,f.CharStrings.length)),f.charset&&(f.charset=V.CFF.readCharset(r,f.charset,f.CharStrings.length)),f.Private&&(t=f.Private[1],f.Private=V.CFF.readDict(r,t,t+f.Private[0]),f.Private.Subrs&&V.CFF.readSubrs(r,t+f.Private.Subrs,f.Private));var c={};for(var v in f)-1!=["FamilyName","FullName","Notice","version","Copyright"].indexOf(v)?c[v]=u[f[v]-426+35]:c[v]=f[v];return c},V.CFF.readSubrs=function(r,t,e){var a=V._bin,n=[];t=V.CFF.readIndex(r,t,n);var o,i=n.length;o=i<1240?107:i<33900?1131:32768,e.Bias=o,e.Subrs=[];for(var s=0;s<n.length-1;s++)e.Subrs.push(a.readBytes(r,t+n[s],n[s+1]-n[s]))},V.CFF.tableSE=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,0,111,112,113,114,0,115,116,117,118,119,120,121,122,0,123,0,124,125,126,127,128,129,130,131,0,132,133,0,134,135,136,137,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,138,0,139,0,0,0,0,140,141,142,143,0,0,0,0,0,144,0,0,0,145,0,0,146,147,148,149,0,0,0,0],V.CFF.glyphByUnicode=function(r,t){for(var e=0;e<r.charset.length;e++)if(r.charset[e]==t)return e;return-1},V.CFF.glyphBySE=function(r,t){return t<0||255<t?-1:V.CFF.glyphByUnicode(r,V.CFF.tableSE[t])},V.CFF.readEncoding=function(r,t,e){V._bin;var a=[".notdef"],n=r[t];if(0!=n)throw"error: unknown encoding format: "+n;var o=r[++t];t++;for(var i=0;i<o;i++)a.push(r[t+i]);return a},V.CFF.readCharset=function(r,t,e){var a=V._bin,n=[".notdef"],o=r[t];if(t++,0==o)for(var i=0;i<e;i++){var s=a.readUshort(r,t);t+=2,n.push(s)}else{if(1!=o&&2!=o)throw"error: format: "+o;for(;n.length<e;){s=a.readUshort(r,t);t+=2;var h=0;1==o?(h=r[t],t++):(h=a.readUshort(r,t),t+=2);for(i=0;i<=h;i++)n.push(s),s++}}return n},V.CFF.readIndex=function(r,t,e){var a=V._bin,n=a.readUshort(r,t),o=r[t+=2];if(t++,1==o)for(var i=0;i<n+1;i++)e.push(r[t+i]);else if(2==o)for(i=0;i<n+1;i++)e.push(a.readUshort(r,t+2*i));else if(3==o)for(i=0;i<n+1;i++)e.push(16777215&a.readUint(r,t+3*i-1));else if(0!=n)throw"unsupported offset size: "+o+", count: "+n;return(t+=(n+1)*o)-1},V.CFF.getCharString=function(r,t,e){var a=V._bin,n=r[t],o=r[t+1],i=(r[t+2],r[t+3],r[t+4],1),s=null,h=null;n<=20&&(s=n,i=1),12==n&&(s=100*n+o,i=2),21<=n&&n<=27&&(s=n,i=1),28==n&&(h=a.readShort(r,t+1),i=3),29<=n&&n<=31&&(s=n,i=1),32<=n&&n<=246&&(h=n-139,i=1),247<=n&&n<=250&&(h=256*(n-247)+o+108,i=2),251<=n&&n<=254&&(h=256*-(n-251)-o-108,i=2),255==n&&(h=a.readInt(r,t+1)/65535,i=5),e.val=null!=h?h:"o"+s,e.size=i},V.CFF.readCharString=function(r,t,e){for(var a=t+e,n=V._bin,o=[];t<a;){var i=r[t],s=r[t+1],h=(r[t+2],r[t+3],r[t+4],1),f=null,l=null;i<=20&&(f=i,h=1),12==i&&(f=100*i+s,h=2),19!=i&&20!=i||(f=i,h=2),21<=i&&i<=27&&(f=i,h=1),28==i&&(l=n.readShort(r,t+1),h=3),29<=i&&i<=31&&(f=i,h=1),32<=i&&i<=246&&(l=i-139,h=1),247<=i&&i<=250&&(l=256*(i-247)+s+108,h=2),251<=i&&i<=254&&(l=256*-(i-251)-s-108,h=2),255==i&&(l=n.readInt(r,t+1)/65535,h=5),o.push(null!=l?l:"o"+f),t+=h}return o},V.CFF.readDict=function(r,t,e){for(var a=V._bin,n={},o=[];t<e;){var i=r[t],s=r[t+1],h=(r[t+2],r[t+3],r[t+4],1),f=null,l=null;if(28==i&&(l=a.readShort(r,t+1),h=3),29==i&&(l=a.readInt(r,t+1),h=5),32<=i&&i<=246&&(l=i-139,h=1),247<=i&&i<=250&&(l=256*(i-247)+s+108,h=2),251<=i&&i<=254&&(l=256*-(i-251)-s-108,h=2),255==i)throw l=a.readInt(r,t+1)/65535,h=5,"unknown number";if(30==i){var u=[];for(h=1;;){var d=r[t+h];h++;var c=d>>4,v=15&d;if(15!=c&&u.push(c),15!=v&&u.push(v),15==v)break}for(var p="",g=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"],U=0;U<u.length;U++)p+=g[u[U]];l=parseFloat(p)}if(i<=21)if(f=["version","Notice","FullName","FamilyName","Weight","FontBBox","BlueValues","OtherBlues","FamilyBlues","FamilyOtherBlues","StdHW","StdVW","escape","UniqueID","XUID","charset","Encoding","CharStrings","Private","Subrs","defaultWidthX","nominalWidthX"][i],h=1,12==i)f=["Copyright","isFixedPitch","ItalicAngle","UnderlinePosition","UnderlineThickness","PaintType","CharstringType","FontMatrix","StrokeWidth","BlueScale","BlueShift","BlueFuzz","StemSnapH","StemSnapV","ForceBold",0,0,"LanguageGroup","ExpansionFactor","initialRandomSeed","SyntheticBase","PostScript","BaseFontName","BaseFontBlend",0,0,0,0,0,0,"ROS","CIDFontVersion","CIDFontRevision","CIDFontType","CIDCount","UIDBase","FDArray","FDSelect","FontName"][s],h=2;null!=f?(n[f]=1==o.length?o[0]:o,o=[]):o.push(l),t+=h}return n},V.cmap={},V.cmap.parse=function(r,t,e){r=new Uint8Array(r.buffer,t,e),t=0;var a=V._bin,n={};a.readUshort(r,t);t+=2;var o=a.readUshort(r,t);t+=2;var i=[];n.tables=[];for(var s=0;s<o;s++){var h=a.readUshort(r,t);t+=2;var f=a.readUshort(r,t);t+=2;var l=a.readUint(r,t);t+=4;var u="p"+h+"e"+f,d=i.indexOf(l);if(-1==d){var c;d=n.tables.length,i.push(l);var v=a.readUshort(r,l);0==v?c=V.cmap.parse0(r,l):4==v?c=V.cmap.parse4(r,l):6==v?c=V.cmap.parse6(r,l):12==v?c=V.cmap.parse12(r,l):console.log("unknown format: "+v,h,f,l),n.tables.push(c)}if(null!=n[u])throw"multiple tables for one platform+encoding";n[u]=d}return n},V.cmap.parse0=function(r,t){var e=V._bin,a={};a.format=e.readUshort(r,t),t+=2;var n=e.readUshort(r,t);t+=2;e.readUshort(r,t);t+=2,a.map=[];for(var o=0;o<n-6;o++)a.map.push(r[t+o]);return a},V.cmap.parse4=function(r,t){var e=V._bin,a=t,n={};n.format=e.readUshort(r,t),t+=2;var o=e.readUshort(r,t);t+=2;e.readUshort(r,t);t+=2;var i=e.readUshort(r,t);t+=2;var s=i/2;n.searchRange=e.readUshort(r,t),t+=2,n.entrySelector=e.readUshort(r,t),t+=2,n.rangeShift=e.readUshort(r,t),t+=2,n.endCount=e.readUshorts(r,t,s),t+=2*s,t+=2,n.startCount=e.readUshorts(r,t,s),t+=2*s,n.idDelta=[];for(var h=0;h<s;h++)n.idDelta.push(e.readShort(r,t)),t+=2;for(n.idRangeOffset=e.readUshorts(r,t,s),t+=2*s,n.glyphIdArray=[];t<a+o;)n.glyphIdArray.push(e.readUshort(r,t)),t+=2;return n},V.cmap.parse6=function(r,t){var e=V._bin,a={};a.format=e.readUshort(r,t),t+=2;e.readUshort(r,t);t+=2;e.readUshort(r,t);t+=2,a.firstCode=e.readUshort(r,t),t+=2;var n=e.readUshort(r,t);t+=2,a.glyphIdArray=[];for(var o=0;o<n;o++)a.glyphIdArray.push(e.readUshort(r,t)),t+=2;return a},V.cmap.parse12=function(r,t){var e=V._bin,a={};a.format=e.readUshort(r,t),t+=2,t+=2;e.readUint(r,t);t+=4;e.readUint(r,t);t+=4;var n=e.readUint(r,t);t+=4,a.groups=[];for(var o=0;o<n;o++){var i=t+12*o,s=e.readUint(r,i+0),h=e.readUint(r,i+4),f=e.readUint(r,i+8);a.groups.push([s,h,f])}return a},V.glyf={},V.glyf.parse=function(r,t,e,a){for(var n=[],o=0;o<a.maxp.numGlyphs;o++)n.push(null);return n},V.glyf._parseGlyf=function(r,t){var e=V._bin,a=r._data,n=V._tabOffset(a,"glyf")+r.loca[t];if(r.loca[t]==r.loca[t+1])return null;var o={};if(o.noc=e.readShort(a,n),n+=2,o.xMin=e.readShort(a,n),n+=2,o.yMin=e.readShort(a,n),n+=2,o.xMax=e.readShort(a,n),n+=2,o.yMax=e.readShort(a,n),n+=2,o.xMin>=o.xMax||o.yMin>=o.yMax)return null;if(0<o.noc){o.endPts=[];for(var i=0;i<o.noc;i++)o.endPts.push(e.readUshort(a,n)),n+=2;var s=e.readUshort(a,n);if(n+=2,a.length-n<s)return null;o.instructions=e.readBytes(a,n,s),n+=s;var h=o.endPts[o.noc-1]+1;o.flags=[];for(i=0;i<h;i++){var f=a[n];if(n++,o.flags.push(f),0!=(8&f)){var l=a[n];n++;for(var u=0;u<l;u++)o.flags.push(f),i++}}o.xs=[];for(i=0;i<h;i++){var d=0!=(2&o.flags[i]),c=0!=(16&o.flags[i]);d?(o.xs.push(c?a[n]:-a[n]),n++):c?o.xs.push(0):(o.xs.push(e.readShort(a,n)),n+=2)}o.ys=[];for(i=0;i<h;i++){d=0!=(4&o.flags[i]),c=0!=(32&o.flags[i]);d?(o.ys.push(c?a[n]:-a[n]),n++):c?o.ys.push(0):(o.ys.push(e.readShort(a,n)),n+=2)}var v=0,p=0;for(i=0;i<h;i++)v+=o.xs[i],p+=o.ys[i],o.xs[i]=v,o.ys[i]=p}else{var g;o.parts=[];do{g=e.readUshort(a,n),n+=2;var U={m:{a:1,b:0,c:0,d:1,tx:0,ty:0},p1:-1,p2:-1};if(o.parts.push(U),U.glyphIndex=e.readUshort(a,n),n+=2,1&g){var m=e.readShort(a,n);n+=2;var S=e.readShort(a,n);n+=2}else{m=e.readInt8(a,n);n++;S=e.readInt8(a,n);n++}2&g?(U.m.tx=m,U.m.ty=S):(U.p1=m,U.p2=S),8&g?(U.m.a=U.m.d=e.readF2dot14(a,n),n+=2):64&g?(U.m.a=e.readF2dot14(a,n),n+=2,U.m.d=e.readF2dot14(a,n),n+=2):128&g&&(U.m.a=e.readF2dot14(a,n),n+=2,U.m.b=e.readF2dot14(a,n),n+=2,U.m.c=e.readF2dot14(a,n),n+=2,U.m.d=e.readF2dot14(a,n),n+=2)}while(32&g);if(256&g){var b=e.readUshort(a,n);n+=2,o.instr=[];for(i=0;i<b;i++)o.instr.push(a[n]),n++}}return o},V.GPOS={},V.GPOS.parse=function(r,t,e,a){return V._lctf.parse(r,t,e,a,V.GPOS.subt)},V.GPOS.subt=function(r,t,e){if(2!=t)return null;var a=V._bin,n=e,o={};o.format=a.readUshort(r,e),e+=2;var i=a.readUshort(r,e);e+=2,o.coverage=V._lctf.readCoverage(r,i+n),o.valFmt1=a.readUshort(r,e),e+=2,o.valFmt2=a.readUshort(r,e),e+=2;var s=V._lctf.numOfOnes(o.valFmt1),h=V._lctf.numOfOnes(o.valFmt2);if(1==o.format){o.pairsets=[];var f=a.readUshort(r,e);e+=2;for(var l=0;l<f;l++){var u=a.readUshort(r,e);e+=2,u+=n;var d=a.readUshort(r,u);u+=2;for(var c=[],v=0;v<d;v++){var p=a.readUshort(r,u);u+=2,0!=o.valFmt1&&(_=V._lctf.readValueRecord(r,u,o.valFmt1),u+=2*s),0!=o.valFmt2&&(y=V._lctf.readValueRecord(r,u,o.valFmt2),u+=2*h),c.push({gid2:p,val1:_,val2:y})}o.pairsets.push(c)}}if(2==o.format){var g=a.readUshort(r,e);e+=2;var U=a.readUshort(r,e);e+=2;var m=a.readUshort(r,e);e+=2;var S=a.readUshort(r,e);e+=2,o.classDef1=V._lctf.readClassDef(r,n+g),o.classDef2=V._lctf.readClassDef(r,n+U),o.matrix=[];for(l=0;l<m;l++){var b=[];for(v=0;v<S;v++){var _=null,y=null;0!=o.valFmt1&&(_=V._lctf.readValueRecord(r,e,o.valFmt1),e+=2*s),0!=o.valFmt2&&(y=V._lctf.readValueRecord(r,e,o.valFmt2),e+=2*h),b.push({val1:_,val2:y})}o.matrix.push(b)}}return o},V.GSUB={},V.GSUB.parse=function(r,t,e,a){return V._lctf.parse(r,t,e,a,V.GSUB.subt)},V.GSUB.subt=function(r,t,e){var a=V._bin,n=e,o={};if(1!=t&&4!=t&&5!=t)return null;o.fmt=a.readUshort(r,e),e+=2;var i=a.readUshort(r,e);if(e+=2,o.coverage=V._lctf.readCoverage(r,i+n),1==t){if(1==o.fmt)o.delta=a.readShort(r,e),e+=2;else if(2==o.fmt){var s=a.readUshort(r,e);e+=2,o.newg=a.readUshorts(r,e,s),e+=2*o.newg.length}}else if(4==t){o.vals=[];s=a.readUshort(r,e);e+=2;for(var h=0;h<s;h++){var f=a.readUshort(r,e);e+=2,o.vals.push(V.GSUB.readLigatureSet(r,n+f))}}else if(5==t)if(2==o.fmt){var l=a.readUshort(r,e);e+=2,o.cDef=V._lctf.readClassDef(r,n+l),o.scset=[];var u=a.readUshort(r,e);e+=2;for(h=0;h<u;h++){var d=a.readUshort(r,e);e+=2,o.scset.push(0==d?null:V.GSUB.readSubClassSet(r,n+d))}}else console.log("unknown table format",o.fmt);return o},V.GSUB.readSubClassSet=function(r,t){var e=V._bin.readUshort,a=t,n=[],o=e(r,t);t+=2;for(var i=0;i<o;i++){var s=e(r,t);t+=2,n.push(V.GSUB.readSubClassRule(r,a+s))}return n},V.GSUB.readSubClassRule=function(r,t){var e=V._bin.readUshort,a={},n=e(r,t),o=e(r,t+=2);t+=2,a.input=[];for(var i=0;i<n-1;i++)a.input.push(e(r,t)),t+=2;return a.substLookupRecords=V.GSUB.readSubstLookupRecords(r,t,o),a},V.GSUB.readSubstLookupRecords=function(r,t,e){for(var a=V._bin.readUshort,n=[],o=0;o<e;o++)n.push(a(r,t),a(r,t+2)),t+=4;return n},V.GSUB.readChainSubClassSet=function(r,t){var e=V._bin,a=t,n=[],o=e.readUshort(r,t);t+=2;for(var i=0;i<o;i++){var s=e.readUshort(r,t);t+=2,n.push(V.GSUB.readChainSubClassRule(r,a+s))}return n},V.GSUB.readChainSubClassRule=function(r,t){for(var e=V._bin,a={},n=["backtrack","input","lookahead"],o=0;o<n.length;o++){var i=e.readUshort(r,t);t+=2,1==o&&i--,a[n[o]]=e.readUshorts(r,t,i),t+=2*a[n[o]].length}i=e.readUshort(r,t);return t+=2,a.subst=e.readUshorts(r,t,2*i),t+=2*a.subst.length,a},V.GSUB.readLigatureSet=function(r,t){var e=V._bin,a=t,n=[],o=e.readUshort(r,t);t+=2;for(var i=0;i<o;i++){var s=e.readUshort(r,t);t+=2,n.push(V.GSUB.readLigature(r,a+s))}return n},V.GSUB.readLigature=function(r,t){var e=V._bin,a={chain:[]};a.nglyph=e.readUshort(r,t),t+=2;var n=e.readUshort(r,t);t+=2;for(var o=0;o<n-1;o++)a.chain.push(e.readUshort(r,t)),t+=2;return a},V.head={},V.head.parse=function(r,t,e){var a=V._bin,n={};a.readFixed(r,t);t+=4,n.fontRevision=a.readFixed(r,t),t+=4;a.readUint(r,t);t+=4;a.readUint(r,t);return t+=4,n.flags=a.readUshort(r,t),t+=2,n.unitsPerEm=a.readUshort(r,t),t+=2,n.created=a.readUint64(r,t),t+=8,n.modified=a.readUint64(r,t),t+=8,n.xMin=a.readShort(r,t),t+=2,n.yMin=a.readShort(r,t),t+=2,n.xMax=a.readShort(r,t),t+=2,n.yMax=a.readShort(r,t),t+=2,n.macStyle=a.readUshort(r,t),t+=2,n.lowestRecPPEM=a.readUshort(r,t),t+=2,n.fontDirectionHint=a.readShort(r,t),t+=2,n.indexToLocFormat=a.readShort(r,t),t+=2,n.glyphDataFormat=a.readShort(r,t),t+=2,n},V.hhea={},V.hhea.parse=function(r,t,e){var a=V._bin,n={};a.readFixed(r,t);return t+=4,n.ascender=a.readShort(r,t),t+=2,n.descender=a.readShort(r,t),t+=2,n.lineGap=a.readShort(r,t),t+=2,n.advanceWidthMax=a.readUshort(r,t),t+=2,n.minLeftSideBearing=a.readShort(r,t),t+=2,n.minRightSideBearing=a.readShort(r,t),t+=2,n.xMaxExtent=a.readShort(r,t),t+=2,n.caretSlopeRise=a.readShort(r,t),t+=2,n.caretSlopeRun=a.readShort(r,t),t+=2,n.caretOffset=a.readShort(r,t),t+=2,t+=8,n.metricDataFormat=a.readShort(r,t),t+=2,n.numberOfHMetrics=a.readUshort(r,t),t+=2,n},V.hmtx={},V.hmtx.parse=function(r,t,e,a){for(var n=V._bin,o={aWidth:[],lsBearing:[]},i=0,s=0,h=0;h<a.maxp.numGlyphs;h++)h<a.hhea.numberOfHMetrics&&(i=n.readUshort(r,t),t+=2,s=n.readShort(r,t),t+=2),o.aWidth.push(i),o.lsBearing.push(s);return o},V.kern={},V.kern.parse=function(r,t,e,a){var n=V._bin,o=n.readUshort(r,t);if(t+=2,1==o)return V.kern.parseV1(r,t-2,e,a);var i=n.readUshort(r,t);t+=2;for(var s={glyph1:[],rval:[]},h=0;h<i;h++){t+=2;e=n.readUshort(r,t);t+=2;var f=n.readUshort(r,t);t+=2;var l=f>>>8;if(0!=(l&=15))throw"unknown kern table format: "+l;t=V.kern.readFormat0(r,t,s)}return s},V.kern.parseV1=function(r,t,e,a){var n=V._bin;n.readFixed(r,t);t+=4;var o=n.readUint(r,t);t+=4;for(var i={glyph1:[],rval:[]},s=0;s<o;s++){n.readUint(r,t);t+=4;var h=n.readUshort(r,t);t+=2;n.readUshort(r,t);t+=2;var f=h>>>8;if(0!=(f&=15))throw"unknown kern table format: "+f;t=V.kern.readFormat0(r,t,i)}return i},V.kern.readFormat0=function(r,t,e){var a=V._bin,n=-1,o=a.readUshort(r,t);t+=2;a.readUshort(r,t);t+=2;a.readUshort(r,t);t+=2;a.readUshort(r,t);t+=2;for(var i=0;i<o;i++){var s=a.readUshort(r,t);t+=2;var h=a.readUshort(r,t);t+=2;var f=a.readShort(r,t);t+=2,s!=n&&(e.glyph1.push(s),e.rval.push({glyph2:[],vals:[]}));var l=e.rval[e.rval.length-1];l.glyph2.push(h),l.vals.push(f),n=s}return t},V.loca={},V.loca.parse=function(r,t,e,a){var n=V._bin,o=[],i=a.head.indexToLocFormat,s=a.maxp.numGlyphs+1;if(0==i)for(var h=0;h<s;h++)o.push(n.readUshort(r,t+(h<<1))<<1);if(1==i)for(h=0;h<s;h++)o.push(n.readUint(r,t+(h<<2)));return o},V.maxp={},V.maxp.parse=function(r,t,e){var a=V._bin,n={},o=a.readUint(r,t);return t+=4,n.numGlyphs=a.readUshort(r,t),t+=2,65536==o&&(n.maxPoints=a.readUshort(r,t),t+=2,n.maxContours=a.readUshort(r,t),t+=2,n.maxCompositePoints=a.readUshort(r,t),t+=2,n.maxCompositeContours=a.readUshort(r,t),t+=2,n.maxZones=a.readUshort(r,t),t+=2,n.maxTwilightPoints=a.readUshort(r,t),t+=2,n.maxStorage=a.readUshort(r,t),t+=2,n.maxFunctionDefs=a.readUshort(r,t),t+=2,n.maxInstructionDefs=a.readUshort(r,t),t+=2,n.maxStackElements=a.readUshort(r,t),t+=2,n.maxSizeOfInstructions=a.readUshort(r,t),t+=2,n.maxComponentElements=a.readUshort(r,t),t+=2,n.maxComponentDepth=a.readUshort(r,t),t+=2),n},V.name={},V.name.parse=function(r,t,e){var a=V._bin,n={};a.readUshort(r,t);t+=2;var o=a.readUshort(r,t);t+=2;a.readUshort(r,t);for(var i,s=t+=2,h=0;h<o;h++){var f=a.readUshort(r,t);t+=2;var l=a.readUshort(r,t);t+=2;var u=a.readUshort(r,t);t+=2;var d=a.readUshort(r,t);t+=2;e=a.readUshort(r,t);t+=2;var c=a.readUshort(r,t);t+=2;var v="p"+f;null==n[v]&&(n[v]={});var p,g=["copyright","fontFamily","fontSubfamily","ID","fullName","version","postScriptName","trademark","manufacturer","designer","description","urlVendor","urlDesigner","licence","licenceURL","---","typoFamilyName","typoSubfamilyName","compatibleFull","sampleText","postScriptCID","wwsFamilyName","wwsSubfamilyName","lightPalette","darkPalette"][d],U=s+12*o+c;if(0==f)p=a.readUnicode(r,U,e/2);else if(3==f&&0==l)p=a.readUnicode(r,U,e/2);else if(0==l)p=a.readASCII(r,U,e);else if(1==l)p=a.readUnicode(r,U,e/2);else if(3==l)p=a.readUnicode(r,U,e/2);else{if(1!=f)throw"unknown encoding "+l+", platformID: "+f;p=a.readASCII(r,U,e),console.log("reading unknown MAC encoding "+l+" as ASCII")}n[v][g]=p,n[v]._lang=u}for(var m in n)if(null!=n[m].postScriptName&&1033==n[m]._lang)return n[m];for(var m in n)if(null!=n[m].postScriptName&&3084==n[m]._lang)return n[m];for(var m in n)if(null!=n[m].postScriptName)return n[m];for(var m in n){i=m;break}return console.log("returning name table with languageID "+n[i]._lang),n[i]},V["OS/2"]={},V["OS/2"].parse=function(r,t,e){var a=V._bin.readUshort(r,t);t+=2;var n={};if(0==a)V["OS/2"].version0(r,t,n);else if(1==a)V["OS/2"].version1(r,t,n);else if(2==a||3==a||4==a)V["OS/2"].version2(r,t,n);else{if(5!=a)throw"unknown OS/2 table version: "+a;V["OS/2"].version5(r,t,n)}return n},V["OS/2"].version0=function(r,t,e){var a=V._bin;return e.xAvgCharWidth=a.readShort(r,t),t+=2,e.usWeightClass=a.readUshort(r,t),t+=2,e.usWidthClass=a.readUshort(r,t),t+=2,e.fsType=a.readUshort(r,t),t+=2,e.ySubscriptXSize=a.readShort(r,t),t+=2,e.ySubscriptYSize=a.readShort(r,t),t+=2,e.ySubscriptXOffset=a.readShort(r,t),t+=2,e.ySubscriptYOffset=a.readShort(r,t),t+=2,e.ySuperscriptXSize=a.readShort(r,t),t+=2,e.ySuperscriptYSize=a.readShort(r,t),t+=2,e.ySuperscriptXOffset=a.readShort(r,t),t+=2,e.ySuperscriptYOffset=a.readShort(r,t),t+=2,e.yStrikeoutSize=a.readShort(r,t),t+=2,e.yStrikeoutPosition=a.readShort(r,t),t+=2,e.sFamilyClass=a.readShort(r,t),t+=2,e.panose=a.readBytes(r,t,10),t+=10,e.ulUnicodeRange1=a.readUint(r,t),t+=4,e.ulUnicodeRange2=a.readUint(r,t),t+=4,e.ulUnicodeRange3=a.readUint(r,t),t+=4,e.ulUnicodeRange4=a.readUint(r,t),t+=4,e.achVendID=[a.readInt8(r,t),a.readInt8(r,t+1),a.readInt8(r,t+2),a.readInt8(r,t+3)],t+=4,e.fsSelection=a.readUshort(r,t),t+=2,e.usFirstCharIndex=a.readUshort(r,t),t+=2,e.usLastCharIndex=a.readUshort(r,t),t+=2,e.sTypoAscender=a.readShort(r,t),t+=2,e.sTypoDescender=a.readShort(r,t),t+=2,e.sTypoLineGap=a.readShort(r,t),t+=2,e.usWinAscent=a.readUshort(r,t),t+=2,e.usWinDescent=a.readUshort(r,t),t+=2},V["OS/2"].version1=function(r,t,e){var a=V._bin;return t=V["OS/2"].version0(r,t,e),e.ulCodePageRange1=a.readUint(r,t),t+=4,e.ulCodePageRange2=a.readUint(r,t),t+=4},V["OS/2"].version2=function(r,t,e){var a=V._bin;return t=V["OS/2"].version1(r,t,e),e.sxHeight=a.readShort(r,t),t+=2,e.sCapHeight=a.readShort(r,t),t+=2,e.usDefault=a.readUshort(r,t),t+=2,e.usBreak=a.readUshort(r,t),t+=2,e.usMaxContext=a.readUshort(r,t),t+=2},V["OS/2"].version5=function(r,t,e){var a=V._bin;return t=V["OS/2"].version2(r,t,e),e.usLowerOpticalPointSize=a.readUshort(r,t),t+=2,e.usUpperOpticalPointSize=a.readUshort(r,t),t+=2},V.post={},V.post.parse=function(r,t,e){var a=V._bin,n={};return n.version=a.readFixed(r,t),t+=4,n.italicAngle=a.readFixed(r,t),t+=4,n.underlinePosition=a.readShort(r,t),t+=2,n.underlineThickness=a.readShort(r,t),t+=2,n},V.SVG={},V.SVG.parse=function(r,t,e){var a=V._bin,n={entries:[]},o=t;a.readUshort(r,t);t+=2;var i=a.readUint(r,t);t+=4;a.readUint(r,t);t+=4,t=i+o;var s=a.readUshort(r,t);t+=2;for(var h=0;h<s;h++){var f=a.readUshort(r,t);t+=2;var l=a.readUshort(r,t);t+=2;var u=a.readUint(r,t);t+=4;var d=a.readUint(r,t);t+=4;for(var c=new Uint8Array(r.buffer,o+u+i,d),v=a.readUTF8(c,0,c.length),p=f;p<=l;p++)n.entries[p]=v}return n},V.SVG.toPath=function(r){var t={cmds:[],crds:[]};if(null==r)return t;for(var e=(new DOMParser).parseFromString(r,"image/svg+xml").firstChild;"svg"!=e.tagName;)e=e.nextSibling;var a=e.getAttribute("viewBox");a=a?a.trim().split(" ").map(parseFloat):[0,0,1e3,1e3],V.SVG._toPath(e.children,t);for(var n=0;n<t.crds.length;n+=2){var o=t.crds[n],i=t.crds[n+1];o-=a[0],i=-(i-=a[1]),t.crds[n]=o,t.crds[n+1]=i}return t},V.SVG._toPath=function(r,t,e){for(var a=0;a<r.length;a++){var n=r[a],o=n.tagName,i=n.getAttribute("fill");if(null==i&&(i=e),"g"==o)V.SVG._toPath(n.children,t,i);else if("path"==o){t.cmds.push(i||"#000000");var s=n.getAttribute("d"),h=V.SVG._tokens(s);V.SVG._toksToPath(h,t),t.cmds.push("X")}else"defs"==o||console.log(o,n)}},V.SVG._tokens=function(r){for(var t=[],e=0,a=!1,n="";e<r.length;){var o=r.charCodeAt(e),i=r.charAt(e);e++;var s=48<=o&&o<=57||"."==i||"-"==i;a?"-"==i?(t.push(parseFloat(n)),n=i):s?n+=i:(t.push(parseFloat(n)),","!=i&&" "!=i&&t.push(i),a=!1):s?(n=i,a=!0):","!=i&&" "!=i&&t.push(i)}return a&&t.push(parseFloat(n)),t},V.SVG._toksToPath=function(r,t){for(var e=0,a=0,n=0,o=0,i=0,s={M:2,L:2,H:1,V:1,S:4,C:6},h=t.cmds,f=t.crds;e<r.length;){var l=r[e];if(e++,"z"==l)h.push("Z"),a=o,n=i;else for(var u=l.toUpperCase(),d=s[u],c=V.SVG._reps(r,e,d),v=0;v<c;v++){var p=0,g=0;if(l!=u&&(p=a,g=n),"M"==u)a=p+r[e++],n=g+r[e++],h.push("M"),f.push(a,n),o=a,i=n;else if("L"==u)a=p+r[e++],n=g+r[e++],h.push("L"),f.push(a,n);else if("H"==u)a=p+r[e++],h.push("L"),f.push(a,n);else if("V"==u)n=g+r[e++],h.push("L"),f.push(a,n);else if("C"==u){var U=p+r[e++],m=g+r[e++],S=p+r[e++],b=g+r[e++],_=p+r[e++],y=g+r[e++];h.push("C"),f.push(U,m,S,b,_,y),a=_,n=y}else if("S"==u){var x=Math.max(f.length-4,0);U=a+a-f[x],m=n+n-f[x+1],S=p+r[e++],b=g+r[e++],_=p+r[e++],y=g+r[e++];h.push("C"),f.push(U,m,S,b,_,y),a=_,n=y}else console.log("Unknown SVG command "+l)}}},V.SVG._reps=function(r,t,e){for(var a=t;a<r.length&&"string"!=typeof r[a];)a+=e;return(a-t)/e},null==V&&(V={}),null==V.U&&(V.U={}),V.U.codeToGlyph=function(r,t){var e=r.cmap,a=-1;if(null!=e.p0e4?a=e.p0e4:null!=e.p3e1?a=e.p3e1:null!=e.p1e0&&(a=e.p1e0),-1==a)throw"no familiar platform and encoding!";var n=e.tables[a];if(0==n.format)return t>=n.map.length?0:n.map[t];if(4==n.format){for(var o=-1,i=0;i<n.endCount.length;i++)if(t<=n.endCount[i]){o=i;break}if(-1==o)return 0;if(n.startCount[o]>t)return 0;return 65535&(0!=n.idRangeOffset[o]?n.glyphIdArray[t-n.startCount[o]+(n.idRangeOffset[o]>>1)-(n.idRangeOffset.length-o)]:t+n.idDelta[o])}if(12!=n.format)throw"unknown cmap table format "+n.format;if(t>n.groups[n.groups.length-1][1])return 0;for(i=0;i<n.groups.length;i++){var s=n.groups[i];if(s[0]<=t&&t<=s[1])return s[2]+(t-s[0])}return 0},V.U.glyphToPath=function(r,t){var e={cmds:[],crds:[]};if(r.SVG&&r.SVG.entries[t]){var a=r.SVG.entries[t];return null==a?e:("string"==typeof a&&(a=V.SVG.toPath(a),r.SVG.entries[t]=a),a)}if(r.CFF){var n={x:0,y:0,stack:[],nStems:0,haveWidth:!1,width:r.CFF.Private?r.CFF.Private.defaultWidthX:0,open:!1};V.U._drawCFF(r.CFF.CharStrings[t],n,r.CFF,e)}else r.glyf&&V.U._drawGlyf(t,r,e);return e},V.U._drawGlyf=function(r,t,e){var a=t.glyf[r];null==a&&(a=t.glyf[r]=V.glyf._parseGlyf(t,r)),null!=a&&(-1<a.noc?V.U._simpleGlyph(a,e):V.U._compoGlyph(a,t,e))},V.U._simpleGlyph=function(r,t){for(var e=0;e<r.noc;e++){for(var a=0==e?0:r.endPts[e-1]+1,n=r.endPts[e],o=a;o<=n;o++){var i=o==a?n:o-1,s=o==n?a:o+1,h=1&r.flags[o],f=1&r.flags[i],l=1&r.flags[s],u=r.xs[o],d=r.ys[o];if(o==a)if(h){if(!f){V.U.P.moveTo(t,u,d);continue}V.U.P.moveTo(t,r.xs[i],r.ys[i])}else f?V.U.P.moveTo(t,r.xs[i],r.ys[i]):V.U.P.moveTo(t,(r.xs[i]+u)/2,(r.ys[i]+d)/2);h?f&&V.U.P.lineTo(t,u,d):l?V.U.P.qcurveTo(t,u,d,r.xs[s],r.ys[s]):V.U.P.qcurveTo(t,u,d,(u+r.xs[s])/2,(d+r.ys[s])/2)}V.U.P.closePath(t)}},V.U._compoGlyph=function(r,t,e){for(var a=0;a<r.parts.length;a++){var n={cmds:[],crds:[]},o=r.parts[a];V.U._drawGlyf(o.glyphIndex,t,n);for(var i=o.m,s=0;s<n.crds.length;s+=2){var h=n.crds[s],f=n.crds[s+1];e.crds.push(h*i.a+f*i.b+i.tx),e.crds.push(h*i.c+f*i.d+i.ty)}for(s=0;s<n.cmds.length;s++)e.cmds.push(n.cmds[s])}},V.U._getGlyphClass=function(r,t){var e=V._lctf.getInterval(t,r);return-1==e?0:t[e+2]},V.U.getPairAdjustment=function(r,t,e){if(r.GPOS){for(var a=null,n=0;n<r.GPOS.featureList.length;n++){var o=r.GPOS.featureList[n];if("kern"==o.tag)for(var i=0;i<o.tab.length;i++)2==r.GPOS.lookupList[o.tab[i]].ltype&&(a=r.GPOS.lookupList[o.tab[i]])}if(a)for(n=0;n<a.tabs.length;n++){var s=a.tabs[n],h=V._lctf.coverageIndex(s.coverage,t);if(-1!=h){if(1==s.format){var f=s.pairsets[h];for(i=0;i<f.length;i++)f[i].gid2==e&&(d=f[i]);if(null==d)continue}else if(2==s.format)var l=V.U._getGlyphClass(t,s.classDef1),u=V.U._getGlyphClass(e,s.classDef2),d=s.matrix[l][u];return d.val1[2]}}}if(r.kern){var c=r.kern.glyph1.indexOf(t);if(-1!=c){var v=r.kern.rval[c].glyph2.indexOf(e);if(-1!=v)return r.kern.rval[c].vals[v]}}return 0},V.U.stringToGlyphs=function(r,t){for(var e=[],a=0;a<t.length;a++){var n=t.codePointAt(a);65535<n&&a++,e.push(V.U.codeToGlyph(r,n))}var o=r.GSUB;if(null==o)return e;for(var i=o.lookupList,s=o.featureList,h='\n\t" ,.:;!?()  ،',f="آأؤإاةدذرزوٱٲٳٵٶٷڈډڊڋڌڍڎڏڐڑڒړڔڕږڗژڙۀۃۄۅۆۇۈۉۊۋۍۏےۓەۮۯܐܕܖܗܘܙܞܨܪܬܯݍݙݚݛݫݬݱݳݴݸݹࡀࡆࡇࡉࡔࡧࡩࡪࢪࢫࢬࢮࢱࢲࢹૅેૉ૊૎૏ૐ૑૒૝ૡ૤૯஁ஃ஄அஉ஌எஏ஑னப஫஬",l=0;l<e.length;l++){var u=e[l],d=0==l||-1!=h.indexOf(t[l-1]),c=l==e.length-1||-1!=h.indexOf(t[l+1]);d||-1==f.indexOf(t[l-1])||(d=!0),c||-1==f.indexOf(t[l])||(c=!0),c||-1=="ꡲ્૗".indexOf(t[l+1])||(c=!0),d||-1=="ꡲ્૗".indexOf(t[l])||(d=!0);var v=null;v=d?c?"isol":"init":c?"fina":"medi";for(var p=0;p<s.length;p++)if(s[p].tag==v)for(var g=0;g<s[p].tab.length;g++){1==(b=i[s[p].tab[g]]).ltype&&V.U._applyType1(e,l,b)}}var U=["rlig","liga","mset"];for(l=0;l<e.length;l++){u=e[l];var m=Math.min(3,e.length-l-1);for(p=0;p<s.length;p++){var S=s[p];if(-1!=U.indexOf(S.tag))for(g=0;g<S.tab.length;g++)for(var b=i[S.tab[g]],_=0;_<b.tabs.length;_++)if(null!=b.tabs[_]){var y=V._lctf.coverageIndex(b.tabs[_].coverage,u);if(-1!=y)if(4==b.ltype)for(var x=b.tabs[_].vals[y],F=0;F<x.length;F++){var C=x[F],P=C.chain.length;if(!(m<P)){for(var T=!0,w=0;w<P;w++)C.chain[w]!=e[l+(1+w)]&&(T=!1);if(T){e[l]=C.nglyph;for(w=0;w<P;w++)e[l+w+1]=-1}}}else if(5==b.ltype){var G=b.tabs[_];if(2!=G.fmt)continue;var k=V._lctf.getInterval(G.cDef,u),O=G.cDef[k+2],I=G.scset[O];for(a=0;a<I.length;a++){var A=I[a],B=A.input;if(!(B.length>m)){for(T=!0,w=0;w<B.length;w++){var L=V._lctf.getInterval(G.cDef,e[l+1+w]);if(-1==k&&G.cDef[L+2]!=B[w]){T=!1;break}}if(T){var z=A.substLookupRecords;for(F=0;F<z.length;F+=2)z[F],z[F+1]}}}}}}}return e},V.U._applyType1=function(r,t,e){for(var a=r[t],n=0;n<e.tabs.length;n++){var o=e.tabs[n],i=V._lctf.coverageIndex(o.coverage,a);-1!=i&&(1==o.fmt?r[t]=r[t]+o.delta:r[t]=o.newg[i])}},V.U.glyphsToPath=function(r,t,e){for(var a={cmds:[],crds:[]},n=0,o=0;o<t.length;o++){var i=t[o];if(-1!=i){for(var s=o<t.length-1&&-1!=t[o+1]?t[o+1]:0,h=V.U.glyphToPath(r,i),f=0;f<h.crds.length;f+=2)a.crds.push(h.crds[f]+n),a.crds.push(h.crds[f+1]);e&&a.cmds.push(e);for(f=0;f<h.cmds.length;f++)a.cmds.push(h.cmds[f]);e&&a.cmds.push("X"),n+=r.hmtx.aWidth[i],o<t.length-1&&(n+=V.U.getPairAdjustment(r,i,s))}}return a},V.U.pathToSVG=function(r,t){null==t&&(t=5);for(var e=[],a=0,n={M:2,L:2,Q:4,C:6},o=0;o<r.cmds.length;o++){var i=r.cmds[o],s=a+(n[i]?n[i]:0);for(e.push(i);a<s;){var h=r.crds[a++];e.push(parseFloat(h.toFixed(t))+(a==s?"":" "))}}return e.join("")},V.U.pathToContext=function(r,t){for(var e=0,a=r.crds,n=0;n<r.cmds.length;n++){var o=r.cmds[n];"M"==o?(t.moveTo(a[e],a[e+1]),e+=2):"L"==o?(t.lineTo(a[e],a[e+1]),e+=2):"C"==o?(t.bezierCurveTo(a[e],a[e+1],a[e+2],a[e+3],a[e+4],a[e+5]),e+=6):"Q"==o?(t.quadraticCurveTo(a[e],a[e+1],a[e+2],a[e+3]),e+=4):"#"==o.charAt(0)?(t.beginPath(),t.fillStyle=o):"Z"==o?t.closePath():"X"==o&&t.fill()}},V.U.P={},V.U.P.moveTo=function(r,t,e){r.cmds.push("M"),r.crds.push(t,e)},V.U.P.lineTo=function(r,t,e){r.cmds.push("L"),r.crds.push(t,e)},V.U.P.curveTo=function(r,t,e,a,n,o,i){r.cmds.push("C"),r.crds.push(t,e,a,n,o,i)},V.U.P.qcurveTo=function(r,t,e,a,n){r.cmds.push("Q"),r.crds.push(t,e,a,n)},V.U.P.closePath=function(r){r.cmds.push("Z")},V.U._drawCFF=function(r,t,e,a){for(var n=t.stack,o=t.nStems,i=t.haveWidth,s=t.width,h=t.open,f=0,l=t.x,u=t.y,d=0,c=0,v=0,p=0,g=0,U=0,m=0,S=0,b=0,_=0,y={val:0,size:0};f<r.length;){V.CFF.getCharString(r,f,y);var x=y.val;if(f+=y.size,"o1"==x||"o18"==x)n.length%2!=0&&!i&&(s=n.shift()+e.Private.nominalWidthX),o+=n.length>>1,i=!(n.length=0);else if("o3"==x||"o23"==x){n.length%2!=0&&!i&&(s=n.shift()+e.Private.nominalWidthX),o+=n.length>>1,i=!(n.length=0)}else if("o4"==x)1<n.length&&!i&&(s=n.shift()+e.Private.nominalWidthX,i=!0),h&&V.U.P.closePath(a),u+=n.pop(),V.U.P.moveTo(a,l,u),h=!0;else if("o5"==x)for(;0<n.length;)l+=n.shift(),u+=n.shift(),V.U.P.lineTo(a,l,u);else if("o6"==x||"o7"==x)for(var F=n.length,C="o6"==x,P=0;P<F;P++){var T=n.shift();C?l+=T:u+=T,C=!C,V.U.P.lineTo(a,l,u)}else if("o8"==x||"o24"==x){F=n.length;for(var w=0;w+6<=F;)d=l+n.shift(),c=u+n.shift(),v=d+n.shift(),p=c+n.shift(),l=v+n.shift(),u=p+n.shift(),V.U.P.curveTo(a,d,c,v,p,l,u),w+=6;"o24"==x&&(l+=n.shift(),u+=n.shift(),V.U.P.lineTo(a,l,u))}else{if("o11"==x)break;if("o1234"==x||"o1235"==x||"o1236"==x||"o1237"==x)"o1234"==x&&(c=u,v=(d=l+n.shift())+n.shift(),U=_=p=c+n.shift(),S=u,l=(m=(g=(b=v+n.shift())+n.shift())+n.shift())+n.shift(),V.U.P.curveTo(a,d,c,v,p,b,_),V.U.P.curveTo(a,g,U,m,S,l,u)),"o1235"==x&&(d=l+n.shift(),c=u+n.shift(),v=d+n.shift(),p=c+n.shift(),b=v+n.shift(),_=p+n.shift(),g=b+n.shift(),U=_+n.shift(),m=g+n.shift(),S=U+n.shift(),l=m+n.shift(),u=S+n.shift(),n.shift(),V.U.P.curveTo(a,d,c,v,p,b,_),V.U.P.curveTo(a,g,U,m,S,l,u)),"o1236"==x&&(d=l+n.shift(),c=u+n.shift(),v=d+n.shift(),U=_=p=c+n.shift(),m=(g=(b=v+n.shift())+n.shift())+n.shift(),S=U+n.shift(),l=m+n.shift(),V.U.P.curveTo(a,d,c,v,p,b,_),V.U.P.curveTo(a,g,U,m,S,l,u)),"o1237"==x&&(d=l+n.shift(),c=u+n.shift(),v=d+n.shift(),p=c+n.shift(),b=v+n.shift(),_=p+n.shift(),g=b+n.shift(),U=_+n.shift(),m=g+n.shift(),S=U+n.shift(),Math.abs(m-l)>Math.abs(S-u)?l=m+n.shift():u=S+n.shift(),V.U.P.curveTo(a,d,c,v,p,b,_),V.U.P.curveTo(a,g,U,m,S,l,u));else if("o14"==x){if(0<n.length&&!i&&(s=n.shift()+e.nominalWidthX,i=!0),4==n.length){var G=n.shift(),k=n.shift(),O=n.shift(),I=n.shift(),A=V.CFF.glyphBySE(e,O),B=V.CFF.glyphBySE(e,I);V.U._drawCFF(e.CharStrings[A],t,e,a),t.x=G,t.y=k,V.U._drawCFF(e.CharStrings[B],t,e,a)}h&&(V.U.P.closePath(a),h=!1)}else if("o19"==x||"o20"==x){n.length%2!=0&&!i&&(s=n.shift()+e.Private.nominalWidthX),o+=n.length>>1,i=!(n.length=0),f+=o+7>>3}else if("o21"==x)2<n.length&&!i&&(s=n.shift()+e.Private.nominalWidthX,i=!0),u+=n.pop(),l+=n.pop(),h&&V.U.P.closePath(a),V.U.P.moveTo(a,l,u),h=!0;else if("o22"==x)1<n.length&&!i&&(s=n.shift()+e.Private.nominalWidthX,i=!0),l+=n.pop(),h&&V.U.P.closePath(a),V.U.P.moveTo(a,l,u),h=!0;else if("o25"==x){for(;6<n.length;)l+=n.shift(),u+=n.shift(),V.U.P.lineTo(a,l,u);d=l+n.shift(),c=u+n.shift(),v=d+n.shift(),p=c+n.shift(),l=v+n.shift(),u=p+n.shift(),V.U.P.curveTo(a,d,c,v,p,l,u)}else if("o26"==x)for(n.length%2&&(l+=n.shift());0<n.length;)d=l,c=u+n.shift(),l=v=d+n.shift(),u=(p=c+n.shift())+n.shift(),V.U.P.curveTo(a,d,c,v,p,l,u);else if("o27"==x)for(n.length%2&&(u+=n.shift());0<n.length;)c=u,v=(d=l+n.shift())+n.shift(),p=c+n.shift(),l=v+n.shift(),u=p,V.U.P.curveTo(a,d,c,v,p,l,u);else if("o10"==x||"o29"==x){var L="o10"==x?e.Private:e;if(0==n.length)console.log("error: empty stack");else{var z=n.pop(),D=L.Subrs[z+L.Bias];t.x=l,t.y=u,t.nStems=o,t.haveWidth=i,t.width=s,t.open=h,V.U._drawCFF(D,t,e,a),l=t.x,u=t.y,o=t.nStems,i=t.haveWidth,s=t.width,h=t.open}}else if("o30"==x||"o31"==x){var R=n.length,M=(w=0,"o31"==x);for(w+=R-(F=-3&R);w<F;)M=M?(c=u,v=(d=l+n.shift())+n.shift(),u=(p=c+n.shift())+n.shift(),F-w==5?(l=v+n.shift(),w++):l=v,!1):(d=l,c=u+n.shift(),v=d+n.shift(),p=c+n.shift(),l=v+n.shift(),F-w==5?(u=p+n.shift(),w++):u=p,!0),V.U.P.curveTo(a,d,c,v,p,l,u),w+=4}else{if("o"==(x+"").charAt(0))throw console.log("Unknown operation: "+x,r),x;n.push(x)}}}t.x=l,t.y=u,t.nStems=o,t.haveWidth=i,t.width=s,t.open=h};var S=V,b=/\r?\n/;function t(h){var r=function(s){function r(r){var t=(r=h.extend({font:null,value:"",fontSize:64,textAlign:"left",textBaseline:"bottom"},r)).font,e=r.value,a=r.fontSize,n=r.textAlign,o=r.textBaseline,i=function(r,t){var e={};for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&-1===t.indexOf(a)&&(e[a]=r[a]);return e}(r,["font","value","fontSize","textAlign","textBaseline"]);s.call(this,Object.assign({},i,{closed:!0,visible:!1,path:[{}]})),this._font=null,this._value=e,this._fontSize=a,this._textAlign=n,this._textBaseline=o,this.font=t}s&&(r.__proto__=s);var t={font:{configurable:!0},value:{configurable:!0},fontSize:{configurable:!0},textAlign:{configurable:!0},textBaseline:{configurable:!0}};return((r.prototype=Object.create(s&&s.prototype)).constructor=r).prototype.updateText=function(){var r=this.font.getTextPath(this.value,this.fontSize,0,0,0,this.textAlign,this.textBaseline);0==r.length?(this.path=[{}],this.visible=!1):(this.path=r,this.visible=!0),this.updatePath()},t.font.set=function(r){var t=this;this._font=r,this.font.waitForLoad().then(function(){t.updateText(),t.visible=!0;for(var r=t.addTo;void 0!==r.addTo;)r=r.addTo;r&&"function"==typeof r.updateRenderGraph&&r.updateRenderGraph()})},t.font.get=function(){return this._font},t.value.set=function(r){this._value=r,this.updateText()},t.value.get=function(){return this._value},t.fontSize.set=function(r){this._fontSize=r,this.updateText()},t.fontSize.get=function(){return this._fontSize},t.textAlign.set=function(r){this._textAlign=r,this.updateText()},t.textAlign.get=function(){return this._textAlign},t.textBaseline.set=function(r){this._textBaseline=r,this.updateText()},t.textBaseline.get=function(){return this._textBaseline},Object.defineProperties(r.prototype,t),r}(h.Shape);return r.optionKeys=r.optionKeys.concat(["font","fontSize","value","textAlign","textBaseline"]),h.Text=r,h}function e(u){var r=function(l){function r(r){var t=(r=u.extend({font:null,value:"",fontSize:64,textAlign:"left",textBaseline:"bottom",color:"#333",fill:!1,stroke:1},r)).font,e=r.value,a=r.fontSize,n=r.textAlign,o=r.textBaseline,i=r.color,s=r.fill,h=r.stroke,f=function(r,t){var e={};for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&-1===t.indexOf(a)&&(e[a]=r[a]);return e}(r,["font","value","fontSize","textAlign","textBaseline","color","fill","stroke"]);l.call(this,Object.assign({},f,{visible:!1})),this._font=null,this._value=e,this._fontSize=a,this._textAlign=n,this._textBaseline=o,this._color=i,this._fill=s,this._stroke=h,this.font=t}l&&(r.__proto__=l);var t={font:{configurable:!0},value:{configurable:!0},fontSize:{configurable:!0},textAlign:{configurable:!0},textBaseline:{configurable:!0},color:{configurable:!0},fill:{configurable:!0},stroke:{configurable:!0}};return((r.prototype=Object.create(l&&l.prototype)).constructor=r).prototype.updateText=function(){for(var t=this;0<this.children.length;)this.removeChild(this.children[0]);this.font.getTextGlyphs(this.value,this.fontSize,0,0,0,this.textAlign,this.textBaseline).filter(function(r){return 0<r.path.length}).forEach(function(r){t.addChild(new u.Shape({translate:r.translate,path:r.path,color:t.color,fill:t.fill,stroke:t.stroke,closed:!0}))}),this.updateFlatGraph()},t.font.set=function(r){var t=this;this._font=r,this._font.waitForLoad().then(function(){t.updateText(),t.visible=!0;for(var r=t.addTo;void 0!==r.addTo;)r=r.addTo;r&&"function"==typeof r.updateRenderGraph&&r.updateRenderGraph()})},t.font.get=function(){return this._font},t.value.set=function(r){this._value=r,this.updateText()},t.value.get=function(){return this._value},t.fontSize.set=function(r){this._fontSize=r,this.updateText()},t.fontSize.get=function(){return this._fontSize},t.textAlign.set=function(r){this._textAlign=r,this.updateText()},t.textAlign.get=function(){return this._textAlign},t.textBaseline.set=function(r){this._textBaseline=r,this.updateText()},t.textBaseline.get=function(){return this._textBaseline},t.color.set=function(t){this._color=t,this.children.forEach(function(r){return r.color=t})},t.color.get=function(){return this._color},t.fill.set=function(t){this._fill=t,this.children.forEach(function(r){return r.fill=t})},t.fill.get=function(){return this._fill},t.stroke.set=function(t){this._stroke=t,this.children.forEach(function(r){return r.stroke=t})},t.stroke.get=function(){return this._stroke},Object.defineProperties(r.prototype,t),r}(u.Group);return r.optionKeys=r.optionKeys.concat(["color","fill","stroke","font","fontSize","value","textAlign","textBaseline"]),u.TextGroup=r,u}return{init:function(r){return r.FontList=[],r.waitForFonts=function(){return Promise.all(r.FontList.map(function(r){return r.waitForLoad()}))},function(e){function r(r){var t=this;r=e.extend({src:""},r),this.src=r.src,this.font=null,this._hasLoaded=!1,this._loadCallbacks=[],e.FontList.push(this),this._fetchFontResource(this.src).then(function(r){var t=S.parse(r);if(t.head&&t.hmtx&&t.hhea&&t.glyf)return t;var e=["head","hmtx","hhea","glyf"].filter(function(r){return!t[r]});throw new Error("Typr.js could not parse this font (unable to find "+e.join(", ")+")")}).then(function(r){t.font=r,t._hasLoaded=!0,t._loadCallbacks.forEach(function(r){return r()})}).catch(function(r){throw new Error("Unable to load font from "+t.src+":\n"+r)})}r.prototype.waitForLoad=function(){var e=this;return new Promise(function(r,t){e._hasLoaded&&e._hasLoaded?r():e._loadCallbacks.push(r)})},r.prototype.getFontScale=function(r){return this._hasLoaded?1/this.font.head.unitsPerEm*r:null},r.prototype.measureText=function(r,t){var e=this;if(void 0===t&&(t=64),!this._hasLoaded)return null;var a=Array.isArray(r)?r:r.split(b),n=this.font,o=n.hmtx.aWidth,i=this.getFontScale(t),s=n.hhea.descender,h=n.hhea.ascender,f=(n.hhea.lineGap,a.map(function(r){return S.U.stringToGlyphs(e.font,r).reduce(function(r,t){return-1<t&&t<o.length&&(r+=o[t]),r},0)})),l=Math.max.apply(Math,f),u=0-s+h,d=u*a.length;return{width:l*i,height:d*i,lineHeight:u*i,lineWidths:f.map(function(r){return r*i}),descender:s*i,ascender:h*i}},r.prototype.getTextPath=function(r,s,h,f,l,u,d){var c=this;if(void 0===s&&(s=64),void 0===h&&(h=0),void 0===f&&(f=0),void 0===l&&(l=0),void 0===u&&(u="left"),void 0===d&&(d="bottom"),!this._hasLoaded)return[];var t=Array.isArray(r)?r:r.split(b),v=this.measureText(r,s),p=v.lineWidths,g=v.lineHeight;return t.map(function(r,t){var e=c.getTextOrigin(Object.assign({},v,{width:p[t]}),h,f,l,u,d),a=e[0],n=e[1];e[2];f+=g;var o=S.U.stringToGlyphs(c.font,r),i=S.U.glyphsToPath(c.font,o);return c._convertPathCommands(i,s,a,n,l)}).flat()},r.prototype.getTextGlyphs=function(r,s,h,f,l,u,d){var c=this;if(void 0===s&&(s=64),void 0===h&&(h=0),void 0===f&&(f=0),void 0===l&&(l=0),void 0===u&&(u="left"),void 0===d&&(d="bottom"),!this._hasLoaded)return[];var v=this.measureText(r,s),p=this.font.hmtx.aWidth,g=this.getFontScale(s),U=v.lineWidths,m=v.lineHeight;return(Array.isArray(r)?r:r.split(b)).map(function(r,t){var e=S.U.stringToGlyphs(c.font,r),a=c.getTextOrigin(Object.assign({},v,{width:U[t]}),h,f,l,u,d),n=a[0],o=a[1],i=a[2];return f+=m,e.filter(function(r){return-1!==r}).map(function(r){var t=S.U.glyphToPath(c.font,r),e={translate:{x:n,y:o,z:i},path:c._convertPathCommands(t,s,0,0,0)};return n+=p[r]*g,e})}).flat()},r.prototype.getTextOrigin=function(r,t,e,a,n,o){void 0===t&&(t=0),void 0===e&&(e=0),void 0===a&&(a=0),void 0===n&&(n="left"),void 0===o&&(o="bottom");var i=r.width,s=r.height,h=r.lineHeight;switch(n){case"right":t-=i;break;case"center":t-=i/2}switch(o){case"middle":e-=s/2-h;break;case"bottom":default:e-=s-h}return[t,e,a]},r.prototype._convertPathCommands=function(r,t,e,a,n){void 0===e&&(e=0),void 0===a&&(a=0),void 0===n&&(n=0);var o=this.getFontScale(t),i=r.cmds,s=r.crds.map(function(r){return r*o}),h=null,f=0;return i.map(function(r){var t=null;switch(h=h||{x:e+1*s[f],y:a+-1*s[f+1],z:n},r){case"M":return t={move:{x:e+1*s[f],y:a+-1*s[f+1],z:n}},f+=2,t;case"L":return t={line:{x:e+1*s[f],y:a+-1*s[f+1],z:n}},f+=2,t;case"C":return t={bezier:[{x:e+1*s[f],y:a+-1*s[f+1],z:n},{x:e+1*s[f+2],y:a+-1*s[f+3],z:n},{x:e+1*s[f+4],y:a+-1*s[f+5],z:n}]},f+=6,t;case"Q":return t={arc:[{x:e+1*s[f],y:a+-1*s[f+1],z:n},{x:e+1*s[f+2],y:a+-1*s[f+3],z:n}]},f+=4,t;case"Z":return h&&(t={line:h},h=null),t;default:return t}}).filter(function(r){return null!==r})},r.prototype._fetchFontResource=function(r){return new Promise(function(t,e){var a=new XMLHttpRequest;a.responseType="arraybuffer",a.open("GET",r,!0),a.onreadystatechange=function(r){4===a.readyState&&(200<=a.status&&a.status<300?t(a.response):e("HTTP error "+a.status+": "+a.statusText))},a.send(null)})},e.Font=r}(r),t(r),e(r),r},version:"1.2.7"}});
//# sourceMappingURL=zfont.min.js.map
