/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../../../../request.js";import t from"../../../../core/pbf.js";class a{constructor(e){for(this._metrics=[],this._bitmaps=[];e.next();)switch(e.tag()){case 1:{const t=e.getMessage();for(;t.next();)switch(t.tag()){case 3:{const e=t.getMessage();let a,s,r,n,i,c,g;for(;e.next();)switch(e.tag()){case 1:a=e.getUInt32();break;case 2:s=e.getBytes();break;case 3:r=e.getUInt32();break;case 4:n=e.getUInt32();break;case 5:i=e.getSInt32();break;case 6:c=e.getSInt32();break;case 7:g=e.getUInt32();break;default:e.skip()}e.release(),a&&(this._metrics[a]={width:r,height:n,left:i,top:c,advance:g},this._bitmaps[a]=s);break}default:t.skip()}t.release();break}default:e.skip()}}getMetrics(e){return this._metrics[e]}getBitmap(e){return this._bitmaps[e]}}class s{constructor(){this._ranges=[]}getRange(e){return this._ranges[e]}addRange(e,t){this._ranges[e]=t}}class r{constructor(e){this._glyphInfo={},this._baseURL=e}getRange(s,r,n){const i=this._getFontStack(s);if(i.getRange(r))return Promise.resolve();const c=256*r,g=c+255,o=this._baseURL.replace("{fontstack}",s).replace("{range}",c+"-"+g);return e(o,{responseType:"array-buffer",...n}).then(e=>{i.addRange(r,new a(new t(new Uint8Array(e.data),new DataView(e.data))))})}async preloadASCIIRange(s){const r=this._getFontStack(s),n=0,i=255,c=this._baseURL.replace("{fontstack}",s).replace("{range}",n+"-"+i),g=await e(c,{responseType:"array-buffer"}),o=new a(new t(new Uint8Array(g.data),new DataView(g.data)));for(let e=n;e<=i;e++)r.getRange(e)||r.addRange(e,o)}getGlyph(e,t){const a=this._getFontStack(e);if(!a)return;const s=Math.floor(t/256),r=a.getRange(s);return r?{metrics:r.getMetrics(t),bitmap:r.getBitmap(t)}:void 0}_getFontStack(e){let t=this._glyphInfo[e];return t||(t=this._glyphInfo[e]=new s),t}}export{r as default};
