Get webgl glyphs scaling to cell size, invalidate on option change

This commit is contained in:
Daniel Imms
2021-08-18 08:29:07 -07:00
parent da0928102b
commit 011026a8d1
4 changed files with 10 additions and 8 deletions
@@ -30,6 +30,8 @@ export function generateConfig(scaledCellWidth: number, scaledCellHeight: number
return { return {
customBlockAndBoxCharacters: terminal.getOption('customBlockAndBoxCharacters'), customBlockAndBoxCharacters: terminal.getOption('customBlockAndBoxCharacters'),
devicePixelRatio: window.devicePixelRatio, devicePixelRatio: window.devicePixelRatio,
letterSpacing: terminal.getOption('letterSpacing'),
lineHeight: terminal.getOption('lineHeight'),
scaledCellWidth, scaledCellWidth,
scaledCellHeight, scaledCellHeight,
scaledCharWidth, scaledCharWidth,
@@ -52,6 +54,9 @@ export function configEquals(a: ICharAtlasConfig, b: ICharAtlasConfig): boolean
} }
} }
return a.devicePixelRatio === b.devicePixelRatio && return a.devicePixelRatio === b.devicePixelRatio &&
a.customBlockAndBoxCharacters === b.customBlockAndBoxCharacters &&
a.lineHeight === b.lineHeight &&
a.letterSpacing === b.letterSpacing &&
a.fontFamily === b.fontFamily && a.fontFamily === b.fontFamily &&
a.fontSize === b.fontSize && a.fontSize === b.fontSize &&
a.fontWeight === b.fontWeight && a.fontWeight === b.fontWeight &&
+2
View File
@@ -19,6 +19,8 @@ export interface IGlyphIdentifier {
export interface ICharAtlasConfig { export interface ICharAtlasConfig {
customBlockAndBoxCharacters: boolean; customBlockAndBoxCharacters: boolean;
devicePixelRatio: number; devicePixelRatio: number;
letterSpacing: number;
lineHeight: number;
fontSize: number; fontSize: number;
fontFamily: string; fontFamily: string;
fontWeight: FontWeight; fontWeight: FontWeight;
@@ -84,8 +84,8 @@ export class WebglCharAtlas implements IDisposable {
this._cacheCtx = throwIfFalsy(this.cacheCanvas.getContext('2d', { alpha: true })); this._cacheCtx = throwIfFalsy(this.cacheCanvas.getContext('2d', { alpha: true }));
this._tmpCanvas = document.createElement('canvas'); this._tmpCanvas = document.createElement('canvas');
this._tmpCanvas.width = this._config.scaledCharWidth * 4 + TMP_CANVAS_GLYPH_PADDING * 2; this._tmpCanvas.width = this._config.scaledCellWidth * 4 + TMP_CANVAS_GLYPH_PADDING * 2;
this._tmpCanvas.height = this._config.scaledCharHeight + TMP_CANVAS_GLYPH_PADDING * 2; this._tmpCanvas.height = this._config.scaledCellHeight + TMP_CANVAS_GLYPH_PADDING * 2;
this._tmpCtx = throwIfFalsy(this._tmpCanvas.getContext('2d', { alpha: this._config.allowTransparency })); this._tmpCtx = throwIfFalsy(this._tmpCanvas.getContext('2d', { alpha: this._config.allowTransparency }));
} }
@@ -321,7 +321,7 @@ export class WebglCharAtlas implements IDisposable {
// Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used // Allow 1 cell width per character, with a minimum of 2 (CJK), plus some padding. This is used
// to draw the glyph to the canvas as well as to restrict the bounding box search to ensure // to draw the glyph to the canvas as well as to restrict the bounding box search to ensure
// giant ligatures (eg. =====>) don't impact overall performance. // giant ligatures (eg. =====>) don't impact overall performance.
const allowedWidth = this._config.scaledCharWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2; let allowedWidth = this._config.scaledCharWidth * Math.max(chars.length, 2) + TMP_CANVAS_GLYPH_PADDING * 2;
if (this._tmpCanvas.width < allowedWidth) { if (this._tmpCanvas.width < allowedWidth) {
this._tmpCanvas.width = allowedWidth; this._tmpCanvas.width = allowedWidth;
} }
-5
View File
@@ -404,15 +404,10 @@ function drawPatternChar(
imageData.data[(y * width + x) * 4 + 3] = charDefinition[y][x] * (a ?? 255); imageData.data[(y * width + x) * 4 + 3] = charDefinition[y][x] * (a ?? 255);
} }
} }
console.log('put', imageData);
tmpCtx.putImageData(imageData, 0, 0); tmpCtx.putImageData(imageData, 0, 0);
// TODO: This will break for different colored patterns
// TODO: This could happen multiple times
pattern = throwIfFalsy(ctx.createPattern(tmpCanvas, null)); pattern = throwIfFalsy(ctx.createPattern(tmpCanvas, null));
patternSet.set(fillStyle, pattern); patternSet.set(fillStyle, pattern);
} }
console.log('fill style', pattern);
ctx.fillStyle = pattern; ctx.fillStyle = pattern;
ctx.fillRect(xOffset, yOffset, scaledCellWidth, scaledCellHeight); ctx.fillRect(xOffset, yOffset, scaledCellWidth, scaledCellHeight);
} }