Bring underlines closer to characters
This commit is contained in:
@@ -439,7 +439,9 @@ export class WebglCharAtlas implements IDisposable {
|
|||||||
if (underline) {
|
if (underline) {
|
||||||
this._tmpCtx.save();
|
this._tmpCtx.save();
|
||||||
const lineWidth = Math.max(1, Math.floor(this._config.fontSize * window.devicePixelRatio / 15));
|
const lineWidth = Math.max(1, Math.floor(this._config.fontSize * window.devicePixelRatio / 15));
|
||||||
const yOffset = lineWidth % 2 === 1 ? 0.5 : 0; // When the width is odd, draw at 0.5 position
|
// When the width is odd, draw at 0.5 position. Offset by an additional 1 dpr to bring the
|
||||||
|
// underline closer to the character
|
||||||
|
const yOffset = (lineWidth % 2 === 1 ? 0.5 : 0) + window.devicePixelRatio;
|
||||||
this._tmpCtx.lineWidth = lineWidth;
|
this._tmpCtx.lineWidth = lineWidth;
|
||||||
|
|
||||||
// Underline color
|
// Underline color
|
||||||
@@ -508,18 +510,18 @@ export class WebglCharAtlas implements IDisposable {
|
|||||||
break;
|
break;
|
||||||
case UnderlineStyle.DOTTED:
|
case UnderlineStyle.DOTTED:
|
||||||
this._tmpCtx.setLineDash([window.devicePixelRatio * 2, window.devicePixelRatio]);
|
this._tmpCtx.setLineDash([window.devicePixelRatio * 2, window.devicePixelRatio]);
|
||||||
this._tmpCtx.moveTo(xLeft, yMid);
|
this._tmpCtx.moveTo(xLeft, yTop);
|
||||||
this._tmpCtx.lineTo(xRight, yMid);
|
this._tmpCtx.lineTo(xRight, yTop);
|
||||||
break;
|
break;
|
||||||
case UnderlineStyle.DASHED:
|
case UnderlineStyle.DASHED:
|
||||||
this._tmpCtx.setLineDash([window.devicePixelRatio * 4, window.devicePixelRatio * 3]);
|
this._tmpCtx.setLineDash([window.devicePixelRatio * 4, window.devicePixelRatio * 3]);
|
||||||
this._tmpCtx.moveTo(xLeft, yMid);
|
this._tmpCtx.moveTo(xLeft, yTop);
|
||||||
this._tmpCtx.lineTo(xRight, yMid);
|
this._tmpCtx.lineTo(xRight, yTop);
|
||||||
break;
|
break;
|
||||||
case UnderlineStyle.SINGLE:
|
case UnderlineStyle.SINGLE:
|
||||||
default:
|
default:
|
||||||
this._tmpCtx.moveTo(xLeft, yMid);
|
this._tmpCtx.moveTo(xLeft, yTop);
|
||||||
this._tmpCtx.lineTo(xRight, yMid);
|
this._tmpCtx.lineTo(xRight, yTop);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this._tmpCtx.stroke();
|
this._tmpCtx.stroke();
|
||||||
|
|||||||
Reference in New Issue
Block a user