提交 fd5dd523 编写于 作者: A Alexandru Dima 提交者: GitHub

Merge pull request #10515 from ramamurthynagaraj/master

Added editor.fontWeight and terminal.integrated.fontWeight configuration
......@@ -17,6 +17,7 @@ export abstract class FastDomNode {
private _bottom: number;
private _right: number;
private _fontFamily: string;
private _fontWeight: string;
private _fontSize: number;
private _lineHeight: number;
private _className: string;
......@@ -40,6 +41,7 @@ export abstract class FastDomNode {
this._bottom = -1;
this._right = -1;
this._fontFamily = '';
this._fontWeight = '';
this._fontSize = -1;
this._lineHeight = -1;
this._className = '';
......@@ -114,6 +116,14 @@ export abstract class FastDomNode {
this._domNode.style.fontFamily = this._fontFamily;
}
public setFontWeight(fontWeight: string): void {
if (this._fontWeight === fontWeight) {
return;
}
this._fontWeight = fontWeight;
this._domNode.style.fontWeight = this._fontWeight;
}
public setFontSize(fontSize: number): void {
if (this._fontSize === fontSize) {
return;
......
......@@ -209,6 +209,7 @@ class CSSBasedConfiguration extends Disposable {
return new FontInfo({
fontFamily: bareFontInfo.fontFamily,
fontWeight: bareFontInfo.fontWeight,
fontSize: bareFontInfo.fontSize,
lineHeight: bareFontInfo.lineHeight,
typicalHalfwidthCharacterWidth: typicalHalfwidthCharacter.width,
......@@ -223,12 +224,14 @@ export class Configuration extends CommonEditorConfiguration {
public static applyFontInfoSlow(domNode: HTMLElement, fontInfo: BareFontInfo): void {
domNode.style.fontFamily = fontInfo.fontFamily;
domNode.style.fontWeight = fontInfo.fontWeight;
domNode.style.fontSize = fontInfo.fontSize + 'px';
domNode.style.lineHeight = fontInfo.lineHeight + 'px';
}
public static applyFontInfo(domNode: FastDomNode, fontInfo: BareFontInfo): void {
domNode.setFontFamily(fontInfo.fontFamily);
domNode.setFontWeight(fontInfo.fontWeight);
domNode.setFontSize(fontInfo.fontSize);
domNode.setLineHeight(fontInfo.lineHeight);
}
......
......@@ -466,6 +466,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
let editorClassName = this._getEditorClassName(opts.theme, toBoolean(opts.fontLigatures));
let fontFamily = String(opts.fontFamily) || DefaultConfig.editor.fontFamily;
let fontWeight = String(opts.fontWeight) || DefaultConfig.editor.fontWeight;
let fontSize = toFloat(opts.fontSize, DefaultConfig.editor.fontSize);
fontSize = Math.max(0, fontSize);
fontSize = Math.min(100, fontSize);
......@@ -490,6 +491,7 @@ export abstract class CommonEditorConfiguration extends Disposable implements ed
opts,
this.readConfiguration(new editorCommon.BareFontInfo({
fontFamily: fontFamily,
fontWeight: fontWeight,
fontSize: fontSize,
lineHeight: lineHeight
})),
......@@ -580,6 +582,11 @@ let editorConfiguration:IConfigurationNode = {
'default': DefaultConfig.editor.fontFamily,
'description': nls.localize('fontFamily', "Controls the font family.")
},
'editor.fontWeight' : {
'type': 'string',
'default': DefaultConfig.editor.fontWeight,
'description': nls.localize('fontWeight', "Controls the font weight.")
},
'editor.fontSize' : {
'type': 'number',
'default': DefaultConfig.editor.fontSize,
......
......@@ -98,6 +98,7 @@ class ConfigClass implements IConfiguration {
fontFamily: (
platform.isMacintosh ? DEFAULT_MAC_FONT_FAMILY : (platform.isLinux ? DEFAULT_LINUX_FONT_FAMILY : DEFAULT_WINDOWS_FONT_FAMILY)
),
fontWeight: 'normal',
fontSize: (
platform.isMacintosh ? 12 : 14
),
......
......@@ -445,6 +445,10 @@ export interface IEditorOptions {
* The font family
*/
fontFamily?: string;
/**
* The font weight
*/
fontWeight?: 'normal'|'bold'|'bolder'|'lighter'|'initial'|'inherit'|'100'|'200'|'300'|'400'|'500'|'600'|'700'|'800'|'900';
/**
* The font size
*/
......@@ -3140,6 +3144,7 @@ export class BareFontInfo {
_bareFontInfoBrand: void;
fontFamily: string;
fontWeight: string;
fontSize: number;
lineHeight: number;
......@@ -3148,10 +3153,12 @@ export class BareFontInfo {
*/
constructor(opts: {
fontFamily: string;
fontWeight: string;
fontSize: number;
lineHeight: number;
}) {
this.fontFamily = String(opts.fontFamily);
this.fontWeight = String(opts.fontWeight);
this.fontSize = opts.fontSize;
this.lineHeight = opts.lineHeight|0;
}
......@@ -3160,7 +3167,7 @@ export class BareFontInfo {
* @internal
*/
public getId(): string {
return this.fontFamily + '-' + this.fontSize + '-' + this.lineHeight;
return this.fontFamily + '-' + this.fontWeight + '-' + this.fontSize + '-' + this.lineHeight + '-';
}
}
......@@ -3177,6 +3184,7 @@ export class FontInfo extends BareFontInfo {
*/
constructor(opts:{
fontFamily: string;
fontWeight: string;
fontSize: number;
lineHeight: number;
typicalHalfwidthCharacterWidth:number;
......@@ -3197,6 +3205,7 @@ export class FontInfo extends BareFontInfo {
public equals(other:FontInfo): boolean {
return (
this.fontFamily === other.fontFamily
&& this.fontWeight === other.fontWeight
&& this.fontSize === other.fontSize
&& this.lineHeight === other.lineHeight
&& this.typicalHalfwidthCharacterWidth === other.typicalHalfwidthCharacterWidth
......
......@@ -69,6 +69,7 @@ export default class RenameInputField implements IContentWidget, IDisposable {
const fontInfo = this._editor.getConfiguration().fontInfo;
this._inputField.style.fontFamily = fontInfo.fontFamily;
this._inputField.style.fontWeight = fontInfo.fontWeight;
this._inputField.style.fontSize = `${ fontInfo.fontSize }px`;
}
......
......@@ -32,6 +32,7 @@ export class MockConfiguration extends CommonEditorConfiguration {
protected readConfiguration(styling: BareFontInfo): FontInfo {
return new FontInfo({
fontFamily: 'mockFont',
fontWeight: 'normal',
fontSize: 14,
lineHeight: 19,
typicalHalfwidthCharacterWidth:10,
......
......@@ -1294,6 +1294,10 @@ declare module monaco.editor {
* The font family
*/
fontFamily?: string;
/**
* The font weight
*/
fontWeight?: 'normal' | 'bold' | 'bolder' | 'lighter' | 'initial' | 'inherit' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
/**
* The font size
*/
......@@ -2710,6 +2714,7 @@ declare module monaco.editor {
export class BareFontInfo {
_bareFontInfoBrand: void;
fontFamily: string;
fontWeight: string;
fontSize: number;
lineHeight: number;
}
......
......@@ -134,19 +134,21 @@ export default class Webview {
}
style(themeId: string): void {
const {color, backgroundColor, fontFamily, fontSize} = window.getComputedStyle(this._styleElement);
const {color, backgroundColor, fontFamily, fontWeight, fontSize} = window.getComputedStyle(this._styleElement);
let value = `
:root {
--background-color: ${backgroundColor};
--color: ${color};
--font-family: ${fontFamily};
--font-weight: ${fontWeight};
--font-size: ${fontSize};
}
body {
background-color: var(--background-color);
color: var(--color);
font-family: var(--font-family);
font-weight: var(--font-weight);
font-size: var(--font-size);
margin: 0;
}
......
......@@ -64,6 +64,10 @@ configurationRegistry.registerConfiguration({
'description': nls.localize('terminal.integrated.fontFamily', "Controls the font family of the terminal, this defaults to editor.fontFamily's value."),
'type': 'string'
},
'terminal.integrated.fontWeight': {
'description': nls.localize('terminal.integrated.fontWeight', "Controls the font weight of the terminal, this defaults to editor.fontWeight's value."),
'type': 'string'
},
'terminal.integrated.fontLigatures': {
'description': nls.localize('terminal.integrated.fontLigatures', "Controls whether font ligatures are enabled in the terminal."),
'type': 'boolean',
......
......@@ -43,6 +43,7 @@ export interface ITerminalConfiguration {
},
cursorBlinking: boolean,
fontFamily: string,
fontWeight: string,
fontLigatures: boolean,
fontSize: number,
lineHeight: number,
......
......@@ -71,6 +71,7 @@ const DEFAULT_ANSI_COLORS = {
export interface ITerminalFont {
fontFamily: string;
fontWeight: string;
fontSize: string;
lineHeight: number;
charWidth: number;
......@@ -99,7 +100,7 @@ export class TerminalConfigHelper {
return DEFAULT_ANSI_COLORS[baseThemeId];
}
private measureFont(fontFamily: string, fontSize: number, lineHeight: number): ITerminalFont {
private measureFont(fontFamily: string, fontWeight: string,fontSize: number, lineHeight: number): ITerminalFont {
// Create charMeasureElement if it hasn't been created or if it was orphaned by its parent
if (!this.charMeasureElement || !this.charMeasureElement.parentElement) {
this.charMeasureElement = this.panelContainer.div().getHTMLElement();
......@@ -107,6 +108,7 @@ export class TerminalConfigHelper {
let style = this.charMeasureElement.style;
style.display = 'block';
style.fontFamily = fontFamily;
style.fontWeight = fontWeight;
style.fontSize = fontSize + 'px';
style.height = Math.floor(lineHeight * fontSize) + 'px';
this.charMeasureElement.innerText = 'X';
......@@ -116,6 +118,7 @@ export class TerminalConfigHelper {
let charHeight = Math.ceil(rect.height);
return {
fontFamily,
fontWeight,
fontSize: fontSize + 'px',
lineHeight,
charWidth,
......@@ -124,7 +127,7 @@ export class TerminalConfigHelper {
}
/**
* Gets the font information based on the terminal.integrated.fontFamily,
* Gets the font information based on the terminal.integrated.fontFamily, terminal.integrated.fontWeight
* terminal.integrated.fontSize, terminal.integrated.lineHeight configuration properties
*/
public getFont(): ITerminalFont {
......@@ -132,13 +135,14 @@ export class TerminalConfigHelper {
let editorConfig = this.configurationService.getConfiguration<IConfiguration>();
let fontFamily = terminalConfig.fontFamily || editorConfig.editor.fontFamily;
let fontWeight = terminalConfig.fontWeight || editorConfig.editor.fontWeight;
let fontSize = this.toInteger(terminalConfig.fontSize, 0) || editorConfig.editor.fontSize;
if (fontSize <= 0) {
fontSize = DefaultConfig.editor.fontSize;
}
let lineHeight = this.toInteger(terminalConfig.lineHeight, DEFAULT_LINE_HEIGHT);
return this.measureFont(fontFamily, fontSize, lineHeight <= 0 ? DEFAULT_LINE_HEIGHT : lineHeight);
return this.measureFont(fontFamily, fontWeight, fontSize, lineHeight <= 0 ? DEFAULT_LINE_HEIGHT : lineHeight);
}
public getFontLigaturesEnabled(): boolean {
......
......@@ -309,6 +309,7 @@ export class TerminalPanel extends Panel {
if (!this.font || this.fontsDiffer(this.font, newFont)) {
this.fontStyleElement.innerHTML = '.monaco-workbench .panel.integrated-terminal .xterm {' +
`font-family: ${newFont.fontFamily};` +
`font-weight: ${newFont.fontWeight};` +
`font-size: ${newFont.fontSize};` +
`line-height: ${newFont.lineHeight};` +
'}';
......@@ -322,6 +323,7 @@ export class TerminalPanel extends Panel {
return a.charHeight !== b.charHeight ||
a.charWidth !== b.charWidth ||
a.fontFamily !== b.fontFamily ||
a.fontWeight !== b.fontWeight ||
a.fontSize !== b.fontSize ||
a.lineHeight !== b.lineHeight;
}
......
......@@ -62,6 +62,40 @@ suite('Workbench - TerminalConfigHelper', () => {
assert.equal(configHelper.getFont().fontFamily, 'foo', 'editor.fontFamily should be the fallback when terminal.integrated.fontFamily not set');
});
test('TerminalConfigHelper - getFont fontWeight', function () {
let configurationService: IConfigurationService;
let configHelper: TerminalConfigHelper;
configurationService = new MockConfigurationService({
editor: {
fontFamily: 'foo',
fontWeight: 'lighter'
},
terminal: {
integrated: {
fontFamily: 'bar',
fontWeight: 'bold'
}
}
});
configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
assert.equal(configHelper.getFont().fontWeight, 'bold', 'terminal.integrated.fontWeight should be selected over editor.fontWeight');
configurationService = new MockConfigurationService({
editor: {
fontFamily: 'foo',
fontWeight: 'lighter'
},
terminal: {
integrated: {
fontFamily: 0
}
}
});
configHelper = new TerminalConfigHelper(Platform.Linux, configurationService, fixture);
assert.equal(configHelper.getFont().fontWeight, 'lighter', 'editor.fontWeight should be the fallback when terminal.integrated.fontWeight not set');
});
test('TerminalConfigHelper - getFont fontSize', function () {
let configurationService: IConfigurationService;
let configHelper: TerminalConfigHelper;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册