@pixi/text-bitmap
Advanced tools
Comparing version 7.0.0-alpha to 7.0.0-alpha.2
/*! | ||
* @pixi/text-bitmap - v7.0.0-alpha | ||
* Compiled Fri, 09 Sep 2022 16:09:18 UTC | ||
* @pixi/text-bitmap - v7.0.0-alpha.2 | ||
* Compiled Sun, 18 Sep 2022 20:45:04 UTC | ||
* | ||
@@ -341,2 +341,3 @@ * @pixi/text-bitmap is licensed under the MIT License. | ||
pageTextures[id].baseTexture.alphaMode = core.ALPHA_MODES.NO_PREMULTIPLIED_ALPHA; | ||
pageTextures[id].baseTexture.mipmap = core.MIPMAP_MODES.OFF; | ||
} | ||
@@ -841,3 +842,3 @@ } | ||
for (const mesh of this._activePagesMeshData) { | ||
mesh.mesh.shader.uniforms.uFWidth = worldScale * distanceFieldRange * fontScale * resolution; | ||
mesh.mesh.shader.uniforms.uFWidth = Math.min(worldScale * distanceFieldRange * fontScale * resolution, 1); | ||
} | ||
@@ -844,0 +845,0 @@ } |
"use strict";/*! | ||
* @pixi/text-bitmap - v7.0.0-alpha | ||
* Compiled Fri, 09 Sep 2022 16:09:18 UTC | ||
* @pixi/text-bitmap - v7.0.0-alpha.2 | ||
* Compiled Sun, 18 Sep 2022 20:45:04 UTC | ||
* | ||
* @pixi/text-bitmap is licensed under the MIT License. | ||
* http://www.opensource.org/licenses/mit-license | ||
*/Object.defineProperty(exports,"__esModule",{value:!0});var v=require("@pixi/core"),W=require("@pixi/text"),H=require("@pixi/mesh"),Q=require("@pixi/display"),K=require("@pixi/assets");class O{constructor(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}}class R{static test(e){return typeof e=="string"&&e.startsWith("info face=")}static parse(e){const s=e.match(/^[a-z]+\s+.+$/gm),l={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const n in s){const r=s[n].match(/^[a-z]+/gm)[0],a=s[n].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),f={};for(const i in a){const g=a[i].split("="),d=g[0],c=g[1].replace(/"/gm,""),x=parseFloat(c),m=isNaN(x)?c:x;f[d]=m}l[r].push(f)}const u=new O;return l.info.forEach(n=>u.info.push({face:n.face,size:parseInt(n.size,10)})),l.common.forEach(n=>u.common.push({lineHeight:parseInt(n.lineHeight,10)})),l.page.forEach(n=>u.page.push({id:parseInt(n.id,10),file:n.file})),l.char.forEach(n=>u.char.push({id:parseInt(n.id,10),page:parseInt(n.page,10),x:parseInt(n.x,10),y:parseInt(n.y,10),width:parseInt(n.width,10),height:parseInt(n.height,10),xoffset:parseInt(n.xoffset,10),yoffset:parseInt(n.yoffset,10),xadvance:parseInt(n.xadvance,10)})),l.kerning.forEach(n=>u.kerning.push({first:parseInt(n.first,10),second:parseInt(n.second,10),amount:parseInt(n.amount,10)})),l.distanceField.forEach(n=>u.distanceField.push({distanceRange:parseInt(n.distanceRange,10),fieldType:n.fieldType})),u}}class ${static test(e){return e instanceof XMLDocument&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null}static parse(e){const s=new O,l=e.getElementsByTagName("info"),u=e.getElementsByTagName("common"),n=e.getElementsByTagName("page"),r=e.getElementsByTagName("char"),a=e.getElementsByTagName("kerning"),f=e.getElementsByTagName("distanceField");for(let i=0;i<l.length;i++)s.info.push({face:l[i].getAttribute("face"),size:parseInt(l[i].getAttribute("size"),10)});for(let i=0;i<u.length;i++)s.common.push({lineHeight:parseInt(u[i].getAttribute("lineHeight"),10)});for(let i=0;i<n.length;i++)s.page.push({id:parseInt(n[i].getAttribute("id"),10)||0,file:n[i].getAttribute("file")});for(let i=0;i<r.length;i++){const g=r[i];s.char.push({id:parseInt(g.getAttribute("id"),10),page:parseInt(g.getAttribute("page"),10)||0,x:parseInt(g.getAttribute("x"),10),y:parseInt(g.getAttribute("y"),10),width:parseInt(g.getAttribute("width"),10),height:parseInt(g.getAttribute("height"),10),xoffset:parseInt(g.getAttribute("xoffset"),10),yoffset:parseInt(g.getAttribute("yoffset"),10),xadvance:parseInt(g.getAttribute("xadvance"),10)})}for(let i=0;i<a.length;i++)s.kerning.push({first:parseInt(a[i].getAttribute("first"),10),second:parseInt(a[i].getAttribute("second"),10),amount:parseInt(a[i].getAttribute("amount"),10)});for(let i=0;i<f.length;i++)s.distanceField.push({fieldType:f[i].getAttribute("fieldType"),distanceRange:parseInt(f[i].getAttribute("distanceRange"),10)});return s}}class U{static test(e){if(typeof e=="string"&&e.includes("<font>")){const s=new globalThis.DOMParser().parseFromString(e,"text/xml");return $.test(s)}return!1}static parse(e){const s=new globalThis.DOMParser().parseFromString(e,"text/xml");return $.parse(s)}}const j=[R,$,U];function q(t){for(let e=0;e<j.length;e++)if(j[e].test(t))return j[e];return null}function tt(t,e,s,l,u,n){const r=s.fill;if(Array.isArray(r)){if(r.length===1)return r[0]}else return r;let a;const f=s.dropShadow?s.dropShadowDistance:0,i=s.padding||0,g=t.width/l-f-i*2,d=t.height/l-f-i*2,c=r.slice(),x=s.fillGradientStops.slice();if(!x.length){const m=c.length+1;for(let w=1;w<m;++w)x.push(w/m)}if(c.unshift(r[0]),x.unshift(0),c.push(r[r.length-1]),x.push(1),s.fillGradientType===W.TEXT_GRADIENT.LINEAR_VERTICAL){a=e.createLinearGradient(g/2,i,g/2,d+i);let m=0;const w=(n.fontProperties.fontSize+s.strokeThickness)/d;for(let S=0;S<u.length;S++){const b=n.lineHeight*S;for(let A=0;A<c.length;A++){let k=0;typeof x[A]=="number"?k=x[A]:k=A/c.length;const I=b/d+k*w;let F=Math.max(m,I);F=Math.min(F,1),a.addColorStop(F,c[A]),m=F}}}else{a=e.createLinearGradient(i,d/2,g+i,d/2);const m=c.length+1;let w=1;for(let S=0;S<c.length;S++){let b;typeof x[S]=="number"?b=x[S]:b=w/m,a.addColorStop(b,c[S]),w++}}return a}function et(t,e,s,l,u,n,r){const a=s.text,f=s.fontProperties;e.translate(l,u),e.scale(n,n);const i=r.strokeThickness/2,g=-(r.strokeThickness/2);if(e.font=r.toFontString(),e.lineWidth=r.strokeThickness,e.textBaseline=r.textBaseline,e.lineJoin=r.lineJoin,e.miterLimit=r.miterLimit,e.fillStyle=tt(t,e,r,n,[a],s),e.strokeStyle=r.stroke,r.dropShadow){const d=r.dropShadowColor,c=v.utils.hex2rgb(typeof d=="number"?d:v.utils.string2hex(d)),x=r.dropShadowBlur*n,m=r.dropShadowDistance*n;e.shadowColor=`rgba(${c[0]*255},${c[1]*255},${c[2]*255},${r.dropShadowAlpha})`,e.shadowBlur=x,e.shadowOffsetX=Math.cos(r.dropShadowAngle)*m,e.shadowOffsetY=Math.sin(r.dropShadowAngle)*m}else e.shadowColor="black",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0;r.stroke&&r.strokeThickness&&e.strokeText(a,i,g+s.lineHeight-f.descent),r.fill&&e.fillText(a,i,g+s.lineHeight-f.descent),e.setTransform(1,0,0,1,0,0),e.fillStyle="rgba(0, 0, 0, 0)"}function G(t){return Array.from?Array.from(t):t.split("")}function it(t){typeof t=="string"&&(t=[t]);const e=[];for(let s=0,l=t.length;s<l;s++){const u=t[s];if(Array.isArray(u)){if(u.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${u.length}.`);const n=u[0].charCodeAt(0),r=u[1].charCodeAt(0);if(r<n)throw new Error("[BitmapFont]: Invalid character range.");for(let a=n,f=r;a<=f;a++)e.push(String.fromCharCode(a))}else e.push(...G(u))}if(e.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return e}function X(t){return t.codePointAt?t.codePointAt(0):t.charCodeAt(0)}const z=class{constructor(t,e,s){const[l]=t.info,[u]=t.common,[n]=t.page,[r]=t.distanceField,a=v.utils.getResolutionOfUrl(n.file),f={};this._ownsTextures=s,this.font=l.face,this.size=l.size,this.lineHeight=u.lineHeight/a,this.chars={},this.pageTextures=f;for(let i=0;i<t.page.length;i++){const{id:g,file:d}=t.page[i];f[g]=e instanceof Array?e[i]:e[d],r?.fieldType&&r.fieldType!=="none"&&(f[g].baseTexture.alphaMode=v.ALPHA_MODES.NO_PREMULTIPLIED_ALPHA)}for(let i=0;i<t.char.length;i++){const{id:g,page:d}=t.char[i];let{x:c,y:x,width:m,height:w,xoffset:S,yoffset:b,xadvance:A}=t.char[i];c/=a,x/=a,m/=a,w/=a,S/=a,b/=a,A/=a;const k=new v.Rectangle(c+f[d].frame.x/a,x+f[d].frame.y/a,m,w);this.chars[g]={xOffset:S,yOffset:b,xAdvance:A,kerning:{},texture:new v.Texture(f[d].baseTexture,k),page:d}}for(let i=0;i<t.kerning.length;i++){let{first:g,second:d,amount:c}=t.kerning[i];g/=a,d/=a,c/=a,this.chars[d]&&(this.chars[d].kerning[g]=c)}this.distanceFieldRange=r?.distanceRange,this.distanceFieldType=r?.fieldType?.toLowerCase()??"none"}destroy(){for(const t in this.chars)this.chars[t].texture.destroy(),this.chars[t].texture=null;for(const t in this.pageTextures)this._ownsTextures&&this.pageTextures[t].destroy(!0),this.pageTextures[t]=null;this.chars=null,this.pageTextures=null}static install(t,e,s){let l;if(t instanceof O)l=t;else{const n=q(t);if(!n)throw new Error("Unrecognized data format for font.");l=n.parse(t)}e instanceof v.Texture&&(e=[e]);const u=new z(l,e,s);return z.available[u.font]=u,u}static uninstall(t){const e=z.available[t];if(!e)throw new Error(`No font found named '${t}'`);e.destroy(),delete z.available[t]}static from(t,e,s){if(!t)throw new Error("[BitmapFont] Property `name` is required.");const{chars:l,padding:u,resolution:n,textureWidth:r,textureHeight:a}=Object.assign({},z.defaultOptions,s),f=it(l),i=e instanceof W.TextStyle?e:new W.TextStyle(e),g=r,d=new O;d.info[0]={face:i.fontFamily,size:i.fontSize},d.common[0]={lineHeight:i.fontSize};let c=0,x=0,m,w,S,b=0;const A=[];for(let I=0;I<f.length;I++){m||(m=v.settings.ADAPTER.createCanvas(),m.width=r,m.height=a,w=m.getContext("2d"),S=new v.BaseTexture(m,{resolution:n}),A.push(new v.Texture(S)),d.page.push({id:A.length-1,file:""}));const F=W.TextMetrics.measureText(f[I],i,!1,m),P=F.width,E=Math.ceil(F.height),B=Math.ceil((i.fontStyle==="italic"?2:1)*P);if(x>=a-E*n){if(x===0)throw new Error(`[BitmapFont] textureHeight ${a}px is too small for ${i.fontSize}px fonts`);--I,m=null,w=null,S=null,x=0,c=0,b=0;continue}if(b=Math.max(E+F.fontProperties.descent,b),B*n+c>=g){--I,x+=b*n,x=Math.ceil(x),c=0,b=0;continue}et(m,w,F,c,x,n,i);const o=X(F.text);d.char.push({id:o,page:A.length-1,x:c/n,y:x/n,width:B,height:E,xoffset:0,yoffset:0,xadvance:Math.ceil(P-(i.dropShadow?i.dropShadowDistance:0)-(i.stroke?i.strokeThickness:0))}),c+=(B+2*u)*n,c=Math.ceil(c)}for(let I=0,F=f.length;I<F;I++){const P=f[I];for(let E=0;E<F;E++){const B=f[E],o=w.measureText(P).width,h=w.measureText(B).width,T=w.measureText(P+B).width-(o+h);T&&d.kerning.push({first:X(P),second:X(B),amount:T})}}const k=new z(d,A,!0);return z.available[t]!==void 0&&z.uninstall(t),z.available[t]=k,k}};let N=z;N.ALPHA=[["a","z"],["A","Z"]," "],N.NUMERIC=[["0","9"]],N.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],N.ASCII=[[" ","~"]],N.defaultOptions={resolution:1,textureWidth:512,textureHeight:512,padding:4,chars:z.ALPHANUMERIC},N.available={};var nt=`// Pixi texture info\r | ||
*/Object.defineProperty(exports,"__esModule",{value:!0});var v=require("@pixi/core"),W=require("@pixi/text"),H=require("@pixi/mesh"),Q=require("@pixi/display"),K=require("@pixi/assets");class O{constructor(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}}class R{static test(e){return typeof e=="string"&&e.startsWith("info face=")}static parse(e){const s=e.match(/^[a-z]+\s+.+$/gm),l={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const n in s){const r=s[n].match(/^[a-z]+/gm)[0],a=s[n].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),f={};for(const i in a){const d=a[i].split("="),g=d[0],c=d[1].replace(/"/gm,""),x=parseFloat(c),m=isNaN(x)?c:x;f[g]=m}l[r].push(f)}const u=new O;return l.info.forEach(n=>u.info.push({face:n.face,size:parseInt(n.size,10)})),l.common.forEach(n=>u.common.push({lineHeight:parseInt(n.lineHeight,10)})),l.page.forEach(n=>u.page.push({id:parseInt(n.id,10),file:n.file})),l.char.forEach(n=>u.char.push({id:parseInt(n.id,10),page:parseInt(n.page,10),x:parseInt(n.x,10),y:parseInt(n.y,10),width:parseInt(n.width,10),height:parseInt(n.height,10),xoffset:parseInt(n.xoffset,10),yoffset:parseInt(n.yoffset,10),xadvance:parseInt(n.xadvance,10)})),l.kerning.forEach(n=>u.kerning.push({first:parseInt(n.first,10),second:parseInt(n.second,10),amount:parseInt(n.amount,10)})),l.distanceField.forEach(n=>u.distanceField.push({distanceRange:parseInt(n.distanceRange,10),fieldType:n.fieldType})),u}}class ${static test(e){return e instanceof XMLDocument&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null}static parse(e){const s=new O,l=e.getElementsByTagName("info"),u=e.getElementsByTagName("common"),n=e.getElementsByTagName("page"),r=e.getElementsByTagName("char"),a=e.getElementsByTagName("kerning"),f=e.getElementsByTagName("distanceField");for(let i=0;i<l.length;i++)s.info.push({face:l[i].getAttribute("face"),size:parseInt(l[i].getAttribute("size"),10)});for(let i=0;i<u.length;i++)s.common.push({lineHeight:parseInt(u[i].getAttribute("lineHeight"),10)});for(let i=0;i<n.length;i++)s.page.push({id:parseInt(n[i].getAttribute("id"),10)||0,file:n[i].getAttribute("file")});for(let i=0;i<r.length;i++){const d=r[i];s.char.push({id:parseInt(d.getAttribute("id"),10),page:parseInt(d.getAttribute("page"),10)||0,x:parseInt(d.getAttribute("x"),10),y:parseInt(d.getAttribute("y"),10),width:parseInt(d.getAttribute("width"),10),height:parseInt(d.getAttribute("height"),10),xoffset:parseInt(d.getAttribute("xoffset"),10),yoffset:parseInt(d.getAttribute("yoffset"),10),xadvance:parseInt(d.getAttribute("xadvance"),10)})}for(let i=0;i<a.length;i++)s.kerning.push({first:parseInt(a[i].getAttribute("first"),10),second:parseInt(a[i].getAttribute("second"),10),amount:parseInt(a[i].getAttribute("amount"),10)});for(let i=0;i<f.length;i++)s.distanceField.push({fieldType:f[i].getAttribute("fieldType"),distanceRange:parseInt(f[i].getAttribute("distanceRange"),10)});return s}}class U{static test(e){if(typeof e=="string"&&e.includes("<font>")){const s=new globalThis.DOMParser().parseFromString(e,"text/xml");return $.test(s)}return!1}static parse(e){const s=new globalThis.DOMParser().parseFromString(e,"text/xml");return $.parse(s)}}const j=[R,$,U];function q(t){for(let e=0;e<j.length;e++)if(j[e].test(t))return j[e];return null}function tt(t,e,s,l,u,n){const r=s.fill;if(Array.isArray(r)){if(r.length===1)return r[0]}else return r;let a;const f=s.dropShadow?s.dropShadowDistance:0,i=s.padding||0,d=t.width/l-f-i*2,g=t.height/l-f-i*2,c=r.slice(),x=s.fillGradientStops.slice();if(!x.length){const m=c.length+1;for(let w=1;w<m;++w)x.push(w/m)}if(c.unshift(r[0]),x.unshift(0),c.push(r[r.length-1]),x.push(1),s.fillGradientType===W.TEXT_GRADIENT.LINEAR_VERTICAL){a=e.createLinearGradient(d/2,i,d/2,g+i);let m=0;const w=(n.fontProperties.fontSize+s.strokeThickness)/g;for(let S=0;S<u.length;S++){const b=n.lineHeight*S;for(let A=0;A<c.length;A++){let k=0;typeof x[A]=="number"?k=x[A]:k=A/c.length;const I=b/g+k*w;let F=Math.max(m,I);F=Math.min(F,1),a.addColorStop(F,c[A]),m=F}}}else{a=e.createLinearGradient(i,g/2,d+i,g/2);const m=c.length+1;let w=1;for(let S=0;S<c.length;S++){let b;typeof x[S]=="number"?b=x[S]:b=w/m,a.addColorStop(b,c[S]),w++}}return a}function et(t,e,s,l,u,n,r){const a=s.text,f=s.fontProperties;e.translate(l,u),e.scale(n,n);const i=r.strokeThickness/2,d=-(r.strokeThickness/2);if(e.font=r.toFontString(),e.lineWidth=r.strokeThickness,e.textBaseline=r.textBaseline,e.lineJoin=r.lineJoin,e.miterLimit=r.miterLimit,e.fillStyle=tt(t,e,r,n,[a],s),e.strokeStyle=r.stroke,r.dropShadow){const g=r.dropShadowColor,c=v.utils.hex2rgb(typeof g=="number"?g:v.utils.string2hex(g)),x=r.dropShadowBlur*n,m=r.dropShadowDistance*n;e.shadowColor=`rgba(${c[0]*255},${c[1]*255},${c[2]*255},${r.dropShadowAlpha})`,e.shadowBlur=x,e.shadowOffsetX=Math.cos(r.dropShadowAngle)*m,e.shadowOffsetY=Math.sin(r.dropShadowAngle)*m}else e.shadowColor="black",e.shadowBlur=0,e.shadowOffsetX=0,e.shadowOffsetY=0;r.stroke&&r.strokeThickness&&e.strokeText(a,i,d+s.lineHeight-f.descent),r.fill&&e.fillText(a,i,d+s.lineHeight-f.descent),e.setTransform(1,0,0,1,0,0),e.fillStyle="rgba(0, 0, 0, 0)"}function G(t){return Array.from?Array.from(t):t.split("")}function it(t){typeof t=="string"&&(t=[t]);const e=[];for(let s=0,l=t.length;s<l;s++){const u=t[s];if(Array.isArray(u)){if(u.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${u.length}.`);const n=u[0].charCodeAt(0),r=u[1].charCodeAt(0);if(r<n)throw new Error("[BitmapFont]: Invalid character range.");for(let a=n,f=r;a<=f;a++)e.push(String.fromCharCode(a))}else e.push(...G(u))}if(e.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return e}function X(t){return t.codePointAt?t.codePointAt(0):t.charCodeAt(0)}const z=class{constructor(t,e,s){const[l]=t.info,[u]=t.common,[n]=t.page,[r]=t.distanceField,a=v.utils.getResolutionOfUrl(n.file),f={};this._ownsTextures=s,this.font=l.face,this.size=l.size,this.lineHeight=u.lineHeight/a,this.chars={},this.pageTextures=f;for(let i=0;i<t.page.length;i++){const{id:d,file:g}=t.page[i];f[d]=e instanceof Array?e[i]:e[g],r?.fieldType&&r.fieldType!=="none"&&(f[d].baseTexture.alphaMode=v.ALPHA_MODES.NO_PREMULTIPLIED_ALPHA,f[d].baseTexture.mipmap=v.MIPMAP_MODES.OFF)}for(let i=0;i<t.char.length;i++){const{id:d,page:g}=t.char[i];let{x:c,y:x,width:m,height:w,xoffset:S,yoffset:b,xadvance:A}=t.char[i];c/=a,x/=a,m/=a,w/=a,S/=a,b/=a,A/=a;const k=new v.Rectangle(c+f[g].frame.x/a,x+f[g].frame.y/a,m,w);this.chars[d]={xOffset:S,yOffset:b,xAdvance:A,kerning:{},texture:new v.Texture(f[g].baseTexture,k),page:g}}for(let i=0;i<t.kerning.length;i++){let{first:d,second:g,amount:c}=t.kerning[i];d/=a,g/=a,c/=a,this.chars[g]&&(this.chars[g].kerning[d]=c)}this.distanceFieldRange=r?.distanceRange,this.distanceFieldType=r?.fieldType?.toLowerCase()??"none"}destroy(){for(const t in this.chars)this.chars[t].texture.destroy(),this.chars[t].texture=null;for(const t in this.pageTextures)this._ownsTextures&&this.pageTextures[t].destroy(!0),this.pageTextures[t]=null;this.chars=null,this.pageTextures=null}static install(t,e,s){let l;if(t instanceof O)l=t;else{const n=q(t);if(!n)throw new Error("Unrecognized data format for font.");l=n.parse(t)}e instanceof v.Texture&&(e=[e]);const u=new z(l,e,s);return z.available[u.font]=u,u}static uninstall(t){const e=z.available[t];if(!e)throw new Error(`No font found named '${t}'`);e.destroy(),delete z.available[t]}static from(t,e,s){if(!t)throw new Error("[BitmapFont] Property `name` is required.");const{chars:l,padding:u,resolution:n,textureWidth:r,textureHeight:a}=Object.assign({},z.defaultOptions,s),f=it(l),i=e instanceof W.TextStyle?e:new W.TextStyle(e),d=r,g=new O;g.info[0]={face:i.fontFamily,size:i.fontSize},g.common[0]={lineHeight:i.fontSize};let c=0,x=0,m,w,S,b=0;const A=[];for(let I=0;I<f.length;I++){m||(m=v.settings.ADAPTER.createCanvas(),m.width=r,m.height=a,w=m.getContext("2d"),S=new v.BaseTexture(m,{resolution:n}),A.push(new v.Texture(S)),g.page.push({id:A.length-1,file:""}));const F=W.TextMetrics.measureText(f[I],i,!1,m),P=F.width,E=Math.ceil(F.height),B=Math.ceil((i.fontStyle==="italic"?2:1)*P);if(x>=a-E*n){if(x===0)throw new Error(`[BitmapFont] textureHeight ${a}px is too small for ${i.fontSize}px fonts`);--I,m=null,w=null,S=null,x=0,c=0,b=0;continue}if(b=Math.max(E+F.fontProperties.descent,b),B*n+c>=d){--I,x+=b*n,x=Math.ceil(x),c=0,b=0;continue}et(m,w,F,c,x,n,i);const o=X(F.text);g.char.push({id:o,page:A.length-1,x:c/n,y:x/n,width:B,height:E,xoffset:0,yoffset:0,xadvance:Math.ceil(P-(i.dropShadow?i.dropShadowDistance:0)-(i.stroke?i.strokeThickness:0))}),c+=(B+2*u)*n,c=Math.ceil(c)}for(let I=0,F=f.length;I<F;I++){const P=f[I];for(let E=0;E<F;E++){const B=f[E],o=w.measureText(P).width,h=w.measureText(B).width,T=w.measureText(P+B).width-(o+h);T&&g.kerning.push({first:X(P),second:X(B),amount:T})}}const k=new z(g,A,!0);return z.available[t]!==void 0&&z.uninstall(t),z.available[t]=k,k}};let N=z;N.ALPHA=[["a","z"],["A","Z"]," "],N.NUMERIC=[["0","9"]],N.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],N.ASCII=[[" ","~"]],N.defaultOptions={resolution:1,textureWidth:512,textureHeight:512,padding:4,chars:z.ALPHANUMERIC},N.available={};var nt=`// Pixi texture info\r | ||
varying vec2 vTextureCoord;\r | ||
@@ -53,5 +53,5 @@ uniform sampler2D uSampler;\r | ||
`;const rt=[],at=[],Y=[],V=class extends Q.Container{constructor(t,e={}){super(),this._tint=16777215;const{align:s,tint:l,maxWidth:u,letterSpacing:n,fontName:r,fontSize:a}=Object.assign({},V.styleDefaults,e);if(!N.available[r])throw new Error(`Missing BitmapFont "${r}"`);this._activePagesMeshData=[],this._textWidth=0,this._textHeight=0,this._align=s,this._tint=l,this._fontName=r,this._fontSize=a||N.available[r].size,this.text=t,this._maxWidth=u,this._maxLineHeight=0,this._letterSpacing=n,this._anchor=new v.ObservablePoint(()=>{this.dirty=!0},this,0,0),this._roundPixels=v.settings.ROUND_PIXELS,this.dirty=!0,this._resolution=v.settings.RESOLUTION,this._autoResolution=!0,this._textureCache={}}updateText(){const t=N.available[this._fontName],e=this._fontSize/t.size,s=new v.Point,l=[],u=[],n=[],r=this._text.replace(/(?:\r\n|\r)/g,` | ||
`)||" ",a=G(r),f=this._maxWidth*t.size/this._fontSize,i=t.distanceFieldType==="none"?rt:at;let g=null,d=0,c=0,x=0,m=-1,w=0,S=0,b=0,A=0;for(let o=0;o<a.length;o++){const h=a[o],T=X(h);if(/(?:\s)/.test(h)&&(m=o,w=d,A++),h==="\r"||h===` | ||
`){u.push(d),n.push(-1),c=Math.max(c,d),++x,++S,s.x=0,s.y+=t.lineHeight,g=null,A=0;continue}const p=t.chars[T];if(!p)continue;g&&p.kerning[g]&&(s.x+=p.kerning[g]);const M=Y.pop()||{texture:v.Texture.EMPTY,line:0,charCode:0,prevSpaces:0,position:new v.Point};M.texture=p.texture,M.line=x,M.charCode=T,M.position.x=s.x+p.xOffset+this._letterSpacing/2,M.position.y=s.y+p.yOffset,M.prevSpaces=A,l.push(M),d=M.position.x+Math.max(p.xAdvance-p.xOffset,p.texture.orig.width),s.x+=p.xAdvance+this._letterSpacing,b=Math.max(b,p.yOffset+p.texture.height),g=T,m!==-1&&f>0&&s.x>f&&(++S,v.utils.removeItems(l,1+m-S,1+o-m),o=m,m=-1,u.push(w),n.push(l.length>0?l[l.length-1].prevSpaces:0),c=Math.max(c,w),x++,s.x=0,s.y+=t.lineHeight,g=null,A=0)}const k=a[a.length-1];k!=="\r"&&k!==` | ||
`&&(/(?:\s)/.test(k)&&(d=w),u.push(d),c=Math.max(c,d),n.push(-1));const I=[];for(let o=0;o<=x;o++){let h=0;this._align==="right"?h=c-u[o]:this._align==="center"?h=(c-u[o])/2:this._align==="justify"&&(h=n[o]<0?0:(c-u[o])/n[o]),I.push(h)}const F=l.length,P={},E=[],B=this._activePagesMeshData;for(let o=0;o<B.length;o++)i.push(B[o]);for(let o=0;o<F;o++){const h=l[o].texture,T=h.baseTexture.uid;if(!P[T]){let p=i.pop();if(!p){const C=new H.MeshGeometry;let y,L;t.distanceFieldType==="none"?(y=new H.MeshMaterial(v.Texture.EMPTY),L=v.BLEND_MODES.NORMAL):(y=new H.MeshMaterial(v.Texture.EMPTY,{program:v.Program.from(st,nt),uniforms:{uFWidth:0}}),L=v.BLEND_MODES.NORMAL_NPM);const D=new H.Mesh(C,y);D.blendMode=L,p={index:0,indexCount:0,vertexCount:0,uvsCount:0,total:0,mesh:D,vertices:null,uvs:null,indices:null}}p.index=0,p.indexCount=0,p.vertexCount=0,p.uvsCount=0,p.total=0;const{_textureCache:M}=this;M[T]=M[T]||new v.Texture(h.baseTexture),p.mesh.texture=M[T],p.mesh.tint=this._tint,E.push(p),P[T]=p}P[T].total++}for(let o=0;o<B.length;o++)E.includes(B[o])||this.removeChild(B[o].mesh);for(let o=0;o<E.length;o++)E[o].mesh.parent!==this&&this.addChild(E[o].mesh);this._activePagesMeshData=E;for(const o in P){const h=P[o],T=h.total;if(!(h.indices?.length>6*T)||h.vertices.length<H.Mesh.BATCHABLE_SIZE*2)h.vertices=new Float32Array(4*2*T),h.uvs=new Float32Array(4*2*T),h.indices=new Uint16Array(6*T);else{const p=h.total,M=h.vertices;for(let C=p*4*2;C<M.length;C++)M[C]=0}h.mesh.size=6*T}for(let o=0;o<F;o++){const h=l[o];let T=h.position.x+I[h.line]*(this._align==="justify"?h.prevSpaces:1);this._roundPixels&&(T=Math.round(T));const p=T*e,M=h.position.y*e,C=h.texture,y=P[C.baseTexture.uid],L=C.frame,D=C._uvs,_=y.index++;y.indices[_*6+0]=0+_*4,y.indices[_*6+1]=1+_*4,y.indices[_*6+2]=2+_*4,y.indices[_*6+3]=0+_*4,y.indices[_*6+4]=2+_*4,y.indices[_*6+5]=3+_*4,y.vertices[_*8+0]=p,y.vertices[_*8+1]=M,y.vertices[_*8+2]=p+L.width*e,y.vertices[_*8+3]=M,y.vertices[_*8+4]=p+L.width*e,y.vertices[_*8+5]=M+L.height*e,y.vertices[_*8+6]=p,y.vertices[_*8+7]=M+L.height*e,y.uvs[_*8+0]=D.x0,y.uvs[_*8+1]=D.y0,y.uvs[_*8+2]=D.x1,y.uvs[_*8+3]=D.y1,y.uvs[_*8+4]=D.x2,y.uvs[_*8+5]=D.y2,y.uvs[_*8+6]=D.x3,y.uvs[_*8+7]=D.y3}this._textWidth=c*e,this._textHeight=(s.y+t.lineHeight)*e;for(const o in P){const h=P[o];if(this.anchor.x!==0||this.anchor.y!==0){let C=0;const y=this._textWidth*this.anchor.x,L=this._textHeight*this.anchor.y;for(let D=0;D<h.total;D++)h.vertices[C++]-=y,h.vertices[C++]-=L,h.vertices[C++]-=y,h.vertices[C++]-=L,h.vertices[C++]-=y,h.vertices[C++]-=L,h.vertices[C++]-=y,h.vertices[C++]-=L}this._maxLineHeight=b*e;const T=h.mesh.geometry.getBuffer("aVertexPosition"),p=h.mesh.geometry.getBuffer("aTextureCoord"),M=h.mesh.geometry.getIndex();T.data=h.vertices,p.data=h.uvs,M.data=h.indices,T.update(),p.update(),M.update()}for(let o=0;o<l.length;o++)Y.push(l[o])}updateTransform(){this.validate(),this.containerUpdateTransform()}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0);const{distanceFieldRange:e,distanceFieldType:s,size:l}=N.available[this._fontName];if(s!=="none"){const{a:u,b:n,c:r,d:a}=this.worldTransform,f=Math.sqrt(u*u+n*n),i=Math.sqrt(r*r+a*a),g=(Math.abs(f)+Math.abs(i))/2,d=this._fontSize/l,c=t._view.resolution;for(const x of this._activePagesMeshData)x.mesh.shader.uniforms.uFWidth=g*e*d*c}super._render(t)}getLocalBounds(){return this.validate(),super.getLocalBounds()}validate(){this.dirty&&(this.updateText(),this.dirty=!1)}get tint(){return this._tint}set tint(t){if(this._tint!==t){this._tint=t;for(let e=0;e<this._activePagesMeshData.length;e++)this._activePagesMeshData[e].mesh.tint=t}}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.dirty=!0)}get fontName(){return this._fontName}set fontName(t){if(!N.available[t])throw new Error(`Missing BitmapFont "${t}"`);this._fontName!==t&&(this._fontName=t,this.dirty=!0)}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.dirty=!0)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get maxWidth(){return this._maxWidth}set maxWidth(t){this._maxWidth!==t&&(this._maxWidth=t,this.dirty=!0)}get maxLineHeight(){return this.validate(),this._maxLineHeight}get textWidth(){return this.validate(),this._textWidth}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.dirty=!0)}get roundPixels(){return this._roundPixels}set roundPixels(t){t!==this._roundPixels&&(this._roundPixels=t,this.dirty=!0)}get textHeight(){return this.validate(),this._textHeight}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}destroy(t){const{_textureCache:e}=this;for(const s in e)e[s].destroy(),delete e[s];this._textureCache=null,super.destroy(t)}};let Z=V;Z.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};const ot=[".xml",".fnt"],J={extension:{type:v.ExtensionType.LoadParser,priority:K.LoaderParserPriority.Normal},test(t){return ot.includes(v.utils.path.extname(t))},async testParse(t){return R.test(t)||U.test(t)},async parse(t,e,s){const l=R.test(t)?R.parse(t):U.parse(t),{src:u}=e,{page:n}=l,r=[];for(let i=0;i<n.length;++i){const g=n[i].file,d=v.utils.path.join(v.utils.path.dirname(u),g);r.push(d)}const a=await s.load(r),f=r.map(i=>a[i]);return N.install(l,f,!0)},async load(t,e){return(await v.settings.ADAPTER.fetch(t)).text()},unload(t){t.destroy()}};v.extensions.add(J),exports.BitmapFont=N,exports.BitmapFontData=O,exports.BitmapText=Z,exports.TextFormat=R,exports.XMLFormat=$,exports.XMLStringFormat=U,exports.autoDetectFormat=q,exports.loadBitmapFont=J; | ||
`)||" ",a=G(r),f=this._maxWidth*t.size/this._fontSize,i=t.distanceFieldType==="none"?rt:at;let d=null,g=0,c=0,x=0,m=-1,w=0,S=0,b=0,A=0;for(let o=0;o<a.length;o++){const h=a[o],T=X(h);if(/(?:\s)/.test(h)&&(m=o,w=g,A++),h==="\r"||h===` | ||
`){u.push(g),n.push(-1),c=Math.max(c,g),++x,++S,s.x=0,s.y+=t.lineHeight,d=null,A=0;continue}const p=t.chars[T];if(!p)continue;d&&p.kerning[d]&&(s.x+=p.kerning[d]);const M=Y.pop()||{texture:v.Texture.EMPTY,line:0,charCode:0,prevSpaces:0,position:new v.Point};M.texture=p.texture,M.line=x,M.charCode=T,M.position.x=s.x+p.xOffset+this._letterSpacing/2,M.position.y=s.y+p.yOffset,M.prevSpaces=A,l.push(M),g=M.position.x+Math.max(p.xAdvance-p.xOffset,p.texture.orig.width),s.x+=p.xAdvance+this._letterSpacing,b=Math.max(b,p.yOffset+p.texture.height),d=T,m!==-1&&f>0&&s.x>f&&(++S,v.utils.removeItems(l,1+m-S,1+o-m),o=m,m=-1,u.push(w),n.push(l.length>0?l[l.length-1].prevSpaces:0),c=Math.max(c,w),x++,s.x=0,s.y+=t.lineHeight,d=null,A=0)}const k=a[a.length-1];k!=="\r"&&k!==` | ||
`&&(/(?:\s)/.test(k)&&(g=w),u.push(g),c=Math.max(c,g),n.push(-1));const I=[];for(let o=0;o<=x;o++){let h=0;this._align==="right"?h=c-u[o]:this._align==="center"?h=(c-u[o])/2:this._align==="justify"&&(h=n[o]<0?0:(c-u[o])/n[o]),I.push(h)}const F=l.length,P={},E=[],B=this._activePagesMeshData;for(let o=0;o<B.length;o++)i.push(B[o]);for(let o=0;o<F;o++){const h=l[o].texture,T=h.baseTexture.uid;if(!P[T]){let p=i.pop();if(!p){const C=new H.MeshGeometry;let y,L;t.distanceFieldType==="none"?(y=new H.MeshMaterial(v.Texture.EMPTY),L=v.BLEND_MODES.NORMAL):(y=new H.MeshMaterial(v.Texture.EMPTY,{program:v.Program.from(st,nt),uniforms:{uFWidth:0}}),L=v.BLEND_MODES.NORMAL_NPM);const D=new H.Mesh(C,y);D.blendMode=L,p={index:0,indexCount:0,vertexCount:0,uvsCount:0,total:0,mesh:D,vertices:null,uvs:null,indices:null}}p.index=0,p.indexCount=0,p.vertexCount=0,p.uvsCount=0,p.total=0;const{_textureCache:M}=this;M[T]=M[T]||new v.Texture(h.baseTexture),p.mesh.texture=M[T],p.mesh.tint=this._tint,E.push(p),P[T]=p}P[T].total++}for(let o=0;o<B.length;o++)E.includes(B[o])||this.removeChild(B[o].mesh);for(let o=0;o<E.length;o++)E[o].mesh.parent!==this&&this.addChild(E[o].mesh);this._activePagesMeshData=E;for(const o in P){const h=P[o],T=h.total;if(!(h.indices?.length>6*T)||h.vertices.length<H.Mesh.BATCHABLE_SIZE*2)h.vertices=new Float32Array(4*2*T),h.uvs=new Float32Array(4*2*T),h.indices=new Uint16Array(6*T);else{const p=h.total,M=h.vertices;for(let C=p*4*2;C<M.length;C++)M[C]=0}h.mesh.size=6*T}for(let o=0;o<F;o++){const h=l[o];let T=h.position.x+I[h.line]*(this._align==="justify"?h.prevSpaces:1);this._roundPixels&&(T=Math.round(T));const p=T*e,M=h.position.y*e,C=h.texture,y=P[C.baseTexture.uid],L=C.frame,D=C._uvs,_=y.index++;y.indices[_*6+0]=0+_*4,y.indices[_*6+1]=1+_*4,y.indices[_*6+2]=2+_*4,y.indices[_*6+3]=0+_*4,y.indices[_*6+4]=2+_*4,y.indices[_*6+5]=3+_*4,y.vertices[_*8+0]=p,y.vertices[_*8+1]=M,y.vertices[_*8+2]=p+L.width*e,y.vertices[_*8+3]=M,y.vertices[_*8+4]=p+L.width*e,y.vertices[_*8+5]=M+L.height*e,y.vertices[_*8+6]=p,y.vertices[_*8+7]=M+L.height*e,y.uvs[_*8+0]=D.x0,y.uvs[_*8+1]=D.y0,y.uvs[_*8+2]=D.x1,y.uvs[_*8+3]=D.y1,y.uvs[_*8+4]=D.x2,y.uvs[_*8+5]=D.y2,y.uvs[_*8+6]=D.x3,y.uvs[_*8+7]=D.y3}this._textWidth=c*e,this._textHeight=(s.y+t.lineHeight)*e;for(const o in P){const h=P[o];if(this.anchor.x!==0||this.anchor.y!==0){let C=0;const y=this._textWidth*this.anchor.x,L=this._textHeight*this.anchor.y;for(let D=0;D<h.total;D++)h.vertices[C++]-=y,h.vertices[C++]-=L,h.vertices[C++]-=y,h.vertices[C++]-=L,h.vertices[C++]-=y,h.vertices[C++]-=L,h.vertices[C++]-=y,h.vertices[C++]-=L}this._maxLineHeight=b*e;const T=h.mesh.geometry.getBuffer("aVertexPosition"),p=h.mesh.geometry.getBuffer("aTextureCoord"),M=h.mesh.geometry.getIndex();T.data=h.vertices,p.data=h.uvs,M.data=h.indices,T.update(),p.update(),M.update()}for(let o=0;o<l.length;o++)Y.push(l[o])}updateTransform(){this.validate(),this.containerUpdateTransform()}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0);const{distanceFieldRange:e,distanceFieldType:s,size:l}=N.available[this._fontName];if(s!=="none"){const{a:u,b:n,c:r,d:a}=this.worldTransform,f=Math.sqrt(u*u+n*n),i=Math.sqrt(r*r+a*a),d=(Math.abs(f)+Math.abs(i))/2,g=this._fontSize/l,c=t._view.resolution;for(const x of this._activePagesMeshData)x.mesh.shader.uniforms.uFWidth=Math.min(d*e*g*c,1)}super._render(t)}getLocalBounds(){return this.validate(),super.getLocalBounds()}validate(){this.dirty&&(this.updateText(),this.dirty=!1)}get tint(){return this._tint}set tint(t){if(this._tint!==t){this._tint=t;for(let e=0;e<this._activePagesMeshData.length;e++)this._activePagesMeshData[e].mesh.tint=t}}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.dirty=!0)}get fontName(){return this._fontName}set fontName(t){if(!N.available[t])throw new Error(`Missing BitmapFont "${t}"`);this._fontName!==t&&(this._fontName=t,this.dirty=!0)}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.dirty=!0)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get maxWidth(){return this._maxWidth}set maxWidth(t){this._maxWidth!==t&&(this._maxWidth=t,this.dirty=!0)}get maxLineHeight(){return this.validate(),this._maxLineHeight}get textWidth(){return this.validate(),this._textWidth}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.dirty=!0)}get roundPixels(){return this._roundPixels}set roundPixels(t){t!==this._roundPixels&&(this._roundPixels=t,this.dirty=!0)}get textHeight(){return this.validate(),this._textHeight}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}destroy(t){const{_textureCache:e}=this;for(const s in e)e[s].destroy(),delete e[s];this._textureCache=null,super.destroy(t)}};let Z=V;Z.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};const ot=[".xml",".fnt"],J={extension:{type:v.ExtensionType.LoadParser,priority:K.LoaderParserPriority.Normal},test(t){return ot.includes(v.utils.path.extname(t))},async testParse(t){return R.test(t)||U.test(t)},async parse(t,e,s){const l=R.test(t)?R.parse(t):U.parse(t),{src:u}=e,{page:n}=l,r=[];for(let i=0;i<n.length;++i){const d=n[i].file,g=v.utils.path.join(v.utils.path.dirname(u),d);r.push(g)}const a=await s.load(r),f=r.map(i=>a[i]);return N.install(l,f,!0)},async load(t,e){return(await v.settings.ADAPTER.fetch(t)).text()},unload(t){t.destroy()}};v.extensions.add(J),exports.BitmapFont=N,exports.BitmapFontData=O,exports.BitmapText=Z,exports.TextFormat=R,exports.XMLFormat=$,exports.XMLStringFormat=U,exports.autoDetectFormat=q,exports.loadBitmapFont=J; | ||
//# sourceMappingURL=text-bitmap.min.js.map |
@@ -140,10 +140,12 @@ /// <reference path="./global.d.ts" /> | ||
* @example | ||
* PIXI.BitmapFont.from("TitleFont", { | ||
* import { BitmapFont, BitmapText } from 'pixi.js'; | ||
* | ||
* BitmapFont.from("TitleFont", { | ||
* fontFamily: "Arial", | ||
* fontSize: 12, | ||
* strokeThickness: 2, | ||
* fill: "purple" | ||
* fill: "purple", | ||
* }); | ||
* | ||
* const title = new PIXI.BitmapText("This is the title", { fontName: "TitleFont" }); | ||
* const title = new BitmapText("This is the title", { fontName: "TitleFont" }); | ||
*/ | ||
@@ -192,6 +194,7 @@ static from(name: string, textStyle?: TextStyle | Partial<ITextStyle>, options?: IBitmapFontOptions): BitmapFont; | ||
* A BitmapText can only be created when the font is loaded. | ||
* @example | ||
* import { BitmapText } from 'pixi.js'; | ||
* | ||
* ```js | ||
* // in this case the font is in a file called 'desyrel.fnt' | ||
* let bitmapText = new PIXI.BitmapText("text using a fancy font!", { | ||
* const bitmapText = new BitmapText("text using a fancy font!", { | ||
* fontName: "Desyrel", | ||
@@ -201,3 +204,2 @@ * fontSize: 35, | ||
* }); | ||
* ``` | ||
* @memberof PIXI | ||
@@ -204,0 +206,0 @@ */ |
{ | ||
"name": "@pixi/text-bitmap", | ||
"version": "7.0.0-alpha", | ||
"version": "7.0.0-alpha.2", | ||
"main": "dist/cjs/text-bitmap.js", | ||
@@ -45,3 +45,3 @@ "module": "dist/esm/text-bitmap.mjs", | ||
], | ||
"gitHead": "da993226df64b804a9c00ed9ee4d011191467b8a" | ||
"gitHead": "439f6c1606ba63b26a93173284d25c35a7682b17" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
575993
2882