/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{isCachedFontFace as o,loadFont as t}from"../../../../core/fontUtils.js";import e from"../../../../core/Logger.js";import{pt2px as i}from"../../../../core/screenUtils.js";import{ZEROS as r}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";class n{constructor(o){this.definition=o,this.key=JSON.stringify(o),this.haloSize=Math.round(o.halo.size),this.textStyle=l(o.color),this.haloStyle=s(o.halo.color),this.backgroundStyle=0!==o.background.color[3]?l(o.background.color):null}fontString(o){const t=this.definition.font,e="sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji";return`${t.style} ${t.weight} ${o}px ${t.family}, ${e}`}setFontProperties(o,t){o.font=this.fontString(t),o.textAlign="left",o.textBaseline="alphabetic"}static async fromSymbol(s,l){const c=s?.material?.color?.toUnitRGBA()??r,f=null!=s.size?i(s.size):12,m=s.lineHeight,g=s.background?.color?.toUnitRGBA()??r,u={family:s.font?.family??"sans-serif",decoration:s.font?.decoration??"none",weight:s.font?.weight??"normal",style:s.font?.style??"normal"},d=s.halo,h=null!=d?.color&&d.size>0?{size:i(d.size),color:d.color.toUnitRGBA()}:{size:0,color:r},y=new n({color:c,size:f,background:{color:g,padding:null!=s.background?[.65*f,.5*f]:[0,0],borderRadius:null!=s.background?f*(6/16):0},lineSpacingFactor:m,font:u,halo:h,pixelRatio:l});if(s.font){let i=!1;const r=y.fontString(f);try{i=(await document.fonts.load(r)).some(t=>!o(t))}catch(b){e.getLogger("esri.views.3d.webgl-engine.lib.TextRenderParameters").warnOnce(`Failed to preload font '${r}'. Some text symbology may be rendered using the default browser font.`)}if(!i&&!a.has(s.font.family))try{await t(s.font)}catch(b){}}return y}}function s(o){return`rgb(${o.slice(0,3).map(o=>Math.floor(255*o)).toString()})`}function l(o){return`rgba(${o.slice(0,3).map(o=>Math.floor(255*o)).toString()},${o[3]})`}const a=new Set(["Arial","Times New Roman","Courier New","serif","sans-serif","monospace","cursive","fantasy","system-ui","ui-serif","ui-sans-serif","ui-monospace","ui-rounded","math","emoji","fangsong"]);export{n as TextRenderParameters};
