From 4982305b51b8a98f6d8f0e2300a69d0a815c46ea Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 22 Dec 2025 10:46:53 -0800 Subject: [PATCH 1/6] Split definitions and rasterizer --- .../addon-webgl/src/CustomGlyphRasterizer.ts | 457 +++++++++++++++++ addons/addon-webgl/src/CustomGlyphs.ts | 469 +----------------- addons/addon-webgl/src/TextureAtlas.ts | 2 +- 3 files changed, 469 insertions(+), 459 deletions(-) create mode 100644 addons/addon-webgl/src/CustomGlyphRasterizer.ts diff --git a/addons/addon-webgl/src/CustomGlyphRasterizer.ts b/addons/addon-webgl/src/CustomGlyphRasterizer.ts new file mode 100644 index 000000000..227f3cd62 --- /dev/null +++ b/addons/addon-webgl/src/CustomGlyphRasterizer.ts @@ -0,0 +1,457 @@ +/** + * Copyright (c) 2021 The xterm.js authors. All rights reserved. + * @license MIT + */ + +import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; +import { blockElementDefinitions, blockShadeComboDefinitions, boxDrawingDefinitions, patternCharacterDefinitions, powerlineDefinitions, rectangularShadeDefinitions, symbolsForLegacyComputingDefinitions } from 'CustomGlyphs'; + +export interface ISolidOctantBlockVector { + x: number; + y: number; + w: number; + h: number; +} + +/** + * @param xp The percentage of 15% of the x axis. + * @param yp The percentage of 15% of the x axis on the y axis. + */ +export type DrawFunctionDefinition = (xp: number, yp: number) => string; + +export interface IVectorShape { + d: string; + type: VectorType; + leftPadding?: number; + rightPadding?: number; +} + +export const enum VectorType { + FILL, + STROKE +} + +/** + * Try drawing a custom block element or box drawing character, returning whether it was + * successfully drawn. + */ +export function tryDrawCustomChar( + ctx: CanvasRenderingContext2D, + c: string, + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number, + fontSize: number, + devicePixelRatio: number +): boolean { + const blockElementDefinition = blockElementDefinitions[c]; + if (blockElementDefinition) { + drawBlockVectorChar(ctx, blockElementDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); + return true; + } + + const symbolsForLegacyComputingDefinition = symbolsForLegacyComputingDefinitions[c]; + if (symbolsForLegacyComputingDefinition) { + drawPathDefinitionCharacter(ctx, symbolsForLegacyComputingDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); + return true; + } + + const rectangularShadeDefinition = rectangularShadeDefinitions[c]; + if (rectangularShadeDefinition) { + drawRectangularShadeChar(ctx, rectangularShadeDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, c === '\u{1FB90}'); + return true; + } + + const blockShadeComboDefinition = blockShadeComboDefinitions[c]; + if (blockShadeComboDefinition) { + drawBlockShadeComboChar(ctx, blockShadeComboDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); + return true; + } + + const patternDefinition = patternCharacterDefinitions[c]; + if (patternDefinition) { + drawPatternChar(ctx, patternDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); + return true; + } + + const boxDrawingDefinition = boxDrawingDefinitions[c]; + if (boxDrawingDefinition) { + drawBoxDrawingChar(ctx, boxDrawingDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, devicePixelRatio); + return true; + } + + const powerlineDefinition = powerlineDefinitions[c]; + if (powerlineDefinition) { + drawPowerlineChar(ctx, powerlineDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, fontSize, devicePixelRatio); + return true; + } + + return false; +} + +function drawBlockVectorChar( + ctx: CanvasRenderingContext2D, + charDefinition: ISolidOctantBlockVector[], + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number +): void { + for (let i = 0; i < charDefinition.length; i++) { + const box = charDefinition[i]; + const xEighth = deviceCellWidth / 8; + const yEighth = deviceCellHeight / 8; + ctx.fillRect( + xOffset + box.x * xEighth, + yOffset + box.y * yEighth, + box.w * xEighth, + box.h * yEighth + ); + } +} + +function drawPathDefinitionCharacter( + ctx: CanvasRenderingContext2D, + charDefinition: DrawFunctionDefinition, + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number +): void { + const instructions = charDefinition(0, 0); + ctx.beginPath(); + for (const instruction of instructions.split(' ')) { + const type = instruction[0]; + const args: string[] = instruction.substring(1).split(','); + if (!args[0] || !args[1]) { + if (type === 'Z') { + ctx.closePath(); + } + continue; + } + const translatedArgs = args.map((e, i) => { + const val = parseFloat(e); + return i % 2 === 0 + ? xOffset + val * deviceCellWidth + : yOffset + val * deviceCellHeight; + }); + if (type === 'M') { + ctx.moveTo(translatedArgs[0], translatedArgs[1]); + } else if (type === 'L') { + ctx.lineTo(translatedArgs[0], translatedArgs[1]); + } + } + ctx.fill(); +} + +export type PatternDefinition = number[][]; +const cachedPatterns: Map> = new Map(); + +function drawPatternChar( + ctx: CanvasRenderingContext2D, + charDefinition: number[][], + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number +): void { + let patternSet = cachedPatterns.get(charDefinition); + if (!patternSet) { + patternSet = new Map(); + cachedPatterns.set(charDefinition, patternSet); + } + const fillStyle = ctx.fillStyle; + if (typeof fillStyle !== 'string') { + throw new Error(`Unexpected fillStyle type "${fillStyle}"`); + } + let pattern = patternSet.get(fillStyle); + if (!pattern) { + const width = charDefinition[0].length; + const height = charDefinition.length; + const tmpCanvas = ctx.canvas.ownerDocument.createElement('canvas'); + tmpCanvas.width = width; + tmpCanvas.height = height; + const tmpCtx = throwIfFalsy(tmpCanvas.getContext('2d')); + const imageData = new ImageData(width, height); + + // Extract rgba from fillStyle + let r: number; + let g: number; + let b: number; + let a: number; + if (fillStyle.startsWith('#')) { + r = parseInt(fillStyle.slice(1, 3), 16); + g = parseInt(fillStyle.slice(3, 5), 16); + b = parseInt(fillStyle.slice(5, 7), 16); + a = fillStyle.length > 7 && parseInt(fillStyle.slice(7, 9), 16) || 1; + } else if (fillStyle.startsWith('rgba')) { + ([r, g, b, a] = fillStyle.substring(5, fillStyle.length - 1).split(',').map(e => parseFloat(e))); + } else { + throw new Error(`Unexpected fillStyle color format "${fillStyle}" when drawing pattern glyph`); + } + + for (let y = 0; y < height; y++) { + for (let x = 0; x < width; x++) { + imageData.data[(y * width + x) * 4 ] = r; + imageData.data[(y * width + x) * 4 + 1] = g; + imageData.data[(y * width + x) * 4 + 2] = b; + imageData.data[(y * width + x) * 4 + 3] = charDefinition[y][x] * (a * 255); + } + } + tmpCtx.putImageData(imageData, 0, 0); + pattern = throwIfFalsy(ctx.createPattern(tmpCanvas, null)); + patternSet.set(fillStyle, pattern); + } + ctx.fillStyle = pattern; + ctx.fillRect(xOffset, yOffset, deviceCellWidth, deviceCellHeight); +} + +/** + * Draws rectangular shade characters - medium shade pattern clipped to a region. + * Uses a checkerboard pattern that shifts 1px each row (same as medium shade U+2592). + */ +function drawRectangularShadeChar( + ctx: CanvasRenderingContext2D, + region: [number, number, number, number], + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number, + isInverse: boolean +): void { + const [rx, ry, rw, rh] = region; + const regionX = Math.round(xOffset + rx * deviceCellWidth); + const regionY = Math.round(yOffset + ry * deviceCellHeight); + const regionW = Math.round(rw * deviceCellWidth); + const regionH = Math.round(rh * deviceCellHeight); + + // For inverse medium shade, we use the opposite pattern (fill where medium shade doesn't) + // Medium shade pattern: fills at (x+y) % 2 === 0, so inverse fills at (x+y) % 2 === 1 + const patternOffset = isInverse ? 1 : 0; + + for (let py = 0; py < regionH; py++) { + // Calculate the absolute y position for pattern calculation + const absY = regionY + py - yOffset; + for (let px = 0; px < regionW; px++) { + const absX = regionX + px - xOffset; + // Checkerboard pattern: fill if (x + y) % 2 matches the offset + if (((absX + absY) % 2) === patternOffset) { + ctx.fillRect(regionX + px, regionY + py, 1, 1); + } + } + } +} + +/** + * Draws block + inverse shade combo characters. + * Fills the solid region completely, then draws inverse medium shade in the shade region. + */ +function drawBlockShadeComboChar( + ctx: CanvasRenderingContext2D, + regions: [[number, number, number, number], [number, number, number, number]], + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number +): void { + const [solidRegion, shadeRegion] = regions; + + // Draw solid block region + const solidX = Math.round(xOffset + solidRegion[0] * deviceCellWidth); + const solidY = Math.round(yOffset + solidRegion[1] * deviceCellHeight); + const solidW = Math.round(solidRegion[2] * deviceCellWidth); + const solidH = Math.round(solidRegion[3] * deviceCellHeight); + ctx.fillRect(solidX, solidY, solidW, solidH); + + // Draw inverse medium shade region + const shadeX = Math.round(xOffset + shadeRegion[0] * deviceCellWidth); + const shadeY = Math.round(yOffset + shadeRegion[1] * deviceCellHeight); + const shadeW = Math.round(shadeRegion[2] * deviceCellWidth); + const shadeH = Math.round(shadeRegion[3] * deviceCellHeight); + + for (let py = 0; py < shadeH; py++) { + const absY = shadeY + py - yOffset; + for (let px = 0; px < shadeW; px++) { + const absX = shadeX + px - xOffset; + // Inverse checkerboard: fill at (x + y) % 2 === 1 + if (((absX + absY) % 2) === 1) { + ctx.fillRect(shadeX + px, shadeY + py, 1, 1); + } + } + } +} + +/** + * Draws the following box drawing characters by mapping a subset of SVG d attribute instructions to + * canvas draw calls. + * + * Box styles: ┎┰┒┍┯┑╓╥╖╒╤╕ ┏┳┓┌┲┓┌┬┐┏┱┐ + * ┌─┬─┐ ┏━┳━┓ ╔═╦═╗ ┠╂┨┝┿┥╟╫╢╞╪╡ ┡╇┩├╊┫┢╈┪┣╉┤ + * │ │ │ ┃ ┃ ┃ ║ ║ ║ ┖┸┚┕┷┙╙╨╜╘╧╛ └┴┘└┺┛┗┻┛┗┹┘ + * ├─┼─┤ ┣━╋━┫ ╠═╬═╣ ┏┱┐┌┲┓┌┬┐┌┬┐ ┏┳┓┌┮┓┌┬┐┏┭┐ + * │ │ │ ┃ ┃ ┃ ║ ║ ║ ┡╃┤├╄┩├╆┪┢╅┤ ┞╀┦├┾┫┟╁┧┣┽┤ + * └─┴─┘ ┗━┻━┛ ╚═╩═╝ └┴┘└┴┘└┺┛┗┹┘ └┴┘└┶┛┗┻┛┗┵┘ + * + * Other: + * ╭─╮ ╲ ╱ ╷╻╎╏┆┇┊┋ ╺╾╴ ╌╌╌ ┄┄┄ ┈┈┈ + * │ │ ╳ ╽╿╎╏┆┇┊┋ ╶╼╸ ╍╍╍ ┅┅┅ ┉┉┉ + * ╰─╯ ╱ ╲ ╹╵╎╏┆┇┊┋ + * + * All box drawing characters: + * ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏ + * ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟ + * ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯ + * ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿ + * ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏ + * ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ + * ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯ + * ╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿ + * + * --- + * + * Box drawing alignment tests: █ + * ▉ + * ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳ + * ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳ + * ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳ + * ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳ + * ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎ + * ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏ + * ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█ + * + * Source: https://www.w3.org/2001/06/utf-8-test/UTF-8-demo.html + */ +function drawBoxDrawingChar( + ctx: CanvasRenderingContext2D, + charDefinition: { [fontWeight: number]: string | ((xp: number, yp: number) => string) }, + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number, + devicePixelRatio: number +): void { + ctx.strokeStyle = ctx.fillStyle; + for (const [fontWeight, instructions] of Object.entries(charDefinition)) { + ctx.beginPath(); + ctx.lineWidth = devicePixelRatio * Number.parseInt(fontWeight); + let actualInstructions: string; + if (typeof instructions === 'function') { + const xp = .15; + const yp = .15 / deviceCellHeight * deviceCellWidth; + actualInstructions = instructions(xp, yp); + } else { + actualInstructions = instructions; + } + for (const instruction of actualInstructions.split(' ')) { + const type = instruction[0]; + const f = svgToCanvasInstructionMap[type]; + if (!f) { + console.error(`Could not find drawing instructions for "${type}"`); + continue; + } + const args: string[] = instruction.substring(1).split(','); + if (!args[0] || !args[1]) { + continue; + } + f(ctx, translateArgs(args, deviceCellWidth, deviceCellHeight, xOffset, yOffset, true, devicePixelRatio)); + } + ctx.stroke(); + ctx.closePath(); + } +} + +function drawPowerlineChar( + ctx: CanvasRenderingContext2D, + charDefinition: IVectorShape, + xOffset: number, + yOffset: number, + deviceCellWidth: number, + deviceCellHeight: number, + fontSize: number, + devicePixelRatio: number +): void { + // Clip the cell to make sure drawing doesn't occur beyond bounds + const clipRegion = new Path2D(); + clipRegion.rect(xOffset, yOffset, deviceCellWidth, deviceCellHeight); + ctx.clip(clipRegion); + + ctx.beginPath(); + // Scale the stroke with DPR and font size + const cssLineWidth = fontSize / 12; + ctx.lineWidth = devicePixelRatio * cssLineWidth; + for (const instruction of charDefinition.d.split(' ')) { + const type = instruction[0]; + const f = svgToCanvasInstructionMap[type]; + if (!f) { + console.error(`Could not find drawing instructions for "${type}"`); + continue; + } + const args: string[] = instruction.substring(1).split(','); + if (!args[0] || !args[1]) { + continue; + } + f(ctx, translateArgs( + args, + deviceCellWidth, + deviceCellHeight, + xOffset, + yOffset, + false, + devicePixelRatio, + (charDefinition.leftPadding ?? 0) * (cssLineWidth / 2), + (charDefinition.rightPadding ?? 0) * (cssLineWidth / 2) + )); + } + if (charDefinition.type === VectorType.STROKE) { + ctx.strokeStyle = ctx.fillStyle; + ctx.stroke(); + } else { + ctx.fill(); + } + ctx.closePath(); +} + +function clamp(value: number, max: number, min: number = 0): number { + return Math.max(Math.min(value, max), min); +} + +const svgToCanvasInstructionMap: { [index: string]: any } = { + 'C': (ctx: CanvasRenderingContext2D, args: number[]) => ctx.bezierCurveTo(args[0], args[1], args[2], args[3], args[4], args[5]), + 'L': (ctx: CanvasRenderingContext2D, args: number[]) => ctx.lineTo(args[0], args[1]), + 'M': (ctx: CanvasRenderingContext2D, args: number[]) => ctx.moveTo(args[0], args[1]) +}; + +function translateArgs(args: string[], cellWidth: number, cellHeight: number, xOffset: number, yOffset: number, doClamp: boolean, devicePixelRatio: number, leftPadding: number = 0, rightPadding: number = 0): number[] { + const result = args.map(e => parseFloat(e) || parseInt(e)); + + if (result.length < 2) { + throw new Error('Too few arguments for instruction'); + } + + for (let x = 0; x < result.length; x += 2) { + // Translate from 0-1 to 0-cellWidth + result[x] *= cellWidth - (leftPadding * devicePixelRatio) - (rightPadding * devicePixelRatio); + // Ensure coordinate doesn't escape cell bounds and round to the nearest 0.5 to ensure a crisp + // line at 100% devicePixelRatio + if (doClamp && result[x] !== 0) { + result[x] = clamp(Math.round(result[x] + 0.5) - 0.5, cellWidth, 0); + } + // Apply the cell's offset (ie. x*cellWidth) + result[x] += xOffset + (leftPadding * devicePixelRatio); + } + + for (let y = 1; y < result.length; y += 2) { + // Translate from 0-1 to 0-cellHeight + result[y] *= cellHeight; + // Ensure coordinate doesn't escape cell bounds and round to the nearest 0.5 to ensure a crisp + // line at 100% devicePixelRatio + if (doClamp && result[y] !== 0) { + result[y] = clamp(Math.round(result[y] + 0.5) - 0.5, cellHeight, 0); + } + // Apply the cell's offset (ie. x*cellHeight) + result[y] += yOffset; + } + + return result; +} diff --git a/addons/addon-webgl/src/CustomGlyphs.ts b/addons/addon-webgl/src/CustomGlyphs.ts index 447511458..e5186526e 100644 --- a/addons/addon-webgl/src/CustomGlyphs.ts +++ b/addons/addon-webgl/src/CustomGlyphs.ts @@ -5,16 +5,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; +import { VectorType, type DrawFunctionDefinition, type ISolidOctantBlockVector, type IVectorShape, type PatternDefinition } from 'CustomGlyphRasterizer'; -interface IBlockVector { - x: number; - y: number; - w: number; - h: number; -} - -export const blockElementDefinitions: { [index: string]: IBlockVector[] | undefined } = { +export const blockElementDefinitions: { [index: string]: ISolidOctantBlockVector[] | undefined } = { // Block elements (0x2580-0x2590) '▀': [{ x: 0, y: 0, w: 8, h: 4 }], // UPPER HALF BLOCK '▁': [{ x: 0, y: 7, w: 8, h: 1 }], // LOWER ONE EIGHTH BLOCK @@ -298,12 +291,14 @@ export const symbolsForLegacyComputingDefinitions: { [index: string]: DrawFuncti '\u{1FB6F}': () => 'M0,1 L1,1 L0.5,0.5 Z' // LOWER TRIANGULAR ONE QUARTER BLOCK }; +/** Region defined as [x, y, width, height] in 0-1 normalized coordinates. */ +type RegionDefinition = [number, number, number, number]; + /** * Rectangular shade characters - these use medium shade pattern with region bounds. * Pattern is a checkerboard that shifts 1px each row (same as medium shade). - * Region is defined as [x, y, width, height] in 0-1 normalized coordinates. */ -export const rectangularShadeDefinitions: { [index: string]: [number, number, number, number] | undefined } = { +export const rectangularShadeDefinitions: { [index: string]: RegionDefinition | undefined } = { '\u{1FB8C}': [0, 0, 0.5, 1], // LEFT HALF MEDIUM SHADE '\u{1FB8D}': [0.5, 0, 0.5, 1], // RIGHT HALF MEDIUM SHADE '\u{1FB8E}': [0, 0, 1, 0.5], // UPPER HALF MEDIUM SHADE @@ -311,25 +306,24 @@ export const rectangularShadeDefinitions: { [index: string]: [number, number, nu '\u{1FB90}': [0, 0, 1, 1] // INVERSE MEDIUM SHADE }; +/** [solidRegion, shadeRegion] where shade region uses inverse medium shade pattern. */ +type BlockShadeComboDefinition = [RegionDefinition, RegionDefinition]; + /** * Block + inverse shade combo characters. - * Each entry: [solidRegion, shadeRegion] where regions are [x, y, w, h] in 0-1 coords. - * Shade region uses inverse medium shade pattern. */ -export const blockShadeComboDefinitions: { [index: string]: [[number, number, number, number], [number, number, number, number]] | undefined } = { +export const blockShadeComboDefinitions: { [index: string]: BlockShadeComboDefinition | undefined } = { '\u{1FB91}': [[0, 0, 1, 0.5], [0, 0.5, 1, 0.5]], // UPPER HALF BLOCK AND LOWER HALF INVERSE MEDIUM SHADE '\u{1FB92}': [[0, 0.5, 1, 0.5], [0, 0, 1, 0.5]], // UPPER HALF INVERSE MEDIUM SHADE AND LOWER HALF BLOCK // 1FB93 is reserved '\u{1FB94}': [[0.5, 0, 0.5, 1], [0, 0, 0.5, 1]] // LEFT HALF INVERSE MEDIUM SHADE AND RIGHT HALF BLOCK }; -type PatternDefinition = number[][]; - /** * Defines the repeating pattern used by special characters, the pattern is made up of a 2d array of * pixel values to be filled (1) or not filled (0). */ -const patternCharacterDefinitions: { [key: string]: PatternDefinition | undefined } = { +export const patternCharacterDefinitions: { [key: string]: PatternDefinition | undefined } = { // Shade characters (0x2591-0x2593) '░': [ // LIGHT SHADE (25%) [1, 0, 0, 0], @@ -385,11 +379,6 @@ const enum Style { BOLD = 3 } -/** - * @param xp The percentage of 15% of the x axis. - * @param yp The percentage of 15% of the x axis on the y axis. - */ -type DrawFunctionDefinition = (xp: number, yp: number) => string; /** * This contains the definitions of all box drawing characters in the format of SVG paths (ie. the @@ -537,18 +526,6 @@ export const boxDrawingDefinitions: { [character: string]: { [fontWeight: number '╰': { [Style.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - (yp / .15 * .5)} C.5,${.5 - (yp / .15 * .5)},.5,.5,1,.5` } }; -interface IVectorShape { - d: string; - type: VectorType; - leftPadding?: number; - rightPadding?: number; -} - -const enum VectorType { - FILL, - STROKE -} - /** * This contains the definitions of the primarily used box drawing characters as vector shapes. The * reason these characters are defined specially is to avoid common problems if a user's font has @@ -600,427 +577,3 @@ export const powerlineDefinitions: { [index: string]: IVectorShape } = { powerlineDefinitions['\u{E0BB}'] = powerlineDefinitions['\u{E0BD}']; // Backslash separator redundant powerlineDefinitions['\u{E0BF}'] = powerlineDefinitions['\u{E0B9}']; - -/** - * Try drawing a custom block element or box drawing character, returning whether it was - * successfully drawn. - */ -export function tryDrawCustomChar( - ctx: CanvasRenderingContext2D, - c: string, - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number, - fontSize: number, - devicePixelRatio: number -): boolean { - const blockElementDefinition = blockElementDefinitions[c]; - if (blockElementDefinition) { - drawBlockVectorChar(ctx, blockElementDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); - return true; - } - - const symbolsForLegacyComputingDefinition = symbolsForLegacyComputingDefinitions[c]; - if (symbolsForLegacyComputingDefinition) { - drawPathDefinitionCharacter(ctx, symbolsForLegacyComputingDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); - return true; - } - - const rectangularShadeDefinition = rectangularShadeDefinitions[c]; - if (rectangularShadeDefinition) { - drawRectangularShadeChar(ctx, rectangularShadeDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, c === '\u{1FB90}'); - return true; - } - - const blockShadeComboDefinition = blockShadeComboDefinitions[c]; - if (blockShadeComboDefinition) { - drawBlockShadeComboChar(ctx, blockShadeComboDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); - return true; - } - - const patternDefinition = patternCharacterDefinitions[c]; - if (patternDefinition) { - drawPatternChar(ctx, patternDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); - return true; - } - - const boxDrawingDefinition = boxDrawingDefinitions[c]; - if (boxDrawingDefinition) { - drawBoxDrawingChar(ctx, boxDrawingDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, devicePixelRatio); - return true; - } - - const powerlineDefinition = powerlineDefinitions[c]; - if (powerlineDefinition) { - drawPowerlineChar(ctx, powerlineDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, fontSize, devicePixelRatio); - return true; - } - - return false; -} - -function drawBlockVectorChar( - ctx: CanvasRenderingContext2D, - charDefinition: IBlockVector[], - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number -): void { - for (let i = 0; i < charDefinition.length; i++) { - const box = charDefinition[i]; - const xEighth = deviceCellWidth / 8; - const yEighth = deviceCellHeight / 8; - ctx.fillRect( - xOffset + box.x * xEighth, - yOffset + box.y * yEighth, - box.w * xEighth, - box.h * yEighth - ); - } -} - -function drawPathDefinitionCharacter( - ctx: CanvasRenderingContext2D, - charDefinition: DrawFunctionDefinition, - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number -): void { - const instructions = charDefinition(0, 0); - ctx.beginPath(); - for (const instruction of instructions.split(' ')) { - const type = instruction[0]; - const args: string[] = instruction.substring(1).split(','); - if (!args[0] || !args[1]) { - if (type === 'Z') { - ctx.closePath(); - } - continue; - } - const translatedArgs = args.map((e, i) => { - const val = parseFloat(e); - return i % 2 === 0 - ? xOffset + val * deviceCellWidth - : yOffset + val * deviceCellHeight; - }); - if (type === 'M') { - ctx.moveTo(translatedArgs[0], translatedArgs[1]); - } else if (type === 'L') { - ctx.lineTo(translatedArgs[0], translatedArgs[1]); - } - } - ctx.fill(); -} - -const cachedPatterns: Map> = new Map(); - -function drawPatternChar( - ctx: CanvasRenderingContext2D, - charDefinition: number[][], - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number -): void { - let patternSet = cachedPatterns.get(charDefinition); - if (!patternSet) { - patternSet = new Map(); - cachedPatterns.set(charDefinition, patternSet); - } - const fillStyle = ctx.fillStyle; - if (typeof fillStyle !== 'string') { - throw new Error(`Unexpected fillStyle type "${fillStyle}"`); - } - let pattern = patternSet.get(fillStyle); - if (!pattern) { - const width = charDefinition[0].length; - const height = charDefinition.length; - const tmpCanvas = ctx.canvas.ownerDocument.createElement('canvas'); - tmpCanvas.width = width; - tmpCanvas.height = height; - const tmpCtx = throwIfFalsy(tmpCanvas.getContext('2d')); - const imageData = new ImageData(width, height); - - // Extract rgba from fillStyle - let r: number; - let g: number; - let b: number; - let a: number; - if (fillStyle.startsWith('#')) { - r = parseInt(fillStyle.slice(1, 3), 16); - g = parseInt(fillStyle.slice(3, 5), 16); - b = parseInt(fillStyle.slice(5, 7), 16); - a = fillStyle.length > 7 && parseInt(fillStyle.slice(7, 9), 16) || 1; - } else if (fillStyle.startsWith('rgba')) { - ([r, g, b, a] = fillStyle.substring(5, fillStyle.length - 1).split(',').map(e => parseFloat(e))); - } else { - throw new Error(`Unexpected fillStyle color format "${fillStyle}" when drawing pattern glyph`); - } - - for (let y = 0; y < height; y++) { - for (let x = 0; x < width; x++) { - imageData.data[(y * width + x) * 4 ] = r; - imageData.data[(y * width + x) * 4 + 1] = g; - imageData.data[(y * width + x) * 4 + 2] = b; - imageData.data[(y * width + x) * 4 + 3] = charDefinition[y][x] * (a * 255); - } - } - tmpCtx.putImageData(imageData, 0, 0); - pattern = throwIfFalsy(ctx.createPattern(tmpCanvas, null)); - patternSet.set(fillStyle, pattern); - } - ctx.fillStyle = pattern; - ctx.fillRect(xOffset, yOffset, deviceCellWidth, deviceCellHeight); -} - -/** - * Draws rectangular shade characters - medium shade pattern clipped to a region. - * Uses a checkerboard pattern that shifts 1px each row (same as medium shade U+2592). - */ -function drawRectangularShadeChar( - ctx: CanvasRenderingContext2D, - region: [number, number, number, number], - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number, - isInverse: boolean -): void { - const [rx, ry, rw, rh] = region; - const regionX = Math.round(xOffset + rx * deviceCellWidth); - const regionY = Math.round(yOffset + ry * deviceCellHeight); - const regionW = Math.round(rw * deviceCellWidth); - const regionH = Math.round(rh * deviceCellHeight); - - // For inverse medium shade, we use the opposite pattern (fill where medium shade doesn't) - // Medium shade pattern: fills at (x+y) % 2 === 0, so inverse fills at (x+y) % 2 === 1 - const patternOffset = isInverse ? 1 : 0; - - for (let py = 0; py < regionH; py++) { - // Calculate the absolute y position for pattern calculation - const absY = regionY + py - yOffset; - for (let px = 0; px < regionW; px++) { - const absX = regionX + px - xOffset; - // Checkerboard pattern: fill if (x + y) % 2 matches the offset - if (((absX + absY) % 2) === patternOffset) { - ctx.fillRect(regionX + px, regionY + py, 1, 1); - } - } - } -} - -/** - * Draws block + inverse shade combo characters. - * Fills the solid region completely, then draws inverse medium shade in the shade region. - */ -function drawBlockShadeComboChar( - ctx: CanvasRenderingContext2D, - regions: [[number, number, number, number], [number, number, number, number]], - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number -): void { - const [solidRegion, shadeRegion] = regions; - - // Draw solid block region - const solidX = Math.round(xOffset + solidRegion[0] * deviceCellWidth); - const solidY = Math.round(yOffset + solidRegion[1] * deviceCellHeight); - const solidW = Math.round(solidRegion[2] * deviceCellWidth); - const solidH = Math.round(solidRegion[3] * deviceCellHeight); - ctx.fillRect(solidX, solidY, solidW, solidH); - - // Draw inverse medium shade region - const shadeX = Math.round(xOffset + shadeRegion[0] * deviceCellWidth); - const shadeY = Math.round(yOffset + shadeRegion[1] * deviceCellHeight); - const shadeW = Math.round(shadeRegion[2] * deviceCellWidth); - const shadeH = Math.round(shadeRegion[3] * deviceCellHeight); - - for (let py = 0; py < shadeH; py++) { - const absY = shadeY + py - yOffset; - for (let px = 0; px < shadeW; px++) { - const absX = shadeX + px - xOffset; - // Inverse checkerboard: fill at (x + y) % 2 === 1 - if (((absX + absY) % 2) === 1) { - ctx.fillRect(shadeX + px, shadeY + py, 1, 1); - } - } - } -} - -/** - * Draws the following box drawing characters by mapping a subset of SVG d attribute instructions to - * canvas draw calls. - * - * Box styles: ┎┰┒┍┯┑╓╥╖╒╤╕ ┏┳┓┌┲┓┌┬┐┏┱┐ - * ┌─┬─┐ ┏━┳━┓ ╔═╦═╗ ┠╂┨┝┿┥╟╫╢╞╪╡ ┡╇┩├╊┫┢╈┪┣╉┤ - * │ │ │ ┃ ┃ ┃ ║ ║ ║ ┖┸┚┕┷┙╙╨╜╘╧╛ └┴┘└┺┛┗┻┛┗┹┘ - * ├─┼─┤ ┣━╋━┫ ╠═╬═╣ ┏┱┐┌┲┓┌┬┐┌┬┐ ┏┳┓┌┮┓┌┬┐┏┭┐ - * │ │ │ ┃ ┃ ┃ ║ ║ ║ ┡╃┤├╄┩├╆┪┢╅┤ ┞╀┦├┾┫┟╁┧┣┽┤ - * └─┴─┘ ┗━┻━┛ ╚═╩═╝ └┴┘└┴┘└┺┛┗┹┘ └┴┘└┶┛┗┻┛┗┵┘ - * - * Other: - * ╭─╮ ╲ ╱ ╷╻╎╏┆┇┊┋ ╺╾╴ ╌╌╌ ┄┄┄ ┈┈┈ - * │ │ ╳ ╽╿╎╏┆┇┊┋ ╶╼╸ ╍╍╍ ┅┅┅ ┉┉┉ - * ╰─╯ ╱ ╲ ╹╵╎╏┆┇┊┋ - * - * All box drawing characters: - * ─ ━ │ ┃ ┄ ┅ ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┍ ┎ ┏ - * ┐ ┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┝ ┞ ┟ - * ┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯ - * ┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸ ┹ ┺ ┻ ┼ ┽ ┾ ┿ - * ╀ ╁ ╂ ╃ ╄ ╅ ╆ ╇ ╈ ╉ ╊ ╋ ╌ ╍ ╎ ╏ - * ═ ║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╝ ╞ ╟ - * ╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯ - * ╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿ - * - * --- - * - * Box drawing alignment tests: █ - * ▉ - * ╔══╦══╗ ┌──┬──┐ ╭──┬──╮ ╭──┬──╮ ┏━━┳━━┓ ┎┒┏┑ ╷ ╻ ┏┯┓ ┌┰┐ ▊ ╱╲╱╲╳╳╳ - * ║┌─╨─┐║ │╔═╧═╗│ │╒═╪═╕│ │╓─╁─╖│ ┃┌─╂─┐┃ ┗╃╄┙ ╶┼╴╺╋╸┠┼┨ ┝╋┥ ▋ ╲╱╲╱╳╳╳ - * ║│╲ ╱│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╿ │┃ ┍╅╆┓ ╵ ╹ ┗┷┛ └┸┘ ▌ ╱╲╱╲╳╳╳ - * ╠╡ ╳ ╞╣ ├╢ ╟┤ ├┼─┼─┼┤ ├╫─╂─╫┤ ┣┿╾┼╼┿┫ ┕┛┖┚ ┌┄┄┐ ╎ ┏┅┅┓ ┋ ▍ ╲╱╲╱╳╳╳ - * ║│╱ ╲│║ │║ ║│ ││ │ ││ │║ ┃ ║│ ┃│ ╽ │┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▎ - * ║└─╥─┘║ │╚═╤═╝│ │╘═╪═╛│ │╙─╀─╜│ ┃└─╂─┘┃ ░░▒▒▓▓██ ┊ ┆ ╎ ╏ ┇ ┋ ▏ - * ╚══╩══╝ └──┴──┘ ╰──┴──╯ ╰──┴──╯ ┗━━┻━━┛ └╌╌┘ ╎ ┗╍╍┛ ┋ ▁▂▃▄▅▆▇█ - * - * Source: https://www.w3.org/2001/06/utf-8-test/UTF-8-demo.html - */ -function drawBoxDrawingChar( - ctx: CanvasRenderingContext2D, - charDefinition: { [fontWeight: number]: string | ((xp: number, yp: number) => string) }, - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number, - devicePixelRatio: number -): void { - ctx.strokeStyle = ctx.fillStyle; - for (const [fontWeight, instructions] of Object.entries(charDefinition)) { - ctx.beginPath(); - ctx.lineWidth = devicePixelRatio * Number.parseInt(fontWeight); - let actualInstructions: string; - if (typeof instructions === 'function') { - const xp = .15; - const yp = .15 / deviceCellHeight * deviceCellWidth; - actualInstructions = instructions(xp, yp); - } else { - actualInstructions = instructions; - } - for (const instruction of actualInstructions.split(' ')) { - const type = instruction[0]; - const f = svgToCanvasInstructionMap[type]; - if (!f) { - console.error(`Could not find drawing instructions for "${type}"`); - continue; - } - const args: string[] = instruction.substring(1).split(','); - if (!args[0] || !args[1]) { - continue; - } - f(ctx, translateArgs(args, deviceCellWidth, deviceCellHeight, xOffset, yOffset, true, devicePixelRatio)); - } - ctx.stroke(); - ctx.closePath(); - } -} - -function drawPowerlineChar( - ctx: CanvasRenderingContext2D, - charDefinition: IVectorShape, - xOffset: number, - yOffset: number, - deviceCellWidth: number, - deviceCellHeight: number, - fontSize: number, - devicePixelRatio: number -): void { - // Clip the cell to make sure drawing doesn't occur beyond bounds - const clipRegion = new Path2D(); - clipRegion.rect(xOffset, yOffset, deviceCellWidth, deviceCellHeight); - ctx.clip(clipRegion); - - ctx.beginPath(); - // Scale the stroke with DPR and font size - const cssLineWidth = fontSize / 12; - ctx.lineWidth = devicePixelRatio * cssLineWidth; - for (const instruction of charDefinition.d.split(' ')) { - const type = instruction[0]; - const f = svgToCanvasInstructionMap[type]; - if (!f) { - console.error(`Could not find drawing instructions for "${type}"`); - continue; - } - const args: string[] = instruction.substring(1).split(','); - if (!args[0] || !args[1]) { - continue; - } - f(ctx, translateArgs( - args, - deviceCellWidth, - deviceCellHeight, - xOffset, - yOffset, - false, - devicePixelRatio, - (charDefinition.leftPadding ?? 0) * (cssLineWidth / 2), - (charDefinition.rightPadding ?? 0) * (cssLineWidth / 2) - )); - } - if (charDefinition.type === VectorType.STROKE) { - ctx.strokeStyle = ctx.fillStyle; - ctx.stroke(); - } else { - ctx.fill(); - } - ctx.closePath(); -} - -function clamp(value: number, max: number, min: number = 0): number { - return Math.max(Math.min(value, max), min); -} - -const svgToCanvasInstructionMap: { [index: string]: any } = { - 'C': (ctx: CanvasRenderingContext2D, args: number[]) => ctx.bezierCurveTo(args[0], args[1], args[2], args[3], args[4], args[5]), - 'L': (ctx: CanvasRenderingContext2D, args: number[]) => ctx.lineTo(args[0], args[1]), - 'M': (ctx: CanvasRenderingContext2D, args: number[]) => ctx.moveTo(args[0], args[1]) -}; - -function translateArgs(args: string[], cellWidth: number, cellHeight: number, xOffset: number, yOffset: number, doClamp: boolean, devicePixelRatio: number, leftPadding: number = 0, rightPadding: number = 0): number[] { - const result = args.map(e => parseFloat(e) || parseInt(e)); - - if (result.length < 2) { - throw new Error('Too few arguments for instruction'); - } - - for (let x = 0; x < result.length; x += 2) { - // Translate from 0-1 to 0-cellWidth - result[x] *= cellWidth - (leftPadding * devicePixelRatio) - (rightPadding * devicePixelRatio); - // Ensure coordinate doesn't escape cell bounds and round to the nearest 0.5 to ensure a crisp - // line at 100% devicePixelRatio - if (doClamp && result[x] !== 0) { - result[x] = clamp(Math.round(result[x] + 0.5) - 0.5, cellWidth, 0); - } - // Apply the cell's offset (ie. x*cellWidth) - result[x] += xOffset + (leftPadding * devicePixelRatio); - } - - for (let y = 1; y < result.length; y += 2) { - // Translate from 0-1 to 0-cellHeight - result[y] *= cellHeight; - // Ensure coordinate doesn't escape cell bounds and round to the nearest 0.5 to ensure a crisp - // line at 100% devicePixelRatio - if (doClamp && result[y] !== 0) { - result[y] = clamp(Math.round(result[y] + 0.5) - 0.5, cellHeight, 0); - } - // Apply the cell's offset (ie. x*cellHeight) - result[y] += yOffset; - } - - return result; -} diff --git a/addons/addon-webgl/src/TextureAtlas.ts b/addons/addon-webgl/src/TextureAtlas.ts index 330c62758..471c761af 100644 --- a/addons/addon-webgl/src/TextureAtlas.ts +++ b/addons/addon-webgl/src/TextureAtlas.ts @@ -5,7 +5,7 @@ import { IColorContrastCache } from 'browser/Types'; import { DIM_OPACITY, TEXT_BASELINE } from './Constants'; -import { tryDrawCustomChar } from './CustomGlyphs'; +import { tryDrawCustomChar } from './CustomGlyphRasterizer'; import { computeNextVariantOffset, treatGlyphAsBackgroundColor, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from './Types'; import { NULL_COLOR, channels, color, rgba } from 'common/Color'; From 28760cf48218881339cd0c2b0b8c0c3a32e08ce2 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 22 Dec 2025 10:47:35 -0800 Subject: [PATCH 2/6] Move custom glyphs into new folder --- addons/addon-webgl/src/TextureAtlas.ts | 2 +- .../{CustomGlyphs.ts => customGlyphs/CustomGlyphDefinitions.ts} | 2 +- .../addon-webgl/src/{ => customGlyphs}/CustomGlyphRasterizer.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename addons/addon-webgl/src/{CustomGlyphs.ts => customGlyphs/CustomGlyphDefinitions.ts} (99%) rename addons/addon-webgl/src/{ => customGlyphs}/CustomGlyphRasterizer.ts (99%) diff --git a/addons/addon-webgl/src/TextureAtlas.ts b/addons/addon-webgl/src/TextureAtlas.ts index 471c761af..a1a9dc38e 100644 --- a/addons/addon-webgl/src/TextureAtlas.ts +++ b/addons/addon-webgl/src/TextureAtlas.ts @@ -5,7 +5,7 @@ import { IColorContrastCache } from 'browser/Types'; import { DIM_OPACITY, TEXT_BASELINE } from './Constants'; -import { tryDrawCustomChar } from './CustomGlyphRasterizer'; +import { tryDrawCustomChar } from './customGlyphs/CustomGlyphRasterizer'; import { computeNextVariantOffset, treatGlyphAsBackgroundColor, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from './Types'; import { NULL_COLOR, channels, color, rgba } from 'common/Color'; diff --git a/addons/addon-webgl/src/CustomGlyphs.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts similarity index 99% rename from addons/addon-webgl/src/CustomGlyphs.ts rename to addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts index e5186526e..6e4f39b79 100644 --- a/addons/addon-webgl/src/CustomGlyphs.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { VectorType, type DrawFunctionDefinition, type ISolidOctantBlockVector, type IVectorShape, type PatternDefinition } from 'CustomGlyphRasterizer'; +import { VectorType, type DrawFunctionDefinition, type ISolidOctantBlockVector, type IVectorShape, type PatternDefinition } from 'customGlyphs/CustomGlyphRasterizer'; export const blockElementDefinitions: { [index: string]: ISolidOctantBlockVector[] | undefined } = { // Block elements (0x2580-0x2590) diff --git a/addons/addon-webgl/src/CustomGlyphRasterizer.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts similarity index 99% rename from addons/addon-webgl/src/CustomGlyphRasterizer.ts rename to addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts index 227f3cd62..d8faca6f3 100644 --- a/addons/addon-webgl/src/CustomGlyphRasterizer.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts @@ -4,7 +4,7 @@ */ import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; -import { blockElementDefinitions, blockShadeComboDefinitions, boxDrawingDefinitions, patternCharacterDefinitions, powerlineDefinitions, rectangularShadeDefinitions, symbolsForLegacyComputingDefinitions } from 'CustomGlyphs'; +import { blockElementDefinitions, blockShadeComboDefinitions, boxDrawingDefinitions, patternCharacterDefinitions, powerlineDefinitions, rectangularShadeDefinitions, symbolsForLegacyComputingDefinitions } from 'customGlyphs/CustomGlyphDefinitions'; export interface ISolidOctantBlockVector { x: number; From f049c42acc821142a262ec305702d1b39d856e38 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 22 Dec 2025 10:48:50 -0800 Subject: [PATCH 3/6] Add CustomGlyph to exports from rasterizer --- addons/addon-webgl/src/TextureAtlas.ts | 4 +- .../customGlyphs/CustomGlyphDefinitions.ts | 48 +++++++++---------- .../src/customGlyphs/CustomGlyphRasterizer.ts | 25 +++++----- 3 files changed, 39 insertions(+), 38 deletions(-) diff --git a/addons/addon-webgl/src/TextureAtlas.ts b/addons/addon-webgl/src/TextureAtlas.ts index a1a9dc38e..a5779afc1 100644 --- a/addons/addon-webgl/src/TextureAtlas.ts +++ b/addons/addon-webgl/src/TextureAtlas.ts @@ -5,7 +5,7 @@ import { IColorContrastCache } from 'browser/Types'; import { DIM_OPACITY, TEXT_BASELINE } from './Constants'; -import { tryDrawCustomChar } from './customGlyphs/CustomGlyphRasterizer'; +import { tryDrawCustomGlyph } from './customGlyphs/CustomGlyphRasterizer'; import { computeNextVariantOffset, treatGlyphAsBackgroundColor, isPowerlineGlyph, isRestrictedPowerlineGlyph, throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { IBoundingBox, ICharAtlasConfig, IRasterizedGlyph, ITextureAtlas } from './Types'; import { NULL_COLOR, channels, color, rgba } from 'common/Color'; @@ -514,7 +514,7 @@ export class TextureAtlas implements ITextureAtlas { // Draw custom characters if applicable let customGlyph = false; if (this._config.customGlyphs !== false) { - customGlyph = tryDrawCustomChar(this._tmpCtx, chars, padding, padding, this._config.deviceCellWidth, this._config.deviceCellHeight, this._config.fontSize, this._config.devicePixelRatio); + customGlyph = tryDrawCustomGlyph(this._tmpCtx, chars, padding, padding, this._config.deviceCellWidth, this._config.deviceCellHeight, this._config.fontSize, this._config.devicePixelRatio); } // Whether to clear pixels based on a threshold difference between the glyph color and the diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts index 6e4f39b79..c21e9b50a 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts @@ -5,9 +5,9 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { VectorType, type DrawFunctionDefinition, type ISolidOctantBlockVector, type IVectorShape, type PatternDefinition } from 'customGlyphs/CustomGlyphRasterizer'; +import { CustomGlyphVectorType, type CustomGlyphDrawFunctionDefinition, type ICustomGlyphSolidOctantBlockVector, type ICustomGlyphVectorShape, type CustomGlyphPatternDefinition } from 'customGlyphs/CustomGlyphRasterizer'; -export const blockElementDefinitions: { [index: string]: ISolidOctantBlockVector[] | undefined } = { +export const blockElementDefinitions: { [index: string]: ICustomGlyphSolidOctantBlockVector[] | undefined } = { // Block elements (0x2580-0x2590) '▀': [{ x: 0, y: 0, w: 8, h: 4 }], // UPPER HALF BLOCK '▁': [{ x: 0, y: 7, w: 8, h: 1 }], // LOWER ONE EIGHTH BLOCK @@ -118,7 +118,7 @@ export const blockElementDefinitions: { [index: string]: ISolidOctantBlockVector * @param pattern A 6-bit pattern where bit 0 = top-left, bit 1 = top-right, bit 2 = middle-left, * bit 3 = middle-right, bit 4 = bottom-left, bit 5 = bottom-right */ -function sextant(pattern: number): DrawFunctionDefinition { +function sextant(pattern: number): CustomGlyphDrawFunctionDefinition { return () => { // Sextant grid: 2 columns, 3 rows // Row heights in 8ths: top=3, middle=2, bottom=3 @@ -145,7 +145,7 @@ function sextant(pattern: number): DrawFunctionDefinition { }; } -export const symbolsForLegacyComputingDefinitions: { [index: string]: DrawFunctionDefinition | undefined } = { +export const symbolsForLegacyComputingDefinitions: { [index: string]: CustomGlyphDrawFunctionDefinition | undefined } = { // Block sextants (0x1FB00-0x1FB3B) // Each sextant is a 2x3 grid of cells in an 8x8 block // Cell positions: bit 0=top-left, bit 1=top-right, bit 2=middle-left, bit 3=middle-right, @@ -323,7 +323,7 @@ export const blockShadeComboDefinitions: { [index: string]: BlockShadeComboDefin * Defines the repeating pattern used by special characters, the pattern is made up of a 2d array of * pixel values to be filled (1) or not filled (0). */ -export const patternCharacterDefinitions: { [key: string]: PatternDefinition | undefined } = { +export const patternCharacterDefinitions: { [key: string]: CustomGlyphPatternDefinition | undefined } = { // Shade characters (0x2591-0x2593) '░': [ // LIGHT SHADE (25%) [1, 0, 0, 0], @@ -384,7 +384,7 @@ const enum Style { * This contains the definitions of all box drawing characters in the format of SVG paths (ie. the * svg d attribute). */ -export const boxDrawingDefinitions: { [character: string]: { [fontWeight: number]: string | DrawFunctionDefinition } | undefined } = { +export const boxDrawingDefinitions: { [character: string]: { [fontWeight: number]: string | CustomGlyphDrawFunctionDefinition } | undefined } = { // Uniform normal and bold '─': { [Style.NORMAL]: Shapes.LEFT_TO_RIGHT }, '━': { [Style.BOLD]: Shapes.LEFT_TO_RIGHT }, @@ -537,41 +537,41 @@ export const boxDrawingDefinitions: { [character: string]: { [fontWeight: number * * Original symbols defined in https://github.com/powerline/fontpatcher */ -export const powerlineDefinitions: { [index: string]: IVectorShape } = { +export const powerlineDefinitions: { [index: string]: ICustomGlyphVectorShape } = { // Git branch - '\u{E0A0}': { d: 'M.3,1 L.03,1 L.03,.88 C.03,.82,.06,.78,.11,.73 C.15,.7,.2,.68,.28,.65 L.43,.6 C.49,.58,.53,.56,.56,.53 C.59,.5,.6,.47,.6,.43 L.6,.27 L.4,.27 L.69,.1 L.98,.27 L.78,.27 L.78,.46 C.78,.52,.76,.56,.72,.61 C.68,.66,.63,.67,.56,.7 L.48,.72 C.42,.74,.38,.76,.35,.78 C.32,.8,.31,.84,.31,.88 L.31,1 M.3,.5 L.03,.59 L.03,.09 L.3,.09 L.3,.655', type: VectorType.FILL }, + '\u{E0A0}': { d: 'M.3,1 L.03,1 L.03,.88 C.03,.82,.06,.78,.11,.73 C.15,.7,.2,.68,.28,.65 L.43,.6 C.49,.58,.53,.56,.56,.53 C.59,.5,.6,.47,.6,.43 L.6,.27 L.4,.27 L.69,.1 L.98,.27 L.78,.27 L.78,.46 C.78,.52,.76,.56,.72,.61 C.68,.66,.63,.67,.56,.7 L.48,.72 C.42,.74,.38,.76,.35,.78 C.32,.8,.31,.84,.31,.88 L.31,1 M.3,.5 L.03,.59 L.03,.09 L.3,.09 L.3,.655', type: CustomGlyphVectorType.FILL }, // L N - '\u{E0A1}': { d: 'M.7,.4 L.7,.47 L.2,.47 L.2,.03 L.355,.03 L.355,.4 L.705,.4 M.7,.5 L.86,.5 L.86,.95 L.69,.95 L.44,.66 L.46,.86 L.46,.95 L.3,.95 L.3,.49 L.46,.49 L.71,.78 L.69,.565 L.69,.5', type: VectorType.FILL }, + '\u{E0A1}': { d: 'M.7,.4 L.7,.47 L.2,.47 L.2,.03 L.355,.03 L.355,.4 L.705,.4 M.7,.5 L.86,.5 L.86,.95 L.69,.95 L.44,.66 L.46,.86 L.46,.95 L.3,.95 L.3,.49 L.46,.49 L.71,.78 L.69,.565 L.69,.5', type: CustomGlyphVectorType.FILL }, // Lock - '\u{E0A2}': { d: 'M.25,.94 C.16,.94,.11,.92,.11,.87 L.11,.53 C.11,.48,.15,.455,.23,.45 L.23,.3 C.23,.25,.26,.22,.31,.19 C.36,.16,.43,.15,.51,.15 C.59,.15,.66,.16,.71,.19 C.77,.22,.79,.26,.79,.3 L.79,.45 C.87,.45,.91,.48,.91,.53 L.91,.87 C.91,.92,.86,.94,.77,.94 L.24,.94 M.53,.2 C.49,.2,.45,.21,.42,.23 C.39,.25,.38,.27,.38,.3 L.38,.45 L.68,.45 L.68,.3 C.68,.27,.67,.25,.64,.23 C.61,.21,.58,.2,.53,.2 M.58,.82 L.58,.66 C.63,.65,.65,.63,.65,.6 C.65,.58,.64,.57,.61,.56 C.58,.55,.56,.54,.52,.54 C.48,.54,.46,.55,.43,.56 C.4,.57,.39,.59,.39,.6 C.39,.63,.41,.64,.46,.66 L.46,.82 L.57,.82', type: VectorType.FILL }, + '\u{E0A2}': { d: 'M.25,.94 C.16,.94,.11,.92,.11,.87 L.11,.53 C.11,.48,.15,.455,.23,.45 L.23,.3 C.23,.25,.26,.22,.31,.19 C.36,.16,.43,.15,.51,.15 C.59,.15,.66,.16,.71,.19 C.77,.22,.79,.26,.79,.3 L.79,.45 C.87,.45,.91,.48,.91,.53 L.91,.87 C.91,.92,.86,.94,.77,.94 L.24,.94 M.53,.2 C.49,.2,.45,.21,.42,.23 C.39,.25,.38,.27,.38,.3 L.38,.45 L.68,.45 L.68,.3 C.68,.27,.67,.25,.64,.23 C.61,.21,.58,.2,.53,.2 M.58,.82 L.58,.66 C.63,.65,.65,.63,.65,.6 C.65,.58,.64,.57,.61,.56 C.58,.55,.56,.54,.52,.54 C.48,.54,.46,.55,.43,.56 C.4,.57,.39,.59,.39,.6 C.39,.63,.41,.64,.46,.66 L.46,.82 L.57,.82', type: CustomGlyphVectorType.FILL }, // Right triangle solid - '\u{E0B0}': { d: 'M0,0 L1,.5 L0,1', type: VectorType.FILL, rightPadding: 2 }, + '\u{E0B0}': { d: 'M0,0 L1,.5 L0,1', type: CustomGlyphVectorType.FILL, rightPadding: 2 }, // Right triangle line - '\u{E0B1}': { d: 'M-1,-.5 L1,.5 L-1,1.5', type: VectorType.STROKE, leftPadding: 1, rightPadding: 1 }, + '\u{E0B1}': { d: 'M-1,-.5 L1,.5 L-1,1.5', type: CustomGlyphVectorType.STROKE, leftPadding: 1, rightPadding: 1 }, // Left triangle solid - '\u{E0B2}': { d: 'M1,0 L0,.5 L1,1', type: VectorType.FILL, leftPadding: 2 }, + '\u{E0B2}': { d: 'M1,0 L0,.5 L1,1', type: CustomGlyphVectorType.FILL, leftPadding: 2 }, // Left triangle line - '\u{E0B3}': { d: 'M2,-.5 L0,.5 L2,1.5', type: VectorType.STROKE, leftPadding: 1, rightPadding: 1 }, + '\u{E0B3}': { d: 'M2,-.5 L0,.5 L2,1.5', type: CustomGlyphVectorType.STROKE, leftPadding: 1, rightPadding: 1 }, // Right semi-circle solid - '\u{E0B4}': { d: 'M0,0 L0,1 C0.552,1,1,0.776,1,.5 C1,0.224,0.552,0,0,0', type: VectorType.FILL, rightPadding: 1 }, + '\u{E0B4}': { d: 'M0,0 L0,1 C0.552,1,1,0.776,1,.5 C1,0.224,0.552,0,0,0', type: CustomGlyphVectorType.FILL, rightPadding: 1 }, // Right semi-circle line - '\u{E0B5}': { d: 'M.2,1 C.422,1,.8,.826,.78,.5 C.8,.174,0.422,0,.2,0', type: VectorType.STROKE, rightPadding: 1 }, + '\u{E0B5}': { d: 'M.2,1 C.422,1,.8,.826,.78,.5 C.8,.174,0.422,0,.2,0', type: CustomGlyphVectorType.STROKE, rightPadding: 1 }, // Left semi-circle solid - '\u{E0B6}': { d: 'M1,0 L1,1 C0.448,1,0,0.776,0,.5 C0,0.224,0.448,0,1,0', type: VectorType.FILL, leftPadding: 1 }, + '\u{E0B6}': { d: 'M1,0 L1,1 C0.448,1,0,0.776,0,.5 C0,0.224,0.448,0,1,0', type: CustomGlyphVectorType.FILL, leftPadding: 1 }, // Left semi-circle line - '\u{E0B7}': { d: 'M.8,1 C0.578,1,0.2,.826,.22,.5 C0.2,0.174,0.578,0,0.8,0', type: VectorType.STROKE, leftPadding: 1 }, + '\u{E0B7}': { d: 'M.8,1 C0.578,1,0.2,.826,.22,.5 C0.2,0.174,0.578,0,0.8,0', type: CustomGlyphVectorType.STROKE, leftPadding: 1 }, // Lower left triangle - '\u{E0B8}': { d: 'M-.5,-.5 L1.5,1.5 L-.5,1.5', type: VectorType.FILL }, + '\u{E0B8}': { d: 'M-.5,-.5 L1.5,1.5 L-.5,1.5', type: CustomGlyphVectorType.FILL }, // Backslash separator - '\u{E0B9}': { d: 'M-.5,-.5 L1.5,1.5', type: VectorType.STROKE, leftPadding: 1, rightPadding: 1 }, + '\u{E0B9}': { d: 'M-.5,-.5 L1.5,1.5', type: CustomGlyphVectorType.STROKE, leftPadding: 1, rightPadding: 1 }, // Lower right triangle - '\u{E0BA}': { d: 'M1.5,-.5 L-.5,1.5 L1.5,1.5', type: VectorType.FILL }, + '\u{E0BA}': { d: 'M1.5,-.5 L-.5,1.5 L1.5,1.5', type: CustomGlyphVectorType.FILL }, // Upper left triangle - '\u{E0BC}': { d: 'M1.5,-.5 L-.5,1.5 L-.5,-.5', type: VectorType.FILL }, + '\u{E0BC}': { d: 'M1.5,-.5 L-.5,1.5 L-.5,-.5', type: CustomGlyphVectorType.FILL }, // Forward slash separator - '\u{E0BD}': { d: 'M1.5,-.5 L-.5,1.5', type: VectorType.STROKE, leftPadding: 1, rightPadding: 1 }, + '\u{E0BD}': { d: 'M1.5,-.5 L-.5,1.5', type: CustomGlyphVectorType.STROKE, leftPadding: 1, rightPadding: 1 }, // Upper right triangle - '\u{E0BE}': { d: 'M-.5,-.5 L1.5,1.5 L1.5,-.5', type: VectorType.FILL } + '\u{E0BE}': { d: 'M-.5,-.5 L1.5,1.5 L1.5,-.5', type: CustomGlyphVectorType.FILL } }; // Forward slash separator redundant powerlineDefinitions['\u{E0BB}'] = powerlineDefinitions['\u{E0BD}']; diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts index d8faca6f3..953570242 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts @@ -6,7 +6,7 @@ import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { blockElementDefinitions, blockShadeComboDefinitions, boxDrawingDefinitions, patternCharacterDefinitions, powerlineDefinitions, rectangularShadeDefinitions, symbolsForLegacyComputingDefinitions } from 'customGlyphs/CustomGlyphDefinitions'; -export interface ISolidOctantBlockVector { +export interface ICustomGlyphSolidOctantBlockVector { x: number; y: number; w: number; @@ -17,25 +17,27 @@ export interface ISolidOctantBlockVector { * @param xp The percentage of 15% of the x axis. * @param yp The percentage of 15% of the x axis on the y axis. */ -export type DrawFunctionDefinition = (xp: number, yp: number) => string; +export type CustomGlyphDrawFunctionDefinition = (xp: number, yp: number) => string; -export interface IVectorShape { +export interface ICustomGlyphVectorShape { d: string; - type: VectorType; + type: CustomGlyphVectorType; leftPadding?: number; rightPadding?: number; } -export const enum VectorType { +export const enum CustomGlyphVectorType { FILL, STROKE } +export type CustomGlyphPatternDefinition = number[][]; + /** * Try drawing a custom block element or box drawing character, returning whether it was * successfully drawn. */ -export function tryDrawCustomChar( +export function tryDrawCustomGlyph( ctx: CanvasRenderingContext2D, c: string, xOffset: number, @@ -92,7 +94,7 @@ export function tryDrawCustomChar( function drawBlockVectorChar( ctx: CanvasRenderingContext2D, - charDefinition: ISolidOctantBlockVector[], + charDefinition: ICustomGlyphSolidOctantBlockVector[], xOffset: number, yOffset: number, deviceCellWidth: number, @@ -113,7 +115,7 @@ function drawBlockVectorChar( function drawPathDefinitionCharacter( ctx: CanvasRenderingContext2D, - charDefinition: DrawFunctionDefinition, + charDefinition: CustomGlyphDrawFunctionDefinition, xOffset: number, yOffset: number, deviceCellWidth: number, @@ -145,8 +147,7 @@ function drawPathDefinitionCharacter( ctx.fill(); } -export type PatternDefinition = number[][]; -const cachedPatterns: Map> = new Map(); +const cachedPatterns: Map> = new Map(); function drawPatternChar( ctx: CanvasRenderingContext2D, @@ -363,7 +364,7 @@ function drawBoxDrawingChar( function drawPowerlineChar( ctx: CanvasRenderingContext2D, - charDefinition: IVectorShape, + charDefinition: ICustomGlyphVectorShape, xOffset: number, yOffset: number, deviceCellWidth: number, @@ -403,7 +404,7 @@ function drawPowerlineChar( (charDefinition.rightPadding ?? 0) * (cssLineWidth / 2) )); } - if (charDefinition.type === VectorType.STROKE) { + if (charDefinition.type === CustomGlyphVectorType.STROKE) { ctx.strokeStyle = ctx.fillStyle; ctx.stroke(); } else { From b64543aa59ddd21693a0087a8280de5272b78af5 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 22 Dec 2025 10:57:59 -0800 Subject: [PATCH 4/6] Make medium shade consistent, make all shades less heavy --- .../customGlyphs/CustomGlyphDefinitions.ts | 49 ++++++++++--------- .../src/customGlyphs/CustomGlyphRasterizer.ts | 34 ++++++------- 2 files changed, 43 insertions(+), 40 deletions(-) diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts index c21e9b50a..3c6da65ff 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts @@ -291,21 +291,32 @@ export const symbolsForLegacyComputingDefinitions: { [index: string]: CustomGlyp '\u{1FB6F}': () => 'M0,1 L1,1 L0.5,0.5 Z' // LOWER TRIANGULAR ONE QUARTER BLOCK }; +/** + * Rectangular shade characters - these use medium shade pattern (50%) like 0x2592. + * Each entry is [pattern, region] where region is [x, y, width, height] in 0-1 normalized + * coordinates. Pattern is the medium shade checkerboard pattern. + */ +const mediumShadePattern: CustomGlyphPatternDefinition = [ + [1, 0], + [0, 1] +]; + +const inverseMediumShadePattern: CustomGlyphPatternDefinition = [ + [0, 1], + [1, 0] +]; + +export const rectangularShadeDefinitions: { [index: string]: [CustomGlyphPatternDefinition, [number, number, number, number]] | undefined } = { + '\u{1FB8C}': [mediumShadePattern, [0, 0, 0.5, 1]], // LEFT HALF MEDIUM SHADE + '\u{1FB8D}': [mediumShadePattern, [0.5, 0, 0.5, 1]], // RIGHT HALF MEDIUM SHADE + '\u{1FB8E}': [mediumShadePattern, [0, 0, 1, 0.5]], // UPPER HALF MEDIUM SHADE + '\u{1FB8F}': [mediumShadePattern, [0, 0.5, 1, 0.5]], // LOWER HALF MEDIUM SHADE + '\u{1FB90}': [inverseMediumShadePattern, [0, 0, 1, 1]] // INVERSE MEDIUM SHADE +}; + /** Region defined as [x, y, width, height] in 0-1 normalized coordinates. */ type RegionDefinition = [number, number, number, number]; -/** - * Rectangular shade characters - these use medium shade pattern with region bounds. - * Pattern is a checkerboard that shifts 1px each row (same as medium shade). - */ -export const rectangularShadeDefinitions: { [index: string]: RegionDefinition | undefined } = { - '\u{1FB8C}': [0, 0, 0.5, 1], // LEFT HALF MEDIUM SHADE - '\u{1FB8D}': [0.5, 0, 0.5, 1], // RIGHT HALF MEDIUM SHADE - '\u{1FB8E}': [0, 0, 1, 0.5], // UPPER HALF MEDIUM SHADE - '\u{1FB8F}': [0, 0.5, 1, 0.5], // LOWER HALF MEDIUM SHADE - '\u{1FB90}': [0, 0, 1, 1] // INVERSE MEDIUM SHADE -}; - /** [solidRegion, shadeRegion] where shade region uses inverse medium shade pattern. */ type BlockShadeComboDefinition = [RegionDefinition, RegionDefinition]; @@ -326,22 +337,16 @@ export const blockShadeComboDefinitions: { [index: string]: BlockShadeComboDefin export const patternCharacterDefinitions: { [key: string]: CustomGlyphPatternDefinition | undefined } = { // Shade characters (0x2591-0x2593) '░': [ // LIGHT SHADE (25%) - [1, 0, 0, 0], - [0, 0, 0, 0], - [0, 0, 1, 0], - [0, 0, 0, 0] + [1, 0], + [0, 0] ], '▒': [ // MEDIUM SHADE (50%) [1, 0], - [0, 0], - [0, 1], - [0, 0] + [0, 1] ], '▓': [ // DARK SHADE (75%) - [0, 1], [1, 1], - [1, 0], - [1, 1] + [1, 0] ] }; diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts index 953570242..8c77bdd77 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts @@ -61,7 +61,7 @@ export function tryDrawCustomGlyph( const rectangularShadeDefinition = rectangularShadeDefinitions[c]; if (rectangularShadeDefinition) { - drawRectangularShadeChar(ctx, rectangularShadeDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight, c === '\u{1FB90}'); + drawRectangularShadeChar(ctx, rectangularShadeDefinition, xOffset, yOffset, deviceCellWidth, deviceCellHeight); return true; } @@ -214,34 +214,32 @@ function drawPatternChar( */ function drawRectangularShadeChar( ctx: CanvasRenderingContext2D, - region: [number, number, number, number], + definition: [CustomGlyphPatternDefinition, [number, number, number, number]], xOffset: number, yOffset: number, deviceCellWidth: number, - deviceCellHeight: number, - isInverse: boolean + deviceCellHeight: number ): void { + const [pattern, region] = definition; const [rx, ry, rw, rh] = region; const regionX = Math.round(xOffset + rx * deviceCellWidth); const regionY = Math.round(yOffset + ry * deviceCellHeight); const regionW = Math.round(rw * deviceCellWidth); const regionH = Math.round(rh * deviceCellHeight); - // For inverse medium shade, we use the opposite pattern (fill where medium shade doesn't) - // Medium shade pattern: fills at (x+y) % 2 === 0, so inverse fills at (x+y) % 2 === 1 - const patternOffset = isInverse ? 1 : 0; + // Save context state + ctx.save(); - for (let py = 0; py < regionH; py++) { - // Calculate the absolute y position for pattern calculation - const absY = regionY + py - yOffset; - for (let px = 0; px < regionW; px++) { - const absX = regionX + px - xOffset; - // Checkerboard pattern: fill if (x + y) % 2 matches the offset - if (((absX + absY) % 2) === patternOffset) { - ctx.fillRect(regionX + px, regionY + py, 1, 1); - } - } - } + // Clip to the region + ctx.beginPath(); + ctx.rect(regionX, regionY, regionW, regionH); + ctx.clip(); + + // Draw the pattern + drawPatternChar(ctx, pattern, xOffset, yOffset, deviceCellWidth, deviceCellHeight); + + // Restore context state + ctx.restore(); } /** From 32b4547c5ab9717739bf161ae6ccf80779c3a4b5 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 22 Dec 2025 11:09:02 -0800 Subject: [PATCH 5/6] Tweak symbol names --- .../customGlyphs/CustomGlyphDefinitions.ts | 264 +++++++++--------- 1 file changed, 133 insertions(+), 131 deletions(-) diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts index 3c6da65ff..7f89e98db 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts @@ -202,8 +202,7 @@ export const symbolsForLegacyComputingDefinitions: { [index: string]: CustomGlyp '\u{1FB2D}': sextant(0b110000), // BLOCK SEXTANT-56 (lower one third block) '\u{1FB2E}': sextant(0b110001), // BLOCK SEXTANT-156 '\u{1FB2F}': sextant(0b110010), // BLOCK SEXTANT-256 - '\u{1FB30}': sextant(0b110011), // BLOCK SEXTANT-1256 (upper and lower one - // third block) + '\u{1FB30}': sextant(0b110011), // BLOCK SEXTANT-1256 (upper and lower one third block) '\u{1FB31}': sextant(0b110100), // BLOCK SEXTANT-356 '\u{1FB32}': sextant(0b110101), // BLOCK SEXTANT-1356 '\u{1FB33}': sextant(0b110110), // BLOCK SEXTANT-2356 @@ -379,7 +378,7 @@ const enum Shapes { /** ┊ */ FOUR_DASHES_VERTICAL = 'M.5,.05 L.5,.2 M.5,.3 L.5,.45 L.5,.55 M.5,.7 L.5,.95', } -const enum Style { +const enum FontWeight { NORMAL = 1, BOLD = 3 } @@ -390,145 +389,148 @@ const enum Style { * svg d attribute). */ export const boxDrawingDefinitions: { [character: string]: { [fontWeight: number]: string | CustomGlyphDrawFunctionDefinition } | undefined } = { + // U+2500-U+257F + // https://www.unicode.org/charts/PDF/U2500.pdf + // Uniform normal and bold - '─': { [Style.NORMAL]: Shapes.LEFT_TO_RIGHT }, - '━': { [Style.BOLD]: Shapes.LEFT_TO_RIGHT }, - '│': { [Style.NORMAL]: Shapes.TOP_TO_BOTTOM }, - '┃': { [Style.BOLD]: Shapes.TOP_TO_BOTTOM }, - '┌': { [Style.NORMAL]: Shapes.RIGHT_TO_BOTTOM }, - '┏': { [Style.BOLD]: Shapes.RIGHT_TO_BOTTOM }, - '┐': { [Style.NORMAL]: Shapes.LEFT_TO_BOTTOM }, - '┓': { [Style.BOLD]: Shapes.LEFT_TO_BOTTOM }, - '└': { [Style.NORMAL]: Shapes.TOP_TO_RIGHT }, - '┗': { [Style.BOLD]: Shapes.TOP_TO_RIGHT }, - '┘': { [Style.NORMAL]: Shapes.TOP_TO_LEFT }, - '┛': { [Style.BOLD]: Shapes.TOP_TO_LEFT }, - '├': { [Style.NORMAL]: Shapes.T_RIGHT }, - '┣': { [Style.BOLD]: Shapes.T_RIGHT }, - '┤': { [Style.NORMAL]: Shapes.T_LEFT }, - '┫': { [Style.BOLD]: Shapes.T_LEFT }, - '┬': { [Style.NORMAL]: Shapes.T_BOTTOM }, - '┳': { [Style.BOLD]: Shapes.T_BOTTOM }, - '┴': { [Style.NORMAL]: Shapes.T_TOP }, - '┻': { [Style.BOLD]: Shapes.T_TOP }, - '┼': { [Style.NORMAL]: Shapes.CROSS }, - '╋': { [Style.BOLD]: Shapes.CROSS }, - '╴': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT }, - '╸': { [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '╵': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP }, - '╹': { [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '╶': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT }, - '╺': { [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '╷': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM }, - '╻': { [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '─': { [FontWeight.NORMAL]: Shapes.LEFT_TO_RIGHT }, + '━': { [FontWeight.BOLD]: Shapes.LEFT_TO_RIGHT }, + '│': { [FontWeight.NORMAL]: Shapes.TOP_TO_BOTTOM }, + '┃': { [FontWeight.BOLD]: Shapes.TOP_TO_BOTTOM }, + '┌': { [FontWeight.NORMAL]: Shapes.RIGHT_TO_BOTTOM }, + '┏': { [FontWeight.BOLD]: Shapes.RIGHT_TO_BOTTOM }, + '┐': { [FontWeight.NORMAL]: Shapes.LEFT_TO_BOTTOM }, + '┓': { [FontWeight.BOLD]: Shapes.LEFT_TO_BOTTOM }, + '└': { [FontWeight.NORMAL]: Shapes.TOP_TO_RIGHT }, + '┗': { [FontWeight.BOLD]: Shapes.TOP_TO_RIGHT }, + '┘': { [FontWeight.NORMAL]: Shapes.TOP_TO_LEFT }, + '┛': { [FontWeight.BOLD]: Shapes.TOP_TO_LEFT }, + '├': { [FontWeight.NORMAL]: Shapes.T_RIGHT }, + '┣': { [FontWeight.BOLD]: Shapes.T_RIGHT }, + '┤': { [FontWeight.NORMAL]: Shapes.T_LEFT }, + '┫': { [FontWeight.BOLD]: Shapes.T_LEFT }, + '┬': { [FontWeight.NORMAL]: Shapes.T_BOTTOM }, + '┳': { [FontWeight.BOLD]: Shapes.T_BOTTOM }, + '┴': { [FontWeight.NORMAL]: Shapes.T_TOP }, + '┻': { [FontWeight.BOLD]: Shapes.T_TOP }, + '┼': { [FontWeight.NORMAL]: Shapes.CROSS }, + '╋': { [FontWeight.BOLD]: Shapes.CROSS }, + '╴': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT }, + '╸': { [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '╵': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP }, + '╹': { [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '╶': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT }, + '╺': { [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '╷': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM }, + '╻': { [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, // Double border - '═': { [Style.NORMAL]: (xp, yp) => `M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp}` }, - '║': { [Style.NORMAL]: (xp, yp) => `M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1` }, - '╒': { [Style.NORMAL]: (xp, yp) => `M.5,1 L.5,${.5 - yp} L1,${.5 - yp} M.5,${.5 + yp} L1,${.5 + yp}` }, - '╓': { [Style.NORMAL]: (xp, yp) => `M${.5 - xp},1 L${.5 - xp},.5 L1,.5 M${.5 + xp},.5 L${.5 + xp},1` }, - '╔': { [Style.NORMAL]: (xp, yp) => `M1,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1` }, - '╕': { [Style.NORMAL]: (xp, yp) => `M0,${.5 - yp} L.5,${.5 - yp} L.5,1 M0,${.5 + yp} L.5,${.5 + yp}` }, - '╖': { [Style.NORMAL]: (xp, yp) => `M${.5 + xp},1 L${.5 + xp},.5 L0,.5 M${.5 - xp},.5 L${.5 - xp},1` }, - '╗': { [Style.NORMAL]: (xp, yp) => `M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M0,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},1` }, - '╘': { [Style.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 + yp} L1,${.5 + yp} M.5,${.5 - yp} L1,${.5 - yp}` }, - '╙': { [Style.NORMAL]: (xp, yp) => `M1,.5 L${.5 - xp},.5 L${.5 - xp},0 M${.5 + xp},.5 L${.5 + xp},0` }, - '╚': { [Style.NORMAL]: (xp, yp) => `M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0 M1,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},0` }, - '╛': { [Style.NORMAL]: (xp, yp) => `M0,${.5 + yp} L.5,${.5 + yp} L.5,0 M0,${.5 - yp} L.5,${.5 - yp}` }, - '╜': { [Style.NORMAL]: (xp, yp) => `M0,.5 L${.5 + xp},.5 L${.5 + xp},0 M${.5 - xp},.5 L${.5 - xp},0` }, - '╝': { [Style.NORMAL]: (xp, yp) => `M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0 M0,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},0` }, - '╞': { [Style.NORMAL]: (xp, yp) => `${Shapes.TOP_TO_BOTTOM} M.5,${.5 - yp} L1,${.5 - yp} M.5,${.5 + yp} L1,${.5 + yp}` }, - '╟': { [Style.NORMAL]: (xp, yp) => `M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1 M${.5 + xp},.5 L1,.5` }, - '╠': { [Style.NORMAL]: (xp, yp) => `M${.5 - xp},0 L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1 M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0` }, - '╡': { [Style.NORMAL]: (xp, yp) => `${Shapes.TOP_TO_BOTTOM} M0,${.5 - yp} L.5,${.5 - yp} M0,${.5 + yp} L.5,${.5 + yp}` }, - '╢': { [Style.NORMAL]: (xp, yp) => `M0,.5 L${.5 - xp},.5 M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1` }, - '╣': { [Style.NORMAL]: (xp, yp) => `M${.5 + xp},0 L${.5 + xp},1 M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0` }, - '╤': { [Style.NORMAL]: (xp, yp) => `M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp} M.5,${.5 + yp} L.5,1` }, - '╥': { [Style.NORMAL]: (xp, yp) => `${Shapes.LEFT_TO_RIGHT} M${.5 - xp},.5 L${.5 - xp},1 M${.5 + xp},.5 L${.5 + xp},1` }, - '╦': { [Style.NORMAL]: (xp, yp) => `M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1` }, - '╧': { [Style.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - yp} M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp}` }, - '╨': { [Style.NORMAL]: (xp, yp) => `${Shapes.LEFT_TO_RIGHT} M${.5 - xp},.5 L${.5 - xp},0 M${.5 + xp},.5 L${.5 + xp},0` }, - '╩': { [Style.NORMAL]: (xp, yp) => `M0,${.5 + yp} L1,${.5 + yp} M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0 M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0` }, - '╪': { [Style.NORMAL]: (xp, yp) => `${Shapes.TOP_TO_BOTTOM} M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp}` }, - '╫': { [Style.NORMAL]: (xp, yp) => `${Shapes.LEFT_TO_RIGHT} M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1` }, - '╬': { [Style.NORMAL]: (xp, yp) => `M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1 M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0 M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0` }, + '═': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp}` }, + '║': { [FontWeight.NORMAL]: (xp, yp) => `M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1` }, + '╒': { [FontWeight.NORMAL]: (xp, yp) => `M.5,1 L.5,${.5 - yp} L1,${.5 - yp} M.5,${.5 + yp} L1,${.5 + yp}` }, + '╓': { [FontWeight.NORMAL]: (xp, yp) => `M${.5 - xp},1 L${.5 - xp},.5 L1,.5 M${.5 + xp},.5 L${.5 + xp},1` }, + '╔': { [FontWeight.NORMAL]: (xp, yp) => `M1,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1` }, + '╕': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 - yp} L.5,${.5 - yp} L.5,1 M0,${.5 + yp} L.5,${.5 + yp}` }, + '╖': { [FontWeight.NORMAL]: (xp, yp) => `M${.5 + xp},1 L${.5 + xp},.5 L0,.5 M${.5 - xp},.5 L${.5 - xp},1` }, + '╗': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M0,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},1` }, + '╘': { [FontWeight.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 + yp} L1,${.5 + yp} M.5,${.5 - yp} L1,${.5 - yp}` }, + '╙': { [FontWeight.NORMAL]: (xp, yp) => `M1,.5 L${.5 - xp},.5 L${.5 - xp},0 M${.5 + xp},.5 L${.5 + xp},0` }, + '╚': { [FontWeight.NORMAL]: (xp, yp) => `M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0 M1,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},0` }, + '╛': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 + yp} L.5,${.5 + yp} L.5,0 M0,${.5 - yp} L.5,${.5 - yp}` }, + '╜': { [FontWeight.NORMAL]: (xp, yp) => `M0,.5 L${.5 + xp},.5 L${.5 + xp},0 M${.5 - xp},.5 L${.5 - xp},0` }, + '╝': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0 M0,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},0` }, + '╞': { [FontWeight.NORMAL]: (xp, yp) => `${Shapes.TOP_TO_BOTTOM} M.5,${.5 - yp} L1,${.5 - yp} M.5,${.5 + yp} L1,${.5 + yp}` }, + '╟': { [FontWeight.NORMAL]: (xp, yp) => `M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1 M${.5 + xp},.5 L1,.5` }, + '╠': { [FontWeight.NORMAL]: (xp, yp) => `M${.5 - xp},0 L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1 M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0` }, + '╡': { [FontWeight.NORMAL]: (xp, yp) => `${Shapes.TOP_TO_BOTTOM} M0,${.5 - yp} L.5,${.5 - yp} M0,${.5 + yp} L.5,${.5 + yp}` }, + '╢': { [FontWeight.NORMAL]: (xp, yp) => `M0,.5 L${.5 - xp},.5 M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1` }, + '╣': { [FontWeight.NORMAL]: (xp, yp) => `M${.5 + xp},0 L${.5 + xp},1 M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0` }, + '╤': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp} M.5,${.5 + yp} L.5,1` }, + '╥': { [FontWeight.NORMAL]: (xp, yp) => `${Shapes.LEFT_TO_RIGHT} M${.5 - xp},.5 L${.5 - xp},1 M${.5 + xp},.5 L${.5 + xp},1` }, + '╦': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1` }, + '╧': { [FontWeight.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - yp} M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp}` }, + '╨': { [FontWeight.NORMAL]: (xp, yp) => `${Shapes.LEFT_TO_RIGHT} M${.5 - xp},.5 L${.5 - xp},0 M${.5 + xp},.5 L${.5 + xp},0` }, + '╩': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 + yp} L1,${.5 + yp} M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0 M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0` }, + '╪': { [FontWeight.NORMAL]: (xp, yp) => `${Shapes.TOP_TO_BOTTOM} M0,${.5 - yp} L1,${.5 - yp} M0,${.5 + yp} L1,${.5 + yp}` }, + '╫': { [FontWeight.NORMAL]: (xp, yp) => `${Shapes.LEFT_TO_RIGHT} M${.5 - xp},0 L${.5 - xp},1 M${.5 + xp},0 L${.5 + xp},1` }, + '╬': { [FontWeight.NORMAL]: (xp, yp) => `M0,${.5 + yp} L${.5 - xp},${.5 + yp} L${.5 - xp},1 M1,${.5 + yp} L${.5 + xp},${.5 + yp} L${.5 + xp},1 M0,${.5 - yp} L${.5 - xp},${.5 - yp} L${.5 - xp},0 M1,${.5 - yp} L${.5 + xp},${.5 - yp} L${.5 + xp},0` }, // Diagonal - '╱': { [Style.NORMAL]: 'M1,0 L0,1' }, - '╲': { [Style.NORMAL]: 'M0,0 L1,1' }, - '╳': { [Style.NORMAL]: 'M1,0 L0,1 M0,0 L1,1' }, + '╱': { [FontWeight.NORMAL]: 'M1,0 L0,1' }, + '╲': { [FontWeight.NORMAL]: 'M0,0 L1,1' }, + '╳': { [FontWeight.NORMAL]: 'M1,0 L0,1 M0,0 L1,1' }, // Mixed weight - '╼': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '╽': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '╾': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '╿': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '┍': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '┎': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '┑': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '┒': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '┕': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '┖': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '┙': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '┚': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '┝': { [Style.NORMAL]: Shapes.TOP_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '┞': { [Style.NORMAL]: Shapes.RIGHT_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '┟': { [Style.NORMAL]: Shapes.TOP_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '┠': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: Shapes.TOP_TO_BOTTOM }, - '┡': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: Shapes.TOP_TO_RIGHT }, - '┢': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: Shapes.RIGHT_TO_BOTTOM }, - '┥': { [Style.NORMAL]: Shapes.TOP_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '┦': { [Style.NORMAL]: Shapes.LEFT_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '┧': { [Style.NORMAL]: Shapes.TOP_TO_LEFT, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '┨': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: Shapes.TOP_TO_BOTTOM }, - '┩': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: Shapes.TOP_TO_LEFT }, - '┪': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: Shapes.LEFT_TO_BOTTOM }, - '┭': { [Style.NORMAL]: Shapes.RIGHT_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '┮': { [Style.NORMAL]: Shapes.LEFT_TO_BOTTOM, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '┯': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: Shapes.LEFT_TO_RIGHT }, - '┰': { [Style.NORMAL]: Shapes.LEFT_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '┱': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: Shapes.LEFT_TO_BOTTOM }, - '┲': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: Shapes.RIGHT_TO_BOTTOM }, - '┵': { [Style.NORMAL]: Shapes.TOP_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '┶': { [Style.NORMAL]: Shapes.TOP_TO_LEFT, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '┷': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: Shapes.LEFT_TO_RIGHT }, - '┸': { [Style.NORMAL]: Shapes.LEFT_TO_RIGHT, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '┹': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: Shapes.TOP_TO_LEFT }, - '┺': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: Shapes.TOP_TO_RIGHT }, - '┽': { [Style.NORMAL]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_RIGHT}`, [Style.BOLD]: Shapes.MIDDLE_TO_LEFT }, - '┾': { [Style.NORMAL]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_LEFT}`, [Style.BOLD]: Shapes.MIDDLE_TO_RIGHT }, - '┿': { [Style.NORMAL]: Shapes.TOP_TO_BOTTOM, [Style.BOLD]: Shapes.LEFT_TO_RIGHT }, - '╀': { [Style.NORMAL]: `${Shapes.LEFT_TO_RIGHT} ${Shapes.MIDDLE_TO_BOTTOM}`, [Style.BOLD]: Shapes.MIDDLE_TO_TOP }, - '╁': { [Style.NORMAL]: `${Shapes.MIDDLE_TO_TOP} ${Shapes.LEFT_TO_RIGHT}`, [Style.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, - '╂': { [Style.NORMAL]: Shapes.LEFT_TO_RIGHT, [Style.BOLD]: Shapes.TOP_TO_BOTTOM }, - '╃': { [Style.NORMAL]: Shapes.RIGHT_TO_BOTTOM, [Style.BOLD]: Shapes.TOP_TO_LEFT }, - '╄': { [Style.NORMAL]: Shapes.LEFT_TO_BOTTOM, [Style.BOLD]: Shapes.TOP_TO_RIGHT }, - '╅': { [Style.NORMAL]: Shapes.TOP_TO_RIGHT, [Style.BOLD]: Shapes.LEFT_TO_BOTTOM }, - '╆': { [Style.NORMAL]: Shapes.TOP_TO_LEFT, [Style.BOLD]: Shapes.RIGHT_TO_BOTTOM }, - '╇': { [Style.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [Style.BOLD]: `${Shapes.MIDDLE_TO_TOP} ${Shapes.LEFT_TO_RIGHT}` }, - '╈': { [Style.NORMAL]: Shapes.MIDDLE_TO_TOP, [Style.BOLD]: `${Shapes.LEFT_TO_RIGHT} ${Shapes.MIDDLE_TO_BOTTOM}` }, - '╉': { [Style.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [Style.BOLD]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_LEFT}` }, - '╊': { [Style.NORMAL]: Shapes.MIDDLE_TO_LEFT, [Style.BOLD]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_RIGHT}` }, + '╼': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '╽': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '╾': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '╿': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '┍': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '┎': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '┑': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '┒': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '┕': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '┖': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '┙': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '┚': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '┝': { [FontWeight.NORMAL]: Shapes.TOP_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '┞': { [FontWeight.NORMAL]: Shapes.RIGHT_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '┟': { [FontWeight.NORMAL]: Shapes.TOP_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '┠': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: Shapes.TOP_TO_BOTTOM }, + '┡': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: Shapes.TOP_TO_RIGHT }, + '┢': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: Shapes.RIGHT_TO_BOTTOM }, + '┥': { [FontWeight.NORMAL]: Shapes.TOP_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '┦': { [FontWeight.NORMAL]: Shapes.LEFT_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '┧': { [FontWeight.NORMAL]: Shapes.TOP_TO_LEFT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '┨': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: Shapes.TOP_TO_BOTTOM }, + '┩': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: Shapes.TOP_TO_LEFT }, + '┪': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: Shapes.LEFT_TO_BOTTOM }, + '┭': { [FontWeight.NORMAL]: Shapes.RIGHT_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '┮': { [FontWeight.NORMAL]: Shapes.LEFT_TO_BOTTOM, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '┯': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: Shapes.LEFT_TO_RIGHT }, + '┰': { [FontWeight.NORMAL]: Shapes.LEFT_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '┱': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: Shapes.LEFT_TO_BOTTOM }, + '┲': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: Shapes.RIGHT_TO_BOTTOM }, + '┵': { [FontWeight.NORMAL]: Shapes.TOP_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '┶': { [FontWeight.NORMAL]: Shapes.TOP_TO_LEFT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '┷': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: Shapes.LEFT_TO_RIGHT }, + '┸': { [FontWeight.NORMAL]: Shapes.LEFT_TO_RIGHT, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '┹': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: Shapes.TOP_TO_LEFT }, + '┺': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: Shapes.TOP_TO_RIGHT }, + '┽': { [FontWeight.NORMAL]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_RIGHT}`, [FontWeight.BOLD]: Shapes.MIDDLE_TO_LEFT }, + '┾': { [FontWeight.NORMAL]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_LEFT}`, [FontWeight.BOLD]: Shapes.MIDDLE_TO_RIGHT }, + '┿': { [FontWeight.NORMAL]: Shapes.TOP_TO_BOTTOM, [FontWeight.BOLD]: Shapes.LEFT_TO_RIGHT }, + '╀': { [FontWeight.NORMAL]: `${Shapes.LEFT_TO_RIGHT} ${Shapes.MIDDLE_TO_BOTTOM}`, [FontWeight.BOLD]: Shapes.MIDDLE_TO_TOP }, + '╁': { [FontWeight.NORMAL]: `${Shapes.MIDDLE_TO_TOP} ${Shapes.LEFT_TO_RIGHT}`, [FontWeight.BOLD]: Shapes.MIDDLE_TO_BOTTOM }, + '╂': { [FontWeight.NORMAL]: Shapes.LEFT_TO_RIGHT, [FontWeight.BOLD]: Shapes.TOP_TO_BOTTOM }, + '╃': { [FontWeight.NORMAL]: Shapes.RIGHT_TO_BOTTOM, [FontWeight.BOLD]: Shapes.TOP_TO_LEFT }, + '╄': { [FontWeight.NORMAL]: Shapes.LEFT_TO_BOTTOM, [FontWeight.BOLD]: Shapes.TOP_TO_RIGHT }, + '╅': { [FontWeight.NORMAL]: Shapes.TOP_TO_RIGHT, [FontWeight.BOLD]: Shapes.LEFT_TO_BOTTOM }, + '╆': { [FontWeight.NORMAL]: Shapes.TOP_TO_LEFT, [FontWeight.BOLD]: Shapes.RIGHT_TO_BOTTOM }, + '╇': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_BOTTOM, [FontWeight.BOLD]: `${Shapes.MIDDLE_TO_TOP} ${Shapes.LEFT_TO_RIGHT}` }, + '╈': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_TOP, [FontWeight.BOLD]: `${Shapes.LEFT_TO_RIGHT} ${Shapes.MIDDLE_TO_BOTTOM}` }, + '╉': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_RIGHT, [FontWeight.BOLD]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_LEFT}` }, + '╊': { [FontWeight.NORMAL]: Shapes.MIDDLE_TO_LEFT, [FontWeight.BOLD]: `${Shapes.TOP_TO_BOTTOM} ${Shapes.MIDDLE_TO_RIGHT}` }, // Dashed - '╌': { [Style.NORMAL]: Shapes.TWO_DASHES_HORIZONTAL }, - '╍': { [Style.BOLD]: Shapes.TWO_DASHES_HORIZONTAL }, - '┄': { [Style.NORMAL]: Shapes.THREE_DASHES_HORIZONTAL }, - '┅': { [Style.BOLD]: Shapes.THREE_DASHES_HORIZONTAL }, - '┈': { [Style.NORMAL]: Shapes.FOUR_DASHES_HORIZONTAL }, - '┉': { [Style.BOLD]: Shapes.FOUR_DASHES_HORIZONTAL }, - '╎': { [Style.NORMAL]: Shapes.TWO_DASHES_VERTICAL }, - '╏': { [Style.BOLD]: Shapes.TWO_DASHES_VERTICAL }, - '┆': { [Style.NORMAL]: Shapes.THREE_DASHES_VERTICAL }, - '┇': { [Style.BOLD]: Shapes.THREE_DASHES_VERTICAL }, - '┊': { [Style.NORMAL]: Shapes.FOUR_DASHES_VERTICAL }, - '┋': { [Style.BOLD]: Shapes.FOUR_DASHES_VERTICAL }, + '╌': { [FontWeight.NORMAL]: Shapes.TWO_DASHES_HORIZONTAL }, + '╍': { [FontWeight.BOLD]: Shapes.TWO_DASHES_HORIZONTAL }, + '┄': { [FontWeight.NORMAL]: Shapes.THREE_DASHES_HORIZONTAL }, + '┅': { [FontWeight.BOLD]: Shapes.THREE_DASHES_HORIZONTAL }, + '┈': { [FontWeight.NORMAL]: Shapes.FOUR_DASHES_HORIZONTAL }, + '┉': { [FontWeight.BOLD]: Shapes.FOUR_DASHES_HORIZONTAL }, + '╎': { [FontWeight.NORMAL]: Shapes.TWO_DASHES_VERTICAL }, + '╏': { [FontWeight.BOLD]: Shapes.TWO_DASHES_VERTICAL }, + '┆': { [FontWeight.NORMAL]: Shapes.THREE_DASHES_VERTICAL }, + '┇': { [FontWeight.BOLD]: Shapes.THREE_DASHES_VERTICAL }, + '┊': { [FontWeight.NORMAL]: Shapes.FOUR_DASHES_VERTICAL }, + '┋': { [FontWeight.BOLD]: Shapes.FOUR_DASHES_VERTICAL }, // Curved - '╭': { [Style.NORMAL]: (xp, yp) => `M.5,1 L.5,${.5 + (yp / .15 * .5)} C.5,${.5 + (yp / .15 * .5)},.5,.5,1,.5` }, - '╮': { [Style.NORMAL]: (xp, yp) => `M.5,1 L.5,${.5 + (yp / .15 * .5)} C.5,${.5 + (yp / .15 * .5)},.5,.5,0,.5` }, - '╯': { [Style.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - (yp / .15 * .5)} C.5,${.5 - (yp / .15 * .5)},.5,.5,0,.5` }, - '╰': { [Style.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - (yp / .15 * .5)} C.5,${.5 - (yp / .15 * .5)},.5,.5,1,.5` } + '╭': { [FontWeight.NORMAL]: (xp, yp) => `M.5,1 L.5,${.5 + (yp / .15 * .5)} C.5,${.5 + (yp / .15 * .5)},.5,.5,1,.5` }, + '╮': { [FontWeight.NORMAL]: (xp, yp) => `M.5,1 L.5,${.5 + (yp / .15 * .5)} C.5,${.5 + (yp / .15 * .5)},.5,.5,0,.5` }, + '╯': { [FontWeight.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - (yp / .15 * .5)} C.5,${.5 - (yp / .15 * .5)},.5,.5,0,.5` }, + '╰': { [FontWeight.NORMAL]: (xp, yp) => `M.5,0 L.5,${.5 - (yp / .15 * .5)} C.5,${.5 - (yp / .15 * .5)},.5,.5,1,.5` } }; /** From ce41b175ee961914f7ecca8c5e4262644207152b Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Mon, 22 Dec 2025 11:11:50 -0800 Subject: [PATCH 6/6] Remove cyclic dep --- .../customGlyphs/CustomGlyphDefinitions.ts | 5 ++- .../src/customGlyphs/CustomGlyphRasterizer.ts | 28 +---------------- addons/addon-webgl/src/customGlyphs/Types.ts | 31 +++++++++++++++++++ 3 files changed, 36 insertions(+), 28 deletions(-) create mode 100644 addons/addon-webgl/src/customGlyphs/Types.ts diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts index 7f89e98db..aa3ef3218 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphDefinitions.ts @@ -3,9 +3,12 @@ * @license MIT */ +import { CustomGlyphVectorType, type CustomGlyphDrawFunctionDefinition, type CustomGlyphPatternDefinition, type ICustomGlyphSolidOctantBlockVector, type ICustomGlyphVectorShape } from 'customGlyphs/Types'; + /* eslint-disable @typescript-eslint/naming-convention */ -import { CustomGlyphVectorType, type CustomGlyphDrawFunctionDefinition, type ICustomGlyphSolidOctantBlockVector, type ICustomGlyphVectorShape, type CustomGlyphPatternDefinition } from 'customGlyphs/CustomGlyphRasterizer'; +export const unifiedCharDefinitions: { [index: string]: ICustomGlyphVectorShape[] | undefined } = { +}; export const blockElementDefinitions: { [index: string]: ICustomGlyphSolidOctantBlockVector[] | undefined } = { // Block elements (0x2580-0x2590) diff --git a/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts index 8c77bdd77..e84883dda 100644 --- a/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts +++ b/addons/addon-webgl/src/customGlyphs/CustomGlyphRasterizer.ts @@ -5,33 +5,7 @@ import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils'; import { blockElementDefinitions, blockShadeComboDefinitions, boxDrawingDefinitions, patternCharacterDefinitions, powerlineDefinitions, rectangularShadeDefinitions, symbolsForLegacyComputingDefinitions } from 'customGlyphs/CustomGlyphDefinitions'; - -export interface ICustomGlyphSolidOctantBlockVector { - x: number; - y: number; - w: number; - h: number; -} - -/** - * @param xp The percentage of 15% of the x axis. - * @param yp The percentage of 15% of the x axis on the y axis. - */ -export type CustomGlyphDrawFunctionDefinition = (xp: number, yp: number) => string; - -export interface ICustomGlyphVectorShape { - d: string; - type: CustomGlyphVectorType; - leftPadding?: number; - rightPadding?: number; -} - -export const enum CustomGlyphVectorType { - FILL, - STROKE -} - -export type CustomGlyphPatternDefinition = number[][]; +import { CustomGlyphVectorType, type CustomGlyphDrawFunctionDefinition, type CustomGlyphPatternDefinition, type ICustomGlyphSolidOctantBlockVector, type ICustomGlyphVectorShape } from 'customGlyphs/Types'; /** * Try drawing a custom block element or box drawing character, returning whether it was diff --git a/addons/addon-webgl/src/customGlyphs/Types.ts b/addons/addon-webgl/src/customGlyphs/Types.ts new file mode 100644 index 000000000..d4aebc733 --- /dev/null +++ b/addons/addon-webgl/src/customGlyphs/Types.ts @@ -0,0 +1,31 @@ +/** + * Copyright (c) 2021 The xterm.js authors. All rights reserved. + * @license MIT + */ + +export interface ICustomGlyphSolidOctantBlockVector { + x: number; + y: number; + w: number; + h: number; +} + +/** + * @param xp The percentage of 15% of the x axis. + * @param yp The percentage of 15% of the x axis on the y axis. + */ +export type CustomGlyphDrawFunctionDefinition = (xp: number, yp: number) => string; + +export interface ICustomGlyphVectorShape { + d: string; + type: CustomGlyphVectorType; + leftPadding?: number; + rightPadding?: number; +} + +export const enum CustomGlyphVectorType { + FILL, + STROKE +} + +export type CustomGlyphPatternDefinition = number[][];