From 4fd630ec5ca23db8346a6a520d8251eb839df338 Mon Sep 17 00:00:00 2001 From: Benjamin Woodruff Date: Mon, 16 Apr 2018 09:49:32 -0700 Subject: [PATCH] Add code to IGlyphIdentifer, use it It turns out that `glyph.char.charCodeAt(0)` isn't equivalent to the character's actual code because of utf-16 garbage, so this adds `glyph.code` to the `glyph` object so that we can use the `code` value, and don't need to regenerate it. --- src/renderer/BaseRenderLayer.ts | 2 +- src/renderer/atlas/DynamicCharAtlas.ts | 2 +- src/renderer/atlas/StaticCharAtlas.ts | 4 ++-- src/renderer/atlas/Types.ts | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/renderer/BaseRenderLayer.ts b/src/renderer/BaseRenderLayer.ts index a55b090d4b..c5b43b3afd 100644 --- a/src/renderer/BaseRenderLayer.ts +++ b/src/renderer/BaseRenderLayer.ts @@ -240,7 +240,7 @@ export abstract class BaseRenderLayer implements IRenderLayer { protected drawChar(terminal: ITerminal, char: string, code: number, width: number, x: number, y: number, fg: number, bg: number, bold: boolean, dim: boolean): void { const atlasDidDraw = this._charAtlas && this._charAtlas.draw( this._ctx, - {char, bg, fg, bold: bold && terminal.options.enableBold, dim}, + {char, code, bg, fg, bold: bold && terminal.options.enableBold, dim}, x * this._scaledCellWidth + this._scaledCharLeft, y * this._scaledCellHeight + this._scaledCharTop ); diff --git a/src/renderer/atlas/DynamicCharAtlas.ts b/src/renderer/atlas/DynamicCharAtlas.ts index 86b6ebfb96..302623dc31 100644 --- a/src/renderer/atlas/DynamicCharAtlas.ts +++ b/src/renderer/atlas/DynamicCharAtlas.ts @@ -121,7 +121,7 @@ export default class DynamicCharAtlas extends BaseCharAtlas { // to draw overlapping glyphs from the atlas: // https://github.com/servo/webrender/issues/464#issuecomment-255632875 // https://webglfundamentals.org/webgl/lessons/webgl-text-texture.html - return glyph.char.charCodeAt(0) < 256; + return glyph.code < 256; } private _toCoordinates(index: number): [number, number] { diff --git a/src/renderer/atlas/StaticCharAtlas.ts b/src/renderer/atlas/StaticCharAtlas.ts index f68c7c6c67..ae29dd0a62 100644 --- a/src/renderer/atlas/StaticCharAtlas.ts +++ b/src/renderer/atlas/StaticCharAtlas.ts @@ -34,7 +34,7 @@ export default class StaticCharAtlas extends BaseCharAtlas { } private _isCached(glyph: IGlyphIdentifier, colorIndex: number): boolean { - const isAscii = glyph.char.charCodeAt(0) < 256; + const isAscii = glyph.code < 256; // A color is basic if it is one of the standard normal or bold weight // colors of the characters held in the char atlas. Note that this excludes // the normal weight _light_ color characters. @@ -86,7 +86,7 @@ export default class StaticCharAtlas extends BaseCharAtlas { ctx.drawImage( this._texture, - glyph.char.charCodeAt(0) * charAtlasCellWidth, + glyph.code * charAtlasCellWidth, colorIndex * charAtlasCellHeight, charAtlasCellWidth, this._config.scaledCharHeight, diff --git a/src/renderer/atlas/Types.ts b/src/renderer/atlas/Types.ts index fe52f5a5e4..84481f6d0d 100644 --- a/src/renderer/atlas/Types.ts +++ b/src/renderer/atlas/Types.ts @@ -8,6 +8,7 @@ export const DIM_OPACITY = 0.5; export interface IGlyphIdentifier { char: string; + code: number; bg: number; fg: number; bold: boolean;