/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import{pt2px as t}from"../../core/screenUtils.js";function e(t){return`rgb(${t.slice(0,3).toString()})`}function i(t){return`rgba(${t.slice(0,3).toString()},${t[3]})`}class s{rasterizeText(t,s){this._textRasterizationCanvas||(this._textRasterizationCanvas=document.createElement("canvas"));const r=this._textRasterizationCanvas,o=r.getContext("2d");this._setFontProperties(o,s),this.parameters=s,this.textLines=t.split(/\r?\n/),this.lineHeight=this._computeLineHeight();const h=this._computeTextWidth(o,s),{decoration:a,weight:l}=s.font;this.lineThroughWidthOffset=a&&"line-through"===a?.1*this.lineHeight:0;const d=this.lineHeight*this.textLines.length;r.width=h+2*this.lineThroughWidthOffset,r.height=d,this.renderedLineHeight=Math.round(this.lineHeight*s.pixelRatio),this.renderedHaloSize=s.halo.size*s.pixelRatio,this.renderedWidth=h*s.pixelRatio,this.renderedHeight=d*s.pixelRatio,this.lineThroughWidthOffset*=s.pixelRatio,this.fillStyle=i(s.color),this.haloStyle=e(s.halo.color);const c=this.renderedLineHeight,g=this.renderedHaloSize;this._setFontProperties(o,s);const f=n(o.textAlign,this.renderedWidth)+g,u=g,p=g>0;let x=this.lineThroughWidthOffset,m=0;p&&this._renderHalo(o,f,u,x,m,s),m+=u,x+=f;for(const e of this.textLines)o.globalCompositeOperation="destination-out",o.fillStyle="rgb(0, 0, 0)",o.fillText(e,x,m),o.globalCompositeOperation="source-over",o.fillStyle=this.fillStyle,o.fillText(e,x,m),a&&"none"!==a&&this._renderDecoration(o,x,m,a,l),m+=c;const _=this.renderedWidth+2*this.lineThroughWidthOffset,H=this.renderedHeight,z=o.getImageData(0,0,_,H),w=new Uint8Array(z.data);if(s.premultiplyColors){let t;for(let e=0;e600)&&(i+=.3*t.measureText("w").width),i+=2*this.parameters.halo.size,Math.round(i)}_computeLineHeight(){let t=1.275*this.parameters.size;const e=this.parameters.font.decoration;return e&&"underline"===e&&(t*=1.3),Math.round(t+2*this.parameters.halo.size)}_renderDecoration(t,e,i,s,n){const r=.9*this.lineHeight,o="bold"===n?.06:"bolder"===n?.09:.04;switch(t.textAlign){case"center":e-=this.renderedWidth/2;break;case"right":e-=this.renderedWidth}const h=t.textBaseline;if("underline"===s)switch(h){case"top":i+=r;break;case"middle":i+=r/2}else if("line-through"===s)switch(h){case"top":i+=r/1.5;break;case"middle":i+=r/3}t.save(),t.beginPath(),t.strokeStyle=t.fillStyle,t.lineWidth=Math.ceil(r*o),t.moveTo(e-this.lineThroughWidthOffset,i),t.lineTo(e+this.renderedWidth+2*this.lineThroughWidthOffset,i),t.stroke(),t.restore()}}function n(t,e){return"center"===t?.5*e:"right"===t?e:0}const r=[];{const t=16;for(let e=0;e<360;e+=360/t)r.push([Math.cos(Math.PI*e/180),Math.sin(Math.PI*e/180)])}export{s as default};