Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

troika-3d-text

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

troika-3d-text - npm Package Compare versions

Comparing version 0.15.7 to 0.16.0

@@ -1,17 +0,18 @@

'use strict';(function(C,z){"object"===typeof exports&&"undefined"!==typeof module?z(exports,require("three"),require("troika-worker-utils"),require("troika-three-utils")):"function"===typeof define&&define.amd?define(["exports","three","troika-worker-utils","troika-three-utils"],z):(C=C||self,z(C.troika_3d_text={},C.THREE,C.troika_worker_utils,C.troika_three_utils))})(this,function(C,z,F,Q){function R(r,g){r=J({},r);K.href=r.font||I.defaultFontURL;r.font=K.href;r.text=""+r.text;var b=I.sdfGlyphSize,
a=L[r.font];a||(a=L[r.font]={sdfTexture:new z.DataTexture(new Uint8Array(b*b*64),b,64*b,z.LuminanceFormat,void 0,void 0,void 0,void 0,z.LinearFilter,z.LinearFilter)},a.sdfTexture.font=r.font);S(r).then(function(c){c.newGlyphSDFs&&(c.newGlyphSDFs.forEach(function(c){var d=c.textureData,f=a.sdfTexture.image;for(c=c.atlasIndex*b*b;c>f.data.length-1;){var g=new Uint8Array(2*f.data.length);g.set(f.data);f.data=g;f.height*=2}f.data.set(d,c)}),a.sdfTexture.needsUpdate=!0);g({sdfTexture:a.sdfTexture,sdfMinDistancePercent:.125,
glyphBounds:c.glyphBounds,glyphIndices:c.glyphIndices,totalBounds:c.totalBounds,totalBlockSize:c.totalBlockSize})})}function J(r,g){for(var b in g)g.hasOwnProperty(b)&&(r[b]=g[b]);return r}function M(r,g,b,a){var c=r.getAttribute(g);c&&c.array.length===b.length?(c.array.set(b),c.needsUpdate=!0):r.setAttribute(g,new z.InstancedBufferAttribute(b,a))}function T(r){r=Q.createDerivedMaterial(r,{extensions:{derivatives:!0},uniforms:{uTroikaSDFTexture:{value:null},uTroikaSDFMinDistancePct:{value:0},uTroikaGlyphVSize:{value:0},
uTroikaTotalBounds:{value:new z.Vector4},uTroikaClipRect:{value:new z.Vector4},uTroikaSDFDebug:{value:!1}},vertexDefs:"\nuniform float uTroikaGlyphVSize;\nuniform vec4 uTroikaTotalBounds;\nattribute vec4 aTroikaGlyphBounds;\nattribute float aTroikaGlyphIndex;\nvarying vec2 vTroikaGlyphUV;\nvarying vec3 vTroikaLocalPos;\n",vertexTransform:"\nvTroikaGlyphUV = vec2(\n position.x,\n uTroikaGlyphVSize * (aTroikaGlyphIndex + position.y)\n);\n\nposition = vec3(\n mix(aTroikaGlyphBounds.x, aTroikaGlyphBounds.z, position.x),\n mix(aTroikaGlyphBounds.y, aTroikaGlyphBounds.w, position.y),\n position.z\n);\nvTroikaLocalPos = vec3(position);\n\nuv = vec2(\n (position.x - uTroikaTotalBounds.x) / (uTroikaTotalBounds.z - uTroikaTotalBounds.x),\n (position.y - uTroikaTotalBounds.y) / (uTroikaTotalBounds.w - uTroikaTotalBounds.y)\n);\n",
fragmentDefs:"\nuniform sampler2D uTroikaSDFTexture;\nuniform float uTroikaSDFMinDistancePct;\nuniform bool uTroikaSDFDebug;\nuniform float uTroikaGlyphVSize;\nuniform vec4 uTroikaClipRect;\nvarying vec2 vTroikaGlyphUV;\nvarying vec3 vTroikaLocalPos;\n\nfloat troikaGetClipAlpha() {\n vec4 clip = uTroikaClipRect;\n vec3 pos = vTroikaLocalPos;\n float dClip = min(\n min(pos.x - min(clip.x, clip.z), max(clip.x, clip.z) - pos.x),\n min(pos.y - min(clip.y, clip.w), max(clip.y, clip.w) - pos.y)\n );\n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n float aa = length(fwidth(pos)) * 0.5;\n return smoothstep(-aa, aa, dClip);\n #else\n return step(0.0, dClip);\n #endif\n}\n\nfloat troikaGetTextAlpha() {\n float troikaSDFValue = texture2D(uTroikaSDFTexture, vTroikaGlyphUV).r;\n \n #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)\n float alpha = step(0.5, troikaSDFValue);\n #else\n \n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n float aaDist = min(\n 0.5,\n 0.5 * min(\n fwidth(vTroikaGlyphUV.x), \n fwidth(vTroikaGlyphUV.y / uTroikaGlyphVSize)\n )\n ) / uTroikaSDFMinDistancePct;\n #else\n float aaDist = 0.01;\n #endif\n \n float alpha = uTroikaSDFDebug ? troikaSDFValue : smoothstep(\n 0.5 - aaDist,\n 0.5 + aaDist,\n troikaSDFValue\n );\n #endif\n \n return min(alpha, troikaGetClipAlpha());\n}\n",
fragmentColorTransform:"\nfloat troikaAlphaMult = troikaGetTextAlpha();\nif (troikaAlphaMult == 0.0) {\n discard;\n} else {\n gl_FragColor.a *= troikaAlphaMult;\n}\n"});r.transparent=!0;Object.defineProperty(r,"shadowSide",{get:function(){return this.side}});return r}var G=F.defineWorkerModule({dependencies:[function(){var r=self,g={parse:function(b){var a=g._bin;b=new Uint8Array(b);if("ttcf"==a.readASCII(b,0,4)){var c=4;a.readUshort(b,c);c+=2;a.readUshort(b,c);c+=2;var d=a.readUint(b,c);c+=4;for(var e=
[],f=0;f<d;f++){var h=a.readUint(b,c);c+=4;e.push(g._readFont(b,h))}return e}return[g._readFont(b,0)]},_readFont:function(b,a){var c=g._bin,d=a;c.readFixed(b,a);a+=4;var e=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;var f="cmap;head;hhea;maxp;hmtx;name;OS/2;post;loca;glyf;kern;CFF ;GPOS;GSUB;SVG ".split(";");d={_data:b,_offset:d};for(var h={},k=0;k<e;k++){var l=c.readASCII(b,a,4);a+=4;c.readUint(b,a);a+=4;var q=c.readUint(b,a);a+=4;var u=c.readUint(b,
a);a+=4;h[l]={offset:q,length:u}}for(k=0;k<f.length;k++)a=f[k],h[a]&&(d[a.trim()]=g[a.trim()].parse(b,h[a].offset,h[a].length,d));return d},_tabOffset:function(b,a,c){var d=g._bin,e=d.readUshort(b,c+4);c+=12;for(var f=0;f<e;f++){var h=d.readASCII(b,c,4);c+=4;d.readUint(b,c);c+=4;var k=d.readUint(b,c);c+=4;d.readUint(b,c);c+=4;if(h==a)return k}return 0}};g._bin={readFixed:function(b,a){return(b[a]<<8|b[a+1])+(b[a+2]<<8|b[a+3])/65540},readF2dot14:function(b,a){return g._bin.readShort(b,a)/16384},readInt:function(b,
'use strict';(function(D,z){"object"===typeof exports&&"undefined"!==typeof module?z(exports,require("three"),require("troika-worker-utils"),require("troika-three-utils")):"function"===typeof define&&define.amd?define(["exports","three","troika-worker-utils","troika-three-utils"],z):(D=D||self,z(D.troika_3d_text={},D.THREE,D.troika_worker_utils,D.troika_three_utils))})(this,function(D,z,M,Y){function Z(m,g){m=R({},m);S.href=m.font||K.defaultFontURL;m.font=S.href;m.text=""+m.text;var b=K.sdfGlyphSize,
a=K.textureWidth,c=T[m.font];c||(c=T[m.font]={sdfTexture:new z.DataTexture(new Uint8Array(b*a),a,b,z.LuminanceFormat,void 0,void 0,void 0,void 0,z.LinearFilter,z.LinearFilter)},c.sdfTexture.font=m.font);aa(m).then(function(a){a.newGlyphSDFs&&(a.newGlyphSDFs.forEach(function(a){var d=a.textureData;a=a.atlasIndex;for(var e=c.sdfTexture.image;e.data.length<(a+1)*b*b;){var g=new Uint8Array(2*e.data.length);g.set(e.data);e.data=g;e.height*=2}g=e.width/b;for(var n=0;n<b;n++)for(var q=n*b,u=e.width*b*Math.floor(a/
g)+a%g*b+n*e.width,l=0;l<b;l++)e.data[u+l]=d[q+l]}),c.sdfTexture.needsUpdate=!0);g(Object.freeze({sdfTexture:c.sdfTexture,sdfGlyphSize:b,sdfMinDistancePercent:.125,glyphBounds:a.glyphBounds,glyphAtlasIndices:a.glyphAtlasIndices,caretPositions:a.caretPositions,caretHeight:a.caretHeight,totalBounds:a.totalBounds,totalBlockSize:a.totalBlockSize}))})}function R(m,g){for(var b in g)g.hasOwnProperty(b)&&(m[b]=g[b]);return m}function U(m,g,b,a){var c=m.getAttribute(g);c&&c.array.length===b.length?(c.array.set(b),
c.needsUpdate=!0):m.setAttribute(g,new z.InstancedBufferAttribute(b,a))}function ba(m){m=Y.createDerivedMaterial(m,{extensions:{derivatives:!0},uniforms:{uTroikaSDFTexture:{value:null},uTroikaSDFTextureSize:{value:new z.Vector2},uTroikaSDFGlyphSize:{value:0},uTroikaSDFMinDistancePct:{value:0},uTroikaTotalBounds:{value:new z.Vector4},uTroikaClipRect:{value:new z.Vector4},uTroikaSDFDebug:{value:!1}},vertexDefs:"\nuniform vec2 uTroikaSDFTextureSize;\nuniform float uTroikaSDFGlyphSize;\nuniform vec4 uTroikaTotalBounds;\nattribute vec4 aTroikaGlyphBounds;\nattribute float aTroikaGlyphIndex;\nvarying vec2 vTroikaSDFTextureUV;\nvarying vec2 vTroikaGlyphUV;\nvarying vec3 vTroikaLocalPos;\n",
vertexTransform:"\nvTroikaGlyphUV = vec2(position);\n\nvec2 colsAndRows = uTroikaSDFTextureSize / uTroikaSDFGlyphSize;\nvTroikaSDFTextureUV = vec2(\n mod(aTroikaGlyphIndex, colsAndRows.x) + position.x,\n floor(aTroikaGlyphIndex / colsAndRows.x) + position.y\n) * uTroikaSDFGlyphSize / uTroikaSDFTextureSize;\n\nposition = vec3(\n mix(aTroikaGlyphBounds.x, aTroikaGlyphBounds.z, position.x),\n mix(aTroikaGlyphBounds.y, aTroikaGlyphBounds.w, position.y),\n position.z\n);\nvTroikaLocalPos = vec3(position);\n\nuv = vec2(\n (position.x - uTroikaTotalBounds.x) / (uTroikaTotalBounds.z - uTroikaTotalBounds.x),\n (position.y - uTroikaTotalBounds.y) / (uTroikaTotalBounds.w - uTroikaTotalBounds.y)\n);\n",
fragmentDefs:"\nuniform sampler2D uTroikaSDFTexture;\nuniform float uTroikaSDFMinDistancePct;\nuniform bool uTroikaSDFDebug;\nuniform vec4 uTroikaClipRect;\nvarying vec2 vTroikaSDFTextureUV;\nvarying vec2 vTroikaGlyphUV;\nvarying vec3 vTroikaLocalPos;\n\nfloat troikaGetClipAlpha() {\n vec4 clip = uTroikaClipRect;\n vec3 pos = vTroikaLocalPos;\n float dClip = min(\n min(pos.x - min(clip.x, clip.z), max(clip.x, clip.z) - pos.x),\n min(pos.y - min(clip.y, clip.w), max(clip.y, clip.w) - pos.y)\n );\n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n float aa = length(fwidth(pos)) * 0.5;\n return smoothstep(-aa, aa, dClip);\n #else\n return step(0.0, dClip);\n #endif\n}\n\nfloat troikaGetTextAlpha() {\n float troikaSDFValue = texture2D(uTroikaSDFTexture, vTroikaSDFTextureUV).r;\n \n #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)\n float alpha = step(0.5, troikaSDFValue);\n #else\n \n #if defined(GL_OES_standard_derivatives) || __VERSION__ >= 300\n float aaDist = min(\n 0.5,\n 0.5 * min(\n fwidth(vTroikaGlyphUV.x),\n fwidth(vTroikaGlyphUV.y)\n )\n ) / uTroikaSDFMinDistancePct;\n #else\n float aaDist = 0.01;\n #endif\n \n float alpha = uTroikaSDFDebug ? troikaSDFValue : smoothstep(\n 0.5 - aaDist,\n 0.5 + aaDist,\n troikaSDFValue\n );\n #endif\n \n return min(alpha, troikaGetClipAlpha());\n}\n",
fragmentColorTransform:"\nfloat troikaAlphaMult = troikaGetTextAlpha();\nif (troikaAlphaMult == 0.0) {\n discard;\n} else {\n gl_FragColor.a *= troikaAlphaMult;\n}\n"});m.transparent=!0;Object.defineProperty(m,"shadowSide",{get:function(){return this.side}});return m}var G=M.defineWorkerModule({dependencies:[function(){var m=self,g={parse:function(b){var a=g._bin;b=new Uint8Array(b);if("ttcf"==a.readASCII(b,0,4)){var c=4;a.readUshort(b,c);c+=2;a.readUshort(b,c);c+=2;var d=a.readUint(b,c);c+=4;for(var e=
[],f=0;f<d;f++){var h=a.readUint(b,c);c+=4;e.push(g._readFont(b,h))}return e}return[g._readFont(b,0)]},_readFont:function(b,a){var c=g._bin,d=a;c.readFixed(b,a);a+=4;var e=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;var f="cmap;head;hhea;maxp;hmtx;name;OS/2;post;loca;glyf;kern;CFF ;GPOS;GSUB;SVG ".split(";");d={_data:b,_offset:d};for(var h={},k=0;k<e;k++){var n=c.readASCII(b,a,4);a+=4;c.readUint(b,a);a+=4;var q=c.readUint(b,a);a+=4;var u=c.readUint(b,
a);a+=4;h[n]={offset:q,length:u}}for(k=0;k<f.length;k++)a=f[k],h[a]&&(d[a.trim()]=g[a.trim()].parse(b,h[a].offset,h[a].length,d));return d},_tabOffset:function(b,a,c){var d=g._bin,e=d.readUshort(b,c+4);c+=12;for(var f=0;f<e;f++){var h=d.readASCII(b,c,4);c+=4;d.readUint(b,c);c+=4;var k=d.readUint(b,c);c+=4;d.readUint(b,c);c+=4;if(h==a)return k}return 0}};g._bin={readFixed:function(b,a){return(b[a]<<8|b[a+1])+(b[a+2]<<8|b[a+3])/65540},readF2dot14:function(b,a){return g._bin.readShort(b,a)/16384},readInt:function(b,
a){var c=g._bin.t.uint8;c[0]=b[a+3];c[1]=b[a+2];c[2]=b[a+1];c[3]=b[a];return g._bin.t.int32[0]},readInt8:function(b,a){g._bin.t.uint8[0]=b[a];return g._bin.t.int8[0]},readShort:function(b,a){var c=g._bin.t.uint8;c[1]=b[a];c[0]=b[a+1];return g._bin.t.int16[0]},readUshort:function(b,a){return b[a]<<8|b[a+1]},readUshorts:function(b,a,c){for(var d=[],e=0;e<c;e++)d.push(g._bin.readUshort(b,a+2*e));return d},readUint:function(b,a){var c=g._bin.t.uint8;c[3]=b[a];c[2]=b[a+1];c[1]=b[a+2];c[0]=b[a+3];return g._bin.t.uint32[0]},
readUint64:function(b,a){return 4294967296*g._bin.readUint(b,a)+g._bin.readUint(b,a+4)},readASCII:function(b,a,c){for(var d="",e=0;e<c;e++)d+=String.fromCharCode(b[a+e]);return d},readUnicode:function(b,a,c){for(var d="",e=0;e<c;e++){var f=b[a++]<<8|b[a++];d+=String.fromCharCode(f)}return d},_tdec:r.TextDecoder?new r.TextDecoder:null,readUTF8:function(b,a,c){var d=g._bin._tdec;return d&&0==a&&c==b.length?d.decode(b):g._bin.readASCII(b,a,c)},readBytes:function(b,a,c){for(var d=[],e=0;e<c;e++)d.push(b[a+
readUint64:function(b,a){return 4294967296*g._bin.readUint(b,a)+g._bin.readUint(b,a+4)},readASCII:function(b,a,c){for(var d="",e=0;e<c;e++)d+=String.fromCharCode(b[a+e]);return d},readUnicode:function(b,a,c){for(var d="",e=0;e<c;e++){var f=b[a++]<<8|b[a++];d+=String.fromCharCode(f)}return d},_tdec:m.TextDecoder?new m.TextDecoder:null,readUTF8:function(b,a,c){var d=g._bin._tdec;return d&&0==a&&c==b.length?d.decode(b):g._bin.readASCII(b,a,c)},readBytes:function(b,a,c){for(var d=[],e=0;e<c;e++)d.push(b[a+
e]);return d},readASCIIArray:function(b,a,c){for(var d=[],e=0;e<c;e++)d.push(String.fromCharCode(b[a+e]));return d}};g._bin.t={buff:new ArrayBuffer(8)};g._bin.t.int8=new Int8Array(g._bin.t.buff);g._bin.t.uint8=new Uint8Array(g._bin.t.buff);g._bin.t.int16=new Int16Array(g._bin.t.buff);g._bin.t.uint16=new Uint16Array(g._bin.t.buff);g._bin.t.int32=new Int32Array(g._bin.t.buff);g._bin.t.uint32=new Uint32Array(g._bin.t.buff);g._lctf={};g._lctf.parse=function(b,a,c,d,e){var f=g._bin;c={};d=a;f.readFixed(b,
a);a+=4;var h=f.readUshort(b,a);a+=2;var k=f.readUshort(b,a);a=f.readUshort(b,a+2);c.scriptList=g._lctf.readScriptList(b,d+h);c.featureList=g._lctf.readFeatureList(b,d+k);c.lookupList=g._lctf.readLookupList(b,d+a,e);return c};g._lctf.readLookupList=function(b,a,c){var d=g._bin,e=a,f=[],h=d.readUshort(b,a);a+=2;for(var k=0;k<h;k++){var l=d.readUshort(b,a);a+=2;l=g._lctf.readLookupTable(b,e+l,c);f.push(l)}return f};g._lctf.readLookupTable=function(b,a,c){var d=g._bin,e=a,f={tabs:[]};f.ltype=d.readUshort(b,
a);a+=2;f.flag=d.readUshort(b,a);a+=2;var h=d.readUshort(b,a);a+=2;for(var k=0;k<h;k++){var l=d.readUshort(b,a);a+=2;l=c(b,f.ltype,e+l);f.tabs.push(l)}return f};g._lctf.numOfOnes=function(b){for(var a=0,c=0;32>c;c++)0!=(b>>>c&1)&&a++;return a};g._lctf.readClassDef=function(b,a){var c=g._bin,d=[],e=c.readUshort(b,a);a+=2;if(1==e){var f=c.readUshort(b,a);a+=2;var h=c.readUshort(b,a);a+=2;for(var k=0;k<h;k++)d.push(f+k),d.push(f+k),d.push(c.readUshort(b,a)),a+=2}if(2==e)for(e=c.readUshort(b,a),a+=2,
a);a+=4;var h=f.readUshort(b,a);a+=2;var k=f.readUshort(b,a);a=f.readUshort(b,a+2);c.scriptList=g._lctf.readScriptList(b,d+h);c.featureList=g._lctf.readFeatureList(b,d+k);c.lookupList=g._lctf.readLookupList(b,d+a,e);return c};g._lctf.readLookupList=function(b,a,c){var d=g._bin,e=a,f=[],h=d.readUshort(b,a);a+=2;for(var k=0;k<h;k++){var n=d.readUshort(b,a);a+=2;n=g._lctf.readLookupTable(b,e+n,c);f.push(n)}return f};g._lctf.readLookupTable=function(b,a,c){var d=g._bin,e=a,f={tabs:[]};f.ltype=d.readUshort(b,
a);a+=2;f.flag=d.readUshort(b,a);a+=2;var h=d.readUshort(b,a);a+=2;for(var k=0;k<h;k++){var n=d.readUshort(b,a);a+=2;n=c(b,f.ltype,e+n);f.tabs.push(n)}return f};g._lctf.numOfOnes=function(b){for(var a=0,c=0;32>c;c++)0!=(b>>>c&1)&&a++;return a};g._lctf.readClassDef=function(b,a){var c=g._bin,d=[],e=c.readUshort(b,a);a+=2;if(1==e){var f=c.readUshort(b,a);a+=2;var h=c.readUshort(b,a);a+=2;for(var k=0;k<h;k++)d.push(f+k),d.push(f+k),d.push(c.readUshort(b,a)),a+=2}if(2==e)for(e=c.readUshort(b,a),a+=2,
k=0;k<e;k++)d.push(c.readUshort(b,a)),a+=2,d.push(c.readUshort(b,a)),a+=2,d.push(c.readUshort(b,a)),a+=2;return d};g._lctf.getInterval=function(b,a){for(var c=0;c<b.length;c+=3){var d=b[c+1];if(b[c]<=a&&a<=d)return c}return-1};g._lctf.readCoverage=function(b,a){var c=g._bin,d={};d.fmt=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;1==d.fmt&&(d.tab=c.readUshorts(b,a,e));2==d.fmt&&(d.tab=c.readUshorts(b,a,3*e));return d};g._lctf.coverageIndex=function(b,a){var c=b.tab;return 1==b.fmt?c.indexOf(a):
2==b.fmt&&(b=g._lctf.getInterval(c,a),-1!=b)?c[b+2]+(a-c[b]):-1};g._lctf.readFeatureList=function(b,a){var c=g._bin,d=a,e=[],f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readASCII(b,a,4);a+=4;var l=c.readUshort(b,a);a+=2;e.push({tag:k.trim(),tab:g._lctf.readFeatureTable(b,d+l)})}return e};g._lctf.readFeatureTable=function(b,a){var c=g._bin;c.readUshort(b,a);a+=2;var d=c.readUshort(b,a);a+=2;for(var e=[],f=0;f<d;f++)e.push(c.readUshort(b,a+2*f));return e};g._lctf.readScriptList=function(b,
a){var c=g._bin,d=a,e={},f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readASCII(b,a,4);a+=4;var l=c.readUshort(b,a);a+=2;e[k.trim()]=g._lctf.readScriptTable(b,d+l)}return e};g._lctf.readScriptTable=function(b,a){var c=g._bin,d=a,e={},f=c.readUshort(b,a);a+=2;e.default=g._lctf.readLangSysTable(b,d+f);f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readASCII(b,a,4);a+=4;var l=c.readUshort(b,a);a+=2;e[k.trim()]=g._lctf.readLangSysTable(b,d+l)}return e};g._lctf.readLangSysTable=function(b,
2==b.fmt&&(b=g._lctf.getInterval(c,a),-1!=b)?c[b+2]+(a-c[b]):-1};g._lctf.readFeatureList=function(b,a){var c=g._bin,d=a,e=[],f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readASCII(b,a,4);a+=4;var n=c.readUshort(b,a);a+=2;e.push({tag:k.trim(),tab:g._lctf.readFeatureTable(b,d+n)})}return e};g._lctf.readFeatureTable=function(b,a){var c=g._bin;c.readUshort(b,a);a+=2;var d=c.readUshort(b,a);a+=2;for(var e=[],f=0;f<d;f++)e.push(c.readUshort(b,a+2*f));return e};g._lctf.readScriptList=function(b,
a){var c=g._bin,d=a,e={},f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readASCII(b,a,4);a+=4;var n=c.readUshort(b,a);a+=2;e[k.trim()]=g._lctf.readScriptTable(b,d+n)}return e};g._lctf.readScriptTable=function(b,a){var c=g._bin,d=a,e={},f=c.readUshort(b,a);a+=2;e.default=g._lctf.readLangSysTable(b,d+f);f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readASCII(b,a,4);a+=4;var n=c.readUshort(b,a);a+=2;e[k.trim()]=g._lctf.readLangSysTable(b,d+n)}return e};g._lctf.readLangSysTable=function(b,
a){var c=g._bin,d={};c.readUshort(b,a);a+=2;d.reqFeature=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);d.features=c.readUshorts(b,a+2,e);return d};g.CFF={};g.CFF.parse=function(b,a,c){var d=g._bin;b=new Uint8Array(b.buffer,a,c);a=0;a++;a++;a++;a++;var e=[];a=g.CFF.readIndex(b,a,e);var f=[];for(c=0;c<e.length-1;c++)f.push(d.readASCII(b,a+e[c],e[c+1]-e[c]));a+=e[e.length-1];e=[];a=g.CFF.readIndex(b,a,e);f=[];for(c=0;c<e.length-1;c++)f.push(g.CFF.readDict(b,a+e[c],a+e[c+1]));a+=e[e.length-1];e=f[0];

@@ -22,21 +23,21 @@ var h=[];a=g.CFF.readIndex(b,a,h);f=[];for(c=0;c<h.length-1;c++)f.push(d.readASCII(b,a+h[c],h[c+1]-h[c]));a+=h[h.length-1];g.CFF.readSubrs(b,a,e);if(e.CharStrings){a=e.CharStrings;h=[];a=g.CFF.readIndex(b,a,h);var k=[];for(c=0;c<h.length-1;c++)k.push(d.readBytes(b,a+h[c],h[c+1]-h[c]));e.CharStrings=k}if(e.ROS){a=e.FDArray;h=[];a=g.CFF.readIndex(b,a,h);e.FDArray=[];for(c=0;c<h.length-1;c++)k=g.CFF.readDict(b,a+h[c],a+h[c+1]),g.CFF._readFDict(b,k,f),e.FDArray.push(k);a=e.FDSelect;e.FDSelect=[];c=b[a];

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];g.CFF.glyphByUnicode=function(b,a){for(var c=0;c<b.charset.length;c++)if(b.charset[c]==
a)return c;return-1};g.CFF.glyphBySE=function(b,a){return 0>a||255<a?-1:g.CFF.glyphByUnicode(b,g.CFF.tableSE[a])};g.CFF.readEncoding=function(b,a,c){c=[".notdef"];var d=b[a];a++;if(0==d){d=b[a];a++;for(var e=0;e<d;e++)c.push(b[a+e])}else throw"error: unknown encoding format: "+d;return c};g.CFF.readCharset=function(b,a,c){var d=g._bin,e=[".notdef"],f=b[a];a++;if(0==f)for(var h=0;h<c;h++){var k=d.readUshort(b,a);a+=2;e.push(k)}else if(1==f||2==f)for(;e.length<c;){k=d.readUshort(b,a);a+=2;if(1==f){var l=
b[a];a++}else l=d.readUshort(b,a),a+=2;for(h=0;h<=l;h++)e.push(k),k++}else throw"error: format: "+f;return e};g.CFF.readIndex=function(b,a,c){var d=g._bin,e=d.readUshort(b,a)+1;a+=2;var f=b[a];a++;if(1==f)for(var h=0;h<e;h++)c.push(b[a+h]);else if(2==f)for(h=0;h<e;h++)c.push(d.readUshort(b,a+2*h));else if(3==f)for(h=0;h<e;h++)c.push(d.readUint(b,a+3*h-1)&16777215);else if(1!=e)throw"unsupported offset size: "+f+", count: "+e;return a+e*f-1};g.CFF.getCharString=function(b,a,c){var d=g._bin,e=b[a],
f=b[a+1],h=1,k=null,l=null;20>=e&&(k=e,h=1);12==e&&(k=100*e+f,h=2);21<=e&&27>=e&&(k=e,h=1);28==e&&(l=d.readShort(b,a+1),h=3);29<=e&&31>=e&&(k=e,h=1);32<=e&&246>=e&&(l=e-139,h=1);247<=e&&250>=e&&(l=256*(e-247)+f+108,h=2);251<=e&&254>=e&&(l=256*-(e-251)-f-108,h=2);255==e&&(l=d.readInt(b,a+1)/65535,h=5);c.val=null!=l?l:"o"+k;c.size=h};g.CFF.readCharString=function(b,a,c){c=a+c;for(var d=g._bin,e=[];a<c;){var f=b[a],h=b[a+1],k=1,l=null,q=null;20>=f&&(l=f,k=1);12==f&&(l=100*f+h,k=2);if(19==f||20==f)l=
f,k=2;21<=f&&27>=f&&(l=f,k=1);28==f&&(q=d.readShort(b,a+1),k=3);29<=f&&31>=f&&(l=f,k=1);32<=f&&246>=f&&(q=f-139,k=1);247<=f&&250>=f&&(q=256*(f-247)+h+108,k=2);251<=f&&254>=f&&(q=256*-(f-251)-h-108,k=2);255==f&&(q=d.readInt(b,a+1)/65535,k=5);e.push(null!=q?q:"o"+l);a+=k}return e};g.CFF.readDict=function(b,a,c){for(var d=g._bin,e={},f=[];a<c;){var h=b[a],k=b[a+1],l=1,q=null,u=null;28==h&&(u=d.readShort(b,a+1),l=3);29==h&&(u=d.readInt(b,a+1),l=5);32<=h&&246>=h&&(u=h-139,l=1);247<=h&&250>=h&&(u=256*(h-
247)+k+108,l=2);251<=h&&254>=h&&(u=256*-(h-251)-k-108,l=2);if(255==h)throw d.readInt(b,a+1),"unknown number";if(30==h){u=[];for(l=1;;){var m=b[a+l];l++;var p=m>>4;m&=15;15!=p&&u.push(p);15!=m&&u.push(m);if(15==m)break}p="";m=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"];for(var n=0;n<u.length;n++)p+=m[u[n]];u=parseFloat(p)}21>=h&&(l="version Notice FullName FamilyName Weight FontBBox BlueValues OtherBlues FamilyBlues FamilyOtherBlues StdHW StdVW escape UniqueID XUID charset Encoding CharStrings Private Subrs defaultWidthX nominalWidthX".split(" "),
q=l[h],l=1,12==h&&(l=["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"],q=l[k],l=2));null!=q?(e[q]=1==f.length?
f[0]:f,f=[]):f.push(u);a+=l}return e};g.cmap={};g.cmap.parse=function(b,a,c){b=new Uint8Array(b.buffer,a,c);a=0;c=g._bin;var d={};c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;var f=[];d.tables=[];for(var h=0;h<e;h++){var k=c.readUshort(b,a);a+=2;var l=c.readUshort(b,a);a+=2;var q=c.readUint(b,a);a+=4;var u="p"+k+"e"+l,m=f.indexOf(q);if(-1==m){m=d.tables.length;var p;f.push(q);var n=c.readUshort(b,q);0==n?p=g.cmap.parse0(b,q):4==n?p=g.cmap.parse4(b,q):6==n?p=g.cmap.parse6(b,q):12==n?p=g.cmap.parse12(b,
q):console.log("unknown format: "+n,k,l,q);d.tables.push(p)}if(null!=d[u])throw"multiple tables for one platform+encoding";d[u]=m}return d};g.cmap.parse0=function(b,a){var c=g._bin,d={};d.format=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;d.map=[];for(c=0;c<e-6;c++)d.map.push(b[a+c]);return d};g.cmap.parse4=function(b,a){var c=g._bin,d=a,e={};e.format=c.readUshort(b,a);a+=2;var f=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;var h=c.readUshort(b,a);a+=2;h/=2;e.searchRange=
a)return c;return-1};g.CFF.glyphBySE=function(b,a){return 0>a||255<a?-1:g.CFF.glyphByUnicode(b,g.CFF.tableSE[a])};g.CFF.readEncoding=function(b,a,c){c=[".notdef"];var d=b[a];a++;if(0==d){d=b[a];a++;for(var e=0;e<d;e++)c.push(b[a+e])}else throw"error: unknown encoding format: "+d;return c};g.CFF.readCharset=function(b,a,c){var d=g._bin,e=[".notdef"],f=b[a];a++;if(0==f)for(var h=0;h<c;h++){var k=d.readUshort(b,a);a+=2;e.push(k)}else if(1==f||2==f)for(;e.length<c;){k=d.readUshort(b,a);a+=2;if(1==f){var n=
b[a];a++}else n=d.readUshort(b,a),a+=2;for(h=0;h<=n;h++)e.push(k),k++}else throw"error: format: "+f;return e};g.CFF.readIndex=function(b,a,c){var d=g._bin,e=d.readUshort(b,a)+1;a+=2;var f=b[a];a++;if(1==f)for(var h=0;h<e;h++)c.push(b[a+h]);else if(2==f)for(h=0;h<e;h++)c.push(d.readUshort(b,a+2*h));else if(3==f)for(h=0;h<e;h++)c.push(d.readUint(b,a+3*h-1)&16777215);else if(1!=e)throw"unsupported offset size: "+f+", count: "+e;return a+e*f-1};g.CFF.getCharString=function(b,a,c){var d=g._bin,e=b[a],
f=b[a+1],h=1,k=null,n=null;20>=e&&(k=e,h=1);12==e&&(k=100*e+f,h=2);21<=e&&27>=e&&(k=e,h=1);28==e&&(n=d.readShort(b,a+1),h=3);29<=e&&31>=e&&(k=e,h=1);32<=e&&246>=e&&(n=e-139,h=1);247<=e&&250>=e&&(n=256*(e-247)+f+108,h=2);251<=e&&254>=e&&(n=256*-(e-251)-f-108,h=2);255==e&&(n=d.readInt(b,a+1)/65535,h=5);c.val=null!=n?n:"o"+k;c.size=h};g.CFF.readCharString=function(b,a,c){c=a+c;for(var d=g._bin,e=[];a<c;){var f=b[a],h=b[a+1],k=1,n=null,q=null;20>=f&&(n=f,k=1);12==f&&(n=100*f+h,k=2);if(19==f||20==f)n=
f,k=2;21<=f&&27>=f&&(n=f,k=1);28==f&&(q=d.readShort(b,a+1),k=3);29<=f&&31>=f&&(n=f,k=1);32<=f&&246>=f&&(q=f-139,k=1);247<=f&&250>=f&&(q=256*(f-247)+h+108,k=2);251<=f&&254>=f&&(q=256*-(f-251)-h-108,k=2);255==f&&(q=d.readInt(b,a+1)/65535,k=5);e.push(null!=q?q:"o"+n);a+=k}return e};g.CFF.readDict=function(b,a,c){for(var d=g._bin,e={},f=[];a<c;){var h=b[a],k=b[a+1],n=1,q=null,u=null;28==h&&(u=d.readShort(b,a+1),n=3);29==h&&(u=d.readInt(b,a+1),n=5);32<=h&&246>=h&&(u=h-139,n=1);247<=h&&250>=h&&(u=256*(h-
247)+k+108,n=2);251<=h&&254>=h&&(u=256*-(h-251)-k-108,n=2);if(255==h)throw d.readInt(b,a+1),"unknown number";if(30==h){u=[];for(n=1;;){var l=b[a+n];n++;var r=l>>4;l&=15;15!=r&&u.push(r);15!=l&&u.push(l);if(15==l)break}r="";l=[0,1,2,3,4,5,6,7,8,9,".","e","e-","reserved","-","endOfNumber"];for(var p=0;p<u.length;p++)r+=l[u[p]];u=parseFloat(r)}21>=h&&(n="version Notice FullName FamilyName Weight FontBBox BlueValues OtherBlues FamilyBlues FamilyOtherBlues StdHW StdVW escape UniqueID XUID charset Encoding CharStrings Private Subrs defaultWidthX nominalWidthX".split(" "),
q=n[h],n=1,12==h&&(n=["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"],q=n[k],n=2));null!=q?(e[q]=1==f.length?
f[0]:f,f=[]):f.push(u);a+=n}return e};g.cmap={};g.cmap.parse=function(b,a,c){b=new Uint8Array(b.buffer,a,c);a=0;c=g._bin;var d={};c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;var f=[];d.tables=[];for(var h=0;h<e;h++){var k=c.readUshort(b,a);a+=2;var n=c.readUshort(b,a);a+=2;var q=c.readUint(b,a);a+=4;var u="p"+k+"e"+n,l=f.indexOf(q);if(-1==l){l=d.tables.length;var r;f.push(q);var p=c.readUshort(b,q);0==p?r=g.cmap.parse0(b,q):4==p?r=g.cmap.parse4(b,q):6==p?r=g.cmap.parse6(b,q):12==p?r=g.cmap.parse12(b,
q):console.log("unknown format: "+p,k,n,q);d.tables.push(r)}if(null!=d[u])throw"multiple tables for one platform+encoding";d[u]=l}return d};g.cmap.parse0=function(b,a){var c=g._bin,d={};d.format=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;d.map=[];for(c=0;c<e-6;c++)d.map.push(b[a+c]);return d};g.cmap.parse4=function(b,a){var c=g._bin,d=a,e={};e.format=c.readUshort(b,a);a+=2;var f=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;var h=c.readUshort(b,a);a+=2;h/=2;e.searchRange=
c.readUshort(b,a);a+=2;e.entrySelector=c.readUshort(b,a);a+=2;e.rangeShift=c.readUshort(b,a);a+=2;e.endCount=c.readUshorts(b,a,h);a=a+2*h+2;e.startCount=c.readUshorts(b,a,h);a+=2*h;e.idDelta=[];for(var k=0;k<h;k++)e.idDelta.push(c.readShort(b,a)),a+=2;e.idRangeOffset=c.readUshorts(b,a,h);a+=2*h;for(e.glyphIdArray=[];a<d+f;)e.glyphIdArray.push(c.readUshort(b,a)),a+=2;return e};g.cmap.parse6=function(b,a){var c=g._bin,d={};d.format=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=
2;d.firstCode=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;d.glyphIdArray=[];for(var f=0;f<e;f++)d.glyphIdArray.push(c.readUshort(b,a)),a+=2;return d};g.cmap.parse12=function(b,a){var c=g._bin,d={};d.format=c.readUshort(b,a);a=a+2+2;c.readUint(b,a);a+=4;c.readUint(b,a);a+=4;var e=c.readUint(b,a);a+=4;d.groups=[];for(var f=0;f<e;f++){var h=a+12*f,k=c.readUint(b,h+0),l=c.readUint(b,h+4);h=c.readUint(b,h+8);d.groups.push([k,l,h])}return d};g.glyf={};g.glyf.parse=function(b,a,c,d){b=[];for(a=0;a<
2;d.firstCode=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;d.glyphIdArray=[];for(var f=0;f<e;f++)d.glyphIdArray.push(c.readUshort(b,a)),a+=2;return d};g.cmap.parse12=function(b,a){var c=g._bin,d={};d.format=c.readUshort(b,a);a=a+2+2;c.readUint(b,a);a+=4;c.readUint(b,a);a+=4;var e=c.readUint(b,a);a+=4;d.groups=[];for(var f=0;f<e;f++){var h=a+12*f,k=c.readUint(b,h+0),n=c.readUint(b,h+4);h=c.readUint(b,h+8);d.groups.push([k,n,h])}return d};g.glyf={};g.glyf.parse=function(b,a,c,d){b=[];for(a=0;a<
d.maxp.numGlyphs;a++)b.push(null);return b};g.glyf._parseGlyf=function(b,a){var c=g._bin,d=b._data,e=g._tabOffset(d,"glyf",b._offset)+b.loca[a];if(b.loca[a]==b.loca[a+1])return null;b={};b.noc=c.readShort(d,e);e+=2;b.xMin=c.readShort(d,e);e+=2;b.yMin=c.readShort(d,e);e+=2;b.xMax=c.readShort(d,e);e+=2;b.yMax=c.readShort(d,e);e+=2;if(b.xMin>=b.xMax||b.yMin>=b.yMax)return null;if(0<b.noc){b.endPts=[];for(a=0;a<b.noc;a++)b.endPts.push(c.readUshort(d,e)),e+=2;a=c.readUshort(d,e);e+=2;if(d.length-e<a)return null;
b.instructions=c.readBytes(d,e,a);e+=a;var f=b.endPts[b.noc-1]+1;b.flags=[];for(a=0;a<f;a++){var h=d[e];e++;b.flags.push(h);if(0!=(h&8)){var k=d[e];e++;for(var l=0;l<k;l++)b.flags.push(h),a++}}b.xs=[];for(a=0;a<f;a++)h=0!=(b.flags[a]&2),k=0!=(b.flags[a]&16),h?(b.xs.push(k?d[e]:-d[e]),e++):k?b.xs.push(0):(b.xs.push(c.readShort(d,e)),e+=2);b.ys=[];for(a=0;a<f;a++)h=0!=(b.flags[a]&4),k=0!=(b.flags[a]&32),h?(b.ys.push(k?d[e]:-d[e]),e++):k?b.ys.push(0):(b.ys.push(c.readShort(d,e)),e+=2);for(a=e=d=0;a<
b.instructions=c.readBytes(d,e,a);e+=a;var f=b.endPts[b.noc-1]+1;b.flags=[];for(a=0;a<f;a++){var h=d[e];e++;b.flags.push(h);if(0!=(h&8)){var k=d[e];e++;for(var n=0;n<k;n++)b.flags.push(h),a++}}b.xs=[];for(a=0;a<f;a++)h=0!=(b.flags[a]&2),k=0!=(b.flags[a]&16),h?(b.xs.push(k?d[e]:-d[e]),e++):k?b.xs.push(0):(b.xs.push(c.readShort(d,e)),e+=2);b.ys=[];for(a=0;a<f;a++)h=0!=(b.flags[a]&4),k=0!=(b.flags[a]&32),h?(b.ys.push(k?d[e]:-d[e]),e++):k?b.ys.push(0):(b.ys.push(c.readShort(d,e)),e+=2);for(a=e=d=0;a<
f;a++)d+=b.xs[a],e+=b.ys[a],b.xs[a]=d,b.ys[a]=e}else{b.parts=[];do a=c.readUshort(d,e),e+=2,f={m:{a:1,b:0,c:0,d:1,tx:0,ty:0},p1:-1,p2:-1},b.parts.push(f),f.glyphIndex=c.readUshort(d,e),e+=2,a&1?(h=c.readShort(d,e),e+=2,k=c.readShort(d,e),e+=2):(h=c.readInt8(d,e),e++,k=c.readInt8(d,e),e++),a&2?(f.m.tx=h,f.m.ty=k):(f.p1=h,f.p2=k),a&8?(f.m.a=f.m.d=c.readF2dot14(d,e),e+=2):a&64?(f.m.a=c.readF2dot14(d,e),e+=2,f.m.d=c.readF2dot14(d,e),e+=2):a&128&&(f.m.a=c.readF2dot14(d,e),e+=2,f.m.b=c.readF2dot14(d,e),
e+=2,f.m.c=c.readF2dot14(d,e),e+=2,f.m.d=c.readF2dot14(d,e),e+=2);while(a&32);if(a&256)for(c=c.readUshort(d,e),e+=2,b.instr=[],a=0;a<c;a++)b.instr.push(d[e]),e++}return b};g.GPOS={};g.GPOS.parse=function(b,a,c,d){return g._lctf.parse(b,a,c,d,g.GPOS.subt)};g.GPOS.subt=function(b,a,c){var d=g._bin,e=c,f={};f.fmt=d.readUshort(b,c);c+=2;if(1==a||2==a||3==a||7==a||8==a&&2>=f.fmt){var h=d.readUshort(b,c);c+=2;f.coverage=g._lctf.readCoverage(b,h+e)}if(1==a&&1==f.fmt){var k=d.readUshort(b,c);c+=2;g._lctf.numOfOnes(k);
0!=k&&(f.pos=g.GPOS.readValueRecord(b,c,k))}else if(2==a){k=d.readUshort(b,c);c+=2;var l=d.readUshort(b,c);c+=2;a=g._lctf.numOfOnes(k);h=g._lctf.numOfOnes(l);if(1==f.fmt){f.pairsets=[];var q=d.readUshort(b,c);c+=2;for(var u=0;u<q;u++){var m=e+d.readUshort(b,c);c+=2;var p=d.readUshort(b,m);m+=2;for(var n=[],t=0;t<p;t++){var w=d.readUshort(b,m);m+=2;if(0!=k){var v=g.GPOS.readValueRecord(b,m,k);m+=2*a}if(0!=l){var y=g.GPOS.readValueRecord(b,m,l);m+=2*h}n.push({gid2:w,val1:v,val2:y})}f.pairsets.push(n)}}if(2==
f.fmt)for(v=d.readUshort(b,c),c+=2,y=d.readUshort(b,c),c+=2,k=d.readUshort(b,c),c+=2,d=d.readUshort(b,c),c+=2,f.classDef1=g._lctf.readClassDef(b,e+v),f.classDef2=g._lctf.readClassDef(b,e+y),f.matrix=[],u=0;u<k;u++){e=[];for(t=0;t<d;t++)y=v=null,0!=f.valFmt1&&(v=g.GPOS.readValueRecord(b,c,f.valFmt1),c+=2*a),0!=f.valFmt2&&(y=g.GPOS.readValueRecord(b,c,f.valFmt2),c+=2*h),e.push({val1:v,val2:y});f.matrix.push(e)}}return f};g.GPOS.readValueRecord=function(b,a,c){var d=g._bin,e=[];e.push(c&1?d.readShort(b,
0!=k&&(f.pos=g.GPOS.readValueRecord(b,c,k))}else if(2==a){k=d.readUshort(b,c);c+=2;var n=d.readUshort(b,c);c+=2;a=g._lctf.numOfOnes(k);h=g._lctf.numOfOnes(n);if(1==f.fmt){f.pairsets=[];var q=d.readUshort(b,c);c+=2;for(var u=0;u<q;u++){var l=e+d.readUshort(b,c);c+=2;var r=d.readUshort(b,l);l+=2;for(var p=[],t=0;t<r;t++){var y=d.readUshort(b,l);l+=2;if(0!=k){var m=g.GPOS.readValueRecord(b,l,k);l+=2*a}if(0!=n){var x=g.GPOS.readValueRecord(b,l,n);l+=2*h}p.push({gid2:y,val1:m,val2:x})}f.pairsets.push(p)}}if(2==
f.fmt)for(m=d.readUshort(b,c),c+=2,x=d.readUshort(b,c),c+=2,k=d.readUshort(b,c),c+=2,d=d.readUshort(b,c),c+=2,f.classDef1=g._lctf.readClassDef(b,e+m),f.classDef2=g._lctf.readClassDef(b,e+x),f.matrix=[],u=0;u<k;u++){e=[];for(t=0;t<d;t++)x=m=null,0!=f.valFmt1&&(m=g.GPOS.readValueRecord(b,c,f.valFmt1),c+=2*a),0!=f.valFmt2&&(x=g.GPOS.readValueRecord(b,c,f.valFmt2),c+=2*h),e.push({val1:m,val2:x});f.matrix.push(e)}}return f};g.GPOS.readValueRecord=function(b,a,c){var d=g._bin,e=[];e.push(c&1?d.readShort(b,
a):0);a+=c&1?2:0;e.push(c&2?d.readShort(b,a):0);a+=c&2?2:0;e.push(c&4?d.readShort(b,a):0);e.push(c&8?d.readShort(b,a+(c&4?2:0)):0);return e};g.GSUB={};g.GSUB.parse=function(b,a,c,d){return g._lctf.parse(b,a,c,d,g.GSUB.subt)};g.GSUB.subt=function(b,a,c){var d=g._bin,e=c,f={};f.fmt=d.readUshort(b,c);c+=2;if(1!=a&&4!=a&&5!=a&&6!=a)return null;if(1==a||4==a||5==a&&2>=f.fmt||6==a&&2>=f.fmt){var h=d.readUshort(b,c);c+=2;f.coverage=g._lctf.readCoverage(b,e+h)}if(1==a)1==f.fmt?f.delta=d.readShort(b,c):2==
f.fmt&&(h=d.readUshort(b,c),f.newg=d.readUshorts(b,c+2,h));else if(4==a)for(f.vals=[],h=d.readUshort(b,c),c+=2,a=0;a<h;a++){var k=d.readUshort(b,c);c+=2;f.vals.push(g.GSUB.readLigatureSet(b,e+k))}else if(5==a){if(2==f.fmt)for(a=d.readUshort(b,c),c+=2,f.cDef=g._lctf.readClassDef(b,e+a),f.scset=[],h=d.readUshort(b,c),c+=2,a=0;a<h;a++)k=d.readUshort(b,c),c+=2,f.scset.push(0==k?null:g.GSUB.readSubClassSet(b,e+k))}else if(6==a&&3==f.fmt){for(a=0;3>a;a++){h=d.readUshort(b,c);c+=2;k=[];for(var l=0;l<h;l++)k.push(g._lctf.readCoverage(b,
e+d.readUshort(b,c+2*l)));c+=2*h;0==a&&(f.backCvg=k);1==a&&(f.inptCvg=k);2==a&&(f.ahedCvg=k)}h=d.readUshort(b,c);f.lookupRec=g.GSUB.readSubstLookupRecords(b,c+2,h)}return f};g.GSUB.readSubClassSet=function(b,a){var c=g._bin.readUshort,d=a,e=[],f=c(b,a);a+=2;for(var h=0;h<f;h++){var k=c(b,a);a+=2;e.push(g.GSUB.readSubClassRule(b,d+k))}return e};g.GSUB.readSubClassRule=function(b,a){var c=g._bin.readUshort,d={},e=c(b,a);a+=2;var f=c(b,a);a+=2;d.input=[];for(var h=0;h<e-1;h++)d.input.push(c(b,a)),a+=
f.fmt&&(h=d.readUshort(b,c),f.newg=d.readUshorts(b,c+2,h));else if(4==a)for(f.vals=[],h=d.readUshort(b,c),c+=2,a=0;a<h;a++){var k=d.readUshort(b,c);c+=2;f.vals.push(g.GSUB.readLigatureSet(b,e+k))}else if(5==a){if(2==f.fmt)for(a=d.readUshort(b,c),c+=2,f.cDef=g._lctf.readClassDef(b,e+a),f.scset=[],h=d.readUshort(b,c),c+=2,a=0;a<h;a++)k=d.readUshort(b,c),c+=2,f.scset.push(0==k?null:g.GSUB.readSubClassSet(b,e+k))}else if(6==a&&3==f.fmt){for(a=0;3>a;a++){h=d.readUshort(b,c);c+=2;k=[];for(var n=0;n<h;n++)k.push(g._lctf.readCoverage(b,
e+d.readUshort(b,c+2*n)));c+=2*h;0==a&&(f.backCvg=k);1==a&&(f.inptCvg=k);2==a&&(f.ahedCvg=k)}h=d.readUshort(b,c);f.lookupRec=g.GSUB.readSubstLookupRecords(b,c+2,h)}return f};g.GSUB.readSubClassSet=function(b,a){var c=g._bin.readUshort,d=a,e=[],f=c(b,a);a+=2;for(var h=0;h<f;h++){var k=c(b,a);a+=2;e.push(g.GSUB.readSubClassRule(b,d+k))}return e};g.GSUB.readSubClassRule=function(b,a){var c=g._bin.readUshort,d={},e=c(b,a);a+=2;var f=c(b,a);a+=2;d.input=[];for(var h=0;h<e-1;h++)d.input.push(c(b,a)),a+=
2;d.substLookupRecords=g.GSUB.readSubstLookupRecords(b,a,f);return d};g.GSUB.readSubstLookupRecords=function(b,a,c){for(var d=g._bin.readUshort,e=[],f=0;f<c;f++)e.push(d(b,a),d(b,a+2)),a+=4;return e};g.GSUB.readChainSubClassSet=function(b,a){var c=g._bin,d=a,e=[],f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readUshort(b,a);a+=2;e.push(g.GSUB.readChainSubClassRule(b,d+k))}return e};g.GSUB.readChainSubClassRule=function(b,a){for(var c=g._bin,d={},e=["backtrack","input","lookahead"],f=0;f<e.length;f++){var h=

@@ -48,7 +49,7 @@ c.readUshort(b,a);a+=2;1==f&&h--;d[e[f]]=c.readUshorts(b,a,h);a+=2*d[e[f]].length}h=c.readUshort(b,a);d.subst=c.readUshorts(b,a+2,2*h);return d};g.GSUB.readLigatureSet=function(b,a){var c=g._bin,d=a,e=[],f=c.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=c.readUshort(b,a);a+=2;e.push(g.GSUB.readLigature(b,d+k))}return e};g.GSUB.readLigature=function(b,a){var c=g._bin,d={chain:[]};d.nglyph=c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;for(var f=0;f<e-1;f++)d.chain.push(c.readUshort(b,a)),a+=

a-2,c,d);c=e.readUshort(b,a);a+=2;d={glyph1:[],rval:[]};for(f=0;f<c;f++){a+=2;e.readUshort(b,a);a+=2;var h=e.readUshort(b,a);a+=2;h>>>=8;h&=15;if(0==h)a=g.kern.readFormat0(b,a,d);else throw"unknown kern table format: "+h;}return d};g.kern.parseV1=function(b,a,c,d){c=g._bin;c.readFixed(b,a);a+=4;d=c.readUint(b,a);a+=4;for(var e={glyph1:[],rval:[]},f=0;f<d;f++){c.readUint(b,a);a+=4;var h=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;h>>>=8;h&=15;if(0==h)a=g.kern.readFormat0(b,a,e);else throw"unknown kern table format: "+
h;}return e};g.kern.readFormat0=function(b,a,c){var d=g._bin,e=-1,f=d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=d.readUshort(b,a);a+=2;var l=d.readUshort(b,a);a+=2;var q=d.readShort(b,a);a+=2;k!=e&&(c.glyph1.push(k),c.rval.push({glyph2:[],vals:[]}));e=c.rval[c.rval.length-1];e.glyph2.push(l);e.vals.push(q);e=k}return a};g.loca={};g.loca.parse=function(b,a,c,d){c=g._bin;var e=[],f=d.head.indexToLocFormat;d=d.maxp.numGlyphs+
h;}return e};g.kern.readFormat0=function(b,a,c){var d=g._bin,e=-1,f=d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;d.readUshort(b,a);a+=2;for(var h=0;h<f;h++){var k=d.readUshort(b,a);a+=2;var n=d.readUshort(b,a);a+=2;var q=d.readShort(b,a);a+=2;k!=e&&(c.glyph1.push(k),c.rval.push({glyph2:[],vals:[]}));e=c.rval[c.rval.length-1];e.glyph2.push(n);e.vals.push(q);e=k}return a};g.loca={};g.loca.parse=function(b,a,c,d){c=g._bin;var e=[],f=d.head.indexToLocFormat;d=d.maxp.numGlyphs+
1;if(0==f)for(var h=0;h<d;h++)e.push(c.readUshort(b,a+(h<<1))<<1);if(1==f)for(h=0;h<d;h++)e.push(c.readUint(b,a+(h<<2)));return e};g.maxp={};g.maxp.parse=function(b,a,c){c=g._bin;var d={},e=c.readUint(b,a);a+=4;d.numGlyphs=c.readUshort(b,a);a+=2;65536==e&&(d.maxPoints=c.readUshort(b,a),a+=2,d.maxContours=c.readUshort(b,a),a+=2,d.maxCompositePoints=c.readUshort(b,a),a+=2,d.maxCompositeContours=c.readUshort(b,a),a+=2,d.maxZones=c.readUshort(b,a),a+=2,d.maxTwilightPoints=c.readUshort(b,a),a+=2,d.maxStorage=
c.readUshort(b,a),a+=2,d.maxFunctionDefs=c.readUshort(b,a),a+=2,d.maxInstructionDefs=c.readUshort(b,a),a+=2,d.maxStackElements=c.readUshort(b,a),a+=2,d.maxSizeOfInstructions=c.readUshort(b,a),a+=2,d.maxComponentElements=c.readUshort(b,a),d.maxComponentDepth=c.readUshort(b,a+2));return d};g.name={};g.name.parse=function(b,a,c){c=g._bin;var d={};c.readUshort(b,a);a+=2;var e=c.readUshort(b,a);a+=2;c.readUshort(b,a);a+=2;for(var f="copyright fontFamily fontSubfamily ID fullName version postScriptName trademark manufacturer designer description urlVendor urlDesigner licence licenceURL --- typoFamilyName typoSubfamilyName compatibleFull sampleText postScriptCID wwsFamilyName wwsSubfamilyName lightPalette darkPalette".split(" "),
h=a,k=0;k<e;k++){var l=c.readUshort(b,a);a+=2;var q=c.readUshort(b,a);a+=2;var u=c.readUshort(b,a);a+=2;var m=c.readUshort(b,a);a+=2;var p=c.readUshort(b,a);a+=2;var n=c.readUshort(b,a);a+=2;m=f[m];n=h+12*e+n;if(0==l)p=c.readUnicode(b,n,p/2);else if(3==l&&0==q)p=c.readUnicode(b,n,p/2);else if(0==q)p=c.readASCII(b,n,p);else if(1==q)p=c.readUnicode(b,n,p/2);else if(3==q)p=c.readUnicode(b,n,p/2);else if(1==l)p=c.readASCII(b,n,p),console.log("reading unknown MAC encoding "+q+" as ASCII");else throw"unknown encoding "+
q+", platformID: "+l;l="p"+l+","+u.toString(16);null==d[l]&&(d[l]={});d[l][m]=p;d[l]._lang=u}for(var t in d)if(null!=d[t].postScriptName&&1033==d[t]._lang)return d[t];for(t in d)if(null!=d[t].postScriptName&&0==d[t]._lang)return d[t];for(t in d)if(null!=d[t].postScriptName&&3084==d[t]._lang)return d[t];for(t in d)if(null!=d[t].postScriptName)return d[t];for(t in d){var w=t;break}console.log("returning name table with languageID "+d[w]._lang);return d[w]};g["OS/2"]={};g["OS/2"].parse=function(b,a,
h=a,k=0;k<e;k++){var n=c.readUshort(b,a);a+=2;var q=c.readUshort(b,a);a+=2;var u=c.readUshort(b,a);a+=2;var l=c.readUshort(b,a);a+=2;var r=c.readUshort(b,a);a+=2;var p=c.readUshort(b,a);a+=2;l=f[l];p=h+12*e+p;if(0==n)r=c.readUnicode(b,p,r/2);else if(3==n&&0==q)r=c.readUnicode(b,p,r/2);else if(0==q)r=c.readASCII(b,p,r);else if(1==q)r=c.readUnicode(b,p,r/2);else if(3==q)r=c.readUnicode(b,p,r/2);else if(1==n)r=c.readASCII(b,p,r),console.log("reading unknown MAC encoding "+q+" as ASCII");else throw"unknown encoding "+
q+", platformID: "+n;n="p"+n+","+u.toString(16);null==d[n]&&(d[n]={});d[n][l]=r;d[n]._lang=u}for(var t in d)if(null!=d[t].postScriptName&&1033==d[t]._lang)return d[t];for(t in d)if(null!=d[t].postScriptName&&0==d[t]._lang)return d[t];for(t in d)if(null!=d[t].postScriptName&&3084==d[t]._lang)return d[t];for(t in d)if(null!=d[t].postScriptName)return d[t];for(t in d){var y=t;break}console.log("returning name table with languageID "+d[y]._lang);return d[y]};g["OS/2"]={};g["OS/2"].parse=function(b,a,
c){c=g._bin.readUshort(b,a);a+=2;var d={};if(0==c)g["OS/2"].version0(b,a,d);else if(1==c)g["OS/2"].version1(b,a,d);else if(2==c||3==c||4==c)g["OS/2"].version2(b,a,d);else if(5==c)g["OS/2"].version5(b,a,d);else throw"unknown OS/2 table version: "+c;return d};g["OS/2"].version0=function(b,a,c){var d=g._bin;c.xAvgCharWidth=d.readShort(b,a);a+=2;c.usWeightClass=d.readUshort(b,a);a+=2;c.usWidthClass=d.readUshort(b,a);a+=2;c.fsType=d.readUshort(b,a);a+=2;c.ySubscriptXSize=d.readShort(b,a);a+=2;c.ySubscriptYSize=

@@ -58,62 +59,62 @@ d.readShort(b,a);a+=2;c.ySubscriptXOffset=d.readShort(b,a);a+=2;c.ySubscriptYOffset=d.readShort(b,a);a+=2;c.ySuperscriptXSize=d.readShort(b,a);a+=2;c.ySuperscriptYSize=d.readShort(b,a);a+=2;c.ySuperscriptXOffset=d.readShort(b,a);a+=2;c.ySuperscriptYOffset=d.readShort(b,a);a+=2;c.yStrikeoutSize=d.readShort(b,a);a+=2;c.yStrikeoutPosition=d.readShort(b,a);a+=2;c.sFamilyClass=d.readShort(b,a);a+=2;c.panose=d.readBytes(b,a,10);a+=10;c.ulUnicodeRange1=d.readUint(b,a);a+=4;c.ulUnicodeRange2=d.readUint(b,

function(b,a,c){var d=g._bin;a=g["OS/2"].version0(b,a,c);c.ulCodePageRange1=d.readUint(b,a);a+=4;c.ulCodePageRange2=d.readUint(b,a);return a+4};g["OS/2"].version2=function(b,a,c){var d=g._bin;a=g["OS/2"].version1(b,a,c);c.sxHeight=d.readShort(b,a);a+=2;c.sCapHeight=d.readShort(b,a);a+=2;c.usDefault=d.readUshort(b,a);a+=2;c.usBreak=d.readUshort(b,a);a+=2;c.usMaxContext=d.readUshort(b,a);return a+2};g["OS/2"].version5=function(b,a,c){var d=g._bin;a=g["OS/2"].version2(b,a,c);c.usLowerOpticalPointSize=
d.readUshort(b,a);a+=2;c.usUpperOpticalPointSize=d.readUshort(b,a);return a+2};g.post={};g.post.parse=function(b,a,c){c=g._bin;var d={};d.version=c.readFixed(b,a);a+=4;d.italicAngle=c.readFixed(b,a);a+=4;d.underlinePosition=c.readShort(b,a);d.underlineThickness=c.readShort(b,a+2);return d};g.SVG={};g.SVG.parse=function(b,a,c){c=g._bin;var d={entries:[]},e=a;c.readUshort(b,a);a+=2;var f=c.readUint(b,a);c.readUint(b,a+4);a=f+e;var h=c.readUshort(b,a);a+=2;for(var k=0;k<h;k++){var l=c.readUshort(b,a);
a+=2;var q=c.readUshort(b,a);a+=2;var u=c.readUint(b,a);a+=4;var m=c.readUint(b,a);a+=4;u=new Uint8Array(b.buffer,e+u+f,m);for(u=c.readUTF8(u,0,u.length);l<=q;l++)d.entries[l]=u}return d};g.SVG.toPath=function(b){var a={cmds:[],crds:[]};if(null==b)return a;for(var c=(new DOMParser).parseFromString(b,"image/svg+xml").firstChild;"svg"!=c.tagName;)c=c.nextSibling;b=(b=c.getAttribute("viewBox"))?b.trim().split(" ").map(parseFloat):[0,0,1E3,1E3];g.SVG._toPath(c.children,a);for(c=0;c<a.crds.length;c+=2){var d=
d.readUshort(b,a);a+=2;c.usUpperOpticalPointSize=d.readUshort(b,a);return a+2};g.post={};g.post.parse=function(b,a,c){c=g._bin;var d={};d.version=c.readFixed(b,a);a+=4;d.italicAngle=c.readFixed(b,a);a+=4;d.underlinePosition=c.readShort(b,a);d.underlineThickness=c.readShort(b,a+2);return d};g.SVG={};g.SVG.parse=function(b,a,c){c=g._bin;var d={entries:[]},e=a;c.readUshort(b,a);a+=2;var f=c.readUint(b,a);c.readUint(b,a+4);a=f+e;var h=c.readUshort(b,a);a+=2;for(var k=0;k<h;k++){var n=c.readUshort(b,a);
a+=2;var q=c.readUshort(b,a);a+=2;var u=c.readUint(b,a);a+=4;var l=c.readUint(b,a);a+=4;u=new Uint8Array(b.buffer,e+u+f,l);for(u=c.readUTF8(u,0,u.length);n<=q;n++)d.entries[n]=u}return d};g.SVG.toPath=function(b){var a={cmds:[],crds:[]};if(null==b)return a;for(var c=(new DOMParser).parseFromString(b,"image/svg+xml").firstChild;"svg"!=c.tagName;)c=c.nextSibling;b=(b=c.getAttribute("viewBox"))?b.trim().split(" ").map(parseFloat):[0,0,1E3,1E3];g.SVG._toPath(c.children,a);for(c=0;c<a.crds.length;c+=2){var d=
a.crds[c],e=a.crds[c+1];d-=b[0];e-=b[1];e=-e;a.crds[c]=d;a.crds[c+1]=e}return a};g.SVG._toPath=function(b,a,c){for(var d=0;d<b.length;d++){var e=b[d],f=e.tagName,h=e.getAttribute("fill");null==h&&(h=c);"g"==f?g.SVG._toPath(e.children,a,h):"path"==f?(a.cmds.push(h?h:"#000000"),e=e.getAttribute("d"),e=g.SVG._tokens(e),g.SVG._toksToPath(e,a),a.cmds.push("X")):"defs"!=f&&console.log(f,e)}};g.SVG._tokens=function(b){for(var a=[],c=0,d=!1,e="";c<b.length;){var f=b.charCodeAt(c),g=b.charAt(c);c++;f=48<=
f&&57>=f||"."==g||"-"==g;d?"-"==g?(a.push(parseFloat(e)),e=g):f?e+=g:(a.push(parseFloat(e)),","!=g&&" "!=g&&a.push(g),d=!1):f?(e=g,d=!0):","!=g&&" "!=g&&a.push(g)}d&&a.push(parseFloat(e));return a};g.SVG._toksToPath=function(b,a){var c=0,d=0,e=0,f=0,h=0,k={M:2,L:2,H:1,V:1,S:4,C:6},l=a.cmds;for(a=a.crds;c<b.length;){var q=b[c];c++;if("z"==q)l.push("Z"),d=f,e=h;else for(var u=q.toUpperCase(),m=g.SVG._reps(b,c,k[u]),p=0;p<m;p++){var n=0,t=0;q!=u&&(n=d,t=e);if("M"==u)d=n+b[c++],e=t+b[c++],l.push("M"),
a.push(d,e),f=d,h=e;else if("L"==u)d=n+b[c++],e=t+b[c++],l.push("L"),a.push(d,e);else if("H"==u)d=n+b[c++],l.push("L"),a.push(d,e);else if("V"==u)e=t+b[c++],l.push("L"),a.push(d,e);else if("C"==u){d=n+b[c++];e=t+b[c++];var w=n+b[c++],v=t+b[c++];n+=b[c++];t+=b[c++];l.push("C");a.push(d,e,w,v,n,t);d=n;e=t}else"S"==u?(w=Math.max(a.length-4,0),d=d+d-a[w],e=e+e-a[w+1],w=n+b[c++],v=t+b[c++],n+=b[c++],t+=b[c++],l.push("C"),a.push(d,e,w,v,n,t),d=n,e=t):console.log("Unknown SVG command "+q)}}};g.SVG._reps=
f&&57>=f||"."==g||"-"==g;d?"-"==g?(a.push(parseFloat(e)),e=g):f?e+=g:(a.push(parseFloat(e)),","!=g&&" "!=g&&a.push(g),d=!1):f?(e=g,d=!0):","!=g&&" "!=g&&a.push(g)}d&&a.push(parseFloat(e));return a};g.SVG._toksToPath=function(b,a){var c=0,d=0,e=0,f=0,h=0,k={M:2,L:2,H:1,V:1,S:4,C:6},n=a.cmds;for(a=a.crds;c<b.length;){var q=b[c];c++;if("z"==q)n.push("Z"),d=f,e=h;else for(var u=q.toUpperCase(),l=g.SVG._reps(b,c,k[u]),r=0;r<l;r++){var p=0,t=0;q!=u&&(p=d,t=e);if("M"==u)d=p+b[c++],e=t+b[c++],n.push("M"),
a.push(d,e),f=d,h=e;else if("L"==u)d=p+b[c++],e=t+b[c++],n.push("L"),a.push(d,e);else if("H"==u)d=p+b[c++],n.push("L"),a.push(d,e);else if("V"==u)e=t+b[c++],n.push("L"),a.push(d,e);else if("C"==u){d=p+b[c++];e=t+b[c++];var y=p+b[c++],m=t+b[c++];p+=b[c++];t+=b[c++];n.push("C");a.push(d,e,y,m,p,t);d=p;e=t}else"S"==u?(y=Math.max(a.length-4,0),d=d+d-a[y],e=e+e-a[y+1],y=p+b[c++],m=t+b[c++],p+=b[c++],t+=b[c++],n.push("C"),a.push(d,e,y,m,p,t),d=p,e=t):console.log("Unknown SVG command "+q)}}};g.SVG._reps=
function(b,a,c){for(var d=a;d<b.length&&"string"!=typeof b[d];)d+=c;return(d-a)/c};null==g&&(g={});null==g.U&&(g.U={});g.U.codeToGlyph=function(b,a){b=b.cmap;var c=-1;null!=b.p0e4?c=b.p0e4:null!=b.p3e1?c=b.p3e1:null!=b.p1e0?c=b.p1e0:null!=b.p0e3&&(c=b.p0e3);if(-1==c)throw"no familiar platform and encoding!";b=b.tables[c];if(0==b.format)return a>=b.map.length?0:b.map[a];if(4==b.format){var d=-1;for(c=0;c<b.endCount.length;c++)if(a<=b.endCount[c]){d=c;break}return-1==d||b.startCount[d]>a?0:(0!=b.idRangeOffset[d]?
b.glyphIdArray[a-b.startCount[d]+(b.idRangeOffset[d]>>1)-(b.idRangeOffset.length-d)]:a+b.idDelta[d])&65535}if(12==b.format){if(a>b.groups[b.groups.length-1][1])return 0;for(c=0;c<b.groups.length;c++)if(d=b.groups[c],d[0]<=a&&a<=d[1])return d[2]+(a-d[0]);return 0}throw"unknown cmap table format "+b.format;};g.U.glyphToPath=function(b,a){var c={cmds:[],crds:[]};if(b.SVG&&b.SVG.entries[a]){var d=b.SVG.entries[a];if(null==d)return c;"string"==typeof d&&(d=g.SVG.toPath(d),b.SVG.entries[a]=d);return d}if(b.CFF){d=
{x:0,y:0,stack:[],nStems:0,haveWidth:!1,width:b.CFF.Private?b.CFF.Private.defaultWidthX:0,open:!1};var e=b.CFF,f=b.CFF.Private;if(e.ROS){for(f=0;e.FDSelect[f+2]<=a;)f+=2;f=e.FDArray[e.FDSelect[f+1]].Private}g.U._drawCFF(b.CFF.CharStrings[a],d,e,f,c)}else b.glyf&&g.U._drawGlyf(a,b,c);return c};g.U._drawGlyf=function(b,a,c){var d=a.glyf[b];null==d&&(d=a.glyf[b]=g.glyf._parseGlyf(a,b));null!=d&&(-1<d.noc?g.U._simpleGlyph(d,c):g.U._compoGlyph(d,a,c))};g.U._simpleGlyph=function(b,a){for(var c=0;c<b.noc;c++){for(var d=
0==c?0:b.endPts[c-1]+1,e=b.endPts[c],f=d;f<=e;f++){var h=f==d?e:f-1,k=f==e?d:f+1,l=b.flags[f]&1,q=b.flags[h]&1,u=b.flags[k]&1,m=b.xs[f],p=b.ys[f];if(f==d)if(l)if(q)g.U.P.moveTo(a,b.xs[h],b.ys[h]);else{g.U.P.moveTo(a,m,p);continue}else q?g.U.P.moveTo(a,b.xs[h],b.ys[h]):g.U.P.moveTo(a,(b.xs[h]+m)/2,(b.ys[h]+p)/2);l?q&&g.U.P.lineTo(a,m,p):u?g.U.P.qcurveTo(a,m,p,b.xs[k],b.ys[k]):g.U.P.qcurveTo(a,m,p,(m+b.xs[k])/2,(p+b.ys[k])/2)}g.U.P.closePath(a)}};g.U._compoGlyph=function(b,a,c){for(var d=0;d<b.parts.length;d++){var e=
{cmds:[],crds:[]},f=b.parts[d];g.U._drawGlyf(f.glyphIndex,a,e);f=f.m;for(var h=0;h<e.crds.length;h+=2){var k=e.crds[h],l=e.crds[h+1];c.crds.push(k*f.a+l*f.b+f.tx);c.crds.push(k*f.c+l*f.d+f.ty)}for(h=0;h<e.cmds.length;h++)c.cmds.push(e.cmds[h])}};g.U._getGlyphClass=function(b,a){b=g._lctf.getInterval(a,b);return-1==b?0:a[b+2]};g.U.getPairAdjustment=function(b,a,c){if(b.GPOS){var d=b.GPOS,e=d.lookupList;d=d.featureList;for(var f=[],h=0;h<d.length;h++){var k=d[h];if("kern"==k.tag)for(var l=0;l<k.tab.length;l++)if(!f[k.tab[l]]){f[k.tab[l]]=
!0;for(var q=e[k.tab[l]],u=0;u<q.tabs.length;u++)if(null!=q.tabs[h]){var m=q.tabs[u];if(m.coverage){var p=g._lctf.coverageIndex(m.coverage,a);if(-1==p)continue}if(1!=q.ltype&&2==q.ltype){var n;if(1==m.fmt)for(m=m.pairsets[p],h=0;h<m.length;h++)m[h].gid2==c&&(n=m[h]);else if(2==m.fmt){n=g.U._getGlyphClass(a,m.classDef1);var t=g.U._getGlyphClass(c,m.classDef2);n=m.matrix[n][t]}if(n&&n.val2)return n.val2[2]}}}}}return b.kern&&(a=b.kern.glyph1.indexOf(a),-1!=a&&(c=b.kern.rval[a].glyph2.indexOf(c),-1!=
c))?b.kern.rval[a].vals[c]:0};g.U.stringToGlyphs=function(b,a){for(var c=[],d=0;d<a.length;d++){var e=a.codePointAt(d);65535<e&&d++;c.push(g.U.codeToGlyph(b,e))}for(d=0;d<a.length;d++){e=a.codePointAt(d);if(2367==e){var f=c[d-1];c[d-1]=c[d];c[d]=f}65535<e&&d++}d=b.GSUB;if(null==d)return c;b=d.lookupList;d=d.featureList;e="rlig liga mset isol init fina medi half pres blws".split(" ");f=[];for(var h=0;h<d.length;h++){var k=d[h];if(-1!=e.indexOf(k.tag))for(var l=0;l<k.tab.length;l++)if(!f[k.tab[l]]){f[k.tab[l]]=
!0;for(var q=b[k.tab[l]],u=0;u<c.length;u++){var m=g.U._getWPfeature(a,u);-1!="isol,init,fina,medi".indexOf(k.tag)&&k.tag!=m||g.U._applySubs(c,u,q,b)}}}return c};g.U._getWPfeature=function(b,a){var c=0==a||-1!='\n\t" ,.:;!?() \u060c'.indexOf(b[a-1]),d=a==b.length-1||-1!='\n\t" ,.:;!?() \u060c'.indexOf(b[a+1]);c||-1=="\u0622\u0623\u0624\u0625\u0627\u0629\u062f\u0630\u0631\u0632\u0648\u0671\u0672\u0673\u0675\u0676\u0677\u0688\u0689\u068a\u068b\u068c\u068d\u068e\u068f\u0690\u0691\u0692\u0693\u0694\u0695\u0696\u0697\u0698\u0699\u06c0\u06c3\u06c4\u06c5\u06c6\u06c7\u06c8\u06c9\u06ca\u06cb\u06cd\u06cf\u06d2\u06d3\u06d5\u06ee\u06ef\u0710\u0715\u0716\u0717\u0718\u0719\u071e\u0728\u072a\u072c\u072f\u074d\u0759\u075a\u075b\u076b\u076c\u0771\u0773\u0774\u0778\u0779\u0840\u0846\u0847\u0849\u0854\u0867\u0869\u086a\u08aa\u08ab\u08ac\u08ae\u08b1\u08b2\u08b9\u0ac5\u0ac7\u0ac9\u0aca\u0ace\u0acf\u0ad0\u0ad1\u0ad2\u0add\u0ae1\u0ae4\u0aef\u0b81\u0b83\u0b84\u0b85\u0b89\u0b8c\u0b8e\u0b8f\u0b91\u0ba9\u0baa\u0bab\u0bac".indexOf(b[a-
0==c?0:b.endPts[c-1]+1,e=b.endPts[c],f=d;f<=e;f++){var h=f==d?e:f-1,k=f==e?d:f+1,n=b.flags[f]&1,q=b.flags[h]&1,u=b.flags[k]&1,l=b.xs[f],r=b.ys[f];if(f==d)if(n)if(q)g.U.P.moveTo(a,b.xs[h],b.ys[h]);else{g.U.P.moveTo(a,l,r);continue}else q?g.U.P.moveTo(a,b.xs[h],b.ys[h]):g.U.P.moveTo(a,(b.xs[h]+l)/2,(b.ys[h]+r)/2);n?q&&g.U.P.lineTo(a,l,r):u?g.U.P.qcurveTo(a,l,r,b.xs[k],b.ys[k]):g.U.P.qcurveTo(a,l,r,(l+b.xs[k])/2,(r+b.ys[k])/2)}g.U.P.closePath(a)}};g.U._compoGlyph=function(b,a,c){for(var d=0;d<b.parts.length;d++){var e=
{cmds:[],crds:[]},f=b.parts[d];g.U._drawGlyf(f.glyphIndex,a,e);f=f.m;for(var h=0;h<e.crds.length;h+=2){var k=e.crds[h],n=e.crds[h+1];c.crds.push(k*f.a+n*f.b+f.tx);c.crds.push(k*f.c+n*f.d+f.ty)}for(h=0;h<e.cmds.length;h++)c.cmds.push(e.cmds[h])}};g.U._getGlyphClass=function(b,a){b=g._lctf.getInterval(a,b);return-1==b?0:a[b+2]};g.U.getPairAdjustment=function(b,a,c){if(b.GPOS){var d=b.GPOS,e=d.lookupList;d=d.featureList;for(var f=[],h=0;h<d.length;h++){var k=d[h];if("kern"==k.tag)for(var n=0;n<k.tab.length;n++)if(!f[k.tab[n]]){f[k.tab[n]]=
!0;for(var q=e[k.tab[n]],u=0;u<q.tabs.length;u++)if(null!=q.tabs[h]){var l=q.tabs[u];if(l.coverage){var r=g._lctf.coverageIndex(l.coverage,a);if(-1==r)continue}if(1!=q.ltype&&2==q.ltype){var p;if(1==l.fmt)for(l=l.pairsets[r],h=0;h<l.length;h++)l[h].gid2==c&&(p=l[h]);else if(2==l.fmt){p=g.U._getGlyphClass(a,l.classDef1);var t=g.U._getGlyphClass(c,l.classDef2);p=l.matrix[p][t]}if(p&&p.val2)return p.val2[2]}}}}}return b.kern&&(a=b.kern.glyph1.indexOf(a),-1!=a&&(c=b.kern.rval[a].glyph2.indexOf(c),-1!=
c))?b.kern.rval[a].vals[c]:0};g.U.stringToGlyphs=function(b,a){for(var c=[],d=0;d<a.length;d++){var e=a.codePointAt(d);65535<e&&d++;c.push(g.U.codeToGlyph(b,e))}for(d=0;d<a.length;d++){e=a.codePointAt(d);if(2367==e){var f=c[d-1];c[d-1]=c[d];c[d]=f}65535<e&&d++}d=b.GSUB;if(null==d)return c;b=d.lookupList;d=d.featureList;e="rlig liga mset isol init fina medi half pres blws".split(" ");f=[];for(var h=0;h<d.length;h++){var k=d[h];if(-1!=e.indexOf(k.tag))for(var n=0;n<k.tab.length;n++)if(!f[k.tab[n]]){f[k.tab[n]]=
!0;for(var q=b[k.tab[n]],u=0;u<c.length;u++){var l=g.U._getWPfeature(a,u);-1!="isol,init,fina,medi".indexOf(k.tag)&&k.tag!=l||g.U._applySubs(c,u,q,b)}}}return c};g.U._getWPfeature=function(b,a){var c=0==a||-1!='\n\t" ,.:;!?() \u060c'.indexOf(b[a-1]),d=a==b.length-1||-1!='\n\t" ,.:;!?() \u060c'.indexOf(b[a+1]);c||-1=="\u0622\u0623\u0624\u0625\u0627\u0629\u062f\u0630\u0631\u0632\u0648\u0671\u0672\u0673\u0675\u0676\u0677\u0688\u0689\u068a\u068b\u068c\u068d\u068e\u068f\u0690\u0691\u0692\u0693\u0694\u0695\u0696\u0697\u0698\u0699\u06c0\u06c3\u06c4\u06c5\u06c6\u06c7\u06c8\u06c9\u06ca\u06cb\u06cd\u06cf\u06d2\u06d3\u06d5\u06ee\u06ef\u0710\u0715\u0716\u0717\u0718\u0719\u071e\u0728\u072a\u072c\u072f\u074d\u0759\u075a\u075b\u076b\u076c\u0771\u0773\u0774\u0778\u0779\u0840\u0846\u0847\u0849\u0854\u0867\u0869\u086a\u08aa\u08ab\u08ac\u08ae\u08b1\u08b2\u08b9\u0ac5\u0ac7\u0ac9\u0aca\u0ace\u0acf\u0ad0\u0ad1\u0ad2\u0add\u0ae1\u0ae4\u0aef\u0b81\u0b83\u0b84\u0b85\u0b89\u0b8c\u0b8e\u0b8f\u0b91\u0ba9\u0baa\u0bab\u0bac".indexOf(b[a-
1])||(c=!0);d||-1=="\u0622\u0623\u0624\u0625\u0627\u0629\u062f\u0630\u0631\u0632\u0648\u0671\u0672\u0673\u0675\u0676\u0677\u0688\u0689\u068a\u068b\u068c\u068d\u068e\u068f\u0690\u0691\u0692\u0693\u0694\u0695\u0696\u0697\u0698\u0699\u06c0\u06c3\u06c4\u06c5\u06c6\u06c7\u06c8\u06c9\u06ca\u06cb\u06cd\u06cf\u06d2\u06d3\u06d5\u06ee\u06ef\u0710\u0715\u0716\u0717\u0718\u0719\u071e\u0728\u072a\u072c\u072f\u074d\u0759\u075a\u075b\u076b\u076c\u0771\u0773\u0774\u0778\u0779\u0840\u0846\u0847\u0849\u0854\u0867\u0869\u086a\u08aa\u08ab\u08ac\u08ae\u08b1\u08b2\u08b9\u0ac5\u0ac7\u0ac9\u0aca\u0ace\u0acf\u0ad0\u0ad1\u0ad2\u0add\u0ae1\u0ae4\u0aef\u0b81\u0b83\u0b84\u0b85\u0b89\u0b8c\u0b8e\u0b8f\u0b91\u0ba9\u0baa\u0bab\u0bac".indexOf(b[a])||
(d=!0);d||-1=="\ua872\u0acd\u0ad7".indexOf(b[a+1])||(d=!0);c||-1=="\ua872\u0acd\u0ad7".indexOf(b[a])||(c=!0);return c?d?"isol":"init":d?"fina":"medi"};g.U._applySubs=function(b,a,c,d){for(var e=b.length-a-1,f=0;f<c.tabs.length;f++)if(null!=c.tabs[f]){var h=c.tabs[f];if(h.coverage){var k=g._lctf.coverageIndex(h.coverage,b[a]);if(-1==k)continue}if(1==c.ltype)b[a]=1==h.fmt?b[a]+h.delta:h.newg[k];else if(4==c.ltype)for(var l=h.vals[k],q=0;q<l.length;q++){var u=l[q];h=u.chain.length;if(!(h>e)){for(var m=
!0,p=0,n=0;n<h;n++){for(;-1==b[a+p+(1+n)];)p++;u.chain[n]!=b[a+p+(1+n)]&&(m=!1)}if(m){b[a]=u.nglyph;for(n=0;n<h+p;n++)b[a+n+1]=-1;break}}}else if(5==c.ltype&&2==h.fmt)for(l=g._lctf.getInterval(h.cDef,b[a]),p=h.scset[h.cDef[l+2]],u=0;u<p.length;u++){q=p[u];var t=q.input;if(!(t.length>e)){m=!0;for(n=0;n<t.length;n++){var w=g._lctf.getInterval(h.cDef,b[a+1+n]);if(-1==l&&h.cDef[w+2]!=t[n]){m=!1;break}}if(m)for(m=q.substLookupRecords,q=0;q<m.length;q+=2);}}else if(6==c.ltype&&3==h.fmt&&g.U._glsCovered(b,
h.backCvg,a-h.backCvg.length)&&g.U._glsCovered(b,h.inptCvg,a)&&g.U._glsCovered(b,h.ahedCvg,a+h.inptCvg.length))for(m=h.lookupRec,u=0;u<m.length;u+=2)l=m[u],g.U._applySubs(b,a+l,d[m[u+1]],d)}};g.U._glsCovered=function(b,a,c){for(var d=0;d<a.length;d++)if(-1==g._lctf.coverageIndex(a[d],b[c+d]))return!1;return!0};g.U.glyphsToPath=function(b,a,c){for(var d={cmds:[],crds:[]},e=0,f=0;f<a.length;f++){var h=a[f];if(-1!=h){for(var k=f<a.length-1&&-1!=a[f+1]?a[f+1]:0,l=g.U.glyphToPath(b,h),q=0;q<l.crds.length;q+=
2)d.crds.push(l.crds[q]+e),d.crds.push(l.crds[q+1]);c&&d.cmds.push(c);for(q=0;q<l.cmds.length;q++)d.cmds.push(l.cmds[q]);c&&d.cmds.push("X");e+=b.hmtx.aWidth[h];f<a.length-1&&(e+=g.U.getPairAdjustment(b,h,k))}}return d};g.U.pathToSVG=function(b,a){null==a&&(a=5);for(var c=[],d=0,e={M:2,L:2,Q:4,C:6},f=0;f<b.cmds.length;f++){var g=b.cmds[f],k=d+(e[g]?e[g]:0);for(c.push(g);d<k;)g=b.crds[d++],c.push(parseFloat(g.toFixed(a))+(d==k?"":" "))}return c.join("")};g.U.pathToContext=function(b,a){for(var c=0,
(d=!0);d||-1=="\ua872\u0acd\u0ad7".indexOf(b[a+1])||(d=!0);c||-1=="\ua872\u0acd\u0ad7".indexOf(b[a])||(c=!0);return c?d?"isol":"init":d?"fina":"medi"};g.U._applySubs=function(b,a,c,d){for(var e=b.length-a-1,f=0;f<c.tabs.length;f++)if(null!=c.tabs[f]){var h=c.tabs[f];if(h.coverage){var k=g._lctf.coverageIndex(h.coverage,b[a]);if(-1==k)continue}if(1==c.ltype)b[a]=1==h.fmt?b[a]+h.delta:h.newg[k];else if(4==c.ltype)for(var n=h.vals[k],q=0;q<n.length;q++){var u=n[q];h=u.chain.length;if(!(h>e)){for(var l=
!0,r=0,p=0;p<h;p++){for(;-1==b[a+r+(1+p)];)r++;u.chain[p]!=b[a+r+(1+p)]&&(l=!1)}if(l){b[a]=u.nglyph;for(p=0;p<h+r;p++)b[a+p+1]=-1;break}}}else if(5==c.ltype&&2==h.fmt)for(n=g._lctf.getInterval(h.cDef,b[a]),r=h.scset[h.cDef[n+2]],u=0;u<r.length;u++){q=r[u];var t=q.input;if(!(t.length>e)){l=!0;for(p=0;p<t.length;p++){var m=g._lctf.getInterval(h.cDef,b[a+1+p]);if(-1==n&&h.cDef[m+2]!=t[p]){l=!1;break}}if(l)for(l=q.substLookupRecords,q=0;q<l.length;q+=2);}}else if(6==c.ltype&&3==h.fmt&&g.U._glsCovered(b,
h.backCvg,a-h.backCvg.length)&&g.U._glsCovered(b,h.inptCvg,a)&&g.U._glsCovered(b,h.ahedCvg,a+h.inptCvg.length))for(l=h.lookupRec,u=0;u<l.length;u+=2)n=l[u],g.U._applySubs(b,a+n,d[l[u+1]],d)}};g.U._glsCovered=function(b,a,c){for(var d=0;d<a.length;d++)if(-1==g._lctf.coverageIndex(a[d],b[c+d]))return!1;return!0};g.U.glyphsToPath=function(b,a,c){for(var d={cmds:[],crds:[]},e=0,f=0;f<a.length;f++){var h=a[f];if(-1!=h){for(var k=f<a.length-1&&-1!=a[f+1]?a[f+1]:0,n=g.U.glyphToPath(b,h),q=0;q<n.crds.length;q+=
2)d.crds.push(n.crds[q]+e),d.crds.push(n.crds[q+1]);c&&d.cmds.push(c);for(q=0;q<n.cmds.length;q++)d.cmds.push(n.cmds[q]);c&&d.cmds.push("X");e+=b.hmtx.aWidth[h];f<a.length-1&&(e+=g.U.getPairAdjustment(b,h,k))}}return d};g.U.pathToSVG=function(b,a){null==a&&(a=5);for(var c=[],d=0,e={M:2,L:2,Q:4,C:6},f=0;f<b.cmds.length;f++){var g=b.cmds[f],k=d+(e[g]?e[g]:0);for(c.push(g);d<k;)g=b.crds[d++],c.push(parseFloat(g.toFixed(a))+(d==k?"":" "))}return c.join("")};g.U.pathToContext=function(b,a){for(var c=0,
d=b.crds,e=0;e<b.cmds.length;e++){var f=b.cmds[e];"M"==f?(a.moveTo(d[c],d[c+1]),c+=2):"L"==f?(a.lineTo(d[c],d[c+1]),c+=2):"C"==f?(a.bezierCurveTo(d[c],d[c+1],d[c+2],d[c+3],d[c+4],d[c+5]),c+=6):"Q"==f?(a.quadraticCurveTo(d[c],d[c+1],d[c+2],d[c+3]),c+=4):"#"==f.charAt(0)?(a.beginPath(),a.fillStyle=f):"Z"==f?a.closePath():"X"==f&&a.fill()}};g.U.P={};g.U.P.moveTo=function(b,a,c){b.cmds.push("M");b.crds.push(a,c)};g.U.P.lineTo=function(b,a,c){b.cmds.push("L");b.crds.push(a,c)};g.U.P.curveTo=function(b,
a,c,d,e,f,g){b.cmds.push("C");b.crds.push(a,c,d,e,f,g)};g.U.P.qcurveTo=function(b,a,c,d,e){b.cmds.push("Q");b.crds.push(a,c,d,e)};g.U.P.closePath=function(b){b.cmds.push("Z")};g.U._drawCFF=function(b,a,c,d,e){for(var f=a.stack,h=a.nStems,k=a.haveWidth,l=a.width,q=a.open,u=0,m=a.x,p=a.y,n,t,w,v,y,A,B,D,E,r,z={val:0,size:0};u<b.length;){g.CFF.getCharString(b,u,z);var x=z.val;u+=z.size;if("o1"==x||"o18"==x)(n=0!==f.length%2)&&!k&&(l=f.shift()+d.nominalWidthX),h+=f.length>>1,f.length=0,k=!0;else if("o3"==
x||"o23"==x)(n=0!==f.length%2)&&!k&&(l=f.shift()+d.nominalWidthX),h+=f.length>>1,f.length=0,k=!0;else if("o4"==x)1<f.length&&!k&&(l=f.shift()+d.nominalWidthX,k=!0),q&&g.U.P.closePath(e),p+=f.pop(),g.U.P.moveTo(e,m,p),q=!0;else if("o5"==x)for(;0<f.length;)m+=f.shift(),p+=f.shift(),g.U.P.lineTo(e,m,p);else if("o6"==x||"o7"==x)for(y=f.length,n="o6"==x,t=0;t<y;t++)w=f.shift(),n?m+=w:p+=w,n=!n,g.U.P.lineTo(e,m,p);else if("o8"==x||"o24"==x){y=f.length;for(A=0;A+6<=y;)n=m+f.shift(),t=p+f.shift(),w=n+f.shift(),
v=t+f.shift(),m=w+f.shift(),p=v+f.shift(),g.U.P.curveTo(e,n,t,w,v,m,p),A+=6;"o24"==x&&(m+=f.shift(),p+=f.shift(),g.U.P.lineTo(e,m,p))}else if("o11"==x)break;else if("o1234"==x||"o1235"==x||"o1236"==x||"o1237"==x)"o1234"==x&&(n=m+f.shift(),t=p,w=n+f.shift(),v=t+f.shift(),E=w+f.shift(),r=v,y=E+f.shift(),A=v,B=y+f.shift(),D=p,m=B+f.shift(),g.U.P.curveTo(e,n,t,w,v,E,r),g.U.P.curveTo(e,y,A,B,D,m,p)),"o1235"==x&&(n=m+f.shift(),t=p+f.shift(),w=n+f.shift(),v=t+f.shift(),E=w+f.shift(),r=v+f.shift(),y=E+f.shift(),
A=r+f.shift(),B=y+f.shift(),D=A+f.shift(),m=B+f.shift(),p=D+f.shift(),f.shift(),g.U.P.curveTo(e,n,t,w,v,E,r),g.U.P.curveTo(e,y,A,B,D,m,p)),"o1236"==x&&(n=m+f.shift(),t=p+f.shift(),w=n+f.shift(),v=t+f.shift(),E=w+f.shift(),r=v,y=E+f.shift(),A=v,B=y+f.shift(),D=A+f.shift(),m=B+f.shift(),g.U.P.curveTo(e,n,t,w,v,E,r),g.U.P.curveTo(e,y,A,B,D,m,p)),"o1237"==x&&(n=m+f.shift(),t=p+f.shift(),w=n+f.shift(),v=t+f.shift(),E=w+f.shift(),r=v+f.shift(),y=E+f.shift(),A=r+f.shift(),B=y+f.shift(),D=A+f.shift(),Math.abs(B-
m)>Math.abs(D-p)?m=B+f.shift():p=D+f.shift(),g.U.P.curveTo(e,n,t,w,v,E,r),g.U.P.curveTo(e,y,A,B,D,m,p));else if("o14"==x)0<f.length&&!k&&(l=f.shift()+c.nominalWidthX,k=!0),4==f.length&&(n=f.shift(),t=f.shift(),v=f.shift(),w=f.shift(),v=g.CFF.glyphBySE(c,v),w=g.CFF.glyphBySE(c,w),g.U._drawCFF(c.CharStrings[v],a,c,d,e),a.x=n,a.y=t,g.U._drawCFF(c.CharStrings[w],a,c,d,e)),q&&(g.U.P.closePath(e),q=!1);else if("o19"==x||"o20"==x)(n=0!==f.length%2)&&!k&&(l=f.shift()+d.nominalWidthX),h+=f.length>>1,f.length=
0,k=!0,u+=h+7>>3;else if("o21"==x)2<f.length&&!k&&(l=f.shift()+d.nominalWidthX,k=!0),p+=f.pop(),m+=f.pop(),q&&g.U.P.closePath(e),g.U.P.moveTo(e,m,p),q=!0;else if("o22"==x)1<f.length&&!k&&(l=f.shift()+d.nominalWidthX,k=!0),m+=f.pop(),q&&g.U.P.closePath(e),g.U.P.moveTo(e,m,p),q=!0;else if("o25"==x){for(;6<f.length;)m+=f.shift(),p+=f.shift(),g.U.P.lineTo(e,m,p);n=m+f.shift();t=p+f.shift();w=n+f.shift();v=t+f.shift();m=w+f.shift();p=v+f.shift();g.U.P.curveTo(e,n,t,w,v,m,p)}else if("o26"==x)for(f.length%
2&&(m+=f.shift());0<f.length;)n=m,t=p+f.shift(),w=n+f.shift(),v=t+f.shift(),m=w,p=v+f.shift(),g.U.P.curveTo(e,n,t,w,v,m,p);else if("o27"==x)for(f.length%2&&(p+=f.shift());0<f.length;)n=m+f.shift(),t=p,w=n+f.shift(),v=t+f.shift(),m=w+f.shift(),p=v,g.U.P.curveTo(e,n,t,w,v,m,p);else if("o10"==x||"o29"==x)n="o10"==x?d:c,0==f.length?console.log("error: empty stack"):(t=f.pop(),n=n.Subrs[t+n.Bias],a.x=m,a.y=p,a.nStems=h,a.haveWidth=k,a.width=l,a.open=q,g.U._drawCFF(n,a,c,d,e),m=a.x,p=a.y,h=a.nStems,k=a.haveWidth,
l=a.width,q=a.open);else if("o30"==x||"o31"==x)for(n=f.length,A=0,x="o31"==x,y=n&-3,A+=n-y;A<y;)x?(n=m+f.shift(),t=p,w=n+f.shift(),v=t+f.shift(),p=v+f.shift(),5==y-A?(m=w+f.shift(),A++):m=w,x=!1):(n=m,t=p+f.shift(),w=n+f.shift(),v=t+f.shift(),m=w+f.shift(),5==y-A?(p=v+f.shift(),A++):p=v,x=!0),g.U.P.curveTo(e,n,t,w,v,m,p),A+=4;else{if("o"==(x+"").charAt(0))throw console.log("Unknown operation: "+x,b),x;f.push(x)}}a.x=m;a.y=p;a.nStems=h;a.haveWidth=k;a.width=l;a.open=q};return g},function(){function r(b,
a){function c(){var a=g.getUint16(k);k+=2;return a}function d(){var a=g.getUint32(k);k+=4;return a}function e(a){y.setUint16(A,a);A+=2}function f(a){y.setUint32(A,a);A+=4}var g=new DataView(b),k=0;d();var l=d();d();var q=c();c();d();c();c();d();d();d();d();d();for(var u=0;Math.pow(2,u)<=q;)u++;u--;for(var m=16*Math.pow(2,u),p=16*q-m,n=12,t=[],r=0;r<q;r++)t.push({tag:d(),offset:d(),compLength:d(),origLength:d(),origChecksum:d()}),n+=16;var v=new Uint8Array(12+16*t.length+t.reduce(function(a,b){return a+
b.origLength+4},0));r=v.buffer;var y=new DataView(r),A=0;f(l);e(q);e(m);e(u);e(p);t.forEach(function(a){f(a.tag);f(a.origChecksum);f(n);f(a.origLength);a.outOffset=n;n+=a.origLength;0!=n%4&&(n+=4-n%4)});var B;t.forEach(function(c){var d=b.slice(c.offset,c.offset+c.compLength);if(c.compLength!=c.origLength){var e=new Uint8Array(c.origLength);a(new Uint8Array(d,2),e)}else e=new Uint8Array(d);v.set(e,c.outOffset);n=c.outOffset+c.origLength;d=0;0!=n%4&&(d=4-n%4);v.set((new Uint8Array(d)).buffer,c.outOffset+
c.origLength);B=n+d});return r.slice(0,B)}var g=function(){function b(){this.table=new Uint16Array(16);this.trans=new Uint16Array(288)}function a(a,c){this.source=a;this.bitcount=this.tag=this.sourceIndex=0;this.dest=c;this.destLen=0;this.ltree=new b;this.dtree=new b}function c(a,b,c,d){var e;for(e=0;e<c;++e)a[e]=0;for(e=0;e<30-c;++e)a[e+c]=e/c|0;c=d;for(e=0;30>e;++e)b[e]=c,c+=1<<a[e]}function d(a,b,c,d){var e,f;for(e=0;16>e;++e)a.table[e]=0;for(e=0;e<d;++e)a.table[b[c+e]]++;for(e=f=a.table[0]=0;16>
a,c,d,e,f,g){b.cmds.push("C");b.crds.push(a,c,d,e,f,g)};g.U.P.qcurveTo=function(b,a,c,d,e){b.cmds.push("Q");b.crds.push(a,c,d,e)};g.U.P.closePath=function(b){b.cmds.push("Z")};g.U._drawCFF=function(b,a,c,d,e){for(var f=a.stack,h=a.nStems,k=a.haveWidth,n=a.width,q=a.open,u=0,l=a.x,r=a.y,p,t,m,v,x,A,B,E,C,F,z={val:0,size:0};u<b.length;){g.CFF.getCharString(b,u,z);var w=z.val;u+=z.size;if("o1"==w||"o18"==w)(p=0!==f.length%2)&&!k&&(n=f.shift()+d.nominalWidthX),h+=f.length>>1,f.length=0,k=!0;else if("o3"==
w||"o23"==w)(p=0!==f.length%2)&&!k&&(n=f.shift()+d.nominalWidthX),h+=f.length>>1,f.length=0,k=!0;else if("o4"==w)1<f.length&&!k&&(n=f.shift()+d.nominalWidthX,k=!0),q&&g.U.P.closePath(e),r+=f.pop(),g.U.P.moveTo(e,l,r),q=!0;else if("o5"==w)for(;0<f.length;)l+=f.shift(),r+=f.shift(),g.U.P.lineTo(e,l,r);else if("o6"==w||"o7"==w)for(x=f.length,p="o6"==w,t=0;t<x;t++)m=f.shift(),p?l+=m:r+=m,p=!p,g.U.P.lineTo(e,l,r);else if("o8"==w||"o24"==w){x=f.length;for(A=0;A+6<=x;)p=l+f.shift(),t=r+f.shift(),m=p+f.shift(),
v=t+f.shift(),l=m+f.shift(),r=v+f.shift(),g.U.P.curveTo(e,p,t,m,v,l,r),A+=6;"o24"==w&&(l+=f.shift(),r+=f.shift(),g.U.P.lineTo(e,l,r))}else if("o11"==w)break;else if("o1234"==w||"o1235"==w||"o1236"==w||"o1237"==w)"o1234"==w&&(p=l+f.shift(),t=r,m=p+f.shift(),v=t+f.shift(),C=m+f.shift(),F=v,x=C+f.shift(),A=v,B=x+f.shift(),E=r,l=B+f.shift(),g.U.P.curveTo(e,p,t,m,v,C,F),g.U.P.curveTo(e,x,A,B,E,l,r)),"o1235"==w&&(p=l+f.shift(),t=r+f.shift(),m=p+f.shift(),v=t+f.shift(),C=m+f.shift(),F=v+f.shift(),x=C+f.shift(),
A=F+f.shift(),B=x+f.shift(),E=A+f.shift(),l=B+f.shift(),r=E+f.shift(),f.shift(),g.U.P.curveTo(e,p,t,m,v,C,F),g.U.P.curveTo(e,x,A,B,E,l,r)),"o1236"==w&&(p=l+f.shift(),t=r+f.shift(),m=p+f.shift(),v=t+f.shift(),C=m+f.shift(),F=v,x=C+f.shift(),A=v,B=x+f.shift(),E=A+f.shift(),l=B+f.shift(),g.U.P.curveTo(e,p,t,m,v,C,F),g.U.P.curveTo(e,x,A,B,E,l,r)),"o1237"==w&&(p=l+f.shift(),t=r+f.shift(),m=p+f.shift(),v=t+f.shift(),C=m+f.shift(),F=v+f.shift(),x=C+f.shift(),A=F+f.shift(),B=x+f.shift(),E=A+f.shift(),Math.abs(B-
l)>Math.abs(E-r)?l=B+f.shift():r=E+f.shift(),g.U.P.curveTo(e,p,t,m,v,C,F),g.U.P.curveTo(e,x,A,B,E,l,r));else if("o14"==w)0<f.length&&!k&&(n=f.shift()+c.nominalWidthX,k=!0),4==f.length&&(p=f.shift(),t=f.shift(),v=f.shift(),m=f.shift(),v=g.CFF.glyphBySE(c,v),m=g.CFF.glyphBySE(c,m),g.U._drawCFF(c.CharStrings[v],a,c,d,e),a.x=p,a.y=t,g.U._drawCFF(c.CharStrings[m],a,c,d,e)),q&&(g.U.P.closePath(e),q=!1);else if("o19"==w||"o20"==w)(p=0!==f.length%2)&&!k&&(n=f.shift()+d.nominalWidthX),h+=f.length>>1,f.length=
0,k=!0,u+=h+7>>3;else if("o21"==w)2<f.length&&!k&&(n=f.shift()+d.nominalWidthX,k=!0),r+=f.pop(),l+=f.pop(),q&&g.U.P.closePath(e),g.U.P.moveTo(e,l,r),q=!0;else if("o22"==w)1<f.length&&!k&&(n=f.shift()+d.nominalWidthX,k=!0),l+=f.pop(),q&&g.U.P.closePath(e),g.U.P.moveTo(e,l,r),q=!0;else if("o25"==w){for(;6<f.length;)l+=f.shift(),r+=f.shift(),g.U.P.lineTo(e,l,r);p=l+f.shift();t=r+f.shift();m=p+f.shift();v=t+f.shift();l=m+f.shift();r=v+f.shift();g.U.P.curveTo(e,p,t,m,v,l,r)}else if("o26"==w)for(f.length%
2&&(l+=f.shift());0<f.length;)p=l,t=r+f.shift(),m=p+f.shift(),v=t+f.shift(),l=m,r=v+f.shift(),g.U.P.curveTo(e,p,t,m,v,l,r);else if("o27"==w)for(f.length%2&&(r+=f.shift());0<f.length;)p=l+f.shift(),t=r,m=p+f.shift(),v=t+f.shift(),l=m+f.shift(),r=v,g.U.P.curveTo(e,p,t,m,v,l,r);else if("o10"==w||"o29"==w)p="o10"==w?d:c,0==f.length?console.log("error: empty stack"):(t=f.pop(),p=p.Subrs[t+p.Bias],a.x=l,a.y=r,a.nStems=h,a.haveWidth=k,a.width=n,a.open=q,g.U._drawCFF(p,a,c,d,e),l=a.x,r=a.y,h=a.nStems,k=a.haveWidth,
n=a.width,q=a.open);else if("o30"==w||"o31"==w)for(p=f.length,A=0,w="o31"==w,x=p&-3,A+=p-x;A<x;)w?(p=l+f.shift(),t=r,m=p+f.shift(),v=t+f.shift(),r=v+f.shift(),5==x-A?(l=m+f.shift(),A++):l=m,w=!1):(p=l,t=r+f.shift(),m=p+f.shift(),v=t+f.shift(),l=m+f.shift(),5==x-A?(r=v+f.shift(),A++):r=v,w=!0),g.U.P.curveTo(e,p,t,m,v,l,r),A+=4;else{if("o"==(w+"").charAt(0))throw console.log("Unknown operation: "+w,b),w;f.push(w)}}a.x=l;a.y=r;a.nStems=h;a.haveWidth=k;a.width=n;a.open=q};return g},function(){function m(b,
a){function c(){var a=g.getUint16(k);k+=2;return a}function d(){var a=g.getUint32(k);k+=4;return a}function e(a){x.setUint16(A,a);A+=2}function f(a){x.setUint32(A,a);A+=4}var g=new DataView(b),k=0;d();var n=d();d();var q=c();c();d();c();c();d();d();d();d();d();for(var m=0;Math.pow(2,m)<=q;)m++;m--;for(var l=16*Math.pow(2,m),r=16*q-l,p=12,t=[],y=0;y<q;y++)t.push({tag:d(),offset:d(),compLength:d(),origLength:d(),origChecksum:d()}),p+=16;var v=new Uint8Array(12+16*t.length+t.reduce(function(a,b){return a+
b.origLength+4},0));y=v.buffer;var x=new DataView(y),A=0;f(n);e(q);e(l);e(m);e(r);t.forEach(function(a){f(a.tag);f(a.origChecksum);f(p);f(a.origLength);a.outOffset=p;p+=a.origLength;0!=p%4&&(p+=4-p%4)});var B;t.forEach(function(c){var d=b.slice(c.offset,c.offset+c.compLength);if(c.compLength!=c.origLength){var e=new Uint8Array(c.origLength);a(new Uint8Array(d,2),e)}else e=new Uint8Array(d);v.set(e,c.outOffset);p=c.outOffset+c.origLength;d=0;0!=p%4&&(d=4-p%4);v.set((new Uint8Array(d)).buffer,c.outOffset+
c.origLength);B=p+d});return y.slice(0,B)}var g=function(){function b(){this.table=new Uint16Array(16);this.trans=new Uint16Array(288)}function a(a,c){this.source=a;this.bitcount=this.tag=this.sourceIndex=0;this.dest=c;this.destLen=0;this.ltree=new b;this.dtree=new b}function c(a,b,c,d){var e;for(e=0;e<c;++e)a[e]=0;for(e=0;e<30-c;++e)a[e+c]=e/c|0;c=d;for(e=0;30>e;++e)b[e]=c,c+=1<<a[e]}function d(a,b,c,d){var e,f;for(e=0;16>e;++e)a.table[e]=0;for(e=0;e<d;++e)a.table[b[c+e]]++;for(e=f=a.table[0]=0;16>
e;++e)v[e]=f,f+=a.table[e];for(e=0;e<d;++e)b[c+e]&&(a.trans[v[b[c+e]]++]=e)}function e(a,b,c){if(!b)return c;for(;24>a.bitcount;)a.tag|=a.source[a.sourceIndex++]<<a.bitcount,a.bitcount+=8;var d=a.tag&65535>>>16-b;a.tag>>>=b;a.bitcount-=b;return d+c}function f(a,b){for(;24>a.bitcount;)a.tag|=a.source[a.sourceIndex++]<<a.bitcount,a.bitcount+=8;var c=0,d=0,e=0,f=a.tag;do d=2*d+(f&1),f>>>=1,++e,c+=b.table[e],d-=b.table[e];while(0<=d);a.tag=f;a.bitcount-=e;return b.trans[c+d]}function g(a,b,c){for(;;){var d=
f(a,b);if(256===d)return 0;if(256>d)a.dest[a.destLen++]=d;else{var g;d-=257;d=e(a,q[d],u[d]);var h=f(a,c);for(g=h=a.destLen-e(a,m[h],p[h]);g<h+d;++g)a.dest[a.destLen++]=a.dest[g]}}}var k=new b,l=new b,q=new Uint8Array(30),u=new Uint16Array(30),m=new Uint8Array(30),p=new Uint16Array(30),n=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),t=new b,r=new Uint8Array(320),v=new Uint16Array(16);(function(a,b){var c;for(c=0;7>c;++c)a.table[c]=0;a.table[7]=24;a.table[8]=152;a.table[9]=112;for(c=
0;24>c;++c)a.trans[c]=256+c;for(c=0;144>c;++c)a.trans[24+c]=c;for(c=0;8>c;++c)a.trans[168+c]=280+c;for(c=0;112>c;++c)a.trans[176+c]=144+c;for(c=0;5>c;++c)b.table[c]=0;b.table[5]=32;for(c=0;32>c;++c)b.trans[c]=c})(k,l);c(q,u,4,3);c(m,p,2,1);q[28]=0;u[28]=258;return function(b,c){b=new a(b,c);do{c=b;c.bitcount--||(c.tag=c.source[c.sourceIndex++],c.bitcount=7);var h=c.tag&1;c.tag>>>=1;c=h;h=e(b,2,0);switch(h){case 0:for(h=b;8<h.bitcount;)h.sourceIndex--,h.bitcount-=8;var m=h.source[h.sourceIndex+1];
m=256*m+h.source[h.sourceIndex];var q=h.source[h.sourceIndex+3];q=256*q+h.source[h.sourceIndex+2];if(m!==(~q&65535))h=-3;else{h.sourceIndex+=4;for(q=m;q;--q)h.dest[h.destLen++]=h.source[h.sourceIndex++];h=h.bitcount=0}break;case 1:h=g(b,k,l);break;case 2:var p;m=b;var u=b.ltree,v=b.dtree;q=e(m,5,257);h=e(m,5,1);var w=e(m,4,4);for(p=0;19>p;++p)r[p]=0;for(p=0;p<w;++p){var y=e(m,3,0);r[n[p]]=y}d(t,r,0,19);for(p=0;p<q+h;)switch(w=f(m,t),w){case 16:y=r[p-1];for(w=e(m,2,3);w;--w)r[p++]=y;break;case 17:for(w=
e(m,3,3);w;--w)r[p++]=0;break;case 18:for(w=e(m,7,11);w;--w)r[p++]=0;break;default:r[p++]=w}d(u,r,0,q);d(v,r,q,h);h=g(b,b.ltree,b.dtree);break;default:h=-3}if(0!==h)throw Error("Data error");}while(!c);return b.destLen<b.dest.length?"function"===typeof b.dest.slice?b.dest.slice(0,b.destLen):b.dest.subarray(0,b.destLen):b.dest}}();return function(b){return r(b,g)}},function(r,g){function b(b){var d=b[0],f=Object.create(null),g={unitsPerEm:d.head.unitsPerEm,ascender:d.hhea.ascender,descender:d.hhea.descender,
forEachGlyph:function(b,e,h,u){var k=0,l=1/g.unitsPerEm*e;r.U.stringToGlyphs(d,b).forEach(function(b){if(-1!==b){var g=f[b];if(!g){g=r.glyf._parseGlyf(d,b)||{xMin:0,xMax:0,yMin:0,yMax:0};var m=r.U.glyphToPath(d,b),q=m.cmds,p=m.crds;g=f[b]={index:b,unicode:a(d,b),advanceWidth:d.hmtx.aWidth[b],xMin:g.xMin,yMin:g.yMin,xMax:g.xMax,yMax:g.yMax,pathCommandCount:q.length,forEachPathCommand:function(a){for(var b=0,d=[],e=0,f=q.length;e<f;e++){var g=c[q[e]];d.length=1+g;d[0]=q[e];for(var h=1;h<=g;h++)d[h]=
p[b++];a.apply(null,d)}}}}u.call(null,g,k);g.advanceWidth&&(k+=g.advanceWidth*l);h&&(k+=h*e)}});return k}};return g}function a(a,b){var c=a.glyphToUnicodeMap;if(!c){c=a.glyphToUnicodeMap=Object.create(null);var d=a.cmap,e=-1;null!=d.p0e4?e=d.p0e4:null!=d.p3e1?e=d.p3e1:null!=d.p1e0?e=d.p1e0:null!=d.p0e3&&(e=d.p0e3);if(-1===e)throw"no familiar platform and encoding!";e=d.tables[e];if(0===e.format)for(a=0;a<e.map.length;a++)c[e.map[a]]=a;else if(4===e.format){d=e.startCount;e=e.endCount;for(var g=0;g<
d.length;g++)for(var q=d[g];q<=e[g];q++)c[r.U.codeToGlyph(a,q)]=q}else if(12===e.format)e.groups.forEach(function(a){var b=a[1],d=a[2];for(a=a[0];a<=b;a++)c[d++]=a});else throw"unknown cmap table format "+e.format;}return c[b]||0}var c={M:2,L:2,Q:4,C:6,Z:0};return function(a){var c=new Uint8Array(a,0,4);c=r._bin.readASCII(c,0,4);if("wOFF"===c)a=g(a);else if("wOF2"===c)throw Error("woff2 fonts not supported");return b(r.parse(a))}}],init:function(r,g,b){r=r();g=g();return b(r,g)}}),I={defaultFontURL:"https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxM.woff",
sdfGlyphSize:64},K=document.createElement("a"),L=Object.create(null);G=F.defineWorkerModule({dependencies:[I,.125,G,function(r){function g(a){return a*a}var b=r.sdfTextureSize,a=r.sdfDistancePercent,c=function(a){var b=a.xMin,c=a.yMin,d=a.xMax-b;a=a.yMax-c;this._root={0:null,1:null,2:null,3:null,data:null,cx:Math.round(b+d/2),cy:Math.round(c+a/2),r:Math.pow(2,Math.floor(Math.log(Math.max(d,a))*Math.LOG2E)),minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}};c.prototype.addLineSegment=function(a,
b,c,g){this._insertSegment({x0:a,y0:b,x1:c,y1:g,cx:(a+c)/2,cy:(b+g)/2,minX:Math.min(a,c),minY:Math.min(b,g),maxX:Math.max(a,c),maxY:Math.max(b,g),next:null},this._root)};c.prototype._insertSegment=function(a,b){var c=a.minX,d=a.minY,e=a.maxX,g=a.maxY,q=a.cx,u=a.cy;c<b.minX&&(b.minX=c);d<b.minY&&(b.minY=d);e>b.maxX&&(b.maxX=e);g>b.maxY&&(b.maxY=g);var m=b.data;if(m)if(m.cx===q&&m.cy===u){for(;m.next;)m=m.next;m.next=a}else b.data=null,this._insertSegment(m,b),this._insertSegment(a,b);else q=(u<b.cy?
0:2)+(q<b.cx?0:1),b[q]?this._insertSegment(a,b[q]):b[q]={0:null,1:null,2:null,3:null,data:a,cx:b.cx+b.r/2*(q%2?1:-1),cy:b.cy+b.r/2*(2>q?-1:1),r:b.r/2,minX:c,minY:d,maxX:e,maxY:g}};c.prototype.walkTree=function(a){this.walkBranch(this._root,a)};c.prototype.walkBranch=function(a,b){if(!1!==b(a)&&!a.data)for(var c=0;4>c;c++)null!==a[c]&&this.walkBranch(a[c],b)};c.prototype.findNearestSignedDistance=function(a,b,c){var d=c;this.walkTree(function(c){if(a-d>c.maxX||a+d<c.minX||b-d>c.maxY||b+d<c.minY)return!1;
if(c.data)for(c=c.data;c;c=c.next)if(a-d<c.maxX||a+d>c.minX||b-d<c.maxY||b+d>c.minY){var e=a;var f=b,h=c.x0,k=c.y0,p=c.x1-h,n=c.y1-k,t=p*p+n*n;t=t?Math.max(0,Math.min(1,((e-h)*p+(f-k)*n)/t)):0;e=Math.sqrt(g(e-(h+t*p))+g(f-(k+t*n)));e<d&&(d=e)}});this.isPointInPoly(a,b)||(d=-d);return d};c.prototype.isPointInPoly=function(a,b){var c=!1;this.walkTree(function(d){if(d.maxX<a||d.minY>b||d.maxY<b)return!1;if(d.data)for(d=d.data;d;d=d.next){var e=d.x0,f=d.y0,g=d.x1,h=d.y1;f>b!==h>b&&a<(g-e)*(b-f)/(h-f)+
e&&(c=!c)}});return c};return function(d){var e=new Uint8Array(b*b),f=d.xMax-d.xMin,g=d.yMax-d.yMin,k=Math.max(f,g)*a,l=(f+2*k)/b,q=(g+2*k)/b;g=d.xMin-k-l;f=d.yMin-k-q;l=d.xMax+k+l;q=d.yMax+k+q;if(d.pathCommandCount){var u=new c(d),m,p,n,t;d.forEachPathCommand(function(a,b,c,d,e,f,g){switch(a){case "M":n=m=b;t=p=c;break;case "L":b===n&&c===t||u.addLineSegment(n,t,n=b,t=c);break;case "Q":f={x:n,y:t};for(g=1;16>g;g++){a=g/15;var h=1-a;a={x:h*h*n+2*h*a*b+a*a*d,y:h*h*t+2*h*a*c+a*a*e};u.addLineSegment(f.x,
f.y,a.x,a.y);f=a}n=d;t=e;break;case "C":a={x:n,y:t};for(h=1;16>h;h++){var k=h/15;var l=1-k;k={x:l*l*l*n+3*l*l*k*b+3*l*k*k*d+k*k*k*f,y:l*l*l*t+3*l*l*k*c+3*l*k*k*e+k*k*k*g};u.addLineSegment(a.x,a.y,k.x,k.y);a=k}n=f;t=g;break;case "Z":n===m&&t===p||u.addLineSegment(n,t,m,p)}});for(d=0;d<b;d++)for(var r=0;r<b;r++){var v=u.findNearestSignedDistance(g+(l-g)*(d+.5)/b,f+(q-f)*(r+.5)/b,k);v=isFinite(v)?Math.round(127.5*(1+v/k)):v;v=Math.max(0,Math.min(255,v));e[r*b+d]=v}}return{textureData:e,renderingBounds:[g,
f,l,q]}}},function(r,g,b){function a(a,b){function c(){var d=function(b){console.error("Failure loading font "+a+(a===f?"":"; trying fallback"),b);a!==f&&(a=f,c())};try{var e=new XMLHttpRequest;e.open("get",a,!0);e.responseType="arraybuffer";e.onload=function(){if(400<=e.status)d(Error(e.statusText));else if(0<e.status)try{var a=r(e.response);b(a)}catch(n){d(n)}};e.onerror=d;e.send()}catch(p){d(p)}}c()}function c(b,c){b||(b=f);var d=h[b];if(d)d.onload?d.onload.push(c):c();else{var e=h[b]={onload:[c]};
a(b,function(a){d=h[b]={fontObj:a,glyphs:{},glyphCount:0};e.onload.forEach(function(a){return a()})})}}function d(a,b){a||(a=f);c(a,function(){b(h[a])})}function e(a,b,c){var e=a.text;void 0===e&&(e="");var h=a.font;void 0===h&&(h=f);var k=a.fontSize;void 0===k&&(k=1);var l=a.letterSpacing;void 0===l&&(l=0);var q=a.lineHeight;void 0===q&&(q="normal");var r=a.maxWidth;void 0===r&&(r=Infinity);var v=a.textAlign;void 0===v&&(v="left");var y=a.whiteSpace;void 0===y&&(y="normal");var A=a.overflowWrap;
void 0===A&&(A="normal");var z=a.anchor;void 0===c&&(c=!1);d(h,function(a){var d=a.fontObj,f=isFinite(r),h=null,m=null,n=null,p=null,t=0,u=0,w="nowrap"!==y,B=k/d.unitsPerEm;"normal"===q&&(q=(d.ascender-d.descender)/d.unitsPerEm);q*=k;var C=(q-(d.ascender-d.descender)*B)/2,D=e.split(/\r?\n/).map(function(a){var b=0,c=[],e=[c];d.forEachGlyph(a,k,l,function(a,d){var g=a.unicode;g="number"===typeof g&&String.fromCharCode(g);var h=a.advanceWidth*B,k=!!g&&/\s/.test(g);if(w&&f&&!k&&d+h+b>r&&c.length){if(c[c.length-
1].isWhitespace){var l=[];b=-d}else for(var m=c.length;m--;)if(0===m&&"break-word"===A){l=[];b=-d;break}else if(c[m].isWhitespace){l=c.splice(m+1);m=l[0].x;b-=m;for(var n=0;n<l.length;n++)l[n].x-=m;break}if(l){for(;c[c.length-1].isWhitespace;)c.pop();e.push(c=l);u=r}}c.push({glyphObj:a,x:d+b,y:0,width:h,char:g,isWhitespace:k,isEmpty:a.xMin===a.xMax||a.yMin===a.yMax,atlasInfo:null})});for(a=0;a<e.length&&u<r;a++){var g=e[a];g.length&&(g=g[g.length-1],u=Math.max(u,g.x+g.width))}t+=e.length;return e});
if(!c){var F=[],I=-(k+C);D.forEach(function(b){for(var c=0;c<b.length;c++){var d=b[c];if(d.length){var e=0,f=d[d.length-1];f=f.x+f.width;var k=0;if("center"===v)e=(u-f)/2;else if("right"===v)e=u-f;else if("justify"===v)for(var l=0,m=d.length;l<m;l++)d[l].isWhitespace&&k++;l=0;for(m=d.length;l<m;l++){var n=d[l];n.isWhitespace&&"justify"===v&&c!==b.length-1&&(e+=(u-f)/k);if(!n.isWhitespace&&!n.isEmpty){var p=n.glyphObj,r=a.glyphs[p.index];r||(r=g(p),r.atlasIndex=a.glyphCount++,h||(h=[]),h.push(r),r=
a.glyphs[p.index]={atlasIndex:r.atlasIndex,glyphObj:p,renderingBounds:r.renderingBounds});n.atlasInfo=r;e&&(n.x+=e);n.y=I;F.push(n)}}}I-=q}});var G=0,H=0;z&&(z[0]&&(G=-u*z[0]),z[1]&&(H=t*q*z[1]));m=new Float32Array(4*F.length);n=new Float32Array(F.length);p=[Infinity,Infinity,-Infinity,-Infinity];F.forEach(function(a,b){var c=a.atlasInfo,d=c.renderingBounds;c=c.atlasIndex;var e=m[4*b]=a.x+d[0]*B+G,f=m[4*b+1]=a.y+d[1]*B+H,g=m[4*b+2]=a.x+d[2]*B+G;a=m[4*b+3]=a.y+d[3]*B+H;e<p[0]&&(p[0]=e);f<p[1]&&(p[1]=
f);g>p[2]&&(p[2]=g);a>p[3]&&(p[3]=a);n[b]=c})}b({glyphBounds:m,glyphIndices:n,totalBounds:p,totalBlockSize:[u,t*q],newGlyphSDFs:h})})}var f=b.defaultFontUrl,h=Object.create(null);return{process:e,measure:function(a,b){e(a,function(a){b({width:a.totalBlockSize[0],height:a.totalBlockSize[1]})},!0)},loadFont:c}}],init:function(r,g,b,a,c){g=a({sdfTextureSize:r.sdfGlyphSize,sdfDistancePercent:g});return c(b,g,{defaultFontUrl:r.defaultFontURL})}});var S=F.defineWorkerModule({dependencies:[G,F.ThenableWorkerModule],
init:function(r,g){return function(b){var a=new g;r.process(b,a.resolve);return a}},getTransferables:function(r){var g=[r.glyphBounds.buffer,r.glyphIndices.buffer];r.newGlyphSDFs&&r.newGlyphSDFs.forEach(function(b){g.push(b.textureData.buffer)});return g}}),U=(new z.PlaneBufferGeometry(1,1)).translate(.5,.5,0),V=new z.Vector3,H=function(r){function g(){r.call(this);this.copy(U);this.boundingSphere=new z.Sphere}r&&(g.__proto__=r);g.prototype=Object.create(r&&r.prototype);g.prototype.constructor=g;
g.prototype.computeBoundingSphere=function(){};g.prototype.updateGlyphs=function(b,a,c){M(this,"aTroikaGlyphBounds",b,4);M(this,"aTroikaGlyphIndex",a,1);this.maxInstancedCount=a.length;b=this.boundingSphere;b.center.set((c[0]+c[2])/2,(c[1]+c[3])/2,0);b.radius=b.center.distanceTo(V.set(c[0],c[1],0))};return g}(z.InstancedBufferGeometry);H.prototype.setAttribute||(H.prototype.setAttribute=function(r,g){this.attributes[r]=g;return this});var N=new z.MeshBasicMaterial({color:16777215,side:z.DoubleSide,
transparent:!0});Object.freeze([-Infinity,-Infinity,Infinity,Infinity]);var W=new z.Matrix4;new z.Plane;new z.Vector3;var O=new z.Mesh((new z.PlaneBufferGeometry(1,1)).translate(.5,.5,0),N),P=function(r){function g(a){a=new H;r.call(this,a,null);this.text="";this.font=this.anchor=null;this.fontSize=.1;this.letterSpacing=0;this.lineHeight="normal";this.maxWidth=Infinity;this.overflowWrap="normal";this.textAlign="left";this.whiteSpace="normal";this.color=this.material=null;this.depthOffset=0;this.clipRect=
null;this.debugSDF=!1}r&&(g.__proto__=r);g.prototype=Object.create(r&&r.prototype);g.prototype.constructor=g;var b={material:{configurable:!0},customDepthMaterial:{configurable:!0},customDistanceMaterial:{configurable:!0}};g.prototype.sync=function(a){var b=this;this._needsSync&&(this._needsSync=!1,this._isSyncing?(this._queuedSyncs||(this._queuedSyncs=[])).push(a):(this._isSyncing=!0,R({text:this.text,font:this.font,fontSize:this.fontSize,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,
maxWidth:this.maxWidth,textAlign:this.textAlign,whiteSpace:this.whiteSpace,overflowWrap:this.overflowWrap,anchor:this.anchor},function(c){b._isSyncing=!1;b._textRenderInfo=c;b.geometry.updateGlyphs(c.glyphBounds,c.glyphIndices,c.totalBounds);var d=b._queuedSyncs;d&&(b._queuedSyncs=null,b._needsSync=!0,b.sync(function(){d.forEach(function(a){return a&&a()})}));a&&a()})))};g.prototype.onBeforeRender=function(){this.sync();this._prepareMaterial()};g.prototype.dispose=function(){this.geometry.dispose()};
b.material.get=function(){var a=this._derivedMaterial,b=this._baseMaterial||N;a&&a.baseMaterial===b||(a&&a.dispose(),a=this._derivedMaterial=T(b),b.addEventListener("dispose",function e(){b.removeEventListener("dispose",e);a.dispose()}));return a};b.material.set=function(a){this._baseMaterial=a};b.customDepthMaterial.get=function(){return this._updateLayoutUniforms(this.material.getDepthMaterial())};b.customDistanceMaterial.get=function(){return this._updateLayoutUniforms(this.material.getDistanceMaterial())};
g.prototype._prepareMaterial=function(){var a=this._derivedMaterial;this._updateLayoutUniforms(a);a.uniforms.uTroikaSDFDebug.value=!!this.debugSDF;a.polygonOffset=!!this.depthOffset;a.polygonOffsetFactor=a.polygonOffsetUnits=this.depthOffset||0;var b=this.color;null!=b&&a.color&&a.color.isColor&&b!==a._troikaColor&&a.color.set(a._troikaColor=b)};g.prototype._updateLayoutUniforms=function(a){var b=this._textRenderInfo,d=a.uniforms;if(b){var e=b.sdfTexture,f=b.totalBounds;d.uTroikaSDFTexture.value=
e;d.uTroikaSDFMinDistancePct.value=b.sdfMinDistancePercent;d.uTroikaGlyphVSize.value=e.image.width/e.image.height;d.uTroikaTotalBounds.value.fromArray(f);(b=this.clipRect)&&Array.isArray(b)&&4===b.length?d.uTroikaClipRect.value.set(Math.max(f[0],b[0]),Math.max(f[1],b[1]),Math.min(f[2],b[2]),Math.min(f[3],b[3])):d.uTroikaClipRect.value.fromArray(f)}return a};g.prototype.raycast=function(a,b){var c=this._textRenderInfo;c&&(c=c.totalBounds,O.matrixWorld.multiplyMatrices(this.matrixWorld,W.set(c[2]-c[0],
0,0,c[0],0,c[3]-c[1],0,c[1],0,0,1,0,0,0,0,1)),O.raycast(a,b))};Object.defineProperties(g.prototype,b);return g}(z.Mesh);"font fontSize letterSpacing lineHeight maxWidth overflowWrap text textAlign whiteSpace anchor".split(" ").forEach(function(r){var g="_private_"+r;Object.defineProperty(P.prototype,r,{get:function(){return this[g]},set:"anchor"===r?function(b){JSON.stringify(b)!==JSON.stringify(this[g])&&(this[g]=b,this._needsSync=!0)}:function(b){b!==this[g]&&(this[g]=b,this._needsSync=!0)}})});
C.GlyphsGeometry=H;C.TextMesh=P;C.configureTextBuilder=function(r){J(I,r)};C.fontProcessorWorkerModule=G;Object.defineProperty(C,"__esModule",{value:!0})});
f(a,b);if(256===d)return 0;if(256>d)a.dest[a.destLen++]=d;else{var g;d-=257;d=e(a,q[d],m[d]);var h=f(a,c);for(g=h=a.destLen-e(a,l[h],r[h]);g<h+d;++g)a.dest[a.destLen++]=a.dest[g]}}}var k=new b,n=new b,q=new Uint8Array(30),m=new Uint16Array(30),l=new Uint8Array(30),r=new Uint16Array(30),p=new Uint8Array([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),t=new b,y=new Uint8Array(320),v=new Uint16Array(16);(function(a,b){var c;for(c=0;7>c;++c)a.table[c]=0;a.table[7]=24;a.table[8]=152;a.table[9]=112;for(c=
0;24>c;++c)a.trans[c]=256+c;for(c=0;144>c;++c)a.trans[24+c]=c;for(c=0;8>c;++c)a.trans[168+c]=280+c;for(c=0;112>c;++c)a.trans[176+c]=144+c;for(c=0;5>c;++c)b.table[c]=0;b.table[5]=32;for(c=0;32>c;++c)b.trans[c]=c})(k,n);c(q,m,4,3);c(l,r,2,1);q[28]=0;m[28]=258;return function(b,c){b=new a(b,c);do{c=b;c.bitcount--||(c.tag=c.source[c.sourceIndex++],c.bitcount=7);var h=c.tag&1;c.tag>>>=1;c=h;h=e(b,2,0);switch(h){case 0:for(h=b;8<h.bitcount;)h.sourceIndex--,h.bitcount-=8;var l=h.source[h.sourceIndex+1];
l=256*l+h.source[h.sourceIndex];var m=h.source[h.sourceIndex+3];m=256*m+h.source[h.sourceIndex+2];if(l!==(~m&65535))h=-3;else{h.sourceIndex+=4;for(m=l;m;--m)h.dest[h.destLen++]=h.source[h.sourceIndex++];h=h.bitcount=0}break;case 1:h=g(b,k,n);break;case 2:var q;l=b;var r=b.ltree,u=b.dtree;m=e(l,5,257);h=e(l,5,1);var v=e(l,4,4);for(q=0;19>q;++q)y[q]=0;for(q=0;q<v;++q){var x=e(l,3,0);y[p[q]]=x}d(t,y,0,19);for(q=0;q<m+h;)switch(v=f(l,t),v){case 16:x=y[q-1];for(v=e(l,2,3);v;--v)y[q++]=x;break;case 17:for(v=
e(l,3,3);v;--v)y[q++]=0;break;case 18:for(v=e(l,7,11);v;--v)y[q++]=0;break;default:y[q++]=v}d(r,y,0,m);d(u,y,m,h);h=g(b,b.ltree,b.dtree);break;default:h=-3}if(0!==h)throw Error("Data error");}while(!c);return b.destLen<b.dest.length?"function"===typeof b.dest.slice?b.dest.slice(0,b.destLen):b.dest.subarray(0,b.destLen):b.dest}}();return function(b){return m(b,g)}},function(m,g){function b(b){var c=b[0],e=Object.create(null),f={unitsPerEm:c.head.unitsPerEm,ascender:c.hhea.ascender,descender:c.hhea.descender,
forEachGlyph:function(b,d,g,q){var h=0,k=1/f.unitsPerEm*d,n=0;m.U.stringToGlyphs(c,b).forEach(function(f){if(-1!==f){var l=e[f];if(!l){l=m.glyf._parseGlyf(c,f)||{xMin:0,xMax:0,yMin:0,yMax:0};var p=m.U.glyphToPath(c,f),r=p.cmds,u=p.crds;l=e[f]={index:f,advanceWidth:c.hmtx.aWidth[f],xMin:l.xMin,yMin:l.yMin,xMax:l.xMax,yMax:l.yMax,pathCommandCount:r.length,forEachPathCommand:function(b){for(var c=0,d=[],e=0,f=r.length;e<f;e++){var g=a[r[e]];d.length=1+g;d[0]=r[e];for(var h=1;h<=g;h++)d[h]=u[c++];b.apply(null,
d)}}}}q.call(null,l,h,n);l.advanceWidth&&(h+=l.advanceWidth*k);g&&(h+=g*d)}n+=65535<b.codePointAt(n)?2:1});return h}};return f}var a={M:2,L:2,Q:4,C:6,Z:0};return function(a){var c=new Uint8Array(a,0,4);c=m._bin.readASCII(c,0,4);if("wOFF"===c)a=g(a);else if("wOF2"===c)throw Error("woff2 fonts not supported");return b(m.parse(a))}}],init:function(m,g,b){m=m();g=g();return b(m,g)}}),K={defaultFontURL:"https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxM.woff",sdfGlyphSize:64,textureWidth:2048},
S=document.createElement("a"),T=Object.create(null);G=M.defineWorkerModule({dependencies:[K,.125,G,function(m){function g(a){return a*a}var b=m.sdfTextureSize,a=m.sdfDistancePercent,c=function(a){var b=a.xMin,c=a.yMin,d=a.xMax-b;a=a.yMax-c;this._root={0:null,1:null,2:null,3:null,data:null,cx:Math.round(b+d/2),cy:Math.round(c+a/2),r:Math.pow(2,Math.floor(Math.log(Math.max(d,a))*Math.LOG2E)),minX:Infinity,minY:Infinity,maxX:-Infinity,maxY:-Infinity}};c.prototype.addLineSegment=function(a,b,c,g){this._insertSegment({x0:a,
y0:b,x1:c,y1:g,cx:(a+c)/2,cy:(b+g)/2,minX:Math.min(a,c),minY:Math.min(b,g),maxX:Math.max(a,c),maxY:Math.max(b,g),next:null},this._root)};c.prototype._insertSegment=function(a,b){var c=a.minX,d=a.minY,e=a.maxX,g=a.maxY,q=a.cx,m=a.cy;c<b.minX&&(b.minX=c);d<b.minY&&(b.minY=d);e>b.maxX&&(b.maxX=e);g>b.maxY&&(b.maxY=g);var l=b.data;if(l)if(l.cx===q&&l.cy===m){for(;l.next;)l=l.next;l.next=a}else b.data=null,this._insertSegment(l,b),this._insertSegment(a,b);else q=(m<b.cy?0:2)+(q<b.cx?0:1),b[q]?this._insertSegment(a,
b[q]):b[q]={0:null,1:null,2:null,3:null,data:a,cx:b.cx+b.r/2*(q%2?1:-1),cy:b.cy+b.r/2*(2>q?-1:1),r:b.r/2,minX:c,minY:d,maxX:e,maxY:g}};c.prototype.walkTree=function(a){this.walkBranch(this._root,a)};c.prototype.walkBranch=function(a,b){if(!1!==b(a)&&!a.data)for(var c=0;4>c;c++)null!==a[c]&&this.walkBranch(a[c],b)};c.prototype.findNearestSignedDistance=function(a,b,c){var d=c;this.walkTree(function(c){if(a-d>c.maxX||a+d<c.minX||b-d>c.maxY||b+d<c.minY)return!1;if(c.data)for(c=c.data;c;c=c.next)if(a-
d<c.maxX||a+d>c.minX||b-d<c.maxY||b+d>c.minY){var e=a;var f=b,h=c.x0,k=c.y0,m=c.x1-h,p=c.y1-k,t=m*m+p*p;t=t?Math.max(0,Math.min(1,((e-h)*m+(f-k)*p)/t)):0;e=Math.sqrt(g(e-(h+t*m))+g(f-(k+t*p)));e<d&&(d=e)}});this.isPointInPoly(a,b)||(d=-d);return d};c.prototype.isPointInPoly=function(a,b){var c=!1;this.walkTree(function(d){if(d.maxX<a||d.minY>b||d.maxY<b)return!1;if(d.data)for(d=d.data;d;d=d.next){var e=d.x0,f=d.y0,g=d.x1,h=d.y1;f>b!==h>b&&a<(g-e)*(b-f)/(h-f)+e&&(c=!c)}});return c};return function(d){var e=
new Uint8Array(b*b),f=d.xMax-d.xMin,g=d.yMax-d.yMin,k=Math.max(f,g)*a,n=(f+2*k)/b,m=(g+2*k)/b;g=d.xMin-k-n;f=d.yMin-k-m;n=d.xMax+k+n;m=d.yMax+k+m;if(d.pathCommandCount){var u=new c(d),l,r,p,t;d.forEachPathCommand(function(a,b,c,d,e,f,g){switch(a){case "M":p=l=b;t=r=c;break;case "L":b===p&&c===t||u.addLineSegment(p,t,p=b,t=c);break;case "Q":f={x:p,y:t};for(g=1;16>g;g++){a=g/15;var h=1-a;a={x:h*h*p+2*h*a*b+a*a*d,y:h*h*t+2*h*a*c+a*a*e};u.addLineSegment(f.x,f.y,a.x,a.y);f=a}p=d;t=e;break;case "C":a={x:p,
y:t};for(h=1;16>h;h++){var k=h/15;var n=1-k;k={x:n*n*n*p+3*n*n*k*b+3*n*k*k*d+k*k*k*f,y:n*n*n*t+3*n*n*k*c+3*n*k*k*e+k*k*k*g};u.addLineSegment(a.x,a.y,k.x,k.y);a=k}p=f;t=g;break;case "Z":p===l&&t===r||u.addLineSegment(p,t,l,r)}});for(d=0;d<b;d++)for(var y=0;y<b;y++){var v=u.findNearestSignedDistance(g+(n-g)*(d+.5)/b,f+(m-f)*(y+.5)/b,k);v=isFinite(v)?Math.round(127.5*(1+v/k)):v;v=Math.max(0,Math.min(255,v));e[y*b+d]=v}}return{textureData:e,renderingBounds:[g,f,n,m]}}},function(m,g,b){function a(a,b){function c(){var d=
function(b){console.error("Failure loading font "+a+(a===f?"":"; trying fallback"),b);a!==f&&(a=f,c())};try{var e=new XMLHttpRequest;e.open("get",a,!0);e.responseType="arraybuffer";e.onload=function(){if(400<=e.status)d(Error(e.statusText));else if(0<e.status)try{var a=m(e.response);b(a)}catch(p){d(p)}};e.onerror=d;e.send()}catch(r){d(r)}}c()}function c(b,c){b||(b=f);var d=h[b];if(d)d.onload?d.onload.push(c):c();else{var e=h[b]={onload:[c]};a(b,function(a){d=h[b]={fontObj:a,glyphs:{},glyphCount:0};
e.onload.forEach(function(a){return a()})})}}function d(a,b){a||(a=f);c(a,function(){b(h[a])})}function e(a,b,c){var e=a.text;void 0===e&&(e="");var h=a.font;void 0===h&&(h=f);var k=a.fontSize;void 0===k&&(k=1);var n=a.letterSpacing;void 0===n&&(n=0);var m=a.lineHeight;void 0===m&&(m="normal");var q=a.maxWidth;void 0===q&&(q=Infinity);var v=a.textAlign;void 0===v&&(v="left");var x=a.whiteSpace;void 0===x&&(x="normal");var A=a.overflowWrap;void 0===A&&(A="normal");var z=a.anchor,E=a.includeCaretPositions;
void 0===E&&(E=!1);void 0===c&&(c=!1);-1<e.indexOf("\r")&&(console.warn("FontProcessor.process: got text with \\r chars; normalizing to \\n"),e=e.replace(/\r\n/g,"\n").replace(/\r/g,"\n"));d(h,function(a){var d=a.fontObj,f=isFinite(q),h=null,l=null,p=null,r=null,t=null,u=0,y="nowrap"!==x,B=d.ascender,D=d.descender,C=d.unitsPerEm,I=k/C;"normal"===m&&(m=(B-D)/C);m*=k;var K=(m-(B-D)*I)/2;C=Math.min(m,(B-D)*I);var M=(B+D)/2*I-C/2,N=0,J={glyphs:[],width:0},O=[J];d.forEachGlyph(e,k,n,function(a,b,c){var d=
e.charAt(c),g=a.advanceWidth*I,h=!!d&&/\s/.test(d),k=J.glyphs;if(y&&f&&!h&&b+g+N>q&&k.length){if(k[k.length-1].isWhitespace){var n=[];N=-b}else for(var m=k.length;m--;)if(0===m&&"break-word"===A){n=[];N=-b;break}else if(k[m].isWhitespace){n=k.splice(m+1);k=n[0].x;N-=k;for(m=0;m<n.length;m++)n[m].x-=k;break}n&&(J.isSoftWrapped=!0,J={glyphs:n,width:0},O.push(J),u=q)}J.glyphs.push({glyphObj:a,x:b+N,y:0,width:g,char:d,charIndex:c,isWhitespace:h,isEmpty:a.xMin===a.xMax||a.yMin===a.yMax,atlasInfo:null});
"\n"===d&&(J={glyphs:[],width:0},O.push(J),N=-(b+g))});O.forEach(function(a){for(var b=a.glyphs,c=b.length;c--;){var d=b[c];if(!d.isWhitespace){a.width=d.x+d.width;a.width>u&&(u=a.width);break}}});if(!c){var G=[],L=-(k+K);E&&(r=new Float32Array(3*e.length));var H=-1;O.forEach(function(b){var c=b.glyphs,d=b.width;if(c.length){var e=0,f=0;if("center"===v)e=(u-d)/2;else if("right"===v)e=u-d;else if("justify"===v)for(var k=c.length;k--;)if(!c[k].isWhitespace){for(;k--;)c[k].isWhitespace&&f++;break}k=
0;for(var n=c.length;k<n;k++){var l=c[k];e&&(l.x+=e);l.y=L;if(l.isWhitespace&&"justify"===v&&b.isSoftWrapped){var p=(u-d)/f;e+=p;l.width+=p}if(E){p=l.charIndex;r[3*p]=l.x;r[3*p+1]=l.x+l.width;for(r[3*p+2]=l.y+M;1<p-H;)r[3*(H+1)]=r[3*H+1],r[3*(H+1)+1]=r[3*H+1],r[3*(H+1)+2]=r[3*H+2],H++;H=p}if(!l.isWhitespace&&!l.isEmpty){p=l.glyphObj;var q=a.glyphs[p.index];q||(q=g(p),q.atlasIndex=a.glyphCount++,h||(h=[]),h.push(q),q=a.glyphs[p.index]={atlasIndex:q.atlasIndex,glyphObj:p,renderingBounds:q.renderingBounds});
l.atlasInfo=q;G.push(l)}}}L-=m});var P=0,Q=0;z&&(z[0]&&(P=-u*z[0]),z[1]&&(Q=O.length*m*z[1]));if(E&&(P||Q))for(d=0,B=r.length;d<B;d+=3)r[d]+=P,r[d+1]+=P,r[d+2]+=Q;l=new Float32Array(4*G.length);p=new Float32Array(G.length);t=[Infinity,Infinity,-Infinity,-Infinity];G.forEach(function(a,b){var c=a.atlasInfo,d=c.renderingBounds;c=c.atlasIndex;var e=l[4*b]=a.x+d[0]*I+P,f=l[4*b+1]=a.y+d[1]*I+Q,g=l[4*b+2]=a.x+d[2]*I+P;a=l[4*b+3]=a.y+d[3]*I+Q;e<t[0]&&(t[0]=e);f<t[1]&&(t[1]=f);g>t[2]&&(t[2]=g);a>t[3]&&(t[3]=
a);p[b]=c})}b({glyphBounds:l,glyphAtlasIndices:p,caretPositions:r,caretHeight:C,totalBounds:t,totalBlockSize:[u,O.length*m],newGlyphSDFs:h})})}var f=b.defaultFontUrl,h=Object.create(null);return{process:e,measure:function(a,b){e(a,function(a){b({width:a.totalBlockSize[0],height:a.totalBlockSize[1]})},{metricsOnly:!0})},loadFont:c}}],init:function(m,g,b,a,c){g=a({sdfTextureSize:m.sdfGlyphSize,sdfDistancePercent:g});return c(b,g,{defaultFontUrl:m.defaultFontURL})}});var aa=M.defineWorkerModule({dependencies:[G,
M.ThenableWorkerModule],init:function(m,g){return function(b){var a=new g;m.process(b,a.resolve);return a}},getTransferables:function(m){var g=[m.glyphBounds.buffer,m.glyphAtlasIndices.buffer];m.caretPositions&&g.push(m.caretPositions.buffer);m.newGlyphSDFs&&m.newGlyphSDFs.forEach(function(b){g.push(b.textureData.buffer)});return g}}),ca=(new z.PlaneBufferGeometry(1,1)).translate(.5,.5,0),da=new z.Vector3,L=function(m){function g(){m.call(this);this.copy(ca);this.boundingSphere=new z.Sphere}m&&(g.__proto__=
m);g.prototype=Object.create(m&&m.prototype);g.prototype.constructor=g;g.prototype.computeBoundingSphere=function(){};g.prototype.updateGlyphs=function(b,a,c){U(this,"aTroikaGlyphBounds",b,4);U(this,"aTroikaGlyphIndex",a,1);this.maxInstancedCount=a.length;b=this.boundingSphere;b.center.set((c[0]+c[2])/2,(c[1]+c[3])/2,0);b.radius=b.center.distanceTo(da.set(c[0],c[1],0))};return g}(z.InstancedBufferGeometry);L.prototype.setAttribute||(L.prototype.setAttribute=function(m,g){this.attributes[m]=g;return this});
var V=new z.MeshBasicMaterial({color:16777215,side:z.DoubleSide,transparent:!0}),ea=new z.Matrix4,W=new z.Mesh((new z.PlaneBufferGeometry(1,1)).translate(.5,.5,0),V),X=function(m){function g(a){a=new L;m.call(this,a,null);this.text="";this.font=this.anchor=null;this.fontSize=.1;this.letterSpacing=0;this.lineHeight="normal";this.maxWidth=Infinity;this.overflowWrap="normal";this.textAlign="left";this.whiteSpace="normal";this.color=this.material=null;this.depthOffset=0;this.clipRect=null;this.debugSDF=
!1}m&&(g.__proto__=m);g.prototype=Object.create(m&&m.prototype);g.prototype.constructor=g;var b={textRenderInfo:{configurable:!0},material:{configurable:!0},customDepthMaterial:{configurable:!0},customDistanceMaterial:{configurable:!0}};g.prototype.sync=function(a){var b=this;this._needsSync&&(this._needsSync=!1,this._isSyncing?(this._queuedSyncs||(this._queuedSyncs=[])).push(a):(this._isSyncing=!0,Z({text:this.text,font:this.font,fontSize:this.fontSize,letterSpacing:this.letterSpacing,lineHeight:this.lineHeight,
maxWidth:this.maxWidth,textAlign:this.textAlign,whiteSpace:this.whiteSpace,overflowWrap:this.overflowWrap,anchor:this.anchor,includeCaretPositions:!0},function(c){b._isSyncing=!1;b._textRenderInfo=c;b.geometry.updateGlyphs(c.glyphBounds,c.glyphAtlasIndices,c.totalBounds);var d=b._queuedSyncs;d&&(b._queuedSyncs=null,b._needsSync=!0,b.sync(function(){d.forEach(function(a){return a&&a()})}));a&&a()})))};g.prototype.onBeforeRender=function(){this.sync();this._prepareMaterial()};g.prototype.dispose=function(){this.geometry.dispose()};
b.textRenderInfo.get=function(){return this._textRenderInfo||null};b.material.get=function(){var a=this._derivedMaterial,b=this._baseMaterial||V;a&&a.baseMaterial===b||(a&&a.dispose(),a=this._derivedMaterial=ba(b),b.addEventListener("dispose",function e(){b.removeEventListener("dispose",e);a.dispose()}));return a};b.material.set=function(a){this._baseMaterial=a};b.customDepthMaterial.get=function(){return this._updateLayoutUniforms(this.material.getDepthMaterial())};b.customDistanceMaterial.get=function(){return this._updateLayoutUniforms(this.material.getDistanceMaterial())};
g.prototype._prepareMaterial=function(){var a=this._derivedMaterial;this._updateLayoutUniforms(a);a.uniforms.uTroikaSDFDebug.value=!!this.debugSDF;a.polygonOffset=!!this.depthOffset;a.polygonOffsetFactor=a.polygonOffsetUnits=this.depthOffset||0;var b=this.color;null!=b&&a.color&&a.color.isColor&&b!==a._troikaColor&&a.color.set(a._troikaColor=b)};g.prototype._updateLayoutUniforms=function(a){var b=this.textRenderInfo,d=a.uniforms;if(b){var e=b.sdfTexture,f=b.totalBounds;d.uTroikaSDFTexture.value=e;
d.uTroikaSDFTextureSize.value.set(e.image.width,e.image.height);d.uTroikaSDFGlyphSize.value=b.sdfGlyphSize;d.uTroikaSDFMinDistancePct.value=b.sdfMinDistancePercent;d.uTroikaTotalBounds.value.fromArray(f);(b=this.clipRect)&&Array.isArray(b)&&4===b.length?d.uTroikaClipRect.value.set(Math.max(f[0],b[0]),Math.max(f[1],b[1]),Math.min(f[2],b[2]),Math.min(f[3],b[3])):d.uTroikaClipRect.value.fromArray(f)}return a};g.prototype.raycast=function(a,b){var c=this.textRenderInfo;c&&(c=c.totalBounds,W.matrixWorld.multiplyMatrices(this.matrixWorld,
ea.set(c[2]-c[0],0,0,c[0],0,c[3]-c[1],0,c[1],0,0,1,0,0,0,0,1)),W.raycast(a,b))};Object.defineProperties(g.prototype,b);return g}(z.Mesh);"font fontSize letterSpacing lineHeight maxWidth overflowWrap text textAlign whiteSpace anchor".split(" ").forEach(function(m){var g="_private_"+m;Object.defineProperty(X.prototype,m,{get:function(){return this[g]},set:"anchor"===m?function(b){JSON.stringify(b)!==JSON.stringify(this[g])&&(this[g]=b,this._needsSync=!0)}:function(b){b!==this[g]&&(this[g]=b,this._needsSync=
!0)}})});D.GlyphsGeometry=L;D.TextMesh=X;D.configureTextBuilder=function(m){R(K,m)};D.fontProcessorWorkerModule=G;Object.defineProperty(D,"__esModule",{value:!0})});
{
"name": "troika-3d-text",
"version": "0.15.7",
"version": "0.16.0",
"description": "Troika 3D Text",

@@ -18,5 +18,5 @@ "author": "Jason Johnston <jason.johnston@protectwise.com>",

"dependencies": {
"troika-3d": "^0.15.7",
"troika-three-utils": "^0.15.7",
"troika-worker-utils": "^0.15.6"
"troika-3d": "^0.16.0",
"troika-three-utils": "^0.16.0",
"troika-worker-utils": "^0.16.0"
},

@@ -31,3 +31,3 @@ "devDependencies": {

},
"gitHead": "603e2abc9959e173ebdd9224999384f89ce22e15"
"gitHead": "b17e3967b2166f102cabc6cd4bf46f5a725a8910"
}

@@ -116,2 +116,10 @@ # `troika-3d-text`

#### `depthOffset`
This is a shortcut for setting the material's [`polygonOffset` and related properties](https://threejs.org/docs/#api/en/materials/Material.polygonOffset), which can be useful in preventing z-fighting when this text is laid on top of another plane in the scene. Positive numbers are further from the camera, negatives closer.
Be aware that while this can help with z-fighting, it does not affect the rendering order; if the text renders before the content behind it, you may see antialiasing pixels that appear too dark or light. You may need to also change the text mesh's `renderOrder`, or set its `z` position a fraction closer to the camera, to ensure the text renders after background objects.
Default: `0`
#### `font`

@@ -118,0 +126,0 @@

import { Object3DFacade } from 'troika-3d'
import { TextMesh } from '../three/TextMesh.js'
import SelectionManagerFacade from './SelectionManagerFacade'
// Properties that will simply be forwarded to the TextMesh:

@@ -34,2 +34,19 @@ const TEXT_MESH_PROPS = [

super(parent, mesh)
/* TODO mirroring to DOM...?
const el = this._domEl = document.createElement('section')
el.style = 'position:fixed;left:-99px;overflow:hidden;width:10px;height:10px;'
document.body.appendChild(el) //should insert into local element
*/
this.selectable = false
this.selectionStart = this.selectionEnd = -1
this._afterSync = () => {
if (!this.isDestroying) {
mesh.geometry.boundingSphere.version++
this.afterUpdate()
this.notifyWorld('needsRender')
}
}
}

@@ -42,13 +59,67 @@

})
textMesh.sync(() => {
if (!this.isDestroying) {
textMesh.geometry.boundingSphere.version++
this.notifyWorld('needsRender')
}
})
textMesh.sync(this._afterSync)
super.afterUpdate()
if (this.text !== this._prevText) {
// TODO mirror to DOM... this._domEl.textContent = this.text
// Clear selection when text changes
this.selectionStart = this.selectionEnd = -1
this._prevText = this.text
}
this._updateSelection()
}
_updateSelection() {
const {selectable, selectionStart, selectionEnd} = this
let selFacade = this._selectionFacade
if (selectable !== this._selectable) {
this._selectable = selectable
if (selectable) {
selFacade = this._selectionFacade = new SelectionManagerFacade(this, (start, end) => {
this.selectionStart = start
this.selectionEnd = end
this._updateSelection()
this.notifyWorld('needsRender')
})
} else {
if (selFacade) {
selFacade.destructor()
selFacade = this._selectionFacade = null
}
this.selectionStart = this.selectionEnd = -1
}
}
if (selFacade) {
selFacade.textRenderInfo = this.threeObject.textRenderInfo
selFacade.selectionStart = selectionStart
selFacade.selectionEnd = selectionEnd
selFacade.renderOrder = this.renderOrder
selFacade.afterUpdate()
}
/* TODO update selection in DOM...
const {selectionStart, selectionEnd} = this
if (selectionStart !== this._prevSelStart || selectionEnd !== this._prevSelEnd) {
this._prevSelStart = selectionStart
this._prevSelEnd = selectionEnd
const sel = document.getSelection()
sel.removeAllRanges()
if (this.selectable && selectionStart > -1 && selectionEnd > selectionStart) {
const range = document.createRange()
range.setStart(this._domEl.firstChild, this.selectionStart)
range.setEnd(this._domEl.firstChild, this.selectionEnd)
sel.addRange(range)
}
}
*/
}
destructor() {
this.threeObject.dispose()
//this._domEl.parentNode.removeChild(this._domEl)
if (this._selectionFacade) {
this._selectionFacade.destructor()
}
super.destructor()

@@ -55,0 +126,0 @@ }

@@ -37,3 +37,2 @@ /**

index: otGlyph.index,
unicode: otGlyph.unicode,
advanceWidth: otGlyph.advanceWidth,

@@ -40,0 +39,0 @@ xMin: otGlyph.xMin,

@@ -31,45 +31,49 @@ /**

const glyphIndices = Typr.U.stringToGlyphs(typrFont, text)
let charIndex = 0
glyphIndices.forEach(glyphIndex => {
if (glyphIndex === -1) return //Typr leaves -1s in the array after ligature substitution
// Typr returns a glyph index per string codepoint, with -1s in place of those that
// were omitted due to ligature substitution. So we can track original index in the
// string via simple increment, and skip everything else when seeing a -1.
if (glyphIndex !== -1) {
let glyphObj = glyphMap[glyphIndex]
if (!glyphObj) {
// !!! NOTE: Typr doesn't expose a public accessor for the glyph data, so this just
// copies how it parses that data in Typr.U._drawGlyf -- this may be fragile.
const typrGlyph = Typr.glyf._parseGlyf(typrFont, glyphIndex) || {xMin: 0, xMax: 0, yMin: 0, yMax: 0}
const {cmds, crds} = Typr.U.glyphToPath(typrFont, glyphIndex)
let glyphObj = glyphMap[glyphIndex]
if (!glyphObj) {
// !!! NOTE: Typr doesn't expose a public accessor for the glyph data, so this just
// copies how it parses that data in Typr.U._drawGlyf -- this may be fragile.
const typrGlyph = Typr.glyf._parseGlyf(typrFont, glyphIndex) || {xMin: 0, xMax: 0, yMin: 0, yMax: 0}
const {cmds, crds} = Typr.U.glyphToPath(typrFont, glyphIndex)
glyphObj = glyphMap[glyphIndex] = {
index: glyphIndex,
unicode: getUnicodeForGlyph(typrFont, glyphIndex),
advanceWidth: typrFont.hmtx.aWidth[glyphIndex],
xMin: typrGlyph.xMin,
yMin: typrGlyph.yMin,
xMax: typrGlyph.xMax,
yMax: typrGlyph.yMax,
pathCommandCount: cmds.length,
forEachPathCommand(callback) {
let argsIndex = 0
const argsArray = []
for (let i = 0, len = cmds.length; i < len; i++) {
const numArgs = cmdArgLengths[cmds[i]]
argsArray.length = 1 + numArgs
argsArray[0] = cmds[i]
for (let j = 1; j <= numArgs; j++) {
argsArray[j] = crds[argsIndex++]
glyphObj = glyphMap[glyphIndex] = {
index: glyphIndex,
advanceWidth: typrFont.hmtx.aWidth[glyphIndex],
xMin: typrGlyph.xMin,
yMin: typrGlyph.yMin,
xMax: typrGlyph.xMax,
yMax: typrGlyph.yMax,
pathCommandCount: cmds.length,
forEachPathCommand(callback) {
let argsIndex = 0
const argsArray = []
for (let i = 0, len = cmds.length; i < len; i++) {
const numArgs = cmdArgLengths[cmds[i]]
argsArray.length = 1 + numArgs
argsArray[0] = cmds[i]
for (let j = 1; j <= numArgs; j++) {
argsArray[j] = crds[argsIndex++]
}
callback.apply(null, argsArray)
}
callback.apply(null, argsArray)
}
}
}
}
callback.call(null, glyphObj, glyphX)
callback.call(null, glyphObj, glyphX, charIndex)
if (glyphObj.advanceWidth) {
glyphX += glyphObj.advanceWidth * fontScale
if (glyphObj.advanceWidth) {
glyphX += glyphObj.advanceWidth * fontScale
}
if (letterSpacing) {
glyphX += letterSpacing * fontSize
}
}
if (letterSpacing) {
glyphX += letterSpacing * fontSize
}
charIndex += (text.codePointAt(charIndex) > 0xffff ? 2 : 1)
})

@@ -83,52 +87,2 @@ return glyphX

function getUnicodeForGlyph(typrFont, glyphIndex) {
let glyphToUnicodeMap = typrFont.glyphToUnicodeMap
if (!glyphToUnicodeMap) {
glyphToUnicodeMap = typrFont.glyphToUnicodeMap = Object.create(null)
// NOTE: this logic for traversing the cmap table formats follows that in Typr.U.codeToGlyph
const cmap = typrFont.cmap;
let tableIndex = -1
if (cmap.p0e4 != null) tableIndex = cmap.p0e4
else if (cmap.p3e1 != null) tableIndex = cmap.p3e1
else if (cmap.p1e0 != null) tableIndex = cmap.p1e0
else if (cmap.p0e3 != null) tableIndex = cmap.p0e3
if (tableIndex === -1) {
throw "no familiar platform and encoding!"
}
const table = cmap.tables[tableIndex];
if (table.format === 0) {
for (let code = 0; code < table.map.length; code++) {
glyphToUnicodeMap[table.map[code]] = code
}
}
else if (table.format === 4) {
const startCodes = table.startCount
const endCodes = table.endCount
for (let i = 0; i < startCodes.length; i++) {
for (let code = startCodes[i]; code <= endCodes[i]; code++) {
glyphToUnicodeMap[Typr.U.codeToGlyph(typrFont, code)] = code
}
}
}
else if (table.format === 12)
{
table.groups.forEach(([startCharCode, endCharCode, startGlyphID]) => {
let glyphId = startGlyphID
for (let code = startCharCode; code <= endCharCode; code++) {
glyphToUnicodeMap[glyphId++] = code
}
})
}
else {
throw "unknown cmap table format " + table.format
}
}
return glyphToUnicodeMap[glyphIndex] || 0
}
return function parse(buffer) {

@@ -135,0 +89,0 @@ // Look to see if we have a WOFF file and convert it if so:

@@ -18,3 +18,2 @@ /**

* index: number,
* unicode: number,
* advanceWidth: number,

@@ -167,3 +166,4 @@ * xMin: number,

overflowWrap='normal',
anchor
anchor,
includeCaretPositions=false
},

@@ -173,2 +173,8 @@ callback,

) {
// Ensure newlines are normalized
if (text.indexOf('\r') > -1) {
console.warn('FontProcessor.process: got text with \\r chars; normalizing to \\n')
text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n')
}
getSdfAtlas(font, atlas => {

@@ -179,11 +185,12 @@ const fontObj = atlas.fontObj

let glyphBounds = null
let glyphIndices = null
let glyphAtlasIndices = null
let caretPositions = null
let totalBounds = null
let lineCount = 0
let maxLineWidth = 0
let canWrap = whiteSpace !== 'nowrap'
const {ascender, descender, unitsPerEm} = fontObj
// Find conversion between native font units and fontSize units; this will already be done
// for the gx/gy values below but everything else we'll need to convert
const fontSizeMult = fontSize / fontObj.unitsPerEm
const fontSizeMult = fontSize / unitsPerEm

@@ -193,3 +200,3 @@ // Determine appropriate value for 'normal' line height based on the font's actual metrics

if (lineHeight === 'normal') {
lineHeight = (fontObj.ascender - fontObj.descender) / fontObj.unitsPerEm
lineHeight = (ascender - descender) / unitsPerEm
}

@@ -199,78 +206,85 @@

lineHeight = lineHeight * fontSize
const halfLeading = (lineHeight - (fontObj.ascender - fontObj.descender) * fontSizeMult) / 2
const halfLeading = (lineHeight - (ascender - descender) * fontSizeMult) / 2
const caretHeight = Math.min(lineHeight, (ascender - descender) * fontSizeMult)
const caretBottomOffset = (ascender + descender) / 2 * fontSizeMult - caretHeight / 2
// Split by hard line breaks
const lineBlocks = text.split(/\r?\n/).map(text => {
let lineXOffset = 0
// Distribute glyphs into lines based on wrapping
let lineXOffset = 0
let currentLine = {glyphs: [], width: 0}
const lines = [currentLine]
fontObj.forEachGlyph(text, fontSize, letterSpacing, (glyphObj, glyphX, charIndex) => {
const char = text.charAt(charIndex)
const glyphWidth = glyphObj.advanceWidth * fontSizeMult
const isWhitespace = !!char && /\s/.test(char)
const curLineGlyphs = currentLine.glyphs
let nextLineGlyphs
// Distribute glyphs into lines based on wrapping
let currentLine = []
const lines = [currentLine]
fontObj.forEachGlyph(text, fontSize, letterSpacing, (glyphObj, glyphX) => {
const charCode = glyphObj.unicode
const char = typeof charCode === 'number' && String.fromCharCode(charCode)
const glyphWidth = glyphObj.advanceWidth * fontSizeMult
const isWhitespace = !!char && /\s/.test(char)
// If a non-whitespace character overflows the max width, we need to wrap
if (canWrap && hasMaxWidth && !isWhitespace && glyphX + glyphWidth + lineXOffset > maxWidth && currentLine.length) {
// If it's the first char after a whitespace, start a new line
let nextLine
if (currentLine[currentLine.length - 1].isWhitespace) {
nextLine = []
lineXOffset = -glyphX
} else {
// Back up looking for a whitespace character to wrap at
for (let i = currentLine.length; i--;) {
// If we got the start of the line there's no soft break point; make hard break if overflowWrap='break-word'
if (i === 0 && overflowWrap==='break-word') {
nextLine = []
lineXOffset = -glyphX
break
// If a non-whitespace character overflows the max width, we need to soft-wrap
if (canWrap && hasMaxWidth && !isWhitespace && glyphX + glyphWidth + lineXOffset > maxWidth && curLineGlyphs.length) {
// If it's the first char after a whitespace, start a new line
if (curLineGlyphs[curLineGlyphs.length - 1].isWhitespace) {
nextLineGlyphs = []
lineXOffset = -glyphX
} else {
// Back up looking for a whitespace character to wrap at
for (let i = curLineGlyphs.length; i--;) {
// If we got the start of the line there's no soft break point; make hard break if overflowWrap='break-word'
if (i === 0 && overflowWrap === 'break-word') {
nextLineGlyphs = []
lineXOffset = -glyphX
break
}
// Found a soft break point; move all chars since it to a new line
else if (curLineGlyphs[i].isWhitespace) {
nextLineGlyphs = curLineGlyphs.splice(i + 1)
const adjustX = nextLineGlyphs[0].x
lineXOffset -= adjustX
for (let j = 0; j < nextLineGlyphs.length; j++) {
nextLineGlyphs[j].x -= adjustX
}
// Found a soft break point; move all chars since it to a new line
else if (currentLine[i].isWhitespace) {
nextLine = currentLine.splice(i + 1)
const adjustX = nextLine[0].x
lineXOffset -= adjustX
for (let j = 0; j < nextLine.length; j++) {
nextLine[j].x -= adjustX
}
break
}
break
}
}
if (nextLine) {
// Strip any trailing whitespace characters from the prior line so they don't affect line length
while (currentLine[currentLine.length - 1].isWhitespace) {
currentLine.pop()
}
lines.push(currentLine = nextLine)
maxLineWidth = maxWidth
}
}
if (nextLineGlyphs) {
currentLine.isSoftWrapped = true
currentLine = {glyphs: nextLineGlyphs, width: 0}
lines.push(currentLine)
maxLineWidth = maxWidth //after soft wrapping use maxWidth as calculated width
}
}
currentLine.push({
glyphObj,
x: glyphX + lineXOffset,
y: 0, //added later
width: glyphWidth,
char: char,
isWhitespace,
isEmpty: glyphObj.xMin === glyphObj.xMax || glyphObj.yMin === glyphObj.yMax,
atlasInfo: null //added later
})
currentLine.glyphs.push({
glyphObj,
x: glyphX + lineXOffset,
y: 0, //added later
width: glyphWidth,
char: char,
charIndex,
isWhitespace,
isEmpty: glyphObj.xMin === glyphObj.xMax || glyphObj.yMin === glyphObj.yMax,
atlasInfo: null //added later
})
// Find max block width after wrapping
for (let i = 0; i < lines.length && maxLineWidth < maxWidth; i++) {
const lineGlyphs = lines[i]
if (lineGlyphs.length) {
const lastChar = lineGlyphs[lineGlyphs.length - 1]
maxLineWidth = Math.max(maxLineWidth, lastChar.x + lastChar.width)
// Handle hard line breaks
if (char === '\n') {
currentLine = {glyphs: [], width: 0}
lines.push(currentLine)
lineXOffset = -(glyphX + glyphWidth)
}
})
// Calculate width of each line (excluding trailing whitespace) and maximum block width
lines.forEach(line => {
const lineGlyphs = line.glyphs
for (let i = lineGlyphs.length; i--;) {
const lastChar = lineGlyphs[i]
if (!lastChar.isWhitespace) {
line.width = lastChar.x + lastChar.width
if (line.width > maxLineWidth) {
maxLineWidth = line.width
}
return
}
}
lineCount += lines.length
return lines
})

@@ -283,68 +297,98 @@

let lineYOffset = -(fontSize + halfLeading)
lineBlocks.forEach(lines => {
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
const lineGlyphs = lines[lineIndex]
if (includeCaretPositions) {
caretPositions = new Float32Array(text.length * 3)
}
let prevCharIndex = -1
lines.forEach(line => {
const {glyphs:lineGlyphs, width:lineWidth} = line
// Ignore empty lines
if (lineGlyphs.length) {
// Find x offset for horizontal alignment
let lineXOffset = 0
const lastChar = lineGlyphs[lineGlyphs.length - 1]
const thisLineWidth = lastChar.x + lastChar.width
let whitespaceCount = 0
if (textAlign === 'center') {
lineXOffset = (maxLineWidth - thisLineWidth) / 2
} else if (textAlign === 'right') {
lineXOffset = maxLineWidth - thisLineWidth
} else if (textAlign === 'justify') {
// just count the whitespace characters, and we'll adjust the offsets per character in the next loop
for (let i = 0, len = lineGlyphs.length; i < len; i++) {
if (lineGlyphs[i].isWhitespace) {
whitespaceCount++
// Ignore empty lines
if (lineGlyphs.length) {
// Find x offset for horizontal alignment
let lineXOffset = 0
let whitespaceCount = 0
if (textAlign === 'center') {
lineXOffset = (maxLineWidth - lineWidth) / 2
} else if (textAlign === 'right') {
lineXOffset = maxLineWidth - lineWidth
} else if (textAlign === 'justify') {
// just count the non-trailing whitespace characters, and we'll adjust the offsets per
// character in the next loop
for (let i = lineGlyphs.length; i--;) {
if (!lineGlyphs[i].isWhitespace) {
while (i--) {
if (lineGlyphs[i].isWhitespace) {
whitespaceCount++
}
}
break
}
}
}
for (let i = 0, len = lineGlyphs.length; i < len; i++) {
const glyphInfo = lineGlyphs[i]
if (glyphInfo.isWhitespace && textAlign === 'justify' && lineIndex !== lines.length - 1) {
lineXOffset += (maxLineWidth - thisLineWidth) / whitespaceCount
for (let i = 0, len = lineGlyphs.length; i < len; i++) {
const glyphInfo = lineGlyphs[i]
// Apply position adjustments
if (lineXOffset) glyphInfo.x += lineXOffset
glyphInfo.y = lineYOffset
// Expand whitespaces for justify alignment
if (glyphInfo.isWhitespace && textAlign === 'justify' && line.isSoftWrapped) {
const adjust = (maxLineWidth - lineWidth) / whitespaceCount
lineXOffset += adjust
glyphInfo.width += adjust
}
// Add initial caret positions
if (includeCaretPositions) {
const {charIndex} = glyphInfo
caretPositions[charIndex * 3] = glyphInfo.x //left edge x
caretPositions[charIndex * 3 + 1] = glyphInfo.x + glyphInfo.width //right edge x
caretPositions[charIndex * 3 + 2] = glyphInfo.y + caretBottomOffset //common bottom y
// If we skipped any chars from the previous glyph (due to ligature subs), copy the
// previous glyph's info to those missing char indices. In the future we may try to
// use the font's LigatureCaretList table to get interior caret positions.
while (charIndex - prevCharIndex > 1) {
caretPositions[(prevCharIndex + 1) * 3] = caretPositions[prevCharIndex * 3 + 1]
caretPositions[(prevCharIndex + 1) * 3 + 1] = caretPositions[prevCharIndex * 3 + 1]
caretPositions[(prevCharIndex + 1) * 3 + 2] = caretPositions[prevCharIndex * 3 + 2]
prevCharIndex++
}
prevCharIndex = charIndex
}
if (!glyphInfo.isWhitespace && !glyphInfo.isEmpty) {
const glyphObj = glyphInfo.glyphObj
// Get atlas data for renderable glyphs
if (!glyphInfo.isWhitespace && !glyphInfo.isEmpty) {
const glyphObj = glyphInfo.glyphObj
// If we haven't seen this glyph yet, generate its SDF
let glyphAtlasInfo = atlas.glyphs[glyphObj.index]
if (!glyphAtlasInfo) {
const glyphSDFData = sdfGenerator(glyphObj)
// If we haven't seen this glyph yet, generate its SDF
let glyphAtlasInfo = atlas.glyphs[glyphObj.index]
if (!glyphAtlasInfo) {
const glyphSDFData = sdfGenerator(glyphObj)
// Assign this glyph the next available atlas index
glyphSDFData.atlasIndex = atlas.glyphCount++
// Assign this glyph the next available atlas index
glyphSDFData.atlasIndex = atlas.glyphCount++
// Queue it up in the response's newGlyphs list
if (!newGlyphs) newGlyphs = []
newGlyphs.push(glyphSDFData)
// Queue it up in the response's newGlyphs list
if (!newGlyphs) newGlyphs = []
newGlyphs.push(glyphSDFData)
// Store its metadata (not the texture) in our atlas info
glyphAtlasInfo = atlas.glyphs[glyphObj.index] = {
atlasIndex: glyphSDFData.atlasIndex,
glyphObj: glyphObj,
renderingBounds: glyphSDFData.renderingBounds
}
// Store its metadata (not the texture) in our atlas info
glyphAtlasInfo = atlas.glyphs[glyphObj.index] = {
atlasIndex: glyphSDFData.atlasIndex,
glyphObj: glyphObj,
renderingBounds: glyphSDFData.renderingBounds
}
glyphInfo.atlasInfo = glyphAtlasInfo
}
glyphInfo.atlasInfo = glyphAtlasInfo
// Apply position adjustments
if (lineXOffset) glyphInfo.x += lineXOffset
glyphInfo.y = lineYOffset
renderableGlyphs.push(glyphInfo)
}
renderableGlyphs.push(glyphInfo)
}
}
}
// Increment y offset for next line
lineYOffset -= lineHeight
}
// Increment y offset for next line
lineYOffset -= lineHeight
})

@@ -361,9 +405,18 @@

if (anchor[1]) {
anchorYOffset = lineCount * lineHeight * anchor[1]
anchorYOffset = lines.length * lineHeight * anchor[1]
}
}
// Adjust caret positions by anchoring offsets
if (includeCaretPositions && (anchorXOffset || anchorYOffset)) {
for (let i = 0, len = caretPositions.length; i < len; i += 3) {
caretPositions[i] += anchorXOffset
caretPositions[i + 1] += anchorXOffset
caretPositions[i + 2] += anchorYOffset
}
}
// Create the final output for the rendeable glyphs
glyphBounds = new Float32Array(renderableGlyphs.length * 4)
glyphIndices = new Float32Array(renderableGlyphs.length)
glyphAtlasIndices = new Float32Array(renderableGlyphs.length)
totalBounds = [INF, INF, -INF, -INF]

@@ -382,3 +435,3 @@ renderableGlyphs.forEach((glyphInfo, i) => {

glyphIndices[i] = atlasIndex
glyphAtlasIndices[i] = atlasIndex
})

@@ -388,7 +441,9 @@ }

callback({
glyphBounds,
glyphIndices,
totalBounds,
totalBlockSize: [maxLineWidth, lineCount * lineHeight],
newGlyphSDFs: newGlyphs
glyphBounds, //rendering quad bounds for each glyph [x1, y1, x2, y2]
glyphAtlasIndices, //atlas indices for each glyph
caretPositions, //x,y of bottom of cursor position before each char, plus one after last char
caretHeight, //height of cursor from bottom to top
totalBounds, //total rect including all glyphBounds; will be slightly larger than glyph edges due to SDF padding
totalBlockSize: [maxLineWidth, lines.length * lineHeight], //width and height of the text block; accurate for layout measurement
newGlyphSDFs: newGlyphs //if this request included any new SDFs for the atlas, they'll be included here
})

@@ -411,3 +466,3 @@ })

})
}, true)
}, {metricsOnly: true})
}

@@ -414,0 +469,0 @@

@@ -1,2 +0,2 @@

import { DataTexture, LinearFilter, LuminanceFormat } from 'three'
import { DataTexture, LinearFilter, LuminanceFormat, Vector2 } from 'three'
import { defineWorkerModule, ThenableWorkerModule } from 'troika-worker-utils'

@@ -13,3 +13,4 @@ import createSDFGenerator from './SDFGenerator.js'

defaultFontURL: 'https://fonts.gstatic.com/s/roboto/v18/KFOmCnqEu92Fr1Mu4mxM.woff', //Roboto Regular
sdfGlyphSize: 64
sdfGlyphSize: 64,
textureWidth: 2048
}

@@ -31,2 +32,8 @@ const linkEl = document.createElement('a') //for resolving relative URLs to absolute

* to 64 which is generally a good balance of size and quality.
* @param {Number} config.textureWidth - The width of the SDF texture; must be a power of 2. Defaults to
* 2048 which is a safe maximum texture dimension according to the stats at
* https://webglstats.com/webgl/parameter/MAX_TEXTURE_SIZE and should allow for a
* reasonably large number of glyphs (default glyph size of 64 and safe texture size of
* 2048^2 allows for 1024 glyphs.) This can be increased if you need to increase the
* glyph size and/or have an extraordinary number of glyphs.
*/

@@ -43,7 +50,2 @@ export function configureTextBuilder(config) {

/**
* How many glyphs the font's SDF texture should initially be created to hold.
*/
const SDF_INITIAL_GLYPH_COUNT = 64
/**
* The radial distance from glyph edges over which the SDF alpha will be calculated; if the alpha

@@ -70,8 +72,26 @@ * at distance:0 is 0.5, then the alpha at this distance will be zero. This is defined as a percentage

/**
* @typedef {object} TroikaTextRenderInfo - Format of the result from `getTextRenderInfo`.
* @property {DataTexture} sdfTexture
* @property {number} sdfGlyphSize
* @property {number} sdfMinDistancePercent
* @property {Float32Array} glyphBounds
* @property {Float32Array} glyphAtlasIndices
* @property {Float32Array} [caretPositions]
* @property {number} [caretHeight]
* @property {Array<number>} totalBounds
* @property {Array<number>} totalBlockSize
* @frozen
*/
/**
* @callback getTextRenderInfo~callback
* @param {TroikaTextRenderInfo} textRenderInfo
*/
/**
* Main entry point for requesting the data needed to render a text string with given font parameters.
* This is an asynchronous call, performing most of the logic in a web worker thread.
* @param args
* @param callback
* @param {object} args
* @param {getTextRenderInfo~callback} callback
*/

@@ -90,3 +110,3 @@ export function getTextRenderInfo(args, callback) {

// Init the atlas for this font if needed
const sdfGlyphSize = CONFIG.sdfGlyphSize
const {sdfGlyphSize, textureWidth} = CONFIG
let atlas = atlases[args.font]

@@ -96,5 +116,5 @@ if (!atlas) {

sdfTexture: new DataTexture(
new Uint8Array(sdfGlyphSize * sdfGlyphSize * SDF_INITIAL_GLYPH_COUNT),
new Uint8Array(sdfGlyphSize * textureWidth),
textureWidth,
sdfGlyphSize,
sdfGlyphSize * SDF_INITIAL_GLYPH_COUNT,
LuminanceFormat,

@@ -118,6 +138,5 @@ undefined,

const texImg = atlas.sdfTexture.image
const arrayOffset = atlasIndex * sdfGlyphSize * sdfGlyphSize
// Grow the texture by power of 2 if needed
while (arrayOffset > texImg.data.length - 1) {
while (texImg.data.length < (atlasIndex + 1) * sdfGlyphSize * sdfGlyphSize) {
const biggerArray = new Uint8Array(texImg.data.length * 2)

@@ -129,4 +148,13 @@ biggerArray.set(texImg.data)

// Insert the new glyph's data at the proper index
texImg.data.set(textureData, arrayOffset)
// Insert the new glyph's data into the full texture image at the correct offsets
const cols = texImg.width / sdfGlyphSize
for (let y = 0; y < sdfGlyphSize; y++) {
const srcStartIndex = y * sdfGlyphSize
const tgtStartIndex = texImg.width * sdfGlyphSize * Math.floor(atlasIndex / cols) //full rows
+ (atlasIndex % cols) * sdfGlyphSize //partial row
+ (y * texImg.width) //row within glyph
for (let x = 0; x < sdfGlyphSize; x++) {
texImg.data[tgtStartIndex + x] = textureData[srcStartIndex + x]
}
}
})

@@ -137,10 +165,13 @@ atlas.sdfTexture.needsUpdate = true

// Invoke callback with the text layout arrays and updated texture
callback({
callback(Object.freeze({
sdfTexture: atlas.sdfTexture,
sdfGlyphSize,
sdfMinDistancePercent: SDF_DISTANCE_PERCENT,
glyphBounds: result.glyphBounds,
glyphIndices: result.glyphIndices,
glyphAtlasIndices: result.glyphAtlasIndices,
caretPositions: result.caretPositions,
caretHeight: result.caretHeight,
totalBounds: result.totalBounds,
totalBlockSize: result.totalBlockSize
})
}))
})

@@ -190,3 +221,9 @@ }

// Mark array buffers as transferable to avoid cloning during postMessage
const transferables = [result.glyphBounds.buffer, result.glyphIndices.buffer]
const transferables = [
result.glyphBounds.buffer,
result.glyphAtlasIndices.buffer
]
if (result.caretPositions) {
transferables.push(result.caretPositions.buffer)
}
if (result.newGlyphSDFs) {

@@ -201,1 +238,25 @@ result.newGlyphSDFs.forEach(d => {

/*
window._dumpSDFs = function() {
Object.values(atlases).forEach(atlas => {
const imgData = atlas.sdfTexture.image.data
const canvas = document.createElement('canvas')
const {width, height} = atlas.sdfTexture.image
canvas.width = width
canvas.height = height
const ctx = canvas.getContext('2d')
ctx.fillStyle = '#fff'
ctx.fillRect(0, 0, width, height)
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
ctx.fillStyle = `rgba(0,0,0,${imgData[y * width + x]/255})`
ctx.fillRect(x, y, 1, 1)
}
}
const img = new Image()
img.src = canvas.toDataURL()
document.body.appendChild(img)
console.log(img)
})
}
*/

@@ -67,11 +67,11 @@ import {

* to be rendered, 4 entries for each glyph: x1,x2,y1,y1
* @param {Float32Array} glyphIndices - An array holding the index of each glyph within
* @param {Float32Array} glyphAtlasIndices - An array holding the index of each glyph within
* the SDF atlas texture.
* @param {Array} totalBounds - An array holding the [minX, minY, maxX, maxY] across all glyphs
*/
updateGlyphs(glyphBounds, glyphIndices, totalBounds) {
updateGlyphs(glyphBounds, glyphAtlasIndices, totalBounds) {
// Update the instance attributes
updateBufferAttr(this, glyphBoundsAttrName, glyphBounds, 4)
updateBufferAttr(this, glyphIndexAttrName, glyphIndices, 1)
this.maxInstancedCount = glyphIndices.length
updateBufferAttr(this, glyphIndexAttrName, glyphAtlasIndices, 1)
this.maxInstancedCount = glyphAtlasIndices.length

@@ -78,0 +78,0 @@ // Update the boundingSphere based on the total bounds

import { createDerivedMaterial } from 'troika-three-utils'
import { Vector4 } from 'three'
import { Vector2, Vector4 } from 'three'
// language=GLSL
const VERTEX_DEFS = `
uniform float uTroikaGlyphVSize;
uniform vec2 uTroikaSDFTextureSize;
uniform float uTroikaSDFGlyphSize;
uniform vec4 uTroikaTotalBounds;
attribute vec4 aTroikaGlyphBounds;
attribute float aTroikaGlyphIndex;
varying vec2 vTroikaSDFTextureUV;
varying vec2 vTroikaGlyphUV;

@@ -16,7 +18,10 @@ varying vec3 vTroikaLocalPos;

const VERTEX_TRANSFORM = `
vTroikaGlyphUV = vec2(
position.x,
uTroikaGlyphVSize * (aTroikaGlyphIndex + position.y)
);
vTroikaGlyphUV = vec2(position);
vec2 colsAndRows = uTroikaSDFTextureSize / uTroikaSDFGlyphSize;
vTroikaSDFTextureUV = vec2(
mod(aTroikaGlyphIndex, colsAndRows.x) + position.x,
floor(aTroikaGlyphIndex / colsAndRows.x) + position.y
) * uTroikaSDFGlyphSize / uTroikaSDFTextureSize;
position = vec3(

@@ -40,4 +45,4 @@ mix(aTroikaGlyphBounds.x, aTroikaGlyphBounds.z, position.x),

uniform bool uTroikaSDFDebug;
uniform float uTroikaGlyphVSize;
uniform vec4 uTroikaClipRect;
varying vec2 vTroikaSDFTextureUV;
varying vec2 vTroikaGlyphUV;

@@ -62,3 +67,3 @@ varying vec3 vTroikaLocalPos;

float troikaGetTextAlpha() {
float troikaSDFValue = texture2D(uTroikaSDFTexture, vTroikaGlyphUV).r;
float troikaSDFValue = texture2D(uTroikaSDFTexture, vTroikaSDFTextureUV).r;

@@ -78,4 +83,4 @@ #if defined(IS_DEPTH_MATERIAL) || defined(IS_DISTANCE_MATERIAL)

0.5 * min(
fwidth(vTroikaGlyphUV.x),
fwidth(vTroikaGlyphUV.y / uTroikaGlyphVSize)
fwidth(vTroikaGlyphUV.x),
fwidth(vTroikaGlyphUV.y)
)

@@ -117,4 +122,5 @@ ) / uTroikaSDFMinDistancePct;

uTroikaSDFTexture: {value: null},
uTroikaSDFTextureSize: {value: new Vector2()},
uTroikaSDFGlyphSize: {value: 0},
uTroikaSDFMinDistancePct: {value: 0},
uTroikaGlyphVSize: {value: 0},
uTroikaTotalBounds: {value: new Vector4()},

@@ -121,0 +127,0 @@ uTroikaClipRect: {value: new Vector4()},

@@ -6,5 +6,3 @@ import {

MeshBasicMaterial,
PlaneBufferGeometry,
Plane,
Vector3
PlaneBufferGeometry
} from 'three'

@@ -23,7 +21,3 @@ import { GlyphsGeometry } from './GlyphsGeometry.js'

const noclip = Object.freeze([-Infinity, -Infinity, Infinity, Infinity])
const tempMat4 = new Matrix4()
const tempPlane = new Plane()
const tempVec3 = new Vector3()

@@ -191,3 +185,4 @@ const raycastMesh = new Mesh(

overflowWrap: this.overflowWrap,
anchor: this.anchor
anchor: this.anchor,
includeCaretPositions: true //TODO parameterize
}, textRenderInfo => {

@@ -200,3 +195,3 @@ this._isSyncing = false

// Update the geometry attributes
this.geometry.updateGlyphs(textRenderInfo.glyphBounds, textRenderInfo.glyphIndices, textRenderInfo.totalBounds)
this.geometry.updateGlyphs(textRenderInfo.glyphBounds, textRenderInfo.glyphAtlasIndices, textRenderInfo.totalBounds)

@@ -243,2 +238,12 @@ // If we had extra sync requests queued up, kick it off

/**
* @property {TroikaTextRenderInfo|null} textRenderInfo
* @readonly
* The current processed rendering data for this TextMesh, returned by the TextBuilder after
* a `sync()` call. This will be `null` initially, and may be stale for a short period until
* the asynchrous `sync()` process completes.
*/
get textRenderInfo() {
return this._textRenderInfo || null
}

@@ -293,3 +298,3 @@ // Handler for automatically wrapping the base material with our upgrades. We do the wrapping

_updateLayoutUniforms(material) {
const textInfo = this._textRenderInfo
const textInfo = this.textRenderInfo
const uniforms = material.uniforms

@@ -299,4 +304,5 @@ if (textInfo) {

uniforms.uTroikaSDFTexture.value = sdfTexture
uniforms.uTroikaSDFTextureSize.value.set(sdfTexture.image.width, sdfTexture.image.height)
uniforms.uTroikaSDFGlyphSize.value = textInfo.sdfGlyphSize
uniforms.uTroikaSDFMinDistancePct.value = textInfo.sdfMinDistancePercent
uniforms.uTroikaGlyphVSize.value = sdfTexture.image.width / sdfTexture.image.height
uniforms.uTroikaTotalBounds.value.fromArray(totalBounds)

@@ -324,3 +330,3 @@

raycast(raycaster, intersects) {
const textInfo = this._textRenderInfo
const textInfo = this.textRenderInfo
if (textInfo) {

@@ -327,0 +333,0 @@ const bounds = textInfo.totalBounds

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display