Webgl underline color rendering

This commit is contained in:
Daniel Imms
2022-07-23 11:19:35 -07:00
parent 03f15a7fb7
commit d9703aa7fe
@@ -414,63 +414,80 @@ export class WebglCharAtlas implements IDisposable {
} }
} }
// Draw underline and strikethrough // Draw underline
if (underline || strikethrough) { if (strikethrough) {
const lineWidth = Math.max(1, Math.floor(this._config.fontSize * window.devicePixelRatio / 10)); const lineWidth = Math.max(1, Math.floor(this._config.fontSize * window.devicePixelRatio / 10));
const yOffset = this._tmpCtx.lineWidth % 2 === 1 ? 0.5 : 0; // When the width is odd, draw at 0.5 position 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.lineWidth = lineWidth;
this._tmpCtx.strokeStyle = this._tmpCtx.fillStyle; this._tmpCtx.strokeStyle = this._tmpCtx.fillStyle;
this._tmpCtx.beginPath(); this._tmpCtx.beginPath();
if (underline) { this._tmpCtx.moveTo(padding, padding + Math.floor(this._config.scaledCharHeight / 2) - yOffset);
console.log('ext', ext, this._workAttributeData.extended.underlineColor, this._workAttributeData.extended.underlineStyle); this._tmpCtx.lineTo(padding + this._config.scaledCharWidth, padding + Math.floor(this._config.scaledCharHeight / 2) - yOffset);
const xLeft = padding; this._tmpCtx.stroke();
const xRight = padding + this._config.scaledCharWidth; }
const yMid = padding + this._config.scaledCharHeight - yOffset;
switch (this._workAttributeData.extended.underlineStyle) { // Draw underline
case UnderlineStyle.DOUBLE: if (underline) {
const yBot = Math.ceil(padding + this._config.scaledCharHeight + lineWidth) - yOffset; const lineWidth = Math.max(1, Math.floor(this._config.fontSize * window.devicePixelRatio / 10));
const yTop = Math.ceil(padding + this._config.scaledCharHeight - lineWidth) - yOffset; const yOffset = this._tmpCtx.lineWidth % 2 === 1 ? 0.5 : 0; // When the width is odd, draw at 0.5 position
this._tmpCtx.moveTo(xLeft, yTop); this._tmpCtx.lineWidth = lineWidth;
this._tmpCtx.lineTo(xRight, yTop); // Underline color
this._tmpCtx.moveTo(xLeft, yBot); if (this._workAttributeData.isUnderlineColorDefault()) {
this._tmpCtx.lineTo(xRight, yBot); this._tmpCtx.strokeStyle = this._tmpCtx.fillStyle;
break; } else if (this._workAttributeData.isUnderlineColorRGB()) {
case UnderlineStyle.CURLY: this._tmpCtx.strokeStyle = `rgb(${AttributeData.toColorRGB(this._workAttributeData.getUnderlineColor()).join(',')})`;
const xMid = padding + this._config.scaledCharWidth / 2; } else {
const yMidBot = Math.ceil(padding + this._config.scaledCharHeight - lineWidth / 2) - yOffset; let fg = this._workAttributeData.getUnderlineColor();
const yMidTop = Math.ceil(padding + this._config.scaledCharHeight + lineWidth / 2) - yOffset; if (this._config.drawBoldTextInBrightColors && this._workAttributeData.isBold() && fg < 8) {
this._tmpCtx.moveTo(xLeft, yMid); fg += 8;
this._tmpCtx.bezierCurveTo(
xLeft, yMidBot,
xMid, yMidBot,
xMid, yMid
);
this._tmpCtx.bezierCurveTo(
xMid, yMidTop,
xRight, yMidTop,
xRight, yMid
);
break;
case UnderlineStyle.DOTTED:
this._tmpCtx.setLineDash([window.devicePixelRatio * 2, window.devicePixelRatio]);
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.lineTo(xRight, yMid);
break;
case UnderlineStyle.DASHED:
this._tmpCtx.setLineDash([window.devicePixelRatio * 4, window.devicePixelRatio * 3]);
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.lineTo(xRight, yMid);
break;
case UnderlineStyle.SINGLE:
default:
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.lineTo(xRight, yMid);
break;
} }
this._tmpCtx.strokeStyle = this._getColorFromAnsiIndex(fg).css;
} }
if (strikethrough) { // Underline style/stroke
this._tmpCtx.moveTo(padding, padding + Math.floor(this._config.scaledCharHeight / 2) - yOffset); this._tmpCtx.beginPath();
this._tmpCtx.lineTo(padding + this._config.scaledCharWidth, padding + Math.floor(this._config.scaledCharHeight / 2) - yOffset); const xLeft = padding;
const xRight = padding + this._config.scaledCharWidth;
const yMid = padding + this._config.scaledCharHeight - yOffset;
switch (this._workAttributeData.extended.underlineStyle) {
case UnderlineStyle.DOUBLE:
const yBot = Math.ceil(padding + this._config.scaledCharHeight + lineWidth) - yOffset;
const yTop = Math.ceil(padding + this._config.scaledCharHeight - lineWidth) - yOffset;
this._tmpCtx.moveTo(xLeft, yTop);
this._tmpCtx.lineTo(xRight, yTop);
this._tmpCtx.moveTo(xLeft, yBot);
this._tmpCtx.lineTo(xRight, yBot);
break;
case UnderlineStyle.CURLY:
const xMid = padding + this._config.scaledCharWidth / 2;
const yMidBot = Math.ceil(padding + this._config.scaledCharHeight - lineWidth / 2) - yOffset;
const yMidTop = Math.ceil(padding + this._config.scaledCharHeight + lineWidth / 2) - yOffset;
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.bezierCurveTo(
xLeft, yMidBot,
xMid, yMidBot,
xMid, yMid
);
this._tmpCtx.bezierCurveTo(
xMid, yMidTop,
xRight, yMidTop,
xRight, yMid
);
break;
case UnderlineStyle.DOTTED:
this._tmpCtx.setLineDash([window.devicePixelRatio * 2, window.devicePixelRatio]);
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.lineTo(xRight, yMid);
break;
case UnderlineStyle.DASHED:
this._tmpCtx.setLineDash([window.devicePixelRatio * 4, window.devicePixelRatio * 3]);
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.lineTo(xRight, yMid);
break;
case UnderlineStyle.SINGLE:
default:
this._tmpCtx.moveTo(xLeft, yMid);
this._tmpCtx.lineTo(xRight, yMid);
break;
} }
this._tmpCtx.stroke(); this._tmpCtx.stroke();
} }