@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
6 lines (5 loc) • 2.32 kB
JavaScript
/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.33/esri/copyright.txt for details.
*/
import o from"../../../../Color.js";import{isCachedFontFace as t,loadFont as e}from"../../../../core/fontUtils.js";import i from"../../../../core/Logger.js";import{pt2px as r}from"../../../../core/screenUtils.js";import{ZEROS as n}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";class s{constructor(o){this.definition=o,this.key=JSON.stringify(o),this.haloSize=Math.round(o.halo.size),this.textStyle=a(o.color),this.haloStyle=l(o.halo.color),this.backgroundStyle=0!==o.background.color[3]?a(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(l,a){const f=l?.material?.color,m=o.toUnitRGBA(f)??n,g=null!=l.size?r(l.size):12,u=l.lineHeight,d=null!=l.background?o.toUnitRGBA(l.background.color):n,h={family:l.font?.family??"sans-serif",decoration:l.font?.decoration??"none",weight:l.font?.weight??"normal",style:l.font?.style??"normal"},y=l.halo,b=null!=y?.color&&y.size>0?{size:r(y.size),color:o.toUnitRGBA(y.color)}:{size:0,color:n},p=new s({color:m,size:g,background:{color:d,padding:null!=l.background?[.65*g,.5*g]:[0,0],borderRadius:null!=l.background?g*(6/16):0},lineSpacingFactor:u,font:h,halo:b,pixelRatio:a});if(l.font){let o=!1;const r=p.fontString(g);try{o=(await document.fonts.load(r)).some((o=>!t(o)))}catch(S){i.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(!o&&!c.has(l.font.family))try{await e(l.font)}catch(S){}}return p}}function l(o){return`rgb(${o.slice(0,3).map((o=>Math.floor(255*o))).toString()})`}function a(o){return`rgba(${o.slice(0,3).map((o=>Math.floor(255*o))).toString()},${o[3]})`}const c=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{s as TextRenderParameters};