Implement lineHeight px format support
Co-authored-by: Tyriar <2193314+Tyriar@users.noreply.github.com>
This commit is contained in:
co-authored by
Tyriar
parent
0dffbedf76
commit
b3503f4916
@@ -10,6 +10,15 @@ import { IColorSet, ReadonlyColorSet } from 'browser/Types';
|
||||
import { NULL_COLOR } from 'common/Color';
|
||||
|
||||
export function generateConfig(deviceCellWidth: number, deviceCellHeight: number, deviceCharWidth: number, deviceCharHeight: number, options: Required<ITerminalOptions>, colors: ReadonlyColorSet, devicePixelRatio: number, deviceMaxTextureSize: number): ICharAtlasConfig {
|
||||
// Convert lineHeight to a numeric multiplier for the char atlas
|
||||
// If it's a px value, calculate the equivalent multiplier
|
||||
let lineHeightMultiplier: number = typeof options.lineHeight === 'number' ? options.lineHeight : 1;
|
||||
if (typeof options.lineHeight === 'string' && options.lineHeight.endsWith('px')) {
|
||||
const pxValue = parseFloat(options.lineHeight.slice(0, -2));
|
||||
// Calculate the multiplier based on font size
|
||||
lineHeightMultiplier = pxValue / options.fontSize;
|
||||
}
|
||||
|
||||
// null out some fields that don't matter
|
||||
const clonedColors: IColorSet = {
|
||||
foreground: colors.foreground,
|
||||
@@ -36,7 +45,7 @@ export function generateConfig(deviceCellWidth: number, deviceCellHeight: number
|
||||
devicePixelRatio,
|
||||
deviceMaxTextureSize,
|
||||
letterSpacing: options.letterSpacing,
|
||||
lineHeight: options.lineHeight,
|
||||
lineHeight: lineHeightMultiplier,
|
||||
deviceCellWidth: deviceCellWidth,
|
||||
deviceCellHeight: deviceCellHeight,
|
||||
deviceCharWidth: deviceCharWidth,
|
||||
|
||||
@@ -27,6 +27,19 @@ import { addDisposableListener } from 'vs/base/browser/dom';
|
||||
import { combinedDisposable, Disposable, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
|
||||
import { createRenderDimensions } from 'browser/renderer/shared/RendererUtils';
|
||||
|
||||
/**
|
||||
* Calculates the line height in pixels based on the lineHeight option and character height.
|
||||
*/
|
||||
function calculateLineHeightInPixels(lineHeight: number | string, charHeight: number): number {
|
||||
if (typeof lineHeight === 'string' && lineHeight.endsWith('px')) {
|
||||
const pxValue = parseFloat(lineHeight.slice(0, -2));
|
||||
// Ensure the pixel value is at least as large as the character height
|
||||
return Math.max(pxValue, charHeight);
|
||||
}
|
||||
// Numeric lineHeight acts as a multiplier
|
||||
return Math.floor(charHeight * (lineHeight as number));
|
||||
}
|
||||
|
||||
export class WebglRenderer extends Disposable implements IRenderer {
|
||||
private _renderLayers: IRenderLayer[];
|
||||
private _cursorBlinkStateManager: MutableDisposable<CursorBlinkStateManager> = new MutableDisposable();
|
||||
@@ -570,14 +583,14 @@ export class WebglRenderer extends Disposable implements IRenderer {
|
||||
// cell.
|
||||
this.dimensions.device.char.height = Math.ceil(this._charSizeService.height * this._devicePixelRatio);
|
||||
|
||||
// Calculate the device cell height, if lineHeight is _not_ 1, the resulting value will be
|
||||
// floored since lineHeight can never be lower then 1, this guarentees the device cell height
|
||||
// will always be larger than device char height.
|
||||
this.dimensions.device.cell.height = Math.floor(this.dimensions.device.char.height * this._optionsService.rawOptions.lineHeight);
|
||||
// Calculate the device cell height, supporting both numeric multipliers and 'px' values
|
||||
this.dimensions.device.cell.height = calculateLineHeightInPixels(this._optionsService.rawOptions.lineHeight, this.dimensions.device.char.height);
|
||||
|
||||
// Calculate the y offset within a cell that glyph should draw at in order for it to be centered
|
||||
// correctly within the cell.
|
||||
this.dimensions.device.char.top = this._optionsService.rawOptions.lineHeight === 1 ? 0 : Math.round((this.dimensions.device.cell.height - this.dimensions.device.char.height) / 2);
|
||||
const isDefaultLineHeight = (typeof this._optionsService.rawOptions.lineHeight === 'number' && this._optionsService.rawOptions.lineHeight === 1) ||
|
||||
(typeof this._optionsService.rawOptions.lineHeight === 'string' && this.dimensions.device.cell.height === this.dimensions.device.char.height);
|
||||
this.dimensions.device.char.top = isDefaultLineHeight ? 0 : Math.round((this.dimensions.device.cell.height - this.dimensions.device.char.height) / 2);
|
||||
|
||||
// Calculate the device cell width, taking the letterSpacing into account.
|
||||
this.dimensions.device.cell.width = this.dimensions.device.char.width + Math.round(this._optionsService.rawOptions.letterSpacing);
|
||||
|
||||
Reference in New Issue
Block a user