@excaliburjs/plugin-sdf-text 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +25 -0
- package/dist/cli.js +294 -0
- package/dist/excalibur-sdf-text.js +712 -0
- package/dist/excalibur-sdf-text.js.map +1 -0
- package/dist/excalibur-sdf-text.min.js +498 -0
- package/dist/excalibur-sdf-text.min.js.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/sdf-font.d.ts +227 -0
- package/dist/types/sdf-text-plugin.d.ts +13 -0
- package/dist/types/sdf-text-renderer.d.ts +79 -0
- package/dist/types/sdf-text.d.ts +59 -0
- package/package.json +68 -4
- package/readme.md +112 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"excalibur-sdf-text.min.js","names":["fragmentSource","BoundingBox","Color","ExcaliburGraphicsContextWebGL","FontSource","Graphic","ImageFiltering","ImageSource","ImageSourceAttributeConstants","Plugin","QuadIndexBuffer","Resource","Shader","Vector","VertexBuffer","VertexLayout","vec","INF","TinySDF","fontSize","buffer","radius","cutoff","fontFamily","fontWeight","fontStyle","lang","size","canvas","ctx","char","glyphAdvance","actualBoundingBoxAscent","actualBoundingBoxDescent","actualBoundingBoxLeft","actualBoundingBoxRight","glyphTop","glyphLeft","glyphWidth","glyphHeight","width","height","len","data","glyph","gridInner","gridOuter","imgData","y","a","j","d","edt","i","x0","y0","gridSize","f","v","z","x","edt1d","grid","offset","stride","length","q","k","s","q2","r","qr","SDF_CUTOFF","getCharactersFromUnicodeRanges","ranges","start","end","_","SDFSource","text","maxWidth","lines","paragraph","line","word","candidate","fit","scale","lineHeight","ascent","SDFFont","options","file","family","cell","dimension","alphaChannel","imageData","tinySdf","glyphs","rowHeight","placement","atlasPath","SDFAtlas","metadata","sdf_text_frag_default","sdf_text_vert_default","getMaxShaderComplexity","gl","numIfs","assembleTestShader","testShader","testComplexity","canCompile","shader","SDF_TEXT_RENDERER","SDFTextRenderer","context","maxTextureUnits","source","maxTextures","texturePicker","image","texture","index","pos","visibleCharacters","textAlign","color","atlas","textureId","atlasWidth","atlasHeight","transform","vertices","blockWidth","alignFactor","drawn","lineIndex","penX","baseline","resident","w","h","quad","u0","v0","u1","v1","u","SDFText","value","key","ex","SDFTextPlugin"],"sources":["../node_modules/@mapbox/tiny-sdf/index.js","../src/sdf-font.ts","../src/sdf-text-renderer.ts","../src/sdf-text.ts","../src/sdf-text-plugin.ts"],"sourcesContent":["const INF = 1e20;\n\nexport default class TinySDF {\n constructor({\n fontSize = 24,\n buffer = 3,\n radius = 8,\n cutoff = 0.25,\n fontFamily = 'sans-serif',\n fontWeight = 'normal',\n fontStyle = 'normal',\n lang = null\n } = {}) {\n this.buffer = buffer;\n this.cutoff = cutoff;\n this.radius = radius;\n this.lang = lang;\n\n // make the canvas size big enough to both have the specified buffer around the glyph\n // for \"halo\", and account for some glyphs possibly being larger than their font size\n const size = this.size = fontSize + buffer * 4;\n\n const canvas = this._createCanvas(size);\n const ctx = this.ctx = canvas.getContext('2d', {willReadFrequently: true});\n ctx.font = `${fontStyle} ${fontWeight} ${fontSize}px ${fontFamily}`;\n\n ctx.textBaseline = 'alphabetic';\n ctx.textAlign = 'left'; // Necessary so that RTL text doesn't have different alignment\n ctx.fillStyle = 'black';\n\n // temporary arrays for the distance transform\n this.gridOuter = new Float64Array(size * size);\n this.gridInner = new Float64Array(size * size);\n this.f = new Float64Array(size);\n this.z = new Float64Array(size + 1);\n this.v = new Uint16Array(size);\n }\n\n _createCanvas(size) {\n const canvas = document.createElement('canvas');\n canvas.width = canvas.height = size;\n return canvas;\n }\n\n draw(char) {\n const {\n width: glyphAdvance,\n actualBoundingBoxAscent,\n actualBoundingBoxDescent,\n actualBoundingBoxLeft,\n actualBoundingBoxRight\n } = this.ctx.measureText(char);\n\n // The integer/pixel part of the top alignment is encoded in metrics.glyphTop\n // The remainder is implicitly encoded in the rasterization\n const glyphTop = Math.ceil(actualBoundingBoxAscent);\n const glyphLeft = 0;\n\n // If the glyph overflows the canvas size, it will be clipped at the bottom/right\n const glyphWidth = Math.max(0, Math.min(this.size - this.buffer, Math.ceil(actualBoundingBoxRight - actualBoundingBoxLeft)));\n const glyphHeight = Math.min(this.size - this.buffer, glyphTop + Math.ceil(actualBoundingBoxDescent));\n\n const width = glyphWidth + 2 * this.buffer;\n const height = glyphHeight + 2 * this.buffer;\n\n const len = Math.max(width * height, 0);\n const data = new Uint8ClampedArray(len);\n const glyph = {data, width, height, glyphWidth, glyphHeight, glyphTop, glyphLeft, glyphAdvance};\n if (glyphWidth === 0 || glyphHeight === 0) return glyph;\n\n const {ctx, buffer, gridInner, gridOuter} = this;\n if (this.lang) ctx.lang = this.lang;\n ctx.clearRect(buffer, buffer, glyphWidth, glyphHeight);\n ctx.fillText(char, buffer, buffer + glyphTop);\n const imgData = ctx.getImageData(buffer, buffer, glyphWidth, glyphHeight);\n\n // Initialize grids outside the glyph range to alpha 0\n gridOuter.fill(INF, 0, len);\n gridInner.fill(0, 0, len);\n\n for (let y = 0; y < glyphHeight; y++) {\n for (let x = 0; x < glyphWidth; x++) {\n const a = imgData.data[4 * (y * glyphWidth + x) + 3] / 255; // alpha value\n if (a === 0) continue; // empty pixels\n\n const j = (y + buffer) * width + x + buffer;\n\n if (a === 1) { // fully drawn pixels\n gridOuter[j] = 0;\n gridInner[j] = INF;\n\n } else { // aliased pixels\n const d = 0.5 - a;\n gridOuter[j] = d > 0 ? d * d : 0;\n gridInner[j] = d < 0 ? d * d : 0;\n }\n }\n }\n\n edt(gridOuter, 0, 0, width, height, width, this.f, this.v, this.z);\n edt(gridInner, buffer, buffer, glyphWidth, glyphHeight, width, this.f, this.v, this.z);\n\n for (let i = 0; i < len; i++) {\n const d = Math.sqrt(gridOuter[i]) - Math.sqrt(gridInner[i]);\n data[i] = Math.round(255 - 255 * (d / this.radius + this.cutoff));\n }\n\n return glyph;\n }\n}\n\n// 2D Euclidean squared distance transform by Felzenszwalb & Huttenlocher https://cs.brown.edu/~pff/papers/dt-final.pdf\nfunction edt(data, x0, y0, width, height, gridSize, f, v, z) {\n for (let x = x0; x < x0 + width; x++) edt1d(data, y0 * gridSize + x, gridSize, height, f, v, z);\n for (let y = y0; y < y0 + height; y++) edt1d(data, y * gridSize + x0, 1, width, f, v, z);\n}\n\n// 1D squared distance transform\nfunction edt1d(grid, offset, stride, length, f, v, z) {\n v[0] = 0;\n z[0] = -INF;\n z[1] = INF;\n f[0] = grid[offset];\n\n for (let q = 1, k = 0, s = 0; q < length; q++) {\n f[q] = grid[offset + q * stride];\n const q2 = q * q;\n do {\n const r = v[k];\n s = (f[q] - f[r] + q2 - r * r) / (q - r) / 2;\n } while (s <= z[k] && --k > -1);\n\n k++;\n v[k] = q;\n z[k] = s;\n z[k + 1] = INF;\n }\n\n for (let q = 0, k = 0; q < length; q++) {\n while (z[k + 1] < q) k++;\n const r = v[k];\n const qr = q - r;\n grid[offset + q * stride] = f[r] + qr * qr;\n }\n}\n","import TinySDF from '@mapbox/tiny-sdf';\nimport type { TinySDFOptions } from '@mapbox/tiny-sdf';\nimport { BoundingBox, Color, FontSource, ImageFiltering, ImageSource, ImageSourceAttributeConstants, Resource, Vector } from 'excalibur';\nimport type { HTMLImageSource, Loadable } from 'excalibur';\n\nexport type UnicodeCodePointRange = [startCodePoint: number, endCodePoint: number];\n\nexport type SDFTextAlign = 'left' | 'center' | 'right';\n\n/**\n * tiny-sdf's default cutoff: the fraction of the distance radius that lies outside the glyph edge\n */\nconst SDF_CUTOFF = 0.25;\n\n/**\n * Placement of one glyph on the atlas, as produced by tiny-sdf\n */\nexport interface SDFGlyph {\n /**\n * x pixel coordinate on the SDF atlas image\n */\n x: number;\n /**\n * y pixel coordinate on the SDF atlas image\n */\n y: number;\n /**\n * SDF image data width on the atlas (includes non-glyph buffer space)\n */\n width: number;\n /**\n * SDF image data height on the atlas (includes non-glyph buffer space)\n */\n height: number;\n /**\n * Actual glyph width\n */\n glyphWidth: number;\n /**\n * Actual glyph height (ascent from baseline + descent from baseline)\n */\n glyphHeight: number;\n /**\n * Top of the glyph, ascent above the baseline in pixels\n */\n glyphTop: number;\n /**\n * Left of the glyph relative to the pen position\n */\n glyphLeft: number;\n /**\n * Amount the glyph advances the pen while writing\n */\n glyphAdvance: number;\n}\n\n/**\n * Glyph metadata plus the raw grayscale SDF pixels, before they are placed on the atlas\n */\nexport interface SDFGlyphData extends Omit<SDFGlyph, 'x' | 'y'> {\n data: Uint8ClampedArray;\n}\n\n/**\n * JSON written next to a pre-generated atlas image, see the `ex-generate-sdf` CLI\n */\nexport interface SDFMetadata {\n /**\n * Atlas image path, relative to the metadata file\n */\n atlas: string;\n color: string;\n alphabet: string;\n fontSize: number;\n buffer: number;\n /**\n * Max ascent above the baseline of any glyph, in atlas pixels\n */\n ascent: number;\n halo: number;\n gamma: number;\n glyphs: Record<string, SDFGlyph>;\n}\n\nexport function getCharactersFromUnicodeRanges(ranges: UnicodeCodePointRange[]) {\n return ranges.flatMap(([start, end]) => Array.from({ length: end - start + 1 }, (_, i) => String.fromCodePoint(start + i))).join('');\n}\n\n/**\n * Everything the renderer needs to lay out and draw text from an SDF atlas. Implemented by\n * {@link SDFFont} (atlas generated in the browser at load time) and {@link SDFAtlas} (pre-generated).\n */\nexport abstract class SDFSource {\n /**\n * Code point to glyph placement on the atlas\n */\n public readonly glyphs: Map<string, SDFGlyph> = new Map();\n\n /**\n * The atlas image, uploaded to the GPU by the renderer\n */\n public abstract get atlas(): HTMLImageSource;\n\n public abstract get isLoaded(): boolean;\n\n /**\n * Default text color when an {@link SDFText} does not specify one\n */\n public color: Color = Color.Black;\n\n /**\n * Font size the atlas was generated at, text is scaled relative to this\n */\n public fontSize: number = 16;\n\n /**\n * Padding around every glyph on the atlas in pixels\n */\n public buffer: number = 2;\n\n /**\n * Max ascent above the baseline of any glyph in atlas pixels, used to place the first line\n */\n public ascent: number = 0;\n\n /**\n * Normalized distance at which a pixel counts as inside a glyph (0..1). tiny-sdf encodes the\n * edge at `1 - cutoff`, with the default cutoff of 0.25 that is 0.75.\n */\n public halo: number = 1 - SDF_CUTOFF;\n\n /**\n * Antialiasing ramp width around the glyph edge\n */\n public gamma: number = 0.1;\n\n private _cachedText?: string;\n private _cachedSize?: number;\n private _cachedMaxWidth?: number;\n private _cachedLines: string[] = [];\n\n /**\n * Split text into lines, honoring explicit newlines and wrapping at `maxWidth` pixels (when given)\n */\n public getLines(text: string, size: number, maxWidth?: number): string[] {\n if (this._cachedText === text && this._cachedSize === size && this._cachedMaxWidth === maxWidth) {\n return this._cachedLines;\n }\n const lines: string[] = [];\n for (const paragraph of text.split('\\n')) {\n if (maxWidth == null || this.measureLine(paragraph, size) <= maxWidth) {\n lines.push(paragraph);\n continue;\n }\n // wrap on spaces, falling back to breaking a word that does not fit on a line by itself\n let line = '';\n for (const word of paragraph.split(' ')) {\n const candidate = line ? line + ' ' + word : word;\n if (this.measureLine(candidate, size) <= maxWidth) {\n line = candidate;\n } else {\n if (line) {\n lines.push(line);\n }\n line = word;\n while (this.measureLine(line, size) > maxWidth && line.length > 1) {\n let fit = line.length - 1;\n while (fit > 1 && this.measureLine(line.slice(0, fit), size) > maxWidth) {\n fit--;\n }\n lines.push(line.slice(0, fit));\n line = line.slice(fit);\n }\n }\n }\n lines.push(line);\n }\n this._cachedText = text;\n this._cachedSize = size;\n this._cachedMaxWidth = maxWidth;\n this._cachedLines = lines;\n return lines;\n }\n\n /**\n * Width in pixels of a single line of text at `size`\n */\n public measureLine(line: string, size: number): number {\n const scale = size / this.fontSize;\n let width = 0;\n for (const char of line) {\n const glyph = this.glyphs.get(char);\n if (glyph) {\n width += glyph.glyphAdvance * scale;\n }\n }\n return width;\n }\n\n /**\n * Bounds of a block of text at `size`, every line is `size * lineHeight` tall\n */\n public measureText(text: string, size: number, maxWidth?: number, lineHeight: number = 1.2): BoundingBox {\n if (!this.isLoaded) {\n throw new Error(`Cannot measureText(\"${text}\") on an SDF source that is not loaded yet`);\n }\n const lines = this.getLines(text, size, maxWidth);\n let width = 0;\n for (const line of lines) {\n width = Math.max(width, this.measureLine(line, size));\n }\n return BoundingBox.fromDimension(width, lines.length * size * lineHeight, Vector.Zero);\n }\n\n protected _computeAscent() {\n let ascent = 0;\n for (const glyph of this.glyphs.values()) {\n ascent = Math.max(ascent, glyph.glyphTop);\n }\n this.ascent = ascent;\n }\n}\n\nexport type SDFCanvas = HTMLCanvasElement & {\n getContext(context: '2d'): any;\n width: number;\n height: number;\n};\n\nexport interface SDFImageData {\n data: any;\n}\n\nexport interface SDFFontOptions {\n /**\n * Font family to rasterize, either a system font or the family name of `fontFile`\n */\n fontFamily: string;\n /**\n * Optional font file (ttf/otf/woff) to load before generating, registered as `fontFamily`\n */\n fontFile?: string;\n /**\n * Default black\n */\n color?: Color;\n /**\n * Default 400\n */\n fontWeight?: number | string;\n /**\n * Default 'normal'\n */\n fontStyle?: string;\n /**\n * Glyphs to bake into the atlas, a string or a list of unicode code point ranges.\n * Default: ASCII printable characters (0x20-0x7E)\n */\n alphabet?: string | UnicodeCodePointRange[];\n /**\n * Font size the atlas is generated at. Roughly pick the \"biggest\" size your text will be drawn at,\n * smaller text scales down cleanly. Default 48.\n */\n fontSize?: number;\n\n // Providers exist so the same code can run headless (see the CLI, which swaps in skia-canvas)\n sdfProvider?: (options: TinySDFOptions) => TinySDF;\n canvasProvider?: (width: number, height: number) => SDFCanvas;\n imageDataProvider?: (width: number, height: number) => SDFImageData;\n fontSourceLoader?: (fontFile: string, fontFamily: string) => Promise<void>;\n}\n\n/**\n * Generates an SDF atlas when loaded, in the browser or headless. To ship a pre-generated atlas\n * instead use {@link SDFAtlas}.\n */\nexport class SDFFont extends SDFSource implements Loadable<SDFCanvas> {\n public readonly atlas: SDFCanvas;\n private _atlasCtx: CanvasRenderingContext2D;\n\n public get data() {\n return this.atlas;\n }\n\n private _isLoaded = false;\n public get isLoaded(): boolean {\n return this._isLoaded;\n }\n\n private _sdfProvider: (options: TinySDFOptions) => TinySDF = (options) => new TinySDF(options);\n private _canvasProvider: (width: number, height: number) => SDFCanvas = (width, height) => {\n const canvas = document.createElement('canvas');\n canvas.width = width;\n canvas.height = height;\n return canvas;\n };\n private _imageDataProvider: (width: number, height: number) => SDFImageData = (width, height) => new ImageData(width, height);\n private _fontSourceLoader: (font: string, family: string) => Promise<void> = async (file, family) => {\n await new FontSource(file, family).load();\n };\n\n public readonly fontFamily: string;\n public readonly fontFile?: string;\n public readonly fontWeight: string;\n public readonly fontStyle: string;\n public readonly alphabet: string;\n /**\n * Distance field radius in pixels\n */\n public readonly radius: number;\n\n constructor(options: SDFFontOptions) {\n super();\n this._sdfProvider = options.sdfProvider ?? this._sdfProvider;\n this._canvasProvider = options.canvasProvider ?? this._canvasProvider;\n this._imageDataProvider = options.imageDataProvider ?? this._imageDataProvider;\n this._fontSourceLoader = options.fontSourceLoader ?? this._fontSourceLoader;\n\n this.color = options.color ?? Color.Black;\n this.fontFile = options.fontFile;\n this.fontFamily = options.fontFamily;\n this.fontSize = options.fontSize ?? 48;\n this.fontWeight = options.fontWeight?.toString() ?? '400';\n this.fontStyle = options.fontStyle ?? 'normal';\n this.alphabet = Array.isArray(options.alphabet)\n ? getCharactersFromUnicodeRanges(options.alphabet)\n : (options.alphabet ?? getCharactersFromUnicodeRanges([[0x0020, 0x007e]]));\n\n this.buffer = Math.ceil(this.fontSize / 8);\n this.radius = Math.ceil(this.fontSize / 3);\n this.gamma = (2 * 1.4142) / this.fontSize;\n\n const cell = this.fontSize + this.buffer * 2;\n const dimension = Math.ceil(Math.sqrt([...this.alphabet].length)) * cell;\n this.atlas = this._canvasProvider(dimension, dimension);\n if (!this.atlas) {\n throw new Error('Cannot build the SDF atlas canvas');\n }\n // Distance fields must be sampled with linear filtering or the edges go jagged\n this.atlas.setAttribute?.(ImageSourceAttributeConstants.Filtering, ImageFiltering.Blended);\n const ctx = this.atlas.getContext('2d') as CanvasRenderingContext2D | null;\n if (!ctx) {\n throw new Error('Cannot build the SDF atlas 2D context');\n }\n this._atlasCtx = ctx;\n }\n\n private _toRGBAImageData(alphaChannel: Uint8ClampedArray, width: number, height: number) {\n const imageData = this._imageDataProvider(width, height);\n for (let i = 0; i < alphaChannel.length; i++) {\n imageData.data[4 * i + 0] = alphaChannel[i];\n imageData.data[4 * i + 1] = alphaChannel[i];\n imageData.data[4 * i + 2] = alphaChannel[i];\n imageData.data[4 * i + 3] = 255;\n }\n return imageData;\n }\n\n async load(): Promise<SDFCanvas> {\n if (this._isLoaded) {\n return this.atlas;\n }\n if (this.fontFile) {\n await this._fontSourceLoader(this.fontFile, this.fontFamily);\n }\n\n const tinySdf = this._sdfProvider({\n fontSize: this.fontSize,\n fontFamily: this.fontFamily,\n fontStyle: this.fontStyle,\n fontWeight: this.fontWeight,\n buffer: this.buffer,\n radius: this.radius,\n cutoff: SDF_CUTOFF\n } satisfies TinySDFOptions);\n\n // Rasterize every glyph into a distance field, then pack them left to right, top to bottom\n const glyphs: [string, SDFGlyphData][] = [];\n for (const char of this.alphabet) {\n glyphs.push([char, tinySdf.draw(char)]);\n }\n let x = 0;\n let y = 0;\n let rowHeight = 0;\n for (const [char, glyph] of glyphs) {\n if (x + glyph.width > this.atlas.width) {\n x = 0;\n y += rowHeight;\n rowHeight = 0;\n }\n if (y + glyph.height > this.atlas.height) {\n throw new Error(`SDF atlas is too small for the alphabet of \"${this.fontFamily}\", this is a bug`);\n }\n this._atlasCtx.putImageData(this._toRGBAImageData(glyph.data, glyph.width, glyph.height) as any, x, y);\n const { data, ...placement } = glyph;\n this.glyphs.set(char, { ...placement, x, y });\n x += glyph.width;\n rowHeight = Math.max(rowHeight, glyph.height);\n }\n this._computeAscent();\n this._isLoaded = true;\n return this.atlas;\n }\n\n /**\n * Metadata describing this atlas, write it next to the atlas image to load later with {@link SDFAtlas}\n */\n public toMetadata(atlasPath: string): SDFMetadata {\n const glyphs: Record<string, SDFGlyph> = {};\n for (const [char, glyph] of this.glyphs) {\n glyphs[char] = glyph;\n }\n return {\n atlas: atlasPath,\n color: this.color.toHex(),\n alphabet: this.alphabet,\n fontSize: this.fontSize,\n buffer: this.buffer,\n ascent: this.ascent,\n halo: this.halo,\n gamma: this.gamma,\n glyphs\n };\n }\n}\n\nexport interface SDFAtlasOptions {\n /**\n * Path to the atlas image file\n */\n atlasPath: string;\n /**\n * Path to the JSON glyph metadata written by the CLI\n */\n metadataPath: string;\n}\n\n/**\n * Loads a pre-generated SDF atlas (image + JSON metadata), see the `ex-generate-sdf` CLI\n */\nexport class SDFAtlas extends SDFSource implements Loadable<ImageSource> {\n public readonly data: ImageSource;\n public readonly metadata: Resource<SDFMetadata>;\n\n public get atlas(): HTMLImageElement {\n return this.data.image;\n }\n\n public get isLoaded(): boolean {\n return this.data.isLoaded && this.metadata.isLoaded;\n }\n\n constructor(options: SDFAtlasOptions) {\n super();\n this.data = new ImageSource(options.atlasPath, { filtering: ImageFiltering.Blended });\n this.metadata = new Resource<SDFMetadata>(options.metadataPath, 'json');\n }\n\n async load(): Promise<ImageSource> {\n const [, metadata] = await Promise.all([this.data.load(), this.metadata.load()]);\n for (const [char, glyph] of Object.entries(metadata.glyphs)) {\n this.glyphs.set(char, glyph);\n }\n this.color = Color.fromHex(metadata.color);\n this.halo = metadata.halo;\n this.gamma = metadata.gamma;\n this.fontSize = metadata.fontSize;\n this.buffer = metadata.buffer;\n if (metadata.ascent != null) {\n this.ascent = metadata.ascent;\n } else {\n this._computeAscent();\n }\n return this.data;\n }\n}\n","import { Color, QuadIndexBuffer, Shader, VertexBuffer, VertexLayout } from 'excalibur';\nimport type { ExcaliburGraphicsContextWebGL, HTMLImageSource, RendererPlugin, Vector } from 'excalibur';\nimport fragmentSource from './shaders/sdf-text.frag.glsl?raw';\nimport vertexSource from './shaders/sdf-text.vert.glsl?raw';\nimport type { SDFSource, SDFTextAlign } from './sdf-font';\n\n/**\n * Per draw options for {@link SDFTextRenderer.draw}\n */\nexport interface SDFDrawOptions {\n /**\n * Only draw the first n characters, handy for typewriter effects. Default all.\n */\n visibleCharacters?: number;\n /**\n * Text color, defaults to the source's color\n */\n color?: Color;\n /**\n * Alignment of lines within the text block. Default 'left'.\n */\n textAlign?: SDFTextAlign;\n /**\n * Wrap lines longer than this many pixels\n */\n maxWidth?: number;\n /**\n * Line height as a multiple of `size`. Default 1.2.\n */\n lineHeight?: number;\n}\n\n/**\n * Finds how many `if` branches the fragment shader can hold on this GPU, which bounds how many\n * atlases a batch can reference\n */\nexport function getMaxShaderComplexity(gl: WebGL2RenderingContext, numIfs: number): number {\n const assembleTestShader = (numIfs: number) => {\n const testShader = `#version 300 es\n precision mediump float;\n out vec4 fragColor;\n void main() {\n float index = 1.01;\n %%complexity%%\n }`;\n let testComplexity = '';\n for (let i = 0; i < numIfs; i++) {\n testComplexity += i === 0 ? `if (index <= ${i}.5) {\\n` : ` else if (index <= ${i}.5) {\\n`;\n testComplexity += ` fragColor = vec4(1.0);\\n`;\n testComplexity += ` }\\n`;\n }\n return testShader.replace('%%complexity%%', testComplexity);\n };\n\n let canCompile = false;\n do {\n const shader = gl.createShader(gl.FRAGMENT_SHADER)!;\n gl.shaderSource(shader, assembleTestShader(numIfs));\n gl.compileShader(shader);\n canCompile = gl.getShaderParameter(shader, gl.COMPILE_STATUS);\n gl.deleteShader(shader);\n if (!canCompile) {\n numIfs = (numIfs / 2) | 0;\n }\n } while (!canCompile && numIfs > 0);\n return Math.max(numIfs, 1);\n}\n\n/**\n * Name the renderer is registered under on the graphics context\n */\nexport const SDF_TEXT_RENDERER = 'ex.sdf-text-renderer' as const;\n\nconst FLOATS_PER_VERTEX = 9; // position (2) + uv (2) + texture index (1) + color (4)\n\n/**\n * Batched WebGL renderer for SDF text. Register it on the graphics context with\n * {@link SDFTextPlugin}, or by hand with `context.lazyRegister('ex.sdf-text-renderer', () => new SDFTextRenderer())`.\n *\n * Every glyph is one textured quad; quads from any number of {@link SDFText} draws are batched into\n * a single draw call until the vertex buffer or the texture slots fill up.\n */\nexport class SDFTextRenderer implements RendererPlugin {\n public readonly type = SDF_TEXT_RENDERER;\n public priority: number = 0;\n\n private _gl!: WebGL2RenderingContext;\n private _context!: ExcaliburGraphicsContextWebGL;\n private _shader!: Shader;\n private _buffer!: VertexBuffer;\n private _quads!: QuadIndexBuffer;\n private _layout!: VertexLayout;\n\n private _maxGlyphs: number = 10922; // max(uint16) / 6 indices per quad\n private _glyphCount: number = 0;\n private _vertexIndex: number = 0;\n\n private _maxTextures: number = 1;\n private _textures: WebGLTexture[] = [];\n private _textureToIndex = new Map<WebGLTexture, number>();\n private _images = new Set<HTMLImageSource>();\n\n private _gamma: number = 0;\n private _halo: number = 0;\n private _quad = [0, 0, 0, 0, 0, 0, 0, 0];\n\n initialize(gl: WebGL2RenderingContext, context: ExcaliburGraphicsContextWebGL): void {\n this._gl = gl;\n this._context = context;\n const maxTextureUnits = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);\n this._maxTextures = Math.min(maxTextureUnits, getMaxShaderComplexity(gl, maxTextureUnits));\n\n this._shader = new Shader({\n name: 'ex.sdf-text-renderer',\n graphicsContext: context,\n vertexSource,\n fragmentSource: this._transformFragmentSource(fragmentSource, this._maxTextures)\n });\n this._shader.compile();\n this._shader.use();\n this._shader.setUniformMatrix('u_matrix', context.ortho);\n // Texture slots are [0, 1, 2, ... maxTextures - 1]\n this._shader.setUniformIntArray(\n 'u_textures',\n [...Array(this._maxTextures)].map((_, i) => i)\n );\n\n this._buffer = new VertexBuffer({\n gl,\n size: FLOATS_PER_VERTEX * 4 * this._maxGlyphs,\n type: 'dynamic'\n });\n this._layout = new VertexLayout({\n gl,\n shader: this._shader,\n vertexBuffer: this._buffer,\n attributes: [\n ['a_position', 2],\n ['a_uv', 2],\n ['a_textureIndex', 1],\n ['a_color', 4]\n ]\n });\n this._quads = new QuadIndexBuffer(gl, this._maxGlyphs, true);\n }\n\n private _transformFragmentSource(source: string, maxTextures: number): string {\n let texturePicker = '';\n for (let i = 0; i < maxTextures; i++) {\n texturePicker += i === 0 ? `if (v_textureIndex <= ${i}.5) {\\n` : ` else if (v_textureIndex <= ${i}.5) {\\n`;\n texturePicker += ` dist = texture(u_textures[${i}], v_uv).r;\\n`;\n texturePicker += ` }\\n`;\n }\n return source.replace('%%count%%', maxTextures.toString()).replace('%%texture_picker%%', texturePicker);\n }\n\n /**\n * Upload the atlas once (the engine's texture loader caches it) and reserve a slot in this batch\n */\n private _addAtlasTexture(image: HTMLImageSource): number {\n const texture = this._context.textureLoader.load(image, undefined, image.getAttribute('forceUpload') === 'true')!;\n image.removeAttribute('forceUpload');\n let index = this._textureToIndex.get(texture);\n if (index === undefined) {\n index = this._textures.length;\n this._textures.push(texture);\n this._textureToIndex.set(texture, index);\n this._images.add(image);\n }\n return index;\n }\n\n private _isFull(): boolean {\n return this._glyphCount >= this._maxGlyphs || this._textures.length >= this._maxTextures;\n }\n\n /**\n * Queue a block of text. `pos` is the top left of the text block, `size` the font size in pixels.\n */\n draw(source: SDFSource, text: string, pos: Vector, size: number, options?: SDFDrawOptions): void {\n if (!source.isLoaded) {\n return;\n }\n const { visibleCharacters = Infinity, textAlign = 'left', maxWidth, lineHeight = 1.2 } = options ?? {};\n const color = options?.color ?? source.color;\n\n // The edge uniforms are per atlas, a change means a new batch\n if (this._gamma !== source.gamma || this._halo !== source.halo) {\n this.flush();\n this._gamma = source.gamma;\n this._halo = source.halo;\n }\n if (this._isFull() && !this._images.has(source.atlas)) {\n this.flush();\n }\n\n const atlas = source.atlas;\n const textureId = this._addAtlasTexture(atlas);\n const atlasWidth = atlas.width;\n const atlasHeight = atlas.height;\n const transform = this._context.getTransform();\n const vertices = this._layout.vertexBuffer.bufferData;\n\n const scale = size / source.fontSize;\n const lines = source.getLines(text, size, maxWidth);\n const blockWidth = maxWidth ?? Math.max(...lines.map((line) => source.measureLine(line, size)));\n const alignFactor = textAlign === 'center' ? 0.5 : textAlign === 'right' ? 1 : 0;\n\n let drawn = 0;\n for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {\n const line = lines[lineIndex];\n let penX = pos.x + (blockWidth - source.measureLine(line, size)) * alignFactor;\n const baseline = pos.y + source.ascent * scale + lineIndex * size * lineHeight;\n\n for (const char of line) {\n if (drawn >= visibleCharacters) {\n return;\n }\n drawn++;\n const glyph = source.glyphs.get(char);\n if (!glyph) {\n continue;\n }\n if (this._isFull()) {\n // flush keeps the current atlas resident so the texture index stays valid\n const resident = atlas;\n this.flush();\n this._addAtlasTexture(resident);\n }\n\n // tiny-sdf rasterizes each glyph at (buffer, buffer + glyphTop) inside its cell\n const x = penX + (glyph.glyphLeft - source.buffer) * scale;\n const y = baseline - (glyph.glyphTop + source.buffer) * scale;\n const w = glyph.width * scale;\n const h = glyph.height * scale;\n penX += glyph.glyphAdvance * scale;\n\n const quad = this._quad;\n quad[0] = x;\n quad[1] = y;\n quad[2] = x + w;\n quad[3] = y;\n quad[4] = x;\n quad[5] = y + h;\n quad[6] = x + w;\n quad[7] = y + h;\n transform.multiplyQuadInPlace(quad);\n\n const u0 = glyph.x / atlasWidth;\n const v0 = glyph.y / atlasHeight;\n const u1 = (glyph.x + glyph.width) / atlasWidth;\n const v1 = (glyph.y + glyph.height) / atlasHeight;\n\n this._pushVertex(vertices, quad[0], quad[1], u0, v0, textureId, color);\n this._pushVertex(vertices, quad[4], quad[5], u0, v1, textureId, color);\n this._pushVertex(vertices, quad[2], quad[3], u1, v0, textureId, color);\n this._pushVertex(vertices, quad[6], quad[7], u1, v1, textureId, color);\n this._glyphCount++;\n }\n }\n }\n\n private _pushVertex(vertices: Float32Array, x: number, y: number, u: number, v: number, textureId: number, color: Color) {\n vertices[this._vertexIndex++] = x;\n vertices[this._vertexIndex++] = y;\n vertices[this._vertexIndex++] = u;\n vertices[this._vertexIndex++] = v;\n vertices[this._vertexIndex++] = textureId;\n vertices[this._vertexIndex++] = color.r / 255;\n vertices[this._vertexIndex++] = color.g / 255;\n vertices[this._vertexIndex++] = color.b / 255;\n vertices[this._vertexIndex++] = color.a;\n }\n\n public get hasPendingDraws(): boolean {\n return this._glyphCount !== 0;\n }\n\n flush(): void {\n if (this._glyphCount === 0) {\n return;\n }\n const gl = this._gl;\n this._shader.use();\n this._layout.use(true, FLOATS_PER_VERTEX * 4 * this._glyphCount);\n this._shader.setUniformMatrix('u_matrix', this._context.ortho);\n this._shader.setUniformFloat('u_gamma', this._gamma);\n this._shader.setUniformFloat('u_buffer', this._halo);\n\n for (let i = 0; i < this._maxTextures; i++) {\n gl.activeTexture(gl.TEXTURE0 + i);\n gl.bindTexture(gl.TEXTURE_2D, this._textures[i] || this._textures[0]);\n }\n\n this._quads.bind();\n gl.drawElements(gl.TRIANGLES, this._glyphCount * 6, this._quads.bufferGlType, 0);\n\n this._glyphCount = 0;\n this._vertexIndex = 0;\n this._textures.length = 0;\n this._textureToIndex.clear();\n this._images.clear();\n }\n\n dispose(): void {\n this._buffer.dispose();\n this._quads.dispose();\n this._shader.dispose();\n this._textures.length = 0;\n this._context = null as any;\n this._gl = null as any;\n }\n}\n","import { Color, ExcaliburGraphicsContextWebGL, Graphic, vec } from 'excalibur';\nimport type { ExcaliburGraphicsContext, GraphicOptions } from 'excalibur';\nimport type { SDFSource, SDFTextAlign } from './sdf-font';\nimport { SDF_TEXT_RENDERER } from './sdf-text-renderer';\nimport type { SDFTextRenderer } from './sdf-text-renderer';\n\nexport interface SDFTextOptions extends GraphicOptions {\n /**\n * The {@link SDFFont} or {@link SDFAtlas} to draw with\n */\n sdf: SDFSource;\n text: string;\n /**\n * Font size in pixels, any size works, the atlas is a distance field. Default is the source's `fontSize`.\n */\n size?: number;\n /**\n * Defaults to the source's color\n */\n color?: Color;\n /**\n * Draw only the first n characters, for typewriter effects. Default all.\n */\n visibleCharacters?: number;\n /**\n * Alignment of lines within the block. Default 'left'.\n */\n textAlign?: SDFTextAlign;\n /**\n * Wrap lines longer than this many pixels\n */\n maxWidth?: number;\n /**\n * Line height as a multiple of `size`. Default 1.2.\n */\n lineHeight?: number;\n}\n\n/**\n * A text {@link Graphic} drawn from a signed distance field atlas by the {@link SDFTextRenderer}.\n * Crisp at any size, rotation or zoom, and batched with other SDF text in the same frame.\n */\nexport class SDFText extends Graphic {\n public sdf: SDFSource;\n public size: number;\n public color?: Color;\n public visibleCharacters: number;\n public textAlign: SDFTextAlign;\n public maxWidth?: number;\n public lineHeight: number;\n\n private _text: string;\n private _measuredFor?: string;\n\n constructor(options: SDFTextOptions) {\n super(options);\n this.sdf = options.sdf;\n this._text = options.text;\n this.size = options.size ?? options.sdf.fontSize;\n this.color = options.color;\n this.visibleCharacters = options.visibleCharacters ?? Infinity;\n this.textAlign = options.textAlign ?? 'left';\n this.maxWidth = options.maxWidth;\n this.lineHeight = options.lineHeight ?? 1.2;\n this._calculateDimension();\n }\n\n public get text(): string {\n return this._text;\n }\n\n public set text(value: string) {\n this._text = value;\n this._calculateDimension();\n }\n\n public override get width(): number {\n this._calculateDimension();\n return super.width;\n }\n\n public override set width(value: number) {\n super.width = value;\n }\n\n public override get height(): number {\n this._calculateDimension();\n return super.height;\n }\n\n public override set height(value: number) {\n super.height = value;\n }\n\n private _calculateDimension() {\n if (!this.sdf.isLoaded) {\n return;\n }\n const key = `${this._text}|${this.size}|${this.maxWidth}|${this.lineHeight}`;\n if (this._measuredFor === key) {\n return;\n }\n this._measuredFor = key;\n const { width, height } = this.sdf.measureText(this._text, this.size, this.maxWidth, this.lineHeight);\n super.width = width;\n super.height = height;\n }\n\n protected _drawImage(ex: ExcaliburGraphicsContext, x: number, y: number): void {\n if (ex instanceof ExcaliburGraphicsContextWebGL) {\n ex.draw<SDFTextRenderer>(SDF_TEXT_RENDERER, this.sdf, this._text, vec(x, y), this.size, {\n visibleCharacters: this.visibleCharacters,\n color: this.color,\n textAlign: this.textAlign,\n maxWidth: this.maxWidth,\n lineHeight: this.lineHeight\n });\n }\n }\n\n clone(): SDFText {\n return new SDFText({\n ...this.cloneGraphicOptions(),\n sdf: this.sdf,\n text: this._text,\n size: this.size,\n color: this.color,\n visibleCharacters: this.visibleCharacters,\n textAlign: this.textAlign,\n maxWidth: this.maxWidth,\n lineHeight: this.lineHeight\n });\n }\n}\n","import { ExcaliburGraphicsContextWebGL, Plugin } from 'excalibur';\nimport type { ExcaliburGraphicsContext } from 'excalibur';\nimport { SDF_TEXT_RENDERER, SDFTextRenderer } from './sdf-text-renderer';\n\n/**\n * Installs the {@link SDFTextRenderer} on the engine's WebGL graphics context.\n *\n * ```typescript\n * const game = new ex.Engine({ plugins: [new SDFTextPlugin()] });\n * ```\n */\nexport class SDFTextPlugin extends Plugin {\n constructor() {\n super('sdf-text');\n }\n\n override onGraphicsPostInitialize(context: ExcaliburGraphicsContext): void {\n if (context instanceof ExcaliburGraphicsContextWebGL) {\n // Lazy: the renderer compiles its shader the first time an SDFText is drawn\n context.lazyRegister(SDF_TEXT_RENDERER, () => new SDFTextRenderer());\n }\n }\n}\n"],"ignoreList":[0],"mappings":";AAAA,IAAMiB,IAAM,MAESC,KAArB,MAA6B;AAAA,EACzB,YAAY,EACR,UAAAC,IAAW,IACX,QAAAC,IAAS,GACT,QAAAC,IAAS,GACT,QAAAC,IAAS,MACT,YAAAC,IAAa,cACb,YAAAC,IAAa,UACb,WAAAC,IAAY,UACZ,MAAAC,IAAO,KAAA,IACP,CAAC,GAAG;AACJ,SAAK,SAASN,GACd,KAAK,SAASE,GACd,KAAK,SAASD,GACd,KAAK,OAAOK;AAIZ,UAAMC,IAAO,KAAK,OAAOR,IAAWC,IAAS,GAEvCQ,IAAS,KAAK,cAAcD,CAAI,GAChCE,IAAM,KAAK,MAAMD,EAAO,WAAW,MAAM,EAAC,oBAAoB,GAAI,CAAC;AACzE,IAAAC,EAAI,OAAO,GAAGJ,CAAA,IAAaD,CAAA,IAAcL,CAAA,MAAcI,CAAA,IAEvDM,EAAI,eAAe,cACnBA,EAAI,YAAY,QAChBA,EAAI,YAAY,SAGhB,KAAK,YAAY,IAAI,aAAaF,IAAOA,CAAI,GAC7C,KAAK,YAAY,IAAI,aAAaA,IAAOA,CAAI,GAC7C,KAAK,IAAI,IAAI,aAAaA,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ptions } from '@mapbox/tiny-sdf';
|
|
3
|
+
import { BoundingBox, Color, ImageSource, Resource } from 'excalibur';
|
|
4
|
+
import type { HTMLImageSource, Loadable } from 'excalibur';
|
|
5
|
+
export type UnicodeCodePointRange = [startCodePoint: number, endCodePoint: number];
|
|
6
|
+
export type SDFTextAlign = 'left' | 'center' | 'right';
|
|
7
|
+
/**
|
|
8
|
+
* Placement of one glyph on the atlas, as produced by tiny-sdf
|
|
9
|
+
*/
|
|
10
|
+
export interface SDFGlyph {
|
|
11
|
+
/**
|
|
12
|
+
* x pixel coordinate on the SDF atlas image
|
|
13
|
+
*/
|
|
14
|
+
x: number;
|
|
15
|
+
/**
|
|
16
|
+
* y pixel coordinate on the SDF atlas image
|
|
17
|
+
*/
|
|
18
|
+
y: number;
|
|
19
|
+
/**
|
|
20
|
+
* SDF image data width on the atlas (includes non-glyph buffer space)
|
|
21
|
+
*/
|
|
22
|
+
width: number;
|
|
23
|
+
/**
|
|
24
|
+
* SDF image data height on the atlas (includes non-glyph buffer space)
|
|
25
|
+
*/
|
|
26
|
+
height: number;
|
|
27
|
+
/**
|
|
28
|
+
* Actual glyph width
|
|
29
|
+
*/
|
|
30
|
+
glyphWidth: number;
|
|
31
|
+
/**
|
|
32
|
+
* Actual glyph height (ascent from baseline + descent from baseline)
|
|
33
|
+
*/
|
|
34
|
+
glyphHeight: number;
|
|
35
|
+
/**
|
|
36
|
+
* Top of the glyph, ascent above the baseline in pixels
|
|
37
|
+
*/
|
|
38
|
+
glyphTop: number;
|
|
39
|
+
/**
|
|
40
|
+
* Left of the glyph relative to the pen position
|
|
41
|
+
*/
|
|
42
|
+
glyphLeft: number;
|
|
43
|
+
/**
|
|
44
|
+
* Amount the glyph advances the pen while writing
|
|
45
|
+
*/
|
|
46
|
+
glyphAdvance: number;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Glyph metadata plus the raw grayscale SDF pixels, before they are placed on the atlas
|
|
50
|
+
*/
|
|
51
|
+
export interface SDFGlyphData extends Omit<SDFGlyph, 'x' | 'y'> {
|
|
52
|
+
data: Uint8ClampedArray;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* JSON written next to a pre-generated atlas image, see the `ex-generate-sdf` CLI
|
|
56
|
+
*/
|
|
57
|
+
export interface SDFMetadata {
|
|
58
|
+
/**
|
|
59
|
+
* Atlas image path, relative to the metadata file
|
|
60
|
+
*/
|
|
61
|
+
atlas: string;
|
|
62
|
+
color: string;
|
|
63
|
+
alphabet: string;
|
|
64
|
+
fontSize: number;
|
|
65
|
+
buffer: number;
|
|
66
|
+
/**
|
|
67
|
+
* Max ascent above the baseline of any glyph, in atlas pixels
|
|
68
|
+
*/
|
|
69
|
+
ascent: number;
|
|
70
|
+
halo: number;
|
|
71
|
+
gamma: number;
|
|
72
|
+
glyphs: Record<string, SDFGlyph>;
|
|
73
|
+
}
|
|
74
|
+
export declare function getCharactersFromUnicodeRanges(ranges: UnicodeCodePointRange[]): string;
|
|
75
|
+
/**
|
|
76
|
+
* Everything the renderer needs to lay out and draw text from an SDF atlas. Implemented by
|
|
77
|
+
* {@link SDFFont} (atlas generated in the browser at load time) and {@link SDFAtlas} (pre-generated).
|
|
78
|
+
*/
|
|
79
|
+
export declare abstract class SDFSource {
|
|
80
|
+
/**
|
|
81
|
+
* Code point to glyph placement on the atlas
|
|
82
|
+
*/
|
|
83
|
+
readonly glyphs: Map<string, SDFGlyph>;
|
|
84
|
+
/**
|
|
85
|
+
* The atlas image, uploaded to the GPU by the renderer
|
|
86
|
+
*/
|
|
87
|
+
abstract get atlas(): HTMLImageSource;
|
|
88
|
+
abstract get isLoaded(): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Default text color when an {@link SDFText} does not specify one
|
|
91
|
+
*/
|
|
92
|
+
color: Color;
|
|
93
|
+
/**
|
|
94
|
+
* Font size the atlas was generated at, text is scaled relative to this
|
|
95
|
+
*/
|
|
96
|
+
fontSize: number;
|
|
97
|
+
/**
|
|
98
|
+
* Padding around every glyph on the atlas in pixels
|
|
99
|
+
*/
|
|
100
|
+
buffer: number;
|
|
101
|
+
/**
|
|
102
|
+
* Max ascent above the baseline of any glyph in atlas pixels, used to place the first line
|
|
103
|
+
*/
|
|
104
|
+
ascent: number;
|
|
105
|
+
/**
|
|
106
|
+
* Normalized distance at which a pixel counts as inside a glyph (0..1). tiny-sdf encodes the
|
|
107
|
+
* edge at `1 - cutoff`, with the default cutoff of 0.25 that is 0.75.
|
|
108
|
+
*/
|
|
109
|
+
halo: number;
|
|
110
|
+
/**
|
|
111
|
+
* Antialiasing ramp width around the glyph edge
|
|
112
|
+
*/
|
|
113
|
+
gamma: number;
|
|
114
|
+
private _cachedText?;
|
|
115
|
+
private _cachedSize?;
|
|
116
|
+
private _cachedMaxWidth?;
|
|
117
|
+
private _cachedLines;
|
|
118
|
+
/**
|
|
119
|
+
* Split text into lines, honoring explicit newlines and wrapping at `maxWidth` pixels (when given)
|
|
120
|
+
*/
|
|
121
|
+
getLines(text: string, size: number, maxWidth?: number): string[];
|
|
122
|
+
/**
|
|
123
|
+
* Width in pixels of a single line of text at `size`
|
|
124
|
+
*/
|
|
125
|
+
measureLine(line: string, size: number): number;
|
|
126
|
+
/**
|
|
127
|
+
* Bounds of a block of text at `size`, every line is `size * lineHeight` tall
|
|
128
|
+
*/
|
|
129
|
+
measureText(text: string, size: number, maxWidth?: number, lineHeight?: number): BoundingBox;
|
|
130
|
+
protected _computeAscent(): void;
|
|
131
|
+
}
|
|
132
|
+
export type SDFCanvas = HTMLCanvasElement & {
|
|
133
|
+
getContext(context: '2d'): any;
|
|
134
|
+
width: number;
|
|
135
|
+
height: number;
|
|
136
|
+
};
|
|
137
|
+
export interface SDFImageData {
|
|
138
|
+
data: any;
|
|
139
|
+
}
|
|
140
|
+
export interface SDFFontOptions {
|
|
141
|
+
/**
|
|
142
|
+
* Font family to rasterize, either a system font or the family name of `fontFile`
|
|
143
|
+
*/
|
|
144
|
+
fontFamily: string;
|
|
145
|
+
/**
|
|
146
|
+
* Optional font file (ttf/otf/woff) to load before generating, registered as `fontFamily`
|
|
147
|
+
*/
|
|
148
|
+
fontFile?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Default black
|
|
151
|
+
*/
|
|
152
|
+
color?: Color;
|
|
153
|
+
/**
|
|
154
|
+
* Default 400
|
|
155
|
+
*/
|
|
156
|
+
fontWeight?: number | string;
|
|
157
|
+
/**
|
|
158
|
+
* Default 'normal'
|
|
159
|
+
*/
|
|
160
|
+
fontStyle?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Glyphs to bake into the atlas, a string or a list of unicode code point ranges.
|
|
163
|
+
* Default: ASCII printable characters (0x20-0x7E)
|
|
164
|
+
*/
|
|
165
|
+
alphabet?: string | UnicodeCodePointRange[];
|
|
166
|
+
/**
|
|
167
|
+
* Font size the atlas is generated at. Roughly pick the "biggest" size your text will be drawn at,
|
|
168
|
+
* smaller text scales down cleanly. Default 48.
|
|
169
|
+
*/
|
|
170
|
+
fontSize?: number;
|
|
171
|
+
sdfProvider?: (options: TinySDFOptions) => TinySDF;
|
|
172
|
+
canvasProvider?: (width: number, height: number) => SDFCanvas;
|
|
173
|
+
imageDataProvider?: (width: number, height: number) => SDFImageData;
|
|
174
|
+
fontSourceLoader?: (fontFile: string, fontFamily: string) => Promise<void>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Generates an SDF atlas when loaded, in the browser or headless. To ship a pre-generated atlas
|
|
178
|
+
* instead use {@link SDFAtlas}.
|
|
179
|
+
*/
|
|
180
|
+
export declare class SDFFont extends SDFSource implements Loadable<SDFCanvas> {
|
|
181
|
+
readonly atlas: SDFCanvas;
|
|
182
|
+
private _atlasCtx;
|
|
183
|
+
get data(): SDFCanvas;
|
|
184
|
+
private _isLoaded;
|
|
185
|
+
get isLoaded(): boolean;
|
|
186
|
+
private _sdfProvider;
|
|
187
|
+
private _canvasProvider;
|
|
188
|
+
private _imageDataProvider;
|
|
189
|
+
private _fontSourceLoader;
|
|
190
|
+
readonly fontFamily: string;
|
|
191
|
+
readonly fontFile?: string;
|
|
192
|
+
readonly fontWeight: string;
|
|
193
|
+
readonly fontStyle: string;
|
|
194
|
+
readonly alphabet: string;
|
|
195
|
+
/**
|
|
196
|
+
* Distance field radius in pixels
|
|
197
|
+
*/
|
|
198
|
+
readonly radius: number;
|
|
199
|
+
constructor(options: SDFFontOptions);
|
|
200
|
+
private _toRGBAImageData;
|
|
201
|
+
load(): Promise<SDFCanvas>;
|
|
202
|
+
/**
|
|
203
|
+
* Metadata describing this atlas, write it next to the atlas image to load later with {@link SDFAtlas}
|
|
204
|
+
*/
|
|
205
|
+
toMetadata(atlasPath: string): SDFMetadata;
|
|
206
|
+
}
|
|
207
|
+
export interface SDFAtlasOptions {
|
|
208
|
+
/**
|
|
209
|
+
* Path to the atlas image file
|
|
210
|
+
*/
|
|
211
|
+
atlasPath: string;
|
|
212
|
+
/**
|
|
213
|
+
* Path to the JSON glyph metadata written by the CLI
|
|
214
|
+
*/
|
|
215
|
+
metadataPath: string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Loads a pre-generated SDF atlas (image + JSON metadata), see the `ex-generate-sdf` CLI
|
|
219
|
+
*/
|
|
220
|
+
export declare class SDFAtlas extends SDFSource implements Loadable<ImageSource> {
|
|
221
|
+
readonly data: ImageSource;
|
|
222
|
+
readonly metadata: Resource<SDFMetadata>;
|
|
223
|
+
get atlas(): HTMLImageElement;
|
|
224
|
+
get isLoaded(): boolean;
|
|
225
|
+
constructor(options: SDFAtlasOptions);
|
|
226
|
+
load(): Promise<ImageSource>;
|
|
227
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Plugin } from 'excalibur';
|
|
2
|
+
import type { ExcaliburGraphicsContext } from 'excalibur';
|
|
3
|
+
/**
|
|
4
|
+
* Installs the {@link SDFTextRenderer} on the engine's WebGL graphics context.
|
|
5
|
+
*
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const game = new ex.Engine({ plugins: [new SDFTextPlugin()] });
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare class SDFTextPlugin extends Plugin {
|
|
11
|
+
constructor();
|
|
12
|
+
onGraphicsPostInitialize(context: ExcaliburGraphicsContext): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Color } from 'excalibur';
|
|
2
|
+
import type { ExcaliburGraphicsContextWebGL, RendererPlugin, Vector } from 'excalibur';
|
|
3
|
+
import type { SDFSource, SDFTextAlign } from './sdf-font';
|
|
4
|
+
/**
|
|
5
|
+
* Per draw options for {@link SDFTextRenderer.draw}
|
|
6
|
+
*/
|
|
7
|
+
export interface SDFDrawOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Only draw the first n characters, handy for typewriter effects. Default all.
|
|
10
|
+
*/
|
|
11
|
+
visibleCharacters?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Text color, defaults to the source's color
|
|
14
|
+
*/
|
|
15
|
+
color?: Color;
|
|
16
|
+
/**
|
|
17
|
+
* Alignment of lines within the text block. Default 'left'.
|
|
18
|
+
*/
|
|
19
|
+
textAlign?: SDFTextAlign;
|
|
20
|
+
/**
|
|
21
|
+
* Wrap lines longer than this many pixels
|
|
22
|
+
*/
|
|
23
|
+
maxWidth?: number;
|
|
24
|
+
/**
|
|
25
|
+
* Line height as a multiple of `size`. Default 1.2.
|
|
26
|
+
*/
|
|
27
|
+
lineHeight?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Finds how many `if` branches the fragment shader can hold on this GPU, which bounds how many
|
|
31
|
+
* atlases a batch can reference
|
|
32
|
+
*/
|
|
33
|
+
export declare function getMaxShaderComplexity(gl: WebGL2RenderingContext, numIfs: number): number;
|
|
34
|
+
/**
|
|
35
|
+
* Name the renderer is registered under on the graphics context
|
|
36
|
+
*/
|
|
37
|
+
export declare const SDF_TEXT_RENDERER: 'ex.sdf-text-renderer';
|
|
38
|
+
/**
|
|
39
|
+
* Batched WebGL renderer for SDF text. Register it on the graphics context with
|
|
40
|
+
* {@link SDFTextPlugin}, or by hand with `context.lazyRegister('ex.sdf-text-renderer', () => new SDFTextRenderer())`.
|
|
41
|
+
*
|
|
42
|
+
* Every glyph is one textured quad; quads from any number of {@link SDFText} draws are batched into
|
|
43
|
+
* a single draw call until the vertex buffer or the texture slots fill up.
|
|
44
|
+
*/
|
|
45
|
+
export declare class SDFTextRenderer implements RendererPlugin {
|
|
46
|
+
readonly type: "ex.sdf-text-renderer";
|
|
47
|
+
priority: number;
|
|
48
|
+
private _gl;
|
|
49
|
+
private _context;
|
|
50
|
+
private _shader;
|
|
51
|
+
private _buffer;
|
|
52
|
+
private _quads;
|
|
53
|
+
private _layout;
|
|
54
|
+
private _maxGlyphs;
|
|
55
|
+
private _glyphCount;
|
|
56
|
+
private _vertexIndex;
|
|
57
|
+
private _maxTextures;
|
|
58
|
+
private _textures;
|
|
59
|
+
private _textureToIndex;
|
|
60
|
+
private _images;
|
|
61
|
+
private _gamma;
|
|
62
|
+
private _halo;
|
|
63
|
+
private _quad;
|
|
64
|
+
initialize(gl: WebGL2RenderingContext, context: ExcaliburGraphicsContextWebGL): void;
|
|
65
|
+
private _transformFragmentSource;
|
|
66
|
+
/**
|
|
67
|
+
* Upload the atlas once (the engine's texture loader caches it) and reserve a slot in this batch
|
|
68
|
+
*/
|
|
69
|
+
private _addAtlasTexture;
|
|
70
|
+
private _isFull;
|
|
71
|
+
/**
|
|
72
|
+
* Queue a block of text. `pos` is the top left of the text block, `size` the font size in pixels.
|
|
73
|
+
*/
|
|
74
|
+
draw(source: SDFSource, text: string, pos: Vector, size: number, options?: SDFDrawOptions): void;
|
|
75
|
+
private _pushVertex;
|
|
76
|
+
get hasPendingDraws(): boolean;
|
|
77
|
+
flush(): void;
|
|
78
|
+
dispose(): void;
|
|
79
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Color, Graphic } from 'excalibur';
|
|
2
|
+
import type { ExcaliburGraphicsContext, GraphicOptions } from 'excalibur';
|
|
3
|
+
import type { SDFSource, SDFTextAlign } from './sdf-font';
|
|
4
|
+
export interface SDFTextOptions extends GraphicOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The {@link SDFFont} or {@link SDFAtlas} to draw with
|
|
7
|
+
*/
|
|
8
|
+
sdf: SDFSource;
|
|
9
|
+
text: string;
|
|
10
|
+
/**
|
|
11
|
+
* Font size in pixels, any size works, the atlas is a distance field. Default is the source's `fontSize`.
|
|
12
|
+
*/
|
|
13
|
+
size?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Defaults to the source's color
|
|
16
|
+
*/
|
|
17
|
+
color?: Color;
|
|
18
|
+
/**
|
|
19
|
+
* Draw only the first n characters, for typewriter effects. Default all.
|
|
20
|
+
*/
|
|
21
|
+
visibleCharacters?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Alignment of lines within the block. Default 'left'.
|
|
24
|
+
*/
|
|
25
|
+
textAlign?: SDFTextAlign;
|
|
26
|
+
/**
|
|
27
|
+
* Wrap lines longer than this many pixels
|
|
28
|
+
*/
|
|
29
|
+
maxWidth?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Line height as a multiple of `size`. Default 1.2.
|
|
32
|
+
*/
|
|
33
|
+
lineHeight?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A text {@link Graphic} drawn from a signed distance field atlas by the {@link SDFTextRenderer}.
|
|
37
|
+
* Crisp at any size, rotation or zoom, and batched with other SDF text in the same frame.
|
|
38
|
+
*/
|
|
39
|
+
export declare class SDFText extends Graphic {
|
|
40
|
+
sdf: SDFSource;
|
|
41
|
+
size: number;
|
|
42
|
+
color?: Color;
|
|
43
|
+
visibleCharacters: number;
|
|
44
|
+
textAlign: SDFTextAlign;
|
|
45
|
+
maxWidth?: number;
|
|
46
|
+
lineHeight: number;
|
|
47
|
+
private _text;
|
|
48
|
+
private _measuredFor?;
|
|
49
|
+
constructor(options: SDFTextOptions);
|
|
50
|
+
get text(): string;
|
|
51
|
+
set text(value: string);
|
|
52
|
+
get width(): number;
|
|
53
|
+
set width(value: number);
|
|
54
|
+
get height(): number;
|
|
55
|
+
set height(value: number);
|
|
56
|
+
private _calculateDimension;
|
|
57
|
+
protected _drawImage(ex: ExcaliburGraphicsContext, x: number, y: number): void;
|
|
58
|
+
clone(): SDFText;
|
|
59
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@excaliburjs/plugin-sdf-text",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Signed distance field text rendering for the Excalibur game engine: a custom WebGL renderer plugin plus atlas generation",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sdf",
|
|
7
|
+
"text",
|
|
8
|
+
"font",
|
|
9
|
+
"excalibur",
|
|
10
|
+
"excaliburjs"
|
|
11
|
+
],
|
|
12
|
+
"license": "BSD-2-Clause",
|
|
13
|
+
"author": "Erik Onarheim",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/excaliburjs/excalibur-sdf-text.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/excaliburjs/excalibur-sdf-text/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/excaliburjs/excalibur-sdf-text#readme",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/excalibur-sdf-text.js",
|
|
24
|
+
"module": "dist/excalibur-sdf-text.js",
|
|
25
|
+
"types": "dist/types/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/types/index.d.ts",
|
|
29
|
+
"import": "./dist/excalibur-sdf-text.js"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"files": [
|
|
34
|
+
"dist",
|
|
35
|
+
"readme.md"
|
|
36
|
+
],
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=24"
|
|
39
|
+
},
|
|
40
|
+
"bin": {
|
|
41
|
+
"ex-generate-sdf": "./dist/cli.js"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"start": "vite",
|
|
45
|
+
"build": "npm run build:lib && npm run build:min && npm run build:types && npm run build:cli",
|
|
46
|
+
"build:lib": "vite build",
|
|
47
|
+
"build:min": "vite build --mode min",
|
|
48
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
49
|
+
"build:cli": "esbuild cli.ts --bundle --platform=node --format=esm --packages=external --outfile=dist/cli.js",
|
|
50
|
+
"type-check": "tsc --noEmit",
|
|
51
|
+
"test": "node test/smoke.mjs"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@mapbox/tiny-sdf": "2.0.7"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"excalibur": "^1.0.0"
|
|
58
|
+
},
|
|
59
|
+
"optionalDependencies": {
|
|
60
|
+
"skia-canvas": "3.0.8"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@types/node": "^25.1.0",
|
|
64
|
+
"esbuild": "0.28.2",
|
|
65
|
+
"excalibur": "1.0.0",
|
|
66
|
+
"playwright": "1.64.1",
|
|
67
|
+
"typescript": "7.0.2",
|
|
68
|
+
"vite": "8.3.8"
|
|
69
|
+
}
|
|
70
|
+
}
|