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