Skip to content

Commit c0ef2cc

Browse files
authored
Merge pull request #4053 from Tyriar/underline_polish
Polish underline for more fonts to prevent odd overlap look
2 parents 7e6282e + 0698afa commit c0ef2cc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

addons/xterm-addon-webgl/src/atlas/WebglCharAtlas.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,8 @@ export class WebglCharAtlas implements IDisposable {
439439
if (underline) {
440440
this._tmpCtx.save();
441441
const lineWidth = Math.max(1, Math.floor(this._config.fontSize * window.devicePixelRatio / 15));
442-
// When the width is odd, draw at 0.5 position. Offset by an additional 1 dpr to bring the
443-
// underline closer to the character
444-
const yOffset = (lineWidth % 2 === 1 ? 0.5 : 0) + window.devicePixelRatio;
442+
// When the line width is odd, draw at a 0.5 position
443+
const yOffset = lineWidth % 2 === 1 ? 0.5 : 0;
445444
this._tmpCtx.lineWidth = lineWidth;
446445

447446
// Underline color
@@ -463,9 +462,9 @@ export class WebglCharAtlas implements IDisposable {
463462
this._tmpCtx.beginPath();
464463
const xLeft = padding;
465464
const xRight = padding + this._config.scaledCellWidth;
466-
const yTop = Math.ceil(padding + this._config.scaledCharHeight - lineWidth) - yOffset;
467-
const yMid = padding + this._config.scaledCharHeight - yOffset;
468-
const yBot = Math.ceil(padding + this._config.scaledCharHeight + lineWidth) - yOffset;
465+
const yTop = Math.ceil(padding + this._config.scaledCharHeight) - yOffset;
466+
const yMid = padding + this._config.scaledCharHeight + lineWidth - yOffset;
467+
const yBot = Math.ceil(padding + this._config.scaledCharHeight + lineWidth * 2) - yOffset;
469468
switch (this._workAttributeData.extended.underlineStyle) {
470469
case UnderlineStyle.DOUBLE:
471470
this._tmpCtx.moveTo(xLeft, yTop);
@@ -528,8 +527,9 @@ export class WebglCharAtlas implements IDisposable {
528527
this._tmpCtx.restore();
529528

530529
// Draw stroke in the background color for non custom characters in order to give an outline
531-
// between the text and the underline
532-
if (!customGlyph) {
530+
// between the text and the underline. Only do this when font size is >= 12 as the underline
531+
// looks odd when the font size is too small
532+
if (!customGlyph && this._config.fontSize >= 12) {
533533
// This only works when transparency is disabled because it's not clear how to clear stroked
534534
// text
535535
if (!this._config.allowTransparency && chars !== ' ') {

0 commit comments

Comments
 (0)