Skip to content

Commit

Permalink
Add code to IGlyphIdentifer, use it
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bgw committed Apr 16, 2018
1 parent ec96c40 commit 4fd630e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/renderer/BaseRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/atlas/DynamicCharAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/atlas/StaticCharAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/renderer/atlas/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const DIM_OPACITY = 0.5;

export interface IGlyphIdentifier {
char: string;
code: number;
bg: number;
fg: number;
bold: boolean;
Expand Down

0 comments on commit 4fd630e

Please sign in to comment.