Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support underline and strikethrough in WebGL renderer #3386

Merged
merged 4 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ export class WebglCharAtlas implements IDisposable {
const inverse = !!this._workAttributeData.isInverse();
const dim = !!this._workAttributeData.isDim();
const italic = !!this._workAttributeData.isItalic();
const underline = !!this._workAttributeData.isUnderline();
const strikethrough = !!this._workAttributeData.isStrikethrough();
let fgColor = this._workAttributeData.getFgColor();
let fgColorMode = this._workAttributeData.getFgColorMode();
let bgColor = this._workAttributeData.getBgColor();
Expand Down Expand Up @@ -390,6 +392,26 @@ export class WebglCharAtlas implements IDisposable {

// Draw the character
this._tmpCtx.fillText(chars, padding, padding + this._config.scaledCharHeight);

// Draw underline and strikethrough
if (underline || strikethrough) {
const lineWidth = Math.max(1, Math.floor(this._config.fontSize / 10));
const yOffset = this._tmpCtx.lineWidth % 2 === 1 ? 0.5 : 0; // When the width is odd, draw at 0.5 position
this._tmpCtx.lineWidth = lineWidth;
this._tmpCtx.strokeStyle = this._tmpCtx.fillStyle;
this._tmpCtx.beginPath();
if (underline) {
this._tmpCtx.moveTo(padding, padding + this._config.scaledCharHeight - yOffset);
this._tmpCtx.lineTo(padding + this._config.scaledCharWidth, padding + this._config.scaledCharHeight - yOffset);
}
if (strikethrough) {
this._tmpCtx.moveTo(padding, padding + Math.floor(this._config.scaledCharHeight / 2) - yOffset);
this._tmpCtx.lineTo(padding + this._config.scaledCharWidth, padding + Math.floor(this._config.scaledCharHeight / 2) - yOffset);
}
this._tmpCtx.stroke();
this._tmpCtx.closePath();
}

this._tmpCtx.restore();

// clear the background from the character to avoid issues with drawing over the previous
Expand Down
4 changes: 2 additions & 2 deletions src/common/InputHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2360,12 +2360,12 @@ export class InputHandler extends Disposable implements IInputHandler {
* | 1 | Bold. (also see `options.drawBoldTextInBrightColors`) | #Y |
* | 2 | Faint, decreased intensity. | #Y |
* | 3 | Italic. | #Y |
* | 4 | Underlined (see below for style support). | #P[Support in DOM and Canvas renderers, not WebGL] |
* | 4 | Underlined (see below for style support). | #Y |
* | 5 | Slowly blinking. | #N |
* | 6 | Rapidly blinking. | #N |
* | 7 | Inverse. Flips foreground and background color. | #Y |
* | 8 | Invisible (hidden). | #Y |
* | 9 | Crossed-out characters (strikethrough). | #P[Support in DOM and Canvas renderers, not WebGL] |
* | 9 | Crossed-out characters (strikethrough). | #Y |
* | 21 | Doubly underlined. | #P[Currently outputs a single underline.] |
* | 22 | Normal (neither bold nor faint). | #Y |
* | 23 | No italic. | #Y |
Expand Down