UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 1.99 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import t from"../../../../config.js";import e from"../../../../request.js";import a from"../../../../core/pbf.js";class s{constructor(t){for(this._metrics=[],this._bitmaps=[];t.next();)switch(t.tag()){case 1:{const e=t.getMessage();for(;e.next();)switch(e.tag()){case 3:{const t=e.getMessage();let a,s,r,n,c,i,o;for(;t.next();)switch(t.tag()){case 1:a=t.getUInt32();break;case 2:s=t.getBytes();break;case 3:r=t.getUInt32();break;case 4:n=t.getUInt32();break;case 5:c=t.getSInt32();break;case 6:i=t.getSInt32();break;case 7:o=t.getUInt32();break;default:t.skip()}t.release(),a&&(this._metrics[a]={width:r,height:n,left:c,top:i,advance:o},this._bitmaps[a]=s);break}default:e.skip()}e.release();break}default:t.skip()}}getMetrics(t){return this._metrics[t]}getBitmap(t){return this._bitmaps[t]}}class r{constructor(){this._ranges=[]}getRange(t){return this._ranges[t]}addRange(t,e){this._ranges[t]=e}}class n{constructor(e){this._glyphInfo={},this._baseURL=e,this._woff2URL=`${t.fontsUrl}/woff2/{fontstack}.woff2`}async getRange(t,r,n){const c=this._getFontStack(t);if(c.getRange(r))return;const i=256*r,o=i+255,g=this._baseURL.replace("{fontstack}",t).replace("{range}",i+"-"+o);return e(g,{responseType:"array-buffer",...n}).then(t=>{c.addRange(r,new s(new a(new Uint8Array(t.data),new DataView(t.data))))})}async preloadASCIIRange(t){const r=this._getFontStack(t),n=0,c=255,i=this._baseURL.replace("{fontstack}",t).replace("{range}",n+"-"+c),o=await e(i,{responseType:"array-buffer"}),g=new s(new a(new Uint8Array(o.data),new DataView(o.data)));for(let e=n;e<=c;e++)r.getRange(e)||r.addRange(e,g)}getGlyph(t,e){const a=this._getFontStack(t);if(!a)return;const s=Math.floor(e/256),r=a.getRange(s);return r?{metrics:r.getMetrics(e),bitmap:r.getBitmap(e)}:void 0}woffURL(t){return this._woff2URL.replace("{fontstack}",t)}_getFontStack(t){let e=this._glyphInfo[t];return e||(e=this._glyphInfo[t]=new r),e}}export{n as default};