Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions addons/addon-image/src/ImageRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,22 +129,22 @@ export class ImageRenderer extends Disposable implements IDisposable {
}

/**
* Current cell size (float).
* Current cell size in device pixels (accounts for devicePixelRatio).
*/
public get cellSize(): ICellSize {
return {
width: this.dimensions?.css.cell.width || -1,
height: this.dimensions?.css.cell.height || -1
width: this.dimensions?.device.cell.width || -1,
height: this.dimensions?.device.cell.height || -1
};
}

/**
* Clear a region of the image layer canvas.
*/
public clearLines(start: number, end: number, layer?: ImageLayer): void {
const y = start * (this.dimensions?.css.cell.height || 0);
const w = this.dimensions?.css.canvas.width || 0;
const h = (++end - start) * (this.dimensions?.css.cell.height || 0);
const y = start * (this.dimensions?.device.cell.height || 0);
const w = this.dimensions?.device.canvas.width || 0;
const h = (++end - start) * (this.dimensions?.device.cell.height || 0);
if (!layer || layer === 'top') {
this._layers.get('top')?.clearRect(0, y, w, h);
}
Expand Down Expand Up @@ -273,12 +273,16 @@ export class ImageRenderer extends Disposable implements IDisposable {
* Checked once from `ImageStorage.render`.
*/
public rescaleCanvas(): void {
const w = this.dimensions?.css.canvas.width || 0;
const h = this.dimensions?.css.canvas.height || 0;
const dw = this.dimensions?.device.canvas.width || 0;
const dh = this.dimensions?.device.canvas.height || 0;
const cw = this.dimensions?.css.canvas.width || 0;
const ch = this.dimensions?.css.canvas.height || 0;
for (const ctx of this._layers.values()) {
if (ctx.canvas.width !== w || ctx.canvas.height !== h) {
ctx.canvas.width = w;
ctx.canvas.height = h;
if (ctx.canvas.width !== dw || ctx.canvas.height !== dh) {
ctx.canvas.width = dw;
ctx.canvas.height = dh;
ctx.canvas.style.width = cw + 'px';
ctx.canvas.style.height = ch + 'px';
}
}
}
Expand Down Expand Up @@ -335,9 +339,11 @@ export class ImageRenderer extends Disposable implements IDisposable {
return;
}
const canvas = ImageRenderer.createCanvas(
this.document, this.dimensions?.css.canvas.width || 0,
this.dimensions?.css.canvas.height || 0
this.document, this.dimensions?.device.canvas.width || 0,
this.dimensions?.device.canvas.height || 0
);
canvas.style.width = (this.dimensions?.css.canvas.width || 0) + 'px';
canvas.style.height = (this.dimensions?.css.canvas.height || 0) + 'px';
canvas.classList.add(`xterm-image-layer-${layer}`);
const screenElement = this._terminal._core.screenElement;
// Use isolation to create a stacking context without overriding z-index,
Expand Down
Loading